|
|
@ -115,9 +115,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage { |
|
|
|
|
|
|
|
|
|
|
|
debugPrint("messages: queryList"); |
|
|
|
debugPrint("messages: queryList"); |
|
|
|
messages = await hxDatabase.queryList(userId); |
|
|
|
messages = await hxDatabase.queryList(userId); |
|
|
|
messages.forEach((element) { |
|
|
|
|
|
|
|
debugPrint("messages: ${element.toJson()}"); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
userIds = messages |
|
|
|
userIds = messages |
|
|
|
.map((e) => e.toId != userId ? e.toId : e.fromId) |
|
|
|
.map((e) => e.toId != userId ? e.toId : e.fromId) |
|
|
|
.toSet() |
|
|
|
.toSet() |
|
|
@ -126,7 +124,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage { |
|
|
|
List<ImUser> contacts = (await hxDatabase.queryImUser(userIds)) ?? []; |
|
|
|
List<ImUser> contacts = (await hxDatabase.queryImUser(userIds)) ?? []; |
|
|
|
|
|
|
|
|
|
|
|
unreadCountMap = await hxDatabase.messageUnreadCount(userIds, userId); |
|
|
|
unreadCountMap = await hxDatabase.messageUnreadCount(userIds, userId); |
|
|
|
lastMessageMap = messages.lGroupBy((p0) => p0.toId != userId ? p0.toId : p0.fromId).mGroupItem; |
|
|
|
lastMessageMap = messages.lGroupBy((p0) => p0.toId != userId ? p0.toId : p0.fromId).mGroupItem(key: (p1) => num.parse(p1.time)); |
|
|
|
|
|
|
|
|
|
|
|
if (contacts?.isEmpty ?? true) { |
|
|
|
if (contacts?.isEmpty ?? true) { |
|
|
|
await queryMemberInfo(userIds); |
|
|
|
await queryMemberInfo(userIds); |
|
|
@ -138,7 +136,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
contactMap = contacts.lGroupBy((p0) => p0.mid).mGroupItem; |
|
|
|
contactMap = contacts.lGroupBy((p0) => p0.mid).mGroupItem(); |
|
|
|
|
|
|
|
|
|
|
|
if (mounted) { |
|
|
|
if (mounted) { |
|
|
|
setState(() {}); |
|
|
|
setState(() {}); |
|
|
@ -147,6 +145,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage { |
|
|
|
|
|
|
|
|
|
|
|
void updateLastMessage(String userId) async { |
|
|
|
void updateLastMessage(String userId) async { |
|
|
|
Message message = await hxDatabase.lastMessage(userId); |
|
|
|
Message message = await hxDatabase.lastMessage(userId); |
|
|
|
|
|
|
|
debugPrint("lastmessage: $userId ${message.content} ${message.toJson()}"); |
|
|
|
if (message != null) { |
|
|
|
if (message != null) { |
|
|
|
lastMessageMap[userId] = message; |
|
|
|
lastMessageMap[userId] = message; |
|
|
|
refreshState(); |
|
|
|
refreshState(); |
|
|
@ -246,7 +245,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage { |
|
|
|
baseData.data.forEach((element) async { |
|
|
|
baseData.data.forEach((element) async { |
|
|
|
await hxDatabase.insertOrUpdateImUser(element.toJson()); |
|
|
|
await hxDatabase.insertOrUpdateImUser(element.toJson()); |
|
|
|
}); |
|
|
|
}); |
|
|
|
contactMap = baseData.data.lGroupBy((p0) => p0.mid).mGroupItem; |
|
|
|
contactMap = baseData.data.lGroupBy((p0) => p0.mid).mGroupItem(); |
|
|
|
setState(() {}); |
|
|
|
setState(() {}); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -423,8 +422,8 @@ class _IMPage extends State<IMPage> implements OnChatMessage { |
|
|
|
"toUser": contactMap[userIds[position]], |
|
|
|
"toUser": contactMap[userIds[position]], |
|
|
|
}, |
|
|
|
}, |
|
|
|
).then((value) { |
|
|
|
).then((value) { |
|
|
|
|
|
|
|
unreadCountMap[userIds[position]] = 0; |
|
|
|
updateLastMessage(userIds[position]); |
|
|
|
updateLastMessage(userIds[position]); |
|
|
|
_refresh(); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
}, |
|
|
|
child: chatItem(userIds[position]), |
|
|
|
child: chatItem(userIds[position]), |
|
|
|