|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
|
|
import 'package:http/http.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/api/api_client.dart';
|
|
|
|
@ -46,13 +47,30 @@ class ChatApiClient {
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Future<ChatUserModel> getRecentChats() async {
|
|
|
|
|
Response response = await ApiClient().getJsonForResponse(
|
|
|
|
|
"${ApiConsts.chatRecentUrl}getchathistorybyuserid",
|
|
|
|
|
token: AppState().chatDetails!.response!.token,
|
|
|
|
|
);
|
|
|
|
|
return ChatUserModel.fromJson(
|
|
|
|
|
json.decode(response.body),
|
|
|
|
|
);
|
|
|
|
|
try {
|
|
|
|
|
Response response = await ApiClient().getJsonForResponse(
|
|
|
|
|
"${ApiConsts.chatRecentUrl}getchathistorybyuserid",
|
|
|
|
|
token: AppState().chatDetails!.response!.token,
|
|
|
|
|
);
|
|
|
|
|
return ChatUserModel.fromJson(
|
|
|
|
|
json.decode(response.body),
|
|
|
|
|
);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
e as APIException;
|
|
|
|
|
if (e.message == "api_common_unauthorized") {
|
|
|
|
|
logger.d("Token Generated On APIIIIII");
|
|
|
|
|
user.UserAutoLoginModel userLoginResponse = await ChatApiClient().getUserLoginToken();
|
|
|
|
|
if (userLoginResponse.response != null) {
|
|
|
|
|
AppState().setchatUserDetails = userLoginResponse;
|
|
|
|
|
getRecentChats();
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast(
|
|
|
|
|
userLoginResponse.errorResponses!.first.fieldName.toString() + " Erorr",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<ChatUserModel> getFavUsers() async {
|
|
|
|
@ -66,11 +84,27 @@ class ChatApiClient {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<Response> getSingleUserChatHistory({required int senderUID, required int receiverUID, required bool loadMore, bool isNewChat = false, required int paginationVal}) async {
|
|
|
|
|
Response response = await ApiClient().getJsonForResponse(
|
|
|
|
|
"${ApiConsts.chatSingleUserHistoryUrl}GetUserChatHistory/$senderUID/$receiverUID/$paginationVal",
|
|
|
|
|
token: AppState().chatDetails!.response!.token,
|
|
|
|
|
);
|
|
|
|
|
return response;
|
|
|
|
|
try {
|
|
|
|
|
Response response = await ApiClient().getJsonForResponse(
|
|
|
|
|
"${ApiConsts.chatSingleUserHistoryUrl}GetUserChatHistory/$senderUID/$receiverUID/$paginationVal",
|
|
|
|
|
token: AppState().chatDetails!.response!.token,
|
|
|
|
|
);
|
|
|
|
|
return response;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
e as APIException;
|
|
|
|
|
if (e.message == "api_common_unauthorized") {
|
|
|
|
|
user.UserAutoLoginModel userLoginResponse = await ChatApiClient().getUserLoginToken();
|
|
|
|
|
if (userLoginResponse.response != null) {
|
|
|
|
|
AppState().setchatUserDetails = userLoginResponse;
|
|
|
|
|
getSingleUserChatHistory(senderUID: senderUID, receiverUID: receiverUID, loadMore: loadMore, paginationVal: paginationVal);
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast(
|
|
|
|
|
userLoginResponse.errorResponses!.first.fieldName.toString() + " Erorr",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<fav.FavoriteChatUser> favUser({required int userID, required int targetUserID}) async {
|
|
|
|
@ -120,4 +154,29 @@ class ChatApiClient {
|
|
|
|
|
StreamedResponse response = await request.send();
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Download File For Chat
|
|
|
|
|
|
|
|
|
|
Future<Uint8List> downloadURL({required String fileName, required String fileTypeDescription}) async {
|
|
|
|
|
Response response = await ApiClient().postJsonForResponse(
|
|
|
|
|
"${ApiConsts.chatMediaImageUploadUrl}download",
|
|
|
|
|
{"fileType": fileTypeDescription, "fileName": fileName, "fileSource": 1},
|
|
|
|
|
token: AppState().chatDetails!.response!.token,
|
|
|
|
|
);
|
|
|
|
|
Uint8List data = Uint8List.fromList(response.bodyBytes);
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future getUsersImages({required List encryptedEmails}) async {
|
|
|
|
|
Response response = await ApiClient().postJsonForResponse(
|
|
|
|
|
"${ApiConsts.chatUserImages}images",
|
|
|
|
|
{
|
|
|
|
|
"encryptedEmails": ["/g8Rc+s6eEOdci41PwJuV5dX+gXe51G9OTHzb9ahcVlHCmVvNhxReirudF79+hdxVSkCnQ6wC5DBFV8xnJlC74X6157PxF7mNYrAYuHRgp4="],
|
|
|
|
|
"fromClient": true
|
|
|
|
|
},
|
|
|
|
|
token: AppState().chatDetails!.response!.token,
|
|
|
|
|
);
|
|
|
|
|
logger.d(response.body);
|
|
|
|
|
// Uint8List data = Uint8List.fromList(response.body);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|