From 148d75ad8dba8e502bb42820d36841d98ba880fa Mon Sep 17 00:00:00 2001 From: zsw Date: Thu, 19 Sep 2024 12:26:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E6=B6=88=E6=81=AF=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/im/im_view/im_page.dart | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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 {