Merge branch 'development_aamir' into 'master'

Chat Fixes

See merge request Cloud_Solution/mohemm-flutter-app!107
merge-requests/109/head
haroon amjad 3 years ago
commit 31c24a54ec

@ -60,17 +60,6 @@ class ChatApiClient {
json.decode(response.body), json.decode(response.body),
); );
} catch (e) { } catch (e) {
// if (e.message == "api_common_unauthorized") {
// user.UserAutoLoginModel userLoginResponse = await ChatApiClient().getUserLoginToken();
// if (userLoginResponse.response != null) {
// AppState().setchatUserDetails = userLoginResponse;
// getRecentChats();
// } else {
// Utils.showToast(
// userLoginResponse.errorResponses!.first.fieldName.toString() + " Erorr",
// );
// }
// }
throw e; throw e;
} }
} }
@ -97,16 +86,6 @@ class ChatApiClient {
} }
return response; return response;
} catch (e) { } catch (e) {
// e as APIException;
// if (e.message == "api_common_unauthorized") {
// user.UserAutoLoginModel userLoginResponse = await ChatApiClient().getUserLoginToken();
// if (userLoginResponse.response != null) {
// AppState().setchatUserDetails = userLoginResponse;
// getSingleUserChatHistory(senderUID: senderUID, receiverUID: receiverUID, loadMore: loadMore, paginationVal: paginationVal);
// } else {
// Utils.showToast(userLoginResponse.errorResponses!.first.fieldName.toString() + " Erorr");
// }
// }
throw e; throw e;
} }
} }
@ -135,15 +114,6 @@ class ChatApiClient {
return favoriteChatUser; return favoriteChatUser;
} catch (e) { } catch (e) {
e as APIException; e as APIException;
// if (e.message == "api_common_unauthorized") {
// user.UserAutoLoginModel userLoginResponse = await ChatApiClient().getUserLoginToken();
// if (userLoginResponse.response != null) {
// AppState().setchatUserDetails = userLoginResponse;
// unFavUser(userID: userID, targetUserID: targetUserID);
// } else {
// Utils.showToast(userLoginResponse.errorResponses!.first.fieldName.toString() + " Erorr");
// }
// }
throw e; throw e;
} }
} }

@ -36,6 +36,8 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
String chatCID = ''; String chatCID = '';
bool isLoading = true; bool isLoading = true;
bool isChatScreenActive = false; bool isChatScreenActive = false;
int receiverID = 0;
late File selectedFile; late File selectedFile;
bool isFileSelected = false; bool isFileSelected = false;
String sFileType = ""; String sFileType = "";
@ -142,6 +144,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
if (isNewChat) userChatHistory = []; if (isNewChat) userChatHistory = [];
if (!loadMore) paginationVal = 0; if (!loadMore) paginationVal = 0;
isChatScreenActive = true; 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 (response.statusCode == 204) {
if (isNewChat) { if (isNewChat) {
@ -160,7 +163,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
isLoading = false; isLoading = false;
notifyListeners(); notifyListeners();
markRead(userChatHistory, receiverUID); if (isChatScreenActive && receiverUID == receiverID) {
markRead(userChatHistory, receiverUID);
}
generateConvId(); generateConvId();
} }
@ -371,9 +376,11 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
} }
setMsgTune(); setMsgTune();
userChatHistory.insert(0, data.first); if (isChatScreenActive && data.first.currentUserId == receiverID) {
userChatHistory.insert(0, data.first);
}
if (searchedChats != null && !isChatScreenActive) { if (searchedChats != null) {
for (ChatUser user in searchedChats!) { for (ChatUser user in searchedChats!) {
if (user.id == data.first.currentUserId) { if (user.id == data.first.currentUserId) {
int tempCount = user.unreadMessageCount ?? 0; int tempCount = user.unreadMessageCount ?? 0;
@ -384,7 +391,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
List list = [ List list = [
{"userChatHistoryId": data.first.userChatHistoryId, "TargetUserId": temp.first.targetUserId, "isDelivered": true, "isSeen": isChatScreenActive ? true : false} {"userChatHistoryId": data.first.userChatHistoryId, "TargetUserId": temp.first.targetUserId, "isDelivered": true, "isSeen": isChatScreenActive && data.first.currentUserId == receiverID ? true : false}
]; ];
updateUserChatHistoryOnMsg(list); updateUserChatHistoryOnMsg(list);
invokeChatCounter(userId: AppState().chatDetails!.response!.id!); invokeChatCounter(userId: AppState().chatDetails!.response!.id!);
@ -746,6 +753,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
searchedChats = pChatHistory; searchedChats = pChatHistory;
search.clear(); search.clear();
isChatScreenActive = false; isChatScreenActive = false;
receiverID = 0;
paginationVal = 0; paginationVal = 0;
message.text = ''; message.text = '';
isFileSelected = false; isFileSelected = false;
@ -759,6 +767,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
searchedChats = pChatHistory; searchedChats = pChatHistory;
search.clear(); search.clear();
isChatScreenActive = false; isChatScreenActive = false;
receiverID = 0;
paginationVal = 0; paginationVal = 0;
message.text = ''; message.text = '';
isFileSelected = false; isFileSelected = false;
@ -868,7 +877,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
void onNewChatConversion(List<Object?>? params) { void onNewChatConversion(List<Object?>? params) {
dynamic items = params!.toList(); dynamic items = params!.toList();
logger.d(items);
chatUConvCounter = items[0]["singleChatCount"] ?? 0; chatUConvCounter = items[0]["singleChatCount"] ?? 0;
notifyListeners(); notifyListeners();
} }

@ -101,15 +101,22 @@ class ChatBubble extends StatelessWidget {
], ],
), ),
), ),
).paddingOnly(right: 5, bottom: 7), ).paddingOnly(bottom: 7),
if (fileTypeID == 12 || fileTypeID == 4 || fileTypeID == 3) if (fileTypeID == 12 || fileTypeID == 4 || fileTypeID == 3)
showImage(isReplyPreview: false, fileName: cItem.contant!, fileTypeDescription: cItem.fileTypeResponse!.fileTypeDescription).paddingOnly(right: 5).onPress(() { ClipRRect(
showDialog( borderRadius: BorderRadius.circular(5.0),
context: context, child: SizedBox(
anchorPoint: screenOffset, height: 140,
builder: (BuildContext context) => ChatImagePreviewScreen(imgTitle: cItem.contant!, img: cItem.image!), width: 227,
); child: showImage(isReplyPreview: false, fileName: cItem.contant!, fileTypeDescription: cItem.fileTypeResponse!.fileTypeDescription).onPress(() {
}) showDialog(
context: context,
anchorPoint: screenOffset,
builder: (BuildContext context) => ChatImagePreviewScreen(imgTitle: cItem.contant!, img: cItem.image!),
);
}),
),
).paddingOnly(bottom: 4)
else else
Row( Row(
children: [ children: [
@ -132,12 +139,12 @@ class ChatBubble extends StatelessWidget {
), ),
), ),
], ],
).paddingOnly(top: 11, left: 13, right: 7, bottom: 5).objectContainerView(disablePadding: true).paddingOnly(left: MediaQuery.of(context).size.width * 0.3); ).paddingOnly(top: 11, left: 13, right: 13, bottom: 5).objectContainerView(disablePadding: true).paddingOnly(left: MediaQuery.of(context).size.width * 0.3);
} }
Widget receiptUser(BuildContext context) { Widget receiptUser(BuildContext context) {
return Container( return Container(
padding: const EdgeInsets.only(top: 11, left: 13, right: 7, bottom: 5), padding: const EdgeInsets.only(top: 11, left: 13, right: 13, bottom: 5),
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),
gradient: const LinearGradient( gradient: const LinearGradient(
@ -190,15 +197,22 @@ class ChatBubble extends StatelessWidget {
], ],
), ),
), ),
).paddingOnly(right: 5, bottom: 7), ).paddingOnly(bottom: 7),
if (fileTypeID == 12 || fileTypeID == 4 || fileTypeID == 3) if (fileTypeID == 12 || fileTypeID == 4 || fileTypeID == 3)
showImage(isReplyPreview: false, fileName: cItem.contant ?? "", fileTypeDescription: cItem.fileTypeResponse!.fileTypeDescription ?? "image/jpg").paddingOnly(right: 5).onPress(() { ClipRRect(
showDialog( borderRadius: BorderRadius.circular(5.0),
context: context, child: SizedBox(
anchorPoint: screenOffset, height: 140,
builder: (BuildContext context) => ChatImagePreviewScreen(imgTitle: cItem.contant ?? "", img: cItem.image!), width: 227,
); child: showImage(isReplyPreview: false, fileName: cItem.contant ?? "", fileTypeDescription: cItem.fileTypeResponse!.fileTypeDescription ?? "image/jpg").onPress(() {
}) showDialog(
context: context,
anchorPoint: screenOffset,
builder: (BuildContext context) => ChatImagePreviewScreen(imgTitle: cItem.contant ?? "", img: cItem.image!),
);
}),
),
).paddingOnly(bottom: 4)
else else
Row( Row(
children: [ children: [
@ -212,7 +226,9 @@ class ChatBubble extends StatelessWidget {
), ),
Align( Align(
alignment: Alignment.centerRight, alignment: Alignment.centerRight,
child: dateTime.toText10(color: Colors.white.withOpacity(.71),), child: dateTime.toText10(
color: Colors.white.withOpacity(.71),
),
), ),
], ],
), ),
@ -220,12 +236,15 @@ class ChatBubble extends StatelessWidget {
} }
Widget showImage({required bool isReplyPreview, required String fileName, required String fileTypeDescription}) { Widget showImage({required bool isReplyPreview, required String fileName, required String fileTypeDescription}) {
if (isReplyPreview) {}
if (cItem.isImageLoaded! && cItem.image != null) { if (cItem.isImageLoaded! && cItem.image != null) {
return Image.memory( return Image.memory(
cItem.image!, cItem.image!,
height: isReplyPreview ? 32 : 140, height: isReplyPreview ? 32 : 140,
width: isReplyPreview ? 32 : 227, width: isReplyPreview ? 32 : 227,
fit: BoxFit.cover, fit: BoxFit.cover,
alignment: Alignment.center,
); );
} else { } else {
return FutureBuilder<Uint8List>( return FutureBuilder<Uint8List>(
@ -233,7 +252,7 @@ class ChatBubble extends StatelessWidget {
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) { builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.connectionState != ConnectionState.waiting) { if (snapshot.connectionState != ConnectionState.waiting) {
if (snapshot.data == null) { if (snapshot.data == null) {
return SizedBox(); return const SizedBox();
} else { } else {
cItem.image = snapshot.data; cItem.image = snapshot.data;
cItem.isImageLoaded = true; cItem.isImageLoaded = true;
@ -242,6 +261,7 @@ class ChatBubble extends StatelessWidget {
height: isReplyPreview ? 32 : 140, height: isReplyPreview ? 32 : 140,
width: isReplyPreview ? 32 : 227, width: isReplyPreview ? 32 : 227,
fit: BoxFit.cover, fit: BoxFit.cover,
alignment: Alignment.center,
); );
} }
} else { } else {

@ -85,14 +85,14 @@ class _ChatDetailScreenState extends State<ChatDetailScreen> {
showTyping: true, showTyping: true,
chatUser: params!.chatUser, chatUser: params!.chatUser,
actions: [ actions: [
SvgPicture.asset("assets/icons/chat/call.svg", width: 21, height: 23).onPress(() { // SvgPicture.asset("assets/icons/chat/call.svg", width: 21, height: 23).onPress(() {
// makeCall(callType: "AUDIO", con: hubConnection); // // makeCall(callType: "AUDIO", con: hubConnection);
}), // }),
24.width, // 24.width,
SvgPicture.asset("assets/icons/chat/video_call.svg", width: 21, height: 18).onPress(() { // SvgPicture.asset("assets/icons/chat/video_call.svg", width: 21, height: 18).onPress(() {
// makeCall(callType: "VIDEO", con: hubConnection); // // makeCall(callType: "VIDEO", con: hubConnection);
}), // }),
21.width, // 21.width,
], ],
), ),
body: SafeArea( body: SafeArea(

Loading…
Cancel
Save