Voip Call

development_aamir
Aamir Muhammad 2 years ago
parent f8ba1957cd
commit 33fb6fe6be

@ -1,9 +1,7 @@
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:mohem_flutter_app/api/api_client.dart';
import 'package:mohem_flutter_app/app_state/app_state.dart';
@ -310,4 +308,59 @@ class ChatApiClient {
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;
String _iosVoipPlayerID = "";
String get iosVoipPlayerID => _iosVoipPlayerID;

@ -1,11 +1,9 @@
import 'dart:convert';
import 'dart:io';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_callkit_incoming/entities/entities.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/app_state/app_state.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/provider/chat_call_provider.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';
class ChatVoipCall {
@ -106,7 +101,7 @@ class ChatVoipCall {
}
}
Future<void> declineCall({ payload}) async {
Future<void> declineCall({payload}) async {
IncomingCallModel data = IncomingCallModel.fromJson(jsonDecode(payload));
if (isUserOnline) {
@ -154,10 +149,11 @@ class ChatVoipCall {
// logger.log(Level.error, "API-EVENT-END");
}
Future<void> voipDeclineCall(IosCallPayload? _iosCallPayload ) async {
Future<void> voipDeclineCall(IosCallPayload? _iosCallPayload) async {
try {
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) {
print(err);
}
@ -177,4 +173,3 @@ class ChatVoipCall {
}
}
}

@ -37,7 +37,6 @@ class ApiConsts {
static String oneSignalCall = "https://onesignal.com/api/v1/";
static String oneSignalAppID = "472e4582-5c44-47ab-a5f5-9369b8967107";
//Brain Marathon Constants
static String marathonBaseUrl = "https://marathoon.com/service/api/";
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:firebase_core_web/firebase_core_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:geolocator_web/geolocator_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:video_player_web/video_player_web.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
// ignore: public_member_api_docs
void registerPlugins(Registrar registrar) {
AudioSessionWeb.registerWith(registrar);

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

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

@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:convert';
import 'package:audio_waveforms/audio_waveforms.dart';
import 'package:easy_localization/easy_localization.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/generated/locale_keys.g.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_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_login_token_model.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/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/custom_auto_direction.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/shimmer/dashboard_shimmer_widget.dart';
import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:signalr_netcore/signalr_client.dart';
import 'package:swipe_to/swipe_to.dart';
class GroupChatDetailedScreenParams {
@ -83,8 +77,7 @@ class _GroupChatDetailScreenState extends State<GroupChatDetailScreen> {
data = Provider.of<ChatProviderModel>(context, listen: false);
// callPro = Provider.of<ChatCallProvider>(context, listen: false);
if (params != null) {
data.getGroupChatHistory(
params!.groupChatDetails!
data.getGroupChatHistory(params!.groupChatDetails!
// senderUID: AppState().chatDetails!.response!.id!.toInt(),
// receiverUID: params!.groupChatHistory!.groupId!,
// loadMore: false,
@ -254,8 +247,7 @@ class _GroupChatDetailScreenState extends State<GroupChatDetailScreen> {
userStatus: 0,
userEmail: "",
targetUserName: params!.groupChatDetails!.groupName!,
userList: params!.groupChatDetails!.groupUserList!
),
userList: params!.groupChatDetails!.groupUserList!),
)
.paddingOnly(right: 21),
],
@ -309,9 +301,7 @@ class _GroupChatDetailScreenState extends State<GroupChatDetailScreen> {
RotationTransition(
turns: const AlwaysStoppedAnimation(45 / 360),
child: const Icon(Icons.attach_file_rounded, size: 26, color: MyColors.grey3AColor).onPress(
() => {
m.selectImageToUpload(context)
},
() => {m.selectImageToUpload(context)},
),
).paddingOnly(right: 15),
const Icon(
@ -322,13 +312,12 @@ class _GroupChatDetailScreenState extends State<GroupChatDetailScreen> {
}),
SvgPicture.asset("assets/icons/chat/chat_send_icon.svg", height: 26, width: 26)
.onPress(
() =>m.sendGroupChatMessage(context,
() => m.sendGroupChatMessage(context,
targetUserId: params!.groupChatDetails!.groupId!,
userStatus: 0,
userEmail: "",
targetUserName: params!.groupChatDetails!.groupName!,
userList: params!.groupChatDetails!.groupUserList!
),
userList: params!.groupChatDetails!.groupUserList!),
)
.paddingOnly(right: 21),
],
@ -362,7 +351,7 @@ class _GroupChatDetailScreenState extends State<GroupChatDetailScreen> {
}
void makeCall({required String callType}) async {
callPro.initCallListeners();
// callPro.initCallListeners();
print("================== Make call Triggered ============================");
// Map<String, dynamic> json = {
// "callerID": AppState().chatDetails!.response!.id!.toString(),
@ -387,8 +376,8 @@ class _GroupChatDetailScreenState extends State<GroupChatDetailScreen> {
// callPro.stopListeners();
// });
}
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:convert';
import 'dart:io';
import 'dart:ui' as ui;
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_callkit_incoming/entities/call_event.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:mohem_flutter_app/api/dashboard_api_client.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/utils.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/generated/locale_keys.g.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/privilege_list_model.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:pull_to_refresh/pull_to_refresh.dart';
import 'package:signalr_netcore/signalr_client.dart';
import 'package:http/http.dart' as http;
class DashboardScreen extends StatefulWidget {
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);
Utils.hideLoading(context);
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) {
return;
}

Loading…
Cancel
Save