Voip Call

development_aamir
Aamir Muhammad 2 years ago
parent f8ba1957cd
commit 33fb6fe6be

@ -1,9 +1,7 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart'; import 'package:http/http.dart';
import 'package:mohem_flutter_app/api/api_client.dart'; import 'package:mohem_flutter_app/api/api_client.dart';
import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart';
@ -310,4 +308,59 @@ class ChatApiClient {
throw e; throw e;
} }
} }
// CallUser Login Token
Future<user.UserAutoLoginModel> getUserCallToken({required String userid}) async {
user.UserAutoLoginModel userLoginResponse = user.UserAutoLoginModel();
Response response = await ApiClient().postJsonForResponse(
"${ApiConsts.chatLoginTokenUrl}externaluserlogin",
{
"employeeNumber": userid,
"password": "FxIu26rWIKoF8n6mpbOmAjDLphzFGmpG",
},
);
if (!kReleaseMode) {
logger.i("login-res: " + response.body);
}
if (response.statusCode == 200) {
userLoginResponse = user.userAutoLoginModelFromJson(response.body);
} else if (response.statusCode == 501 || response.statusCode == 502 || response.statusCode == 503 || response.statusCode == 504) {
getUserCallToken(userid: userid);
} else {
userLoginResponse = user.userAutoLoginModelFromJson(response.body);
Utils.showToast(userLoginResponse.errorResponses!.first.message!);
}
return userLoginResponse;
}
// Call Decline On App Terminated State
Future<Response> callDecline({required int cUserID, required int tUserID, required String targetUsertoken}) async {
Response response = await ApiClient().postJsonForResponse(
"${ApiConsts.chatLoginTokenUrl}calldecline",
{"currentUserId": cUserID, "targetUserId": tUserID, "secretKey": "derichatmobileuser", "targetUserToken": targetUsertoken},
);
print("res: " + response.body);
if (!kReleaseMode) {
logger.i({"currentUserId": cUserID, "targetUserId": tUserID, "secretKey": "derichatmobileuser", "targetUserToken": targetUsertoken});
print("res: " + response.body);
}
return response;
}
Future<String> oneSignalVoip(String value) async {
String id = "";
Response response = await ApiClient().postJsonForResponse(
"${ApiConsts.oneSignalCall}players",
{"app_id": ApiConsts.oneSignalAppID, "identifier": value, "device_type": 0, "test_type": !kReleaseMode ? 1 : 0},
);
Map<String, dynamic> values = jsonDecode(response.body) as Map<String, dynamic>;
id = values["id"];
if (!kReleaseMode) {
print("res: " + response.body);
}
return id;
}
} }

@ -194,7 +194,6 @@ class AppState {
bool cancelRequestTrancsection = true; bool cancelRequestTrancsection = true;
String _iosVoipPlayerID = ""; String _iosVoipPlayerID = "";
String get iosVoipPlayerID => _iosVoipPlayerID; String get iosVoipPlayerID => _iosVoipPlayerID;

@ -1,11 +1,9 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:io';
import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_callkit_incoming/entities/entities.dart'; import 'package:flutter_callkit_incoming/entities/entities.dart';
import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart'; import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart';
import 'package:logger/logger.dart';
import 'package:mohem_flutter_app/api/chat/chat_api_client.dart'; import 'package:mohem_flutter_app/api/chat/chat_api_client.dart';
import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart';
import 'package:mohem_flutter_app/classes/consts.dart'; import 'package:mohem_flutter_app/classes/consts.dart';
@ -17,9 +15,6 @@ import 'package:mohem_flutter_app/models/chat/get_user_login_token_model.dart' a
import 'package:mohem_flutter_app/models/chat/incoming_call_model.dart'; import 'package:mohem_flutter_app/models/chat/incoming_call_model.dart';
import 'package:mohem_flutter_app/provider/chat_call_provider.dart'; import 'package:mohem_flutter_app/provider/chat_call_provider.dart';
import 'package:mohem_flutter_app/provider/chat_provider_model.dart'; import 'package:mohem_flutter_app/provider/chat_provider_model.dart';
import 'package:mohem_flutter_app/ui/landing/dashboard_screen.dart';
import 'package:path_provider/path_provider.dart';
import 'package:signalr_netcore/hub_connection.dart';
import 'package:signalr_netcore/signalr_client.dart'; import 'package:signalr_netcore/signalr_client.dart';
class ChatVoipCall { class ChatVoipCall {
@ -106,7 +101,7 @@ class ChatVoipCall {
} }
} }
Future<void> declineCall({ payload}) async { Future<void> declineCall({payload}) async {
IncomingCallModel data = IncomingCallModel.fromJson(jsonDecode(payload)); IncomingCallModel data = IncomingCallModel.fromJson(jsonDecode(payload));
if (isUserOnline) { if (isUserOnline) {
@ -154,10 +149,11 @@ class ChatVoipCall {
// logger.log(Level.error, "API-EVENT-END"); // logger.log(Level.error, "API-EVENT-END");
} }
Future<void> voipDeclineCall(IosCallPayload? _iosCallPayload ) async { Future<void> voipDeclineCall(IosCallPayload? _iosCallPayload) async {
try { try {
ALM.UserAutoLoginModel model = await ChatApiClient().getUserCallToken(userid: _iosCallPayload!.incomingCallReciverId.toString()); ALM.UserAutoLoginModel model = await ChatApiClient().getUserCallToken(userid: _iosCallPayload!.incomingCallReciverId.toString());
dynamic Res = await ChatApiClient().callDecline(cUserID: int.parse(_iosCallPayload!.incomingCallerId!), tUserID: int.parse(_iosCallPayload!.incomingCallReciverId.toString()), targetUsertoken: model.response!.token!); dynamic Res = await ChatApiClient()
.callDecline(cUserID: int.parse(_iosCallPayload!.incomingCallerId!), tUserID: int.parse(_iosCallPayload!.incomingCallReciverId.toString()), targetUsertoken: model.response!.token!);
} catch (err) { } catch (err) {
print(err); print(err);
} }
@ -177,4 +173,3 @@ class ChatVoipCall {
} }
} }
} }

@ -37,7 +37,6 @@ class ApiConsts {
static String oneSignalCall = "https://onesignal.com/api/v1/"; static String oneSignalCall = "https://onesignal.com/api/v1/";
static String oneSignalAppID = "472e4582-5c44-47ab-a5f5-9369b8967107"; static String oneSignalAppID = "472e4582-5c44-47ab-a5f5-9369b8967107";
//Brain Marathon Constants //Brain Marathon Constants
static String marathonBaseUrl = "https://marathoon.com/service/api/"; static String marathonBaseUrl = "https://marathoon.com/service/api/";
static String marathonBaseUrlServices = "https://marathoon.com/service/"; static String marathonBaseUrlServices = "https://marathoon.com/service/";

@ -10,6 +10,7 @@ import 'package:audio_session/audio_session_web.dart';
import 'package:file_picker/_internal/file_picker_web.dart'; import 'package:file_picker/_internal/file_picker_web.dart';
import 'package:firebase_core_web/firebase_core_web.dart'; import 'package:firebase_core_web/firebase_core_web.dart';
import 'package:firebase_messaging_web/firebase_messaging_web.dart'; import 'package:firebase_messaging_web/firebase_messaging_web.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'package:fluttertoast/fluttertoast_web.dart'; import 'package:fluttertoast/fluttertoast_web.dart';
import 'package:geolocator_web/geolocator_web.dart'; import 'package:geolocator_web/geolocator_web.dart';
import 'package:image_picker_for_web/image_picker_for_web.dart'; import 'package:image_picker_for_web/image_picker_for_web.dart';
@ -19,8 +20,6 @@ import 'package:shared_preferences_web/shared_preferences_web.dart';
import 'package:url_launcher_web/url_launcher_web.dart'; import 'package:url_launcher_web/url_launcher_web.dart';
import 'package:video_player_web/video_player_web.dart'; import 'package:video_player_web/video_player_web.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
// ignore: public_member_api_docs // ignore: public_member_api_docs
void registerPlugins(Registrar registrar) { void registerPlugins(Registrar registrar) {
AudioSessionWeb.registerWith(registrar); AudioSessionWeb.registerWith(registrar);

@ -20,7 +20,6 @@ import 'package:provider/single_child_widget.dart';
import 'package:signalr_netcore/hub_connection.dart'; import 'package:signalr_netcore/hub_connection.dart';
import 'package:sizer/sizer.dart'; import 'package:sizer/sizer.dart';
// test uat account // test uat account
// username 199067 // username 199067
// pass h123456 // pass h123456

@ -1,11 +1,12 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'dart:typed_data';
import 'package:audio_waveforms/audio_waveforms.dart'; import 'package:audio_waveforms/audio_waveforms.dart';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart' as Material;
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:http/http.dart'; import 'package:http/http.dart';
import 'package:just_audio/just_audio.dart' as JustAudio; import 'package:just_audio/just_audio.dart' as JustAudio;
@ -19,33 +20,24 @@ import 'package:mohem_flutter_app/classes/utils.dart';
import 'package:mohem_flutter_app/config/routes.dart'; import 'package:mohem_flutter_app/config/routes.dart';
import 'package:mohem_flutter_app/main.dart'; import 'package:mohem_flutter_app/main.dart';
import 'package:mohem_flutter_app/models/chat/chat_user_image_model.dart'; import 'package:mohem_flutter_app/models/chat/chat_user_image_model.dart';
import 'package:mohem_flutter_app/models/chat/create_group_request.dart' import 'package:mohem_flutter_app/models/chat/create_group_request.dart' as createGroup;
as createGroup; import 'package:mohem_flutter_app/models/chat/get_group_chat_history.dart' as groupchathistory;
import 'package:mohem_flutter_app/models/chat/get_group_chat_history.dart'
as groupchathistory;
import 'package:mohem_flutter_app/models/chat/get_search_user_chat_model.dart'; import 'package:mohem_flutter_app/models/chat/get_search_user_chat_model.dart';
import 'package:mohem_flutter_app/models/chat/get_single_user_chat_list_model.dart'; import 'package:mohem_flutter_app/models/chat/get_single_user_chat_list_model.dart';
import 'package:mohem_flutter_app/models/chat/get_user_groups_by_id.dart' import 'package:mohem_flutter_app/models/chat/get_user_groups_by_id.dart' as groups;
as groups;
import 'package:mohem_flutter_app/models/chat/get_user_groups_by_id.dart'; import 'package:mohem_flutter_app/models/chat/get_user_groups_by_id.dart';
import 'package:mohem_flutter_app/models/chat/get_user_login_token_model.dart' import 'package:mohem_flutter_app/models/chat/get_user_login_token_model.dart' as userLoginToken;
as userLoginToken; import 'package:mohem_flutter_app/models/chat/make_user_favotire_unfavorite_chat_model.dart' as fav;
import 'package:mohem_flutter_app/models/chat/make_user_favotire_unfavorite_chat_model.dart'
as fav;
import 'package:mohem_flutter_app/models/chat/target_users.dart'; import 'package:mohem_flutter_app/models/chat/target_users.dart';
import 'package:mohem_flutter_app/models/my_team/get_employee_subordinates_list.dart'; import 'package:mohem_flutter_app/models/my_team/get_employee_subordinates_list.dart';
import 'package:mohem_flutter_app/provider/chat_call_provider.dart'; import 'package:mohem_flutter_app/provider/chat_call_provider.dart';
import 'package:mohem_flutter_app/ui/chat/chat_detailed_screen.dart'; import 'package:mohem_flutter_app/ui/chat/chat_detailed_screen.dart';
import 'package:mohem_flutter_app/ui/landing/dashboard_screen.dart';
import 'package:mohem_flutter_app/widgets/image_picker.dart'; import 'package:mohem_flutter_app/widgets/image_picker.dart';
import 'package:open_file/open_file.dart'; import 'package:open_file/open_file.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
import 'package:signalr_netcore/hub_connection.dart';
import 'package:signalr_netcore/signalr_client.dart'; import 'package:signalr_netcore/signalr_client.dart';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
import 'package:flutter/material.dart' as Material;
class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
ScrollController scrollController = ScrollController(); ScrollController scrollController = ScrollController();
@ -66,10 +58,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
List<ChatUser> favUsersList = []; List<ChatUser> favUsersList = [];
int paginationVal = 0; int paginationVal = 0;
int? cTypingUserId = 0; int? cTypingUserId = 0;
bool isTextMsg = false, bool isTextMsg = false, isReplyMsg = false, isAttachmentMsg = false, isVoiceMsg = false;
isReplyMsg = false,
isAttachmentMsg = false,
isVoiceMsg = false;
// Audio Recoding Work // Audio Recoding Work
Timer? _timer; Timer? _timer;
@ -113,7 +102,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
AppState().setchatUserDetails = userLoginResponse; AppState().setchatUserDetails = userLoginResponse;
Utils.saveStringFromPrefs("userLoginChatDetails", jsonEncode(userLoginResponse.response)); Utils.saveStringFromPrefs("userLoginChatDetails", jsonEncode(userLoginResponse.response));
isUserOnline = true; isUserOnline = true;
if(Platform.isIOS){ if (Platform.isIOS) {
AppState().setisUserOnline = true; AppState().setisUserOnline = true;
} }
} else { } else {
@ -124,7 +113,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
); );
disableChatForThisUser = true; disableChatForThisUser = true;
isUserOnline = false; isUserOnline = false;
if(Platform.isIOS){ if (Platform.isIOS) {
AppState().setisUserOnline = false; AppState().setisUserOnline = false;
} }
notifyListeners(); notifyListeners();
@ -132,7 +121,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} catch (e) { } catch (e) {
disableChatForThisUser = true; disableChatForThisUser = true;
isUserOnline = false; isUserOnline = false;
if(Platform.isIOS){ if (Platform.isIOS) {
AppState().setisUserOnline = false; AppState().setisUserOnline = false;
} }
notifyListeners(); notifyListeners();
@ -160,15 +149,10 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
Future<HubConnection> getHubConnection() async { Future<HubConnection> getHubConnection() async {
HubConnection hub; HubConnection hub;
HttpConnectionOptions httpOp = HttpConnectionOptions httpOp = HttpConnectionOptions(skipNegotiation: false, logMessageContent: true);
HttpConnectionOptions(skipNegotiation: false, logMessageContent: true);
hub = HubConnectionBuilder() hub = HubConnectionBuilder()
.withUrl( .withUrl(ApiConsts.chatHubConnectionUrl + "?UserId=${AppState().chatDetails!.response!.id}&source=Desktop&access_token=${AppState().chatDetails!.response!.token}", options: httpOp)
ApiConsts.chatHubConnectionUrl + .withAutomaticReconnect(retryDelays: <int>[2000, 5000, 10000, 20000]).build();
"?UserId=${AppState().chatDetails!.response!.id}&source=Desktop&access_token=${AppState().chatDetails!.response!.token}",
options: httpOp)
.withAutomaticReconnect(
retryDelays: <int>[2000, 5000, 10000, 20000]).build();
return hub; return hub;
} }
@ -180,12 +164,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
chatHubConnection.on("OnUserTypingAsync", onUserTyping); chatHubConnection.on("OnUserTypingAsync", onUserTyping);
chatHubConnection.on("OnUserCountAsync", userCountAsync); chatHubConnection.on("OnUserCountAsync", userCountAsync);
// chatHubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow); // chatHubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow);
chatHubConnection.on( chatHubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered);
"OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered); chatHubConnection.on("OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus);
chatHubConnection.on( chatHubConnection.on("OnGetGroupUserStatusAsync", getGroupUserStatus);
"OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus);
chatHubConnection.on(
"OnGetGroupUserStatusAsync", getGroupUserStatus);
// //
// {"type":1,"target":"","arguments":[[{"id":217869,"userName":"Sultan.Khan","email":"Sultan.Khan@cloudsolutions.com.sa","phone":null,"title":"Sultan.Khan","userStatus":1,"image":null,"unreadMessageCount":0,"userAction":3,"isPin":false,"isFav":false,"isAdmin":false,"rKey":null,"totalCount":0,"isHuaweiDevice":false,"deviceToken":null},{"id":15153,"userName":"Tamer.Fanasheh","email":"Tamer.F@cloudsolutions.com.sa","phone":null,"title":"Tamer Fanasheh","userStatus":2,"image":null,"unreadMessageCount":0,"userAction":3,"isPin":false,"isFav":false,"isAdmin":true,"rKey":null,"totalCount":0,"isHuaweiDevice":false,"deviceToken":null}]]} // {"type":1,"target":"","arguments":[[{"id":217869,"userName":"Sultan.Khan","email":"Sultan.Khan@cloudsolutions.com.sa","phone":null,"title":"Sultan.Khan","userStatus":1,"image":null,"unreadMessageCount":0,"userAction":3,"isPin":false,"isFav":false,"isAdmin":false,"rKey":null,"totalCount":0,"isHuaweiDevice":false,"deviceToken":null},{"id":15153,"userName":"Tamer.Fanasheh","email":"Tamer.F@cloudsolutions.com.sa","phone":null,"title":"Tamer Fanasheh","userStatus":2,"image":null,"unreadMessageCount":0,"userAction":3,"isPin":false,"isFav":false,"isAdmin":true,"rKey":null,"totalCount":0,"isHuaweiDevice":false,"deviceToken":null}]]}
@ -201,8 +182,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
// userGroups = await ChatApiClient().getGroupsByUserId(); // userGroups = await ChatApiClient().getGroupsByUserId();
if (favUList.response != null && recentChat.response != null) { if (favUList.response != null && recentChat.response != null) {
favUsersList = favUList.response!; favUsersList = favUList.response!;
favUsersList.sort((ChatUser a, ChatUser b) => favUsersList.sort((ChatUser a, ChatUser b) => a.userName!.toLowerCase().compareTo(b.userName!.toLowerCase()));
a.userName!.toLowerCase().compareTo(b.userName!.toLowerCase()));
for (dynamic user in recentChat.response!) { for (dynamic user in recentChat.response!) {
for (dynamic favUser in favUList.response!) { for (dynamic favUser in favUList.response!) {
if (user.id == favUser.id) { if (user.id == favUser.id) {
@ -213,12 +193,10 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
pChatHistory = recentChat.response ?? []; pChatHistory = recentChat.response ?? [];
uGroups = userGroups.groupresponse ?? []; uGroups = userGroups.groupresponse ?? [];
pChatHistory!.sort((ChatUser a, ChatUser b) => pChatHistory!.sort((ChatUser a, ChatUser b) => a.userName!.toLowerCase().compareTo(b.userName!.toLowerCase()));
a.userName!.toLowerCase().compareTo(b.userName!.toLowerCase()));
searchedChats = pChatHistory; searchedChats = pChatHistory;
isLoading = false; isLoading = false;
await invokeUserChatHistoryNotDeliveredAsync( await invokeUserChatHistoryNotDeliveredAsync(userId: int.parse(AppState().chatDetails!.response!.id.toString()));
userId: int.parse(AppState().chatDetails!.response!.id.toString()));
sort(); sort();
notifyListeners(); notifyListeners();
if (searchedChats!.isNotEmpty || favUsersList.isNotEmpty) { if (searchedChats!.isNotEmpty || favUsersList.isNotEmpty) {
@ -227,38 +205,27 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
Future invokeUserChatHistoryNotDeliveredAsync({required int userId}) async { Future invokeUserChatHistoryNotDeliveredAsync({required int userId}) async {
await chatHubConnection await chatHubConnection.invoke("GetUserChatHistoryNotDeliveredAsync", args: [userId]);
.invoke("GetUserChatHistoryNotDeliveredAsync", args: [userId]);
return ""; return "";
} }
void getSingleUserChatHistory( void getSingleUserChatHistory({required int senderUID, required int receiverUID, required bool loadMore, bool isNewChat = false}) async {
{required int senderUID,
required int receiverUID,
required bool loadMore,
bool isNewChat = false}) async {
isLoading = true; isLoading = true;
if (isNewChat) userChatHistory = []; if (isNewChat) userChatHistory = [];
if (!loadMore) paginationVal = 0; if (!loadMore) paginationVal = 0;
isChatScreenActive = true; isChatScreenActive = true;
receiverID = receiverUID; receiverID = receiverUID;
Response response = await ChatApiClient().getSingleUserChatHistory( Response response = await ChatApiClient().getSingleUserChatHistory(senderUID: senderUID, receiverUID: receiverUID, loadMore: loadMore, paginationVal: paginationVal);
senderUID: senderUID,
receiverUID: receiverUID,
loadMore: loadMore,
paginationVal: paginationVal);
if (response.statusCode == 204) { if (response.statusCode == 204) {
if (isNewChat) { if (isNewChat) {
userChatHistory = []; userChatHistory = [];
} else if (loadMore) {} } else if (loadMore) {}
} else { } else {
if (loadMore) { if (loadMore) {
List<SingleUserChatModel> temp = List<SingleUserChatModel> temp = getSingleUserChatModel(response.body).reversed.toList();
getSingleUserChatModel(response.body).reversed.toList();
userChatHistory.addAll(temp); userChatHistory.addAll(temp);
} else { } else {
userChatHistory = userChatHistory = getSingleUserChatModel(response.body).reversed.toList();
getSingleUserChatModel(response.body).reversed.toList();
} }
} }
isLoading = false; isLoading = false;
@ -285,9 +252,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
dynamic data = [ dynamic data = [
{ {
"userChatHistoryId": element.userChatHistoryId, "userChatHistoryId": element.userChatHistoryId,
"TargetUserId": element.currentUserId == receiverID "TargetUserId": element.currentUserId == receiverID ? element.currentUserId : element.targetUserId,
? element.currentUserId
: element.targetUserId,
"isDelivered": true, "isDelivered": true,
"isSeen": true, "isSeen": true,
} }
@ -309,8 +274,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
void updateUserChatHistoryStatusAsync(List data) { void updateUserChatHistoryStatusAsync(List data) {
try { try {
chatHubConnection chatHubConnection.invoke("UpdateUserChatHistoryStatusAsync", args: [data]);
.invoke("UpdateUserChatHistoryStatusAsync", args: [data]);
} catch (e) { } catch (e) {
throw e; throw e;
} }
@ -318,21 +282,16 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
void updateUserChatHistoryOnMsg(List data) { void updateUserChatHistoryOnMsg(List data) {
try { try {
chatHubConnection chatHubConnection.invoke("UpdateUserChatHistoryStatusAsync", args: [data]);
.invoke("UpdateUserChatHistoryStatusAsync", args: [data]);
} catch (e) { } catch (e) {
throw e; throw e;
} }
} }
List<SingleUserChatModel> getSingleUserChatModel(String str) => List<SingleUserChatModel> getSingleUserChatModel(String str) => List<SingleUserChatModel>.from(json.decode(str).map((x) => SingleUserChatModel.fromJson(x)));
List<SingleUserChatModel>.from(
json.decode(str).map((x) => SingleUserChatModel.fromJson(x)));
List<groupchathistory.GetGroupChatHistoryAsync> getGroupChatHistoryAsync(String str) => List<groupchathistory.GetGroupChatHistoryAsync> getGroupChatHistoryAsync(String str) =>
List<groupchathistory.GetGroupChatHistoryAsync>.from( List<groupchathistory.GetGroupChatHistoryAsync>.from(json.decode(str).map((x) => groupchathistory.GetGroupChatHistoryAsync.fromJson(x)));
json.decode(str).map((x) => groupchathistory.GetGroupChatHistoryAsync.fromJson(x)));
Future<dynamic> uploadAttachments(String userId, File file) async { Future<dynamic> uploadAttachments(String userId, File file) async {
dynamic result; dynamic result;
@ -362,7 +321,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
notifyListeners(); notifyListeners();
} }
void getGroupUserStatus(List<Object?>? args){ void getGroupUserStatus(List<Object?>? args) {
//note: need to implement this function... //note: need to implement this function...
print(args); print(args);
} }
@ -393,8 +352,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
void updateChatHistoryWindow(List<Object?>? args) { void updateChatHistoryWindow(List<Object?>? args) {
dynamic items = args!.toList(); dynamic items = args!.toList();
if (kDebugMode) { if (kDebugMode) {
logger.i( logger.i("---------------------------------Update Chat History Windows Async -------------------------------------");
"---------------------------------Update Chat History Windows Async -------------------------------------");
} }
logger.d(items); logger.d(items);
// for (var user in searchedChats!) { // for (var user in searchedChats!) {
@ -464,26 +422,14 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
data.first.currentUserName = temp.first.targetUserName; data.first.currentUserName = temp.first.targetUserName;
data.first.currentUserEmail = temp.first.targetUserEmail; data.first.currentUserEmail = temp.first.targetUserEmail;
if (data.first.fileTypeId == 12 || if (data.first.fileTypeId == 12 || data.first.fileTypeId == 4 || data.first.fileTypeId == 3) {
data.first.fileTypeId == 4 || data.first.image = await ChatApiClient().downloadURL(fileName: data.first.contant!, fileTypeDescription: data.first.fileTypeResponse!.fileTypeDescription ?? "image/jpg");
data.first.fileTypeId == 3) {
data.first.image = await ChatApiClient().downloadURL(
fileName: data.first.contant!,
fileTypeDescription:
data.first.fileTypeResponse!.fileTypeDescription ??
"image/jpg");
} }
if (data.first.userChatReplyResponse != null) { if (data.first.userChatReplyResponse != null) {
if (data.first.fileTypeResponse != null) { if (data.first.fileTypeResponse != null) {
if (data.first.userChatReplyResponse!.fileTypeId == 12 || if (data.first.userChatReplyResponse!.fileTypeId == 12 || data.first.userChatReplyResponse!.fileTypeId == 4 || data.first.userChatReplyResponse!.fileTypeId == 3) {
data.first.userChatReplyResponse!.fileTypeId == 4 || data.first.userChatReplyResponse!.image =
data.first.userChatReplyResponse!.fileTypeId == 3) { await ChatApiClient().downloadURL(fileName: data.first.userChatReplyResponse!.contant!, fileTypeDescription: data.first.fileTypeResponse!.fileTypeDescription ?? "image/jpg");
data.first.userChatReplyResponse!.image = await ChatApiClient()
.downloadURL(
fileName: data.first.userChatReplyResponse!.contant!,
fileTypeDescription:
data.first.fileTypeResponse!.fileTypeDescription ??
"image/jpg");
data.first.userChatReplyResponse!.isImageLoaded = true; data.first.userChatReplyResponse!.isImageLoaded = true;
} }
} }
@ -491,14 +437,11 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
if (searchedChats != null) { if (searchedChats != null) {
dynamic contain = searchedChats! dynamic contain = searchedChats!.where((ChatUser element) => element.id == data.first.currentUserId);
.where((ChatUser element) => element.id == data.first.currentUserId);
if (contain.isEmpty) { if (contain.isEmpty) {
List<String> emails = []; List<String> emails = [];
emails.add(await EmailImageEncryption() emails.add(await EmailImageEncryption().encrypt(val: data.first.currentUserEmail!));
.encrypt(val: data.first.currentUserEmail!)); List<ChatUserImageModel> chatImages = await ChatApiClient().getUsersImages(encryptedEmails: emails);
List<ChatUserImageModel> chatImages =
await ChatApiClient().getUsersImages(encryptedEmails: emails);
searchedChats!.add( searchedChats!.add(
ChatUser( ChatUser(
id: data.first.currentUserId, id: data.first.currentUserId,
@ -510,9 +453,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
isImageLoaded: true, isImageLoaded: true,
userStatus: 1, userStatus: 1,
isTyping: false, isTyping: false,
userLocalDownlaodedImage: await downloadImageLocal( userLocalDownlaodedImage: await downloadImageLocal(chatImages.first.profilePicture, data.first.currentUserId.toString()),
chatImages.first.profilePicture,
data.first.currentUserId.toString()),
), ),
); );
} }
@ -539,9 +480,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
"userChatHistoryId": data.first.userChatHistoryId, "userChatHistoryId": data.first.userChatHistoryId,
"TargetUserId": temp.first.targetUserId, "TargetUserId": temp.first.targetUserId,
"isDelivered": true, "isDelivered": true,
"isSeen": isChatScreenActive && data.first.currentUserId == receiverID "isSeen": isChatScreenActive && data.first.currentUserId == receiverID ? true : false
? true
: false
} }
]; ];
updateUserChatHistoryOnMsg(list); updateUserChatHistoryOnMsg(list);
@ -552,38 +491,24 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
Future<void> onGroupMsgReceived(List<Object?>? parameters) async { Future<void> onGroupMsgReceived(List<Object?>? parameters) async {
List<groupchathistory.GetGroupChatHistoryAsync> data = [], temp = []; List<groupchathistory.GetGroupChatHistoryAsync> data = [], temp = [];
for (dynamic msg in parameters!) { for (dynamic msg in parameters!) {
// groupChatHistory.add(groupchathistory.GetGroupChatHistoryAsync.fromJson(msg)); // groupChatHistory.add(groupchathistory.GetGroupChatHistoryAsync.fromJson(msg));
data.add(groupchathistory.GetGroupChatHistoryAsync.fromJson(msg)); data.add(groupchathistory.GetGroupChatHistoryAsync.fromJson(msg));
temp =data; temp = data;
// data.first.currentUserId = temp.first.currentUserId; // data.first.currentUserId = temp.first.currentUserId;
// data.first.currentUserName = temp.first.currentUserName; // data.first.currentUserName = temp.first.currentUserName;
// //
// data.first.currentUserId = temp.first.currentUserId; // data.first.currentUserId = temp.first.currentUserId;
// data.first.currentUserName = temp.first.currentUserName; // data.first.currentUserName = temp.first.currentUserName;
if (data.first.fileTypeId == 12 || data.first.fileTypeId == 4 || data.first.fileTypeId == 3) {
if (data.first.fileTypeId == 12 || data.first.image = await ChatApiClient().downloadURL(fileName: data.first.contant!, fileTypeDescription: data.first.fileTypeResponse!.fileTypeDescription ?? "image/jpg");
data.first.fileTypeId == 4 ||
data.first.fileTypeId == 3) {
data.first.image = await ChatApiClient().downloadURL(
fileName: data.first.contant!,
fileTypeDescription:
data.first.fileTypeResponse!.fileTypeDescription ??
"image/jpg");
} }
if (data.first.groupChatReplyResponse != null) { if (data.first.groupChatReplyResponse != null) {
if (data.first.fileTypeResponse != null) { if (data.first.fileTypeResponse != null) {
if (data.first.groupChatReplyResponse!.fileTypeId == 12 || if (data.first.groupChatReplyResponse!.fileTypeId == 12 || data.first.groupChatReplyResponse!.fileTypeId == 4 || data.first.groupChatReplyResponse!.fileTypeId == 3) {
data.first.groupChatReplyResponse!.fileTypeId == 4 || data.first.groupChatReplyResponse!.image =
data.first.groupChatReplyResponse!.fileTypeId == 3) { await ChatApiClient().downloadURL(fileName: data.first.groupChatReplyResponse!.contant!, fileTypeDescription: data.first.fileTypeResponse!.fileTypeDescription ?? "image/jpg");
data.first.groupChatReplyResponse!.image = await ChatApiClient()
.downloadURL(
fileName: data.first.groupChatReplyResponse!.contant!,
fileTypeDescription:
data.first.fileTypeResponse!.fileTypeDescription ??
"image/jpg");
data.first.groupChatReplyResponse!.isImageLoaded = true; data.first.groupChatReplyResponse!.isImageLoaded = true;
} }
} }
@ -648,8 +573,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
notifyListeners(); notifyListeners();
} }
void OnSubmitChatAsync(List<Object?>? parameters) { void OnSubmitChatAsync(List<Object?>? parameters) {
List<SingleUserChatModel> data = [], temp = []; List<SingleUserChatModel> data = [], temp = [];
for (dynamic msg in parameters!) { for (dynamic msg in parameters!) {
@ -674,8 +597,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
void sort() { void sort() {
searchedChats!.sort( searchedChats!.sort(
(ChatUser a, ChatUser b) => (ChatUser a, ChatUser b) => b.unreadMessageCount!.compareTo(a.unreadMessageCount!),
b.unreadMessageCount!.compareTo(a.unreadMessageCount!),
); );
} }
@ -805,22 +727,14 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
targetUserName: targetUserName, targetUserName: targetUserName,
isReplied: false, isReplied: false,
fileTypeId: fileTypeId, fileTypeId: fileTypeId,
userChatReplyResponse: isReply userChatReplyResponse: isReply ? UserChatReplyResponse.fromJson(repliedMsg.first.toJson()) : null,
? UserChatReplyResponse.fromJson(repliedMsg.first.toJson())
: null,
fileTypeResponse: isAttachment fileTypeResponse: isAttachment
? FileTypeResponse( ? FileTypeResponse(
fileTypeId: fileTypeId, fileTypeId: fileTypeId,
fileTypeName: isVoiceMsg fileTypeName: isVoiceMsg ? getFileExtension(voiceFile!.path).toString() : getFileExtension(selectedFile.path).toString(),
? getFileExtension(voiceFile!.path).toString()
: getFileExtension(selectedFile.path).toString(),
fileKind: "file", fileKind: "file",
fileName: isVoiceMsg ? msg : selectedFile.path.split("/").last, fileName: isVoiceMsg ? msg : selectedFile.path.split("/").last,
fileTypeDescription: isVoiceMsg fileTypeDescription: isVoiceMsg ? getFileTypeDescription(getFileExtension(voiceFile!.path).toString()) : getFileTypeDescription(getFileExtension(selectedFile.path).toString()),
? getFileTypeDescription(
getFileExtension(voiceFile!.path).toString())
: getFileTypeDescription(
getFileExtension(selectedFile.path).toString()),
) )
: null, : null,
image: image, image: image,
@ -842,8 +756,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
String chatData = String chatData =
'{"contant":"$msg","contantNo":"$contentNo","chatEventId":$chatEventId,"fileTypeId": $fileTypeId,"currentUserId":${AppState().chatDetails!.response!.id},"chatSource":1,"userChatHistoryLineRequestList":[{"isSeen":false,"isDelivered":false,"targetUserId":$targetUserId,"targetUserStatus":1}],"chatReplyId":$chatReplyId,"conversationId":"$chatCID"}'; '{"contant":"$msg","contantNo":"$contentNo","chatEventId":$chatEventId,"fileTypeId": $fileTypeId,"currentUserId":${AppState().chatDetails!.response!.id},"chatSource":1,"userChatHistoryLineRequestList":[{"isSeen":false,"isDelivered":false,"targetUserId":$targetUserId,"targetUserStatus":1}],"chatReplyId":$chatReplyId,"conversationId":"$chatCID"}';
await chatHubConnection await chatHubConnection.invoke("AddChatUserAsync", args: <Object>[json.decode(chatData)]);
.invoke("AddChatUserAsync", args: <Object>[json.decode(chatData)]);
} }
//groupChatMessage //groupChatMessage
@ -862,8 +775,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
int? userStatus, int? userStatus,
File? voiceFile, File? voiceFile,
required bool isVoiceAttached, required bool isVoiceAttached,
required List<GroupUserList> userList required List<GroupUserList> userList}) async {
}) async {
Uuid uuid = const Uuid(); Uuid uuid = const Uuid();
String contentNo = uuid.v4(); String contentNo = uuid.v4();
String msg; String msg;
@ -873,8 +785,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
msg = message.text; msg = message.text;
logger.w(msg); logger.w(msg);
} }
groupchathistory.GetGroupChatHistoryAsync data = groupchathistory.GetGroupChatHistoryAsync data = groupchathistory.GetGroupChatHistoryAsync(
groupchathistory.GetGroupChatHistoryAsync(
//userChatHistoryId: 0, //userChatHistoryId: 0,
chatEventId: chatEventId, chatEventId: chatEventId,
chatSource: 1, chatSource: 1,
@ -894,7 +805,8 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
fileTypeName: isVoiceMsg ? getFileExtension(voiceFile!.path).toString() : getFileExtension(selectedFile.path).toString(), fileTypeName: isVoiceMsg ? getFileExtension(voiceFile!.path).toString() : getFileExtension(selectedFile.path).toString(),
fileKind: "file", fileKind: "file",
fileName: isVoiceMsg ? msg : selectedFile.path.split("/").last, fileName: isVoiceMsg ? msg : selectedFile.path.split("/").last,
fileTypeDescription: isVoiceMsg ? getFileTypeDescription(getFileExtension(voiceFile!.path).toString()) : getFileTypeDescription(getFileExtension(selectedFile.path).toString())) : null, fileTypeDescription: isVoiceMsg ? getFileTypeDescription(getFileExtension(voiceFile!.path).toString()) : getFileTypeDescription(getFileExtension(selectedFile.path).toString()))
: null,
image: image, image: image,
isImageLoaded: isImageLoaded, isImageLoaded: isImageLoaded,
voice: isVoiceMsg ? voiceFile! : null, voice: isVoiceMsg ? voiceFile! : null,
@ -911,22 +823,21 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
message.clear(); message.clear();
notifyListeners(); notifyListeners();
List<TargetUsers> targetUsers =[]; List<TargetUsers> targetUsers = [];
for (GroupUserList element in userList) { for (GroupUserList element in userList) {
targetUsers.add(TargetUsers(isDelivered: false,isSeen: false, targetUserId: element.id, userAction: element.userAction, userStatus: element.userStatus)); targetUsers.add(TargetUsers(isDelivered: false, isSeen: false, targetUserId: element.id, userAction: element.userAction, userStatus: element.userStatus));
} }
String chatData = String chatData =
'{"contant":"$msg","contantNo":"$contentNo","chatEventId":$chatEventId,"fileTypeId":$fileTypeId,"currentUserId":${AppState().chatDetails!.response!.id},"chatSource":1,"groupId":$targetGroupId,"groupChatHistoryLineRequestList":${json.encode(targetUsers)},"chatReplyId": $chatReplyId,"conversationId":"${uuid.v4()}"}'; '{"contant":"$msg","contantNo":"$contentNo","chatEventId":$chatEventId,"fileTypeId":$fileTypeId,"currentUserId":${AppState().chatDetails!.response!.id},"chatSource":1,"groupId":$targetGroupId,"groupChatHistoryLineRequestList":${json.encode(targetUsers)},"chatReplyId": $chatReplyId,"conversationId":"${uuid.v4()}"}';
await chatHubConnection.invoke("AddGroupChatHistoryAsync", await chatHubConnection.invoke("AddGroupChatHistoryAsync", args: <Object>[json.decode(chatData)]);
args: <Object>[json.decode(chatData)]);
} }
void sendGroupChatMessage(BuildContext context, void sendGroupChatMessage(
{required int targetUserId, BuildContext context, {
required int targetUserId,
required int userStatus, required int userStatus,
required String userEmail, required String userEmail,
required String targetUserName, required String targetUserName,
@ -950,8 +861,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
isVoiceAttached: false, isVoiceAttached: false,
userEmail: userEmail, userEmail: userEmail,
userStatus: userStatus, userStatus: userStatus,
userList:userList userList: userList);
);
} else if (isTextMsg && !isAttachmentMsg && !isVoiceMsg && isReplyMsg) { } else if (isTextMsg && !isAttachmentMsg && !isVoiceMsg && isReplyMsg) {
logger.d("// Text Message as Reply"); logger.d("// Text Message as Reply");
if (message.text.isEmpty) { if (message.text.isEmpty) {
@ -971,15 +881,13 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
voiceFile: null, voiceFile: null,
userEmail: userEmail, userEmail: userEmail,
userStatus: userStatus, userStatus: userStatus,
userList:userList userList: userList);
);
} }
// Attachment // Attachment
else if (!isTextMsg && isAttachmentMsg && !isVoiceMsg && !isReplyMsg) { else if (!isTextMsg && isAttachmentMsg && !isVoiceMsg && !isReplyMsg) {
logger.d("// Normal Image Message"); logger.d("// Normal Image Message");
Utils.showLoading(context); Utils.showLoading(context);
dynamic value = await uploadAttachments( dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), selectedFile);
AppState().chatDetails!.response!.id.toString(), selectedFile);
String? ext = getFileExtension(selectedFile.path); String? ext = getFileExtension(selectedFile.path);
Utils.hideLoading(context); Utils.hideLoading(context);
sendGroupChatToServer( sendGroupChatToServer(
@ -995,19 +903,16 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
isVoiceAttached: false, isVoiceAttached: false,
userEmail: userEmail, userEmail: userEmail,
userStatus: userStatus, userStatus: userStatus,
userList:userList userList: userList);
);
} else if (!isTextMsg && isAttachmentMsg && !isVoiceMsg && isReplyMsg) { } else if (!isTextMsg && isAttachmentMsg && !isVoiceMsg && isReplyMsg) {
logger.d("// Image as Reply Msg"); logger.d("// Image as Reply Msg");
Utils.showLoading(context); Utils.showLoading(context);
dynamic value = await uploadAttachments( dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), selectedFile);
AppState().chatDetails!.response!.id.toString(), selectedFile);
String? ext = getFileExtension(selectedFile.path); String? ext = getFileExtension(selectedFile.path);
Utils.hideLoading(context); Utils.hideLoading(context);
sendGroupChatToServer( sendGroupChatToServer(
chatEventId: 2, chatEventId: 2,
fileTypeId: getFileType(ext.toString()), fileTypeId: getFileType(ext.toString()),
targetGroupId: targetUserId, targetGroupId: targetUserId,
targetUserName: targetUserName, targetUserName: targetUserName,
isAttachment: true, isAttachment: true,
@ -1018,8 +923,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
isVoiceAttached: false, isVoiceAttached: false,
userEmail: userEmail, userEmail: userEmail,
userStatus: userStatus, userStatus: userStatus,
userList:userList userList: userList);
);
} }
//Voice //Voice
@ -1039,8 +943,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
isPlaying = false; isPlaying = false;
isRecoding = false; isRecoding = false;
Utils.showLoading(context); Utils.showLoading(context);
dynamic value = await uploadAttachments( dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), voiceFile);
AppState().chatDetails!.response!.id.toString(), voiceFile);
String? ext = getFileExtension(voiceFile.path); String? ext = getFileExtension(voiceFile.path);
Utils.hideLoading(context); Utils.hideLoading(context);
sendGroupChatToServer( sendGroupChatToServer(
@ -1057,8 +960,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
isVoiceAttached: true, isVoiceAttached: true,
userEmail: userEmail, userEmail: userEmail,
userStatus: userStatus, userStatus: userStatus,
userList:userList userList: userList);
);
notifyListeners(); notifyListeners();
} else if (!isTextMsg && !isAttachmentMsg && isVoiceMsg && isReplyMsg) { } else if (!isTextMsg && !isAttachmentMsg && isVoiceMsg && isReplyMsg) {
logger.d("// Voice as Reply Msg"); logger.d("// Voice as Reply Msg");
@ -1077,8 +979,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
isRecoding = false; isRecoding = false;
Utils.showLoading(context); Utils.showLoading(context);
dynamic value = await uploadAttachments( dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), voiceFile);
AppState().chatDetails!.response!.id.toString(), voiceFile);
String? ext = getFileExtension(voiceFile.path); String? ext = getFileExtension(voiceFile.path);
Utils.hideLoading(context); Utils.hideLoading(context);
sendGroupChatToServer( sendGroupChatToServer(
@ -1094,18 +995,15 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
isVoiceAttached: true, isVoiceAttached: true,
userEmail: userEmail, userEmail: userEmail,
userStatus: userStatus, userStatus: userStatus,
userList:userList userList: userList);
);
notifyListeners(); notifyListeners();
} }
if (searchedChats != null) { if (searchedChats != null) {
dynamic contain = searchedChats! dynamic contain = searchedChats!.where((ChatUser element) => element.id == targetUserId);
.where((ChatUser element) => element.id == targetUserId);
if (contain.isEmpty) { if (contain.isEmpty) {
List<String> emails = []; List<String> emails = [];
emails.add(await EmailImageEncryption().encrypt(val: userEmail)); emails.add(await EmailImageEncryption().encrypt(val: userEmail));
List<ChatUserImageModel> chatImages = List<ChatUserImageModel> chatImages = await ChatApiClient().getUsersImages(encryptedEmails: emails);
await ChatApiClient().getUsersImages(encryptedEmails: emails);
searchedChats!.add( searchedChats!.add(
ChatUser( ChatUser(
id: targetUserId, id: targetUserId,
@ -1126,12 +1024,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
} }
void sendChatMessage(BuildContext context, void sendChatMessage(
{required int targetUserId, BuildContext context, {
required int targetUserId,
required int userStatus, required int userStatus,
required String userEmail, required String userEmail,
required String targetUserName, required String targetUserName,
}) async { }) async {
if (kDebugMode) { if (kDebugMode) {
print("====================== Values ============================"); print("====================== Values ============================");
@ -1183,8 +1081,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
else if (!isTextMsg && isAttachmentMsg && !isVoiceMsg && !isReplyMsg) { else if (!isTextMsg && isAttachmentMsg && !isVoiceMsg && !isReplyMsg) {
logger.d("// Normal Image Message"); logger.d("// Normal Image Message");
Utils.showLoading(context); Utils.showLoading(context);
dynamic value = await uploadAttachments( dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), selectedFile);
AppState().chatDetails!.response!.id.toString(), selectedFile);
String? ext = getFileExtension(selectedFile.path); String? ext = getFileExtension(selectedFile.path);
Utils.hideLoading(context); Utils.hideLoading(context);
sendChatToServer( sendChatToServer(
@ -1203,8 +1100,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} else if (!isTextMsg && isAttachmentMsg && !isVoiceMsg && isReplyMsg) { } else if (!isTextMsg && isAttachmentMsg && !isVoiceMsg && isReplyMsg) {
logger.d("// Image as Reply Msg"); logger.d("// Image as Reply Msg");
Utils.showLoading(context); Utils.showLoading(context);
dynamic value = await uploadAttachments( dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), selectedFile);
AppState().chatDetails!.response!.id.toString(), selectedFile);
String? ext = getFileExtension(selectedFile.path); String? ext = getFileExtension(selectedFile.path);
Utils.hideLoading(context); Utils.hideLoading(context);
sendChatToServer( sendChatToServer(
@ -1239,8 +1135,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
isPlaying = false; isPlaying = false;
isRecoding = false; isRecoding = false;
Utils.showLoading(context); Utils.showLoading(context);
dynamic value = await uploadAttachments( dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), voiceFile);
AppState().chatDetails!.response!.id.toString(), voiceFile);
String? ext = getFileExtension(voiceFile.path); String? ext = getFileExtension(voiceFile.path);
Utils.hideLoading(context); Utils.hideLoading(context);
sendChatToServer( sendChatToServer(
@ -1274,8 +1169,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
isRecoding = false; isRecoding = false;
Utils.showLoading(context); Utils.showLoading(context);
dynamic value = await uploadAttachments( dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), voiceFile);
AppState().chatDetails!.response!.id.toString(), voiceFile);
String? ext = getFileExtension(voiceFile.path); String? ext = getFileExtension(voiceFile.path);
Utils.hideLoading(context); Utils.hideLoading(context);
sendChatToServer( sendChatToServer(
@ -1294,13 +1188,11 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
notifyListeners(); notifyListeners();
} }
if (searchedChats != null) { if (searchedChats != null) {
dynamic contain = searchedChats! dynamic contain = searchedChats!.where((ChatUser element) => element.id == targetUserId);
.where((ChatUser element) => element.id == targetUserId);
if (contain.isEmpty) { if (contain.isEmpty) {
List<String> emails = []; List<String> emails = [];
emails.add(await EmailImageEncryption().encrypt(val: userEmail)); emails.add(await EmailImageEncryption().encrypt(val: userEmail));
List<ChatUserImageModel> chatImages = List<ChatUserImageModel> chatImages = await ChatApiClient().getUsersImages(encryptedEmails: emails);
await ChatApiClient().getUsersImages(encryptedEmails: emails);
searchedChats!.add( searchedChats!.add(
ChatUser( ChatUser(
id: targetUserId, id: targetUserId,
@ -1313,8 +1205,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
isTyping: false, isTyping: false,
isFav: false, isFav: false,
userStatus: userStatus, userStatus: userStatus,
userLocalDownlaodedImage: await downloadImageLocal( userLocalDownlaodedImage: await downloadImageLocal(chatImages.first.profilePicture, targetUserId.toString()),
chatImages.first.profilePicture, targetUserId.toString()),
), ),
); );
notifyListeners(); notifyListeners();
@ -1344,8 +1235,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
void selectImageToUpload(BuildContext context) { void selectImageToUpload(BuildContext context) {
ImageOptions.showImageOptionsNew(context, true, ImageOptions.showImageOptionsNew(context, true, (String image, File file) async {
(String image, File file) async {
if (checkFileSize(file.path)) { if (checkFileSize(file.path)) {
selectedFile = file; selectedFile = file;
isAttachmentMsg = true; isAttachmentMsg = true;
@ -1434,6 +1324,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
repliedMsg.add(data); repliedMsg.add(data);
notifyListeners(); notifyListeners();
} }
void groupChatReply(groupchathistory.GetGroupChatHistoryAsync data) { void groupChatReply(groupchathistory.GetGroupChatHistoryAsync data) {
groupChatReplyData = []; groupChatReplyData = [];
data.isReplied = true; data.isReplied = true;
@ -1441,6 +1332,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
groupChatReplyData.add(data); groupChatReplyData.add(data);
notifyListeners(); notifyListeners();
} }
void closeMe() { void closeMe() {
repliedMsg = []; repliedMsg = [];
isReplyMsg = false; isReplyMsg = false;
@ -1453,18 +1345,13 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
return f.format(data); return f.format(data);
} }
Future<void> favoriteUser( Future<void> favoriteUser({required int userID, required int targetUserID, required bool fromSearch}) async {
{required int userID, fav.FavoriteChatUser favoriteChatUser = await ChatApiClient().favUser(userID: userID, targetUserID: targetUserID);
required int targetUserID,
required bool fromSearch}) async {
fav.FavoriteChatUser favoriteChatUser = await ChatApiClient()
.favUser(userID: userID, targetUserID: targetUserID);
if (favoriteChatUser.response != null) { if (favoriteChatUser.response != null) {
for (ChatUser user in searchedChats!) { for (ChatUser user in searchedChats!) {
if (user.id == favoriteChatUser.response!.targetUserId!) { if (user.id == favoriteChatUser.response!.targetUserId!) {
user.isFav = favoriteChatUser.response!.isFav; user.isFav = favoriteChatUser.response!.isFav;
dynamic contain = favUsersList!.where((ChatUser element) => dynamic contain = favUsersList!.where((ChatUser element) => element.id == favoriteChatUser.response!.targetUserId!);
element.id == favoriteChatUser.response!.targetUserId!);
if (contain.isEmpty) { if (contain.isEmpty) {
favUsersList.add(user); favUsersList.add(user);
} }
@ -1474,8 +1361,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
for (ChatUser user in chatUsersList!) { for (ChatUser user in chatUsersList!) {
if (user.id == favoriteChatUser.response!.targetUserId!) { if (user.id == favoriteChatUser.response!.targetUserId!) {
user.isFav = favoriteChatUser.response!.isFav; user.isFav = favoriteChatUser.response!.isFav;
dynamic contain = favUsersList!.where((ChatUser element) => dynamic contain = favUsersList!.where((ChatUser element) => element.id == favoriteChatUser.response!.targetUserId!);
element.id == favoriteChatUser.response!.targetUserId!);
if (contain.isEmpty) { if (contain.isEmpty) {
favUsersList.add(user); favUsersList.add(user);
} }
@ -1494,10 +1380,8 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
notifyListeners(); notifyListeners();
} }
Future<void> unFavoriteUser( Future<void> unFavoriteUser({required int userID, required int targetUserID}) async {
{required int userID, required int targetUserID}) async { fav.FavoriteChatUser favoriteChatUser = await ChatApiClient().unFavUser(userID: userID, targetUserID: targetUserID);
fav.FavoriteChatUser favoriteChatUser = await ChatApiClient()
.unFavUser(userID: userID, targetUserID: targetUserID);
if (favoriteChatUser.response != null) { if (favoriteChatUser.response != null) {
for (ChatUser user in searchedChats!) { for (ChatUser user in searchedChats!) {
@ -1602,14 +1486,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
emails.add(await EmailImageEncryption().encrypt(val: element.email!)); emails.add(await EmailImageEncryption().encrypt(val: element.email!));
} }
List<ChatUserImageModel> chatImages = List<ChatUserImageModel> chatImages = await ChatApiClient().getUsersImages(encryptedEmails: emails);
await ChatApiClient().getUsersImages(encryptedEmails: emails);
for (ChatUser user in searchedChats!) { for (ChatUser user in searchedChats!) {
for (ChatUserImageModel uImage in chatImages) { for (ChatUserImageModel uImage in chatImages) {
if (user.email == uImage.email) { if (user.email == uImage.email) {
user.image = uImage.profilePicture ?? ""; user.image = uImage.profilePicture ?? "";
user.userLocalDownlaodedImage = await downloadImageLocal( user.userLocalDownlaodedImage = await downloadImageLocal(uImage.profilePicture, user.id.toString());
uImage.profilePicture, user.id.toString());
user.isImageLoading = false; user.isImageLoading = false;
user.isImageLoaded = true; user.isImageLoaded = true;
} }
@ -1619,8 +1501,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
for (ChatUserImageModel uImage in chatImages) { for (ChatUserImageModel uImage in chatImages) {
if (favUser.email == uImage.email) { if (favUser.email == uImage.email) {
favUser.image = uImage.profilePicture ?? ""; favUser.image = uImage.profilePicture ?? "";
favUser.userLocalDownlaodedImage = await downloadImageLocal( favUser.userLocalDownlaodedImage = await downloadImageLocal(uImage.profilePicture, favUser.id.toString());
uImage.profilePicture, favUser.id.toString());
favUser.isImageLoading = false; favUser.isImageLoading = false;
favUser.isImageLoaded = true; favUser.isImageLoaded = true;
} }
@ -1637,8 +1518,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} else { } else {
await deleteFile(userID); await deleteFile(userID);
Uint8List decodedBytes = base64Decode(encodedBytes); Uint8List decodedBytes = base64Decode(encodedBytes);
Directory appDocumentsDirectory = Directory appDocumentsDirectory = await getApplicationDocumentsDirectory();
await getApplicationDocumentsDirectory();
String dirPath = '${appDocumentsDirectory.path}/chat_images'; String dirPath = '${appDocumentsDirectory.path}/chat_images';
if (!await Directory(dirPath).exists()) { if (!await Directory(dirPath).exists()) {
await Directory(dirPath).create(); await Directory(dirPath).create();
@ -1661,8 +1541,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
Future<String> downChatMedia(Uint8List bytes, String ext) async { Future<String> downChatMedia(Uint8List bytes, String ext) async {
String dir = (await getApplicationDocumentsDirectory()).path; String dir = (await getApplicationDocumentsDirectory()).path;
File file = File( File file = File("$dir/" + DateTime.now().millisecondsSinceEpoch.toString() + "." + ext);
"$dir/" + DateTime.now().millisecondsSinceEpoch.toString() + "." + ext);
await file.writeAsBytes(bytes); await file.writeAsBytes(bytes);
return file.path; return file.path;
} }
@ -1685,20 +1564,10 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
} }
Future<void> getChatMedia(BuildContext context, Future<void> getChatMedia(BuildContext context, {required String fileName, required String fileTypeName, required int fileTypeID}) async {
{required String fileName,
required String fileTypeName,
required int fileTypeID}) async {
Utils.showLoading(context); Utils.showLoading(context);
if (fileTypeID == 1 || if (fileTypeID == 1 || fileTypeID == 5 || fileTypeID == 7 || fileTypeID == 6 || fileTypeID == 8 || fileTypeID == 2) {
fileTypeID == 5 || Uint8List encodedString = await ChatApiClient().downloadURL(fileName: fileName, fileTypeDescription: getFileTypeDescription(fileTypeName));
fileTypeID == 7 ||
fileTypeID == 6 ||
fileTypeID == 8 ||
fileTypeID == 2) {
Uint8List encodedString = await ChatApiClient().downloadURL(
fileName: fileName,
fileTypeDescription: getFileTypeDescription(fileTypeName));
try { try {
String path = await downChatMedia(encodedString, fileTypeName ?? ""); String path = await downChatMedia(encodedString, fileTypeName ?? "");
Utils.hideLoading(context); Utils.hideLoading(context);
@ -1720,19 +1589,15 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
return ""; return "";
} }
void userTypingInvoke( void userTypingInvoke({required int currentUser, required int reciptUser}) async {
{required int currentUser, required int reciptUser}) async { await chatHubConnection.invoke("UserTypingAsync", args: [reciptUser, currentUser]);
await chatHubConnection
.invoke("UserTypingAsync", args: [reciptUser, currentUser]);
} }
void groupTypingInvoke(
{required GroupResponse groupDetails, required int groupId}) async { void groupTypingInvoke({required GroupResponse groupDetails, required int groupId}) async {
var data = json.decode(json.encode(groupDetails.groupUserList)); var data = json.decode(json.encode(groupDetails.groupUserList));
await chatHubConnection await chatHubConnection.invoke("GroupTypingAsync", args: ["${groupDetails.adminUser!.userName}", data, groupId]);
.invoke("GroupTypingAsync", args: ["${groupDetails.adminUser!.userName}",data, groupId ]);
} }
//////// Audio Recoding Work //////////////////// //////// Audio Recoding Work ////////////////////
Future<void> initAudio({required int receiverId}) async { Future<void> initAudio({required int receiverId}) async {
@ -1746,8 +1611,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
await Directory(dirPath).create(); await Directory(dirPath).create();
await File('$dirPath/.nomedia').create(); await File('$dirPath/.nomedia').create();
} }
path = path = "$dirPath/${AppState().chatDetails!.response!.id}-$receiverID-${DateTime.now().microsecondsSinceEpoch}.aac";
"$dirPath/${AppState().chatDetails!.response!.id}-$receiverID-${DateTime.now().microsecondsSinceEpoch}.aac";
recorderController = RecorderController() recorderController = RecorderController()
..androidEncoder = AndroidEncoder.aac ..androidEncoder = AndroidEncoder.aac
..androidOutputFormat = AndroidOutputFormat.mpeg4 ..androidOutputFormat = AndroidOutputFormat.mpeg4
@ -1877,19 +1741,15 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
return numberStr; return numberStr;
} }
Future<File> downChatVoice( Future<File> downChatVoice(Uint8List bytes, String ext, SingleUserChatModel data) async {
Uint8List bytes, String ext, SingleUserChatModel data) async {
File file; File file;
try { try {
String dirPath = String dirPath = '${(await getApplicationDocumentsDirectory()).path}/chat_audios';
'${(await getApplicationDocumentsDirectory()).path}/chat_audios';
if (!await Directory(dirPath).exists()) { if (!await Directory(dirPath).exists()) {
await Directory(dirPath).create(); await Directory(dirPath).create();
await File('$dirPath/.nomedia').create(); await File('$dirPath/.nomedia').create();
} }
file = File( file = File("$dirPath/${data.currentUserId}-${data.targetUserId}-${DateTime.now().microsecondsSinceEpoch}" + ext);
"$dirPath/${data.currentUserId}-${data.targetUserId}-${DateTime.now().microsecondsSinceEpoch}" +
ext);
await file.writeAsBytes(bytes); await file.writeAsBytes(bytes);
} catch (e) { } catch (e) {
if (kDebugMode) { if (kDebugMode) {
@ -1901,14 +1761,10 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
void scrollToMsg(SingleUserChatModel data) { void scrollToMsg(SingleUserChatModel data) {
if (data.userChatReplyResponse != null && if (data.userChatReplyResponse != null && data.userChatReplyResponse!.userChatHistoryId != null) {
data.userChatReplyResponse!.userChatHistoryId != null) { int index = userChatHistory.indexWhere((SingleUserChatModel element) => element.userChatHistoryId == data.userChatReplyResponse!.userChatHistoryId);
int index = userChatHistory.indexWhere((SingleUserChatModel element) =>
element.userChatHistoryId ==
data.userChatReplyResponse!.userChatHistoryId);
if (index >= 1) { if (index >= 1) {
double contentSize = scrollController.position.viewportDimension + double contentSize = scrollController.position.viewportDimension + scrollController.position.maxScrollExtent;
scrollController.position.maxScrollExtent;
double target = contentSize * index / userChatHistory.length; double target = contentSize * index / userChatHistory.length;
scrollController.position.animateTo( scrollController.position.animateTo(
target, target,
@ -1940,18 +1796,14 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
isImageLoading: false, isImageLoading: false,
image: element.eMPLOYEEIMAGE ?? "", image: element.eMPLOYEEIMAGE ?? "",
isImageLoaded: element.eMPLOYEEIMAGE == null ? false : true, isImageLoaded: element.eMPLOYEEIMAGE == null ? false : true,
userLocalDownlaodedImage: element.eMPLOYEEIMAGE == null userLocalDownlaodedImage: element.eMPLOYEEIMAGE == null ? null : await downloadImageLocal(element.eMPLOYEEIMAGE ?? "", element.eMPLOYEENUMBER!),
? null
: await downloadImageLocal(
element.eMPLOYEEIMAGE ?? "", element.eMPLOYEENUMBER!),
), ),
); );
} }
} }
} }
} else { } else {
getEmployeeSubordinatesList = getEmployeeSubordinatesList = await MyTeamApiClient().getEmployeeSubordinates("", "", "");
await MyTeamApiClient().getEmployeeSubordinates("", "", "");
AppState().setemployeeSubordinatesList = getEmployeeSubordinatesList; AppState().setemployeeSubordinatesList = getEmployeeSubordinatesList;
for (GetEmployeeSubordinatesList element in getEmployeeSubordinatesList) { for (GetEmployeeSubordinatesList element in getEmployeeSubordinatesList) {
if (element.eMPLOYEEEMAILADDRESS != null) { if (element.eMPLOYEEEMAILADDRESS != null) {
@ -1969,10 +1821,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
isImageLoading: false, isImageLoading: false,
image: element.eMPLOYEEIMAGE ?? "", image: element.eMPLOYEEIMAGE ?? "",
isImageLoaded: element.eMPLOYEEIMAGE == null ? false : true, isImageLoaded: element.eMPLOYEEIMAGE == null ? false : true,
userLocalDownlaodedImage: element.eMPLOYEEIMAGE == null userLocalDownlaodedImage: element.eMPLOYEEIMAGE == null ? null : await downloadImageLocal(element.eMPLOYEEIMAGE ?? "", element.eMPLOYEENUMBER!),
? null
: await downloadImageLocal(
element.eMPLOYEEIMAGE ?? "", element.eMPLOYEENUMBER!),
), ),
); );
} }
@ -2041,14 +1890,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
SingleUserChatModel nUser = SingleUserChatModel(); SingleUserChatModel nUser = SingleUserChatModel();
Utils.saveStringFromPrefs("isAppOpendByChat", "false"); Utils.saveStringFromPrefs("isAppOpendByChat", "false");
if (await Utils.getStringFromPrefs("notificationData") != "null") { if (await Utils.getStringFromPrefs("notificationData") != "null") {
nUser = SingleUserChatModel.fromJson( nUser = SingleUserChatModel.fromJson(jsonDecode(await Utils.getStringFromPrefs("notificationData")));
jsonDecode(await Utils.getStringFromPrefs("notificationData")));
Utils.saveStringFromPrefs("notificationData", "null"); Utils.saveStringFromPrefs("notificationData", "null");
Future.delayed(const Duration(seconds: 2)); Future.delayed(const Duration(seconds: 2));
for (ChatUser user in searchedChats!) { for (ChatUser user in searchedChats!) {
if (user.id == nUser.targetUserId) { if (user.id == nUser.targetUserId) {
Navigator.pushNamed(context, AppRoutes.chatDetailed, Navigator.pushNamed(context, AppRoutes.chatDetailed, arguments: ChatDetailedScreenParams(user, false));
arguments: ChatDetailedScreenParams(user, false));
return; return;
} }
} }
@ -2085,9 +1932,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
Future getGroupChatHistory(groups.GroupResponse groupDetails) async { Future getGroupChatHistory(groups.GroupResponse groupDetails) async {
isLoading = true; isLoading = true;
groupChatHistory = await ChatApiClient().getGroupChatHistory( groupChatHistory = await ChatApiClient().getGroupChatHistory(groupDetails.groupId, groupDetails.groupUserList as List<GroupUserList>);
groupDetails.groupId,
groupDetails.groupUserList as List<GroupUserList>);
isLoading = false; isLoading = false;
@ -2104,12 +1949,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
Future addGroupAndUsers(createGroup.CreateGroupRequest request) async { Future addGroupAndUsers(createGroup.CreateGroupRequest request) async {
isLoading = true; isLoading = true;
var groups = await ChatApiClient().addGroupAndUsers(request); var groups = await ChatApiClient().addGroupAndUsers(request);
userGroups.groupresponse! userGroups.groupresponse!.add(GroupResponse.fromJson(json.decode(groups)['response']));
.add(GroupResponse.fromJson(json.decode(groups)['response']));
isLoading = false; isLoading = false;
notifyListeners(); notifyListeners();
} }
Future updateGroupAndUsers(createGroup.CreateGroupRequest request) async { Future updateGroupAndUsers(createGroup.CreateGroupRequest request) async {
isLoading = true; isLoading = true;
await ChatApiClient().updateGroupAndUsers(request); await ChatApiClient().updateGroupAndUsers(request);

@ -1,5 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'package:audio_waveforms/audio_waveforms.dart'; import 'package:audio_waveforms/audio_waveforms.dart';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -11,24 +12,17 @@ import 'package:mohem_flutter_app/extensions/string_extensions.dart';
import 'package:mohem_flutter_app/extensions/widget_extensions.dart'; import 'package:mohem_flutter_app/extensions/widget_extensions.dart';
import 'package:mohem_flutter_app/generated/locale_keys.g.dart'; import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
import 'package:mohem_flutter_app/main.dart'; import 'package:mohem_flutter_app/main.dart';
import 'package:mohem_flutter_app/models/chat/call.dart';
import 'package:mohem_flutter_app/models/chat/get_group_chat_history.dart'; import 'package:mohem_flutter_app/models/chat/get_group_chat_history.dart';
import 'package:mohem_flutter_app/models/chat/get_search_user_chat_model.dart';
import 'package:mohem_flutter_app/models/chat/get_single_user_chat_list_model.dart';
import 'package:mohem_flutter_app/models/chat/get_user_groups_by_id.dart'; import 'package:mohem_flutter_app/models/chat/get_user_groups_by_id.dart';
import 'package:mohem_flutter_app/models/chat/get_user_login_token_model.dart';
import 'package:mohem_flutter_app/provider/chat_call_provider.dart'; import 'package:mohem_flutter_app/provider/chat_call_provider.dart';
import 'package:mohem_flutter_app/provider/chat_provider_model.dart'; import 'package:mohem_flutter_app/provider/chat_provider_model.dart';
import 'package:mohem_flutter_app/ui/chat/custom_auto_direction.dart';
import 'package:mohem_flutter_app/ui/chat/call/chat_outgoing_call_screen.dart';
import 'package:mohem_flutter_app/ui/chat/chat_bubble.dart';
import 'package:mohem_flutter_app/ui/chat/common.dart'; import 'package:mohem_flutter_app/ui/chat/common.dart';
import 'package:mohem_flutter_app/ui/chat/custom_auto_direction.dart';
import 'package:mohem_flutter_app/ui/chat/group_chat_bubble.dart'; import 'package:mohem_flutter_app/ui/chat/group_chat_bubble.dart';
import 'package:mohem_flutter_app/widgets/chat_app_bar_widge.dart'; import 'package:mohem_flutter_app/widgets/chat_app_bar_widge.dart';
import 'package:mohem_flutter_app/widgets/shimmer/dashboard_shimmer_widget.dart'; import 'package:mohem_flutter_app/widgets/shimmer/dashboard_shimmer_widget.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:signalr_netcore/signalr_client.dart';
import 'package:swipe_to/swipe_to.dart'; import 'package:swipe_to/swipe_to.dart';
class GroupChatDetailedScreenParams { class GroupChatDetailedScreenParams {
@ -83,8 +77,7 @@ class _GroupChatDetailScreenState extends State<GroupChatDetailScreen> {
data = Provider.of<ChatProviderModel>(context, listen: false); data = Provider.of<ChatProviderModel>(context, listen: false);
// callPro = Provider.of<ChatCallProvider>(context, listen: false); // callPro = Provider.of<ChatCallProvider>(context, listen: false);
if (params != null) { if (params != null) {
data.getGroupChatHistory( data.getGroupChatHistory(params!.groupChatDetails!
params!.groupChatDetails!
// senderUID: AppState().chatDetails!.response!.id!.toInt(), // senderUID: AppState().chatDetails!.response!.id!.toInt(),
// receiverUID: params!.groupChatHistory!.groupId!, // receiverUID: params!.groupChatHistory!.groupId!,
// loadMore: false, // loadMore: false,
@ -254,8 +247,7 @@ class _GroupChatDetailScreenState extends State<GroupChatDetailScreen> {
userStatus: 0, userStatus: 0,
userEmail: "", userEmail: "",
targetUserName: params!.groupChatDetails!.groupName!, targetUserName: params!.groupChatDetails!.groupName!,
userList: params!.groupChatDetails!.groupUserList! userList: params!.groupChatDetails!.groupUserList!),
),
) )
.paddingOnly(right: 21), .paddingOnly(right: 21),
], ],
@ -309,9 +301,7 @@ class _GroupChatDetailScreenState extends State<GroupChatDetailScreen> {
RotationTransition( RotationTransition(
turns: const AlwaysStoppedAnimation(45 / 360), turns: const AlwaysStoppedAnimation(45 / 360),
child: const Icon(Icons.attach_file_rounded, size: 26, color: MyColors.grey3AColor).onPress( child: const Icon(Icons.attach_file_rounded, size: 26, color: MyColors.grey3AColor).onPress(
() => { () => {m.selectImageToUpload(context)},
m.selectImageToUpload(context)
},
), ),
).paddingOnly(right: 15), ).paddingOnly(right: 15),
const Icon( const Icon(
@ -322,13 +312,12 @@ class _GroupChatDetailScreenState extends State<GroupChatDetailScreen> {
}), }),
SvgPicture.asset("assets/icons/chat/chat_send_icon.svg", height: 26, width: 26) SvgPicture.asset("assets/icons/chat/chat_send_icon.svg", height: 26, width: 26)
.onPress( .onPress(
() =>m.sendGroupChatMessage(context, () => m.sendGroupChatMessage(context,
targetUserId: params!.groupChatDetails!.groupId!, targetUserId: params!.groupChatDetails!.groupId!,
userStatus: 0, userStatus: 0,
userEmail: "", userEmail: "",
targetUserName: params!.groupChatDetails!.groupName!, targetUserName: params!.groupChatDetails!.groupName!,
userList: params!.groupChatDetails!.groupUserList! userList: params!.groupChatDetails!.groupUserList!),
),
) )
.paddingOnly(right: 21), .paddingOnly(right: 21),
], ],
@ -362,7 +351,7 @@ class _GroupChatDetailScreenState extends State<GroupChatDetailScreen> {
} }
void makeCall({required String callType}) async { void makeCall({required String callType}) async {
callPro.initCallListeners(); // callPro.initCallListeners();
print("================== Make call Triggered ============================"); print("================== Make call Triggered ============================");
// Map<String, dynamic> json = { // Map<String, dynamic> json = {
// "callerID": AppState().chatDetails!.response!.id!.toString(), // "callerID": AppState().chatDetails!.response!.id!.toString(),
@ -387,8 +376,8 @@ class _GroupChatDetailScreenState extends State<GroupChatDetailScreen> {
// callPro.stopListeners(); // callPro.stopListeners();
// }); // });
} }
GroupUserList getCurrentUser(int id, GroupResponse groupChatDetails) { GroupUserList getCurrentUser(int id, GroupResponse groupChatDetails) {
return groupChatDetails.groupUserList!.firstWhere((GroupUserList item) => item.id ==id); return groupChatDetails.groupUserList!.firstWhere((GroupUserList item) => item.id == id);
} }
} }

@ -1,10 +1,8 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_callkit_incoming/entities/call_event.dart'; import 'package:flutter_callkit_incoming/entities/call_event.dart';
import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart'; import 'package:flutter_callkit_incoming/flutter_callkit_incoming.dart';
@ -12,7 +10,6 @@ import 'package:flutter_countdown_timer/flutter_countdown_timer.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:mohem_flutter_app/api/dashboard_api_client.dart'; import 'package:mohem_flutter_app/api/dashboard_api_client.dart';
import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart';
import 'package:mohem_flutter_app/classes/chat_call_kit.dart';
import 'package:mohem_flutter_app/classes/colors.dart'; import 'package:mohem_flutter_app/classes/colors.dart';
import 'package:mohem_flutter_app/classes/utils.dart'; import 'package:mohem_flutter_app/classes/utils.dart';
import 'package:mohem_flutter_app/config/routes.dart'; import 'package:mohem_flutter_app/config/routes.dart';
@ -21,9 +18,6 @@ import 'package:mohem_flutter_app/extensions/string_extensions.dart';
import 'package:mohem_flutter_app/extensions/widget_extensions.dart'; import 'package:mohem_flutter_app/extensions/widget_extensions.dart';
import 'package:mohem_flutter_app/generated/locale_keys.g.dart'; import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
import 'package:mohem_flutter_app/main.dart'; import 'package:mohem_flutter_app/main.dart';
import 'package:mohem_flutter_app/models/chat/incoming_call_model.dart';
import 'package:mohem_flutter_app/models/itg/itg_main_response.dart';
import 'package:mohem_flutter_app/models/itg/itg_response_model.dart';
import 'package:mohem_flutter_app/models/offers_and_discounts/get_offers_list.dart'; import 'package:mohem_flutter_app/models/offers_and_discounts/get_offers_list.dart';
import 'package:mohem_flutter_app/models/privilege_list_model.dart'; import 'package:mohem_flutter_app/models/privilege_list_model.dart';
import 'package:mohem_flutter_app/provider/chat_call_provider.dart'; import 'package:mohem_flutter_app/provider/chat_call_provider.dart';
@ -42,7 +36,6 @@ import 'package:mohem_flutter_app/widgets/shimmer/offers_shimmer_widget.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:signalr_netcore/signalr_client.dart'; import 'package:signalr_netcore/signalr_client.dart';
import 'package:http/http.dart' as http;
class DashboardScreen extends StatefulWidget { class DashboardScreen extends StatefulWidget {
DashboardScreen({Key? key}) : super(key: key); DashboardScreen({Key? key}) : super(key: key);

@ -96,7 +96,8 @@ class _DynamicInputScreenState extends State<DynamicInputScreen> {
SubmitEITTransactionList submitEITTransactionList = await MyAttendanceApiClient().submitEitTransaction(dESCFLEXCONTEXTCODE, dynamicParams!.dynamicId, values, empID: dynamicParams!.selectedEmp); SubmitEITTransactionList submitEITTransactionList = await MyAttendanceApiClient().submitEitTransaction(dESCFLEXCONTEXTCODE, dynamicParams!.dynamicId, values, empID: dynamicParams!.selectedEmp);
Utils.hideLoading(context); Utils.hideLoading(context);
await Navigator.pushNamed(context, AppRoutes.requestSubmitScreen, await Navigator.pushNamed(context, AppRoutes.requestSubmitScreen,
arguments: RequestSubmitScreenParams(LocaleKeys.submit.tr(), submitEITTransactionList.pTRANSACTIONID!, submitEITTransactionList.pITEMKEY!, 'eit',isAttachmentMandatory: dynamicParams!.isAttachmentMandatory)); arguments: RequestSubmitScreenParams(LocaleKeys.submit.tr(), submitEITTransactionList.pTRANSACTIONID!, submitEITTransactionList.pITEMKEY!, 'eit',
isAttachmentMandatory: dynamicParams!.isAttachmentMandatory));
if (!AppState().cancelRequestTrancsection) { if (!AppState().cancelRequestTrancsection) {
return; return;
} }

Loading…
Cancel
Save