diff --git a/lib/im/im_view/im_page.dart b/lib/im/im_view/im_page.dart index 1518ca38..e1a27538 100644 --- a/lib/im/im_view/im_page.dart +++ b/lib/im/im_view/im_page.dart @@ -127,7 +127,7 @@ class _IMPage extends State implements OnChatMessage { List queryUserIds = userIds.where((u) => contacts.where((c) => c.userId == u).isEmpty).toList(); /// TODO: queryUserIds request Api } - contactMap = groupBy(contacts, (p0) => p0.userId); + contactMap = contacts.lGroupBy((p0) => p0.userId).mGroupItem; if (mounted) { setState(() {}); @@ -138,15 +138,19 @@ class _IMPage extends State implements OnChatMessage { Message message = await hxDatabase.lastMessage(userId); if (message != null) { lastMessageMap[userId] = message; + refreshState(); } } - Map groupBy(Iterable values, S Function(T) key) { - var map = {}; - for (var element in values) { - map[key(element)] ??= element; - } - return map; + void updateUnreadCount() async { + SharedPreferences shared = await SharedPreferences.getInstance(); + String userId = shared.getString("userId"); + unreadCountMap = await hxDatabase.messageUnreadCount(userIds, userId); + refreshState(); + } + + refreshState() { + if (mounted) setState(() {}); } // queryMessage() async {