Merge branch 'development_aamir' into 'master'

Fav Users Images Fix

See merge request Cloud_Solution/mohemm-flutter-app!100
merge-requests/101/merge
haroon amjad 3 years ago
commit ac2691f4ae

@ -125,8 +125,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
AppState().chatDetails!.response!.id.toString(), AppState().chatDetails!.response!.id.toString(),
), ),
); );
sort();
notifyListeners(); notifyListeners();
if (searchedChats!.isNotEmpty) { if (searchedChats!.isNotEmpty || favUsersList.isNotEmpty) {
getUserImages(); getUserImages();
} }
} }
@ -141,19 +142,11 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
if (isNewChat) userChatHistory = []; if (isNewChat) userChatHistory = [];
if (!loadMore) paginationVal = 0; if (!loadMore) paginationVal = 0;
isChatScreenActive = true; isChatScreenActive = true;
// if (chatHubConnection.state != HubConnectionState.Connected) {
// getUserAutoLoginToken().whenComplete(() async {
// await buildHubConnection();
// getSingleUserChatHistory(senderUID: senderUID, receiverUID: receiverUID, loadMore: loadMore);
// });
// return;
// }
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) {
userChatHistory = []; userChatHistory = [];
} else if (loadMore) { } else if (loadMore) {
// userChatHistory = [];
Utils.showToast("No More Data To Load"); Utils.showToast("No More Data To Load");
} }
} else { } else {
@ -533,7 +526,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
await chatHubConnection.invoke("AddChatUserAsync", args: <Object>[json.decode(chatData)]); await chatHubConnection.invoke("AddChatUserAsync", args: <Object>[json.decode(chatData)]);
} }
void sendChatMessage(int targetUserId, String targetUserName, BuildContext context) async { void sendChatMessage(int targetUserId, int userStatus, String targetUserName, BuildContext context) async {
dynamic contain = searchedChats!.where((ChatUser element) => element.id == targetUserId); dynamic contain = searchedChats!.where((ChatUser element) => element.id == targetUserId);
if (contain.isEmpty) { if (contain.isEmpty) {
searchedChats!.add( searchedChats!.add(
@ -546,6 +539,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
isImageLoaded: true, isImageLoaded: true,
isTyping: false, isTyping: false,
isFav: false, isFav: false,
userStatus: userStatus,
userLocalDownlaodedImage: null, userLocalDownlaodedImage: null,
), ),
); );
@ -764,9 +758,18 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
void getUserImages() async { void getUserImages() async {
List<String> emails = []; List<String> emails = [];
for (ChatUser element in searchedChats!) { List<ChatUser> exists = [], unique = [];
exists.addAll(searchedChats!);
exists.addAll(favUsersList!);
Map<String, ChatUser> profileMap = {};
for (ChatUser item in exists) {
profileMap[item.email!] = item;
}
unique = profileMap.values.toList();
for (ChatUser element in unique!) {
emails.add(await EmailImageEncryption().encrypt(val: element.email!)); 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 (ChatUser user in searchedChats!) {
for (ChatUserImageModel uImage in chatImages) { for (ChatUserImageModel uImage in chatImages) {
@ -847,7 +850,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
String path = await downChatMedia(encodedString, fileTypeName ?? ""); String path = await downChatMedia(encodedString, fileTypeName ?? "");
Utils.hideLoading(context); Utils.hideLoading(context);
OpenFile.open(path); OpenFile.open(path);
} catch (e) { } catch (e) {
Utils.showToast("Cannot open file."); Utils.showToast("Cannot open file.");
} }

@ -54,11 +54,10 @@ class ChatBubble extends StatelessWidget {
screenOffset = Offset(windowSize.width / 2, windowSize.height / 2); screenOffset = Offset(windowSize.width / 2, windowSize.height / 2);
makeAssign(); makeAssign();
data = Provider.of<ChatProviderModel>(context, listen: false); data = Provider.of<ChatProviderModel>(context, listen: false);
return isCurrentUser ? currentUser(context) : receiptUser(context); return isCurrentUser ? currentUser(context) : receiptUser(context);
} }
Widget currentUser(context) { Widget currentUser(BuildContext context) {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [

@ -223,7 +223,7 @@ class _ChatDetailScreenState extends State<ChatDetailScreen> {
), ),
).paddingOnly(right: 25), ).paddingOnly(right: 25),
SvgPicture.asset("assets/icons/chat/chat_send_icon.svg", height: 26, width: 26).onPress( SvgPicture.asset("assets/icons/chat/chat_send_icon.svg", height: 26, width: 26).onPress(
() => m.sendChatMessage(params!.chatUser!.id!, params!.chatUser!.userName!, context), () => m.sendChatMessage(params!.chatUser!.id!, params!.chatUser!.userStatus ?? 0, params!.chatUser!.userName!, context),
), ),
], ],
), ),
@ -239,7 +239,6 @@ class _ChatDetailScreenState extends State<ChatDetailScreen> {
} }
Widget showReplyImage(List<SingleUserChatModel> data, ChatProviderModel m) { Widget showReplyImage(List<SingleUserChatModel> data, ChatProviderModel m) {
logger.d(jsonEncode(data));
if (data.first.isImageLoaded! && data.first.image != null) { if (data.first.isImageLoaded! && data.first.image != null) {
return Container( return Container(
width: 43, width: 43,

@ -38,23 +38,23 @@ class _ChatHomeState extends State<ChatHome> {
data.clearAll(); data.clearAll();
} }
void fetchAgain() { // void fetchAgain() {
print("Fetch Triggered"); // print("Fetch Triggered");
if (chatHubConnection.state != HubConnectionState.Connected) { // if (chatHubConnection.state != HubConnectionState.Connected) {
data.getUserAutoLoginToken().whenComplete(() async { // data.getUserAutoLoginToken().whenComplete(() async {
await data.buildHubConnection(); // await data.buildHubConnection();
data.getUserRecentChats(); // data.getUserRecentChats();
}); // });
return; // return;
} // }
if (data.searchedChats == null || data.searchedChats!.isEmpty) { // if (data.searchedChats == null || data.searchedChats!.isEmpty) {
data.getUserRecentChats(); // data.getUserRecentChats();
} // }
} // }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
fetchAgain(); // fetchAgain();
return Scaffold( return Scaffold(
backgroundColor: MyColors.white, backgroundColor: MyColors.white,
appBar: AppBarWidget(context, title: LocaleKeys.chat.tr(), showHomeButton: true), appBar: AppBarWidget(context, title: LocaleKeys.chat.tr(), showHomeButton: true),

@ -72,6 +72,9 @@ class _DashboardScreenState extends State<DashboardScreen> {
void _bHubCon() { void _bHubCon() {
cProvider.getUserAutoLoginToken().whenComplete(() { cProvider.getUserAutoLoginToken().whenComplete(() {
cProvider.buildHubConnection(); cProvider.buildHubConnection();
Future.delayed(const Duration(seconds: 2), () {
cProvider.invokeChatCounter(userId: AppState().chatDetails!.response!.id!);
});
}); });
} }

Loading…
Cancel
Save