Merge branch 'master' into development_haroon

merge-requests/101/head
haroon amjad 3 years ago
commit b22ecaff3a

@ -125,8 +125,9 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
AppState().chatDetails!.response!.id.toString(),
),
);
sort();
notifyListeners();
if (searchedChats!.isNotEmpty) {
if (searchedChats!.isNotEmpty || favUsersList.isNotEmpty) {
getUserImages();
}
}
@ -141,19 +142,11 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
if (isNewChat) userChatHistory = [];
if (!loadMore) paginationVal = 0;
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);
if (response.statusCode == 204) {
if (isNewChat) {
userChatHistory = [];
} else if (loadMore) {
// userChatHistory = [];
Utils.showToast("No More Data To Load");
}
} else {
@ -533,7 +526,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
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);
if (contain.isEmpty) {
searchedChats!.add(
@ -546,6 +539,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
isImageLoaded: true,
isTyping: false,
isFav: false,
userStatus: userStatus,
userLocalDownlaodedImage: null,
),
);
@ -764,9 +758,18 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
void getUserImages() async {
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!));
}
List<ChatUserImageModel> chatImages = await ChatApiClient().getUsersImages(encryptedEmails: emails);
for (ChatUser user in searchedChats!) {
for (ChatUserImageModel uImage in chatImages) {
@ -847,7 +850,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
String path = await downChatMedia(encodedString, fileTypeName ?? "");
Utils.hideLoading(context);
OpenFile.open(path);
} catch (e) {
Utils.showToast("Cannot open file.");
}

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

@ -223,7 +223,7 @@ class _ChatDetailScreenState extends State<ChatDetailScreen> {
),
).paddingOnly(right: 25),
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) {
logger.d(jsonEncode(data));
if (data.first.isImageLoaded! && data.first.image != null) {
return Container(
width: 43,

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

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

Loading…
Cancel
Save