From cff9e73cafe21c6bba4eb3fc1f4dba1b3b566fc0 Mon Sep 17 00:00:00 2001 From: SL Date: Sun, 18 Aug 2024 17:34:18 +0800 Subject: [PATCH] fix:update conversation reminders --- example/lib/chat.dart | 34 ++++++++++----------- example/lib/contestation.dart | 4 +-- example/lib/home.dart | 57 +++++++++++++---------------------- 3 files changed, 40 insertions(+), 55 deletions(-) diff --git a/example/lib/chat.dart b/example/lib/chat.dart index 3a9768a..0bcf952 100644 --- a/example/lib/chat.dart +++ b/example/lib/chat.dart @@ -246,23 +246,23 @@ class ChatListDataState extends State { padding: const EdgeInsets.only(left: 0, top: 5, right: 0, bottom: 5), child: Row( children: [ - // Container( - // decoration: const BoxDecoration( - // shape: BoxShape.rectangle, - // borderRadius: BorderRadius.all(Radius.circular(20)), - // color: Color.fromARGB(255, 215, 80, 1)), - // width: 50, - // alignment: Alignment.center, - // height: 50, - // margin: const EdgeInsets.fromLTRB(0, 0, 10, 0), - // child: Text( - // CommonUtils.getAvatar(uiMsg.wkMsg.fromUID), - // style: const TextStyle( - // color: Colors.white, - // fontSize: 20, - // fontWeight: FontWeight.bold), - // ), - // ), + Container( + decoration: const BoxDecoration( + shape: BoxShape.rectangle, + borderRadius: BorderRadius.all(Radius.circular(20)), + color: Color.fromARGB(255, 215, 80, 1)), + width: 50, + alignment: Alignment.center, + height: 50, + margin: const EdgeInsets.fromLTRB(0, 0, 10, 0), + child: Text( + CommonUtils.getAvatar(uiMsg.wkMsg.fromUID), + style: const TextStyle( + color: Colors.white, + fontSize: 20, + fontWeight: FontWeight.bold), + ), + ), Expanded( child: Container( alignment: Alignment.centerLeft, diff --git a/example/lib/contestation.dart b/example/lib/contestation.dart index 52ff0ad..666d54b 100644 --- a/example/lib/contestation.dart +++ b/example/lib/contestation.dart @@ -1,13 +1,13 @@ import 'package:wukongimfluttersdk/entity/conversation.dart'; +import 'package:wukongimfluttersdk/entity/reminder.dart'; class UIConversation { String lastContent = ''; String channelAvatar = ''; String channelName = ''; - int isMentionMe = 0; WKUIConversationMsg msg; UIConversation(this.msg); - + List? reminders = []; String getUnreadCount() { if (msg.unreadCount > 0) { return '${msg.unreadCount}'; diff --git a/example/lib/home.dart b/example/lib/home.dart index d13e35c..706a47a 100644 --- a/example/lib/home.dart +++ b/example/lib/home.dart @@ -1,5 +1,6 @@ import 'package:example/const.dart'; import 'package:flutter/material.dart'; +import 'package:wukongimfluttersdk/common/logs.dart'; import 'package:wukongimfluttersdk/entity/conversation.dart'; import 'package:wukongimfluttersdk/entity/reminder.dart'; import 'package:wukongimfluttersdk/type/const.dart'; @@ -77,7 +78,7 @@ class ListViewShowDataState extends State { setState(() {}); }); WKIM.shared.conversationManager - .addOnRefreshMsgListListener('chat_conversation', (msgs) { + .addOnRefreshMsgListListener('chat_conversation', (msgs) async { if (msgs.isEmpty) { return; } @@ -88,6 +89,7 @@ class ListViewShowDataState extends State { if (msgList[i].msg.channelID == msg.channelID) { msgList[i].msg = msg; msgList[i].lastContent = ''; + msgList[i].reminders = null; isAdd = false; break; } @@ -103,26 +105,7 @@ class ListViewShowDataState extends State { setState(() {}); } }); - // 监听更新消息事件 - // WKIM.shared.conversationManager.addOnRefreshMsgListener('chat_conversation', - // (msg, isEnd) async { - // bool isAdd = true; - // for (var i = 0; i < msgList.length; i++) { - // if (msgList[i].msg.channelID == msg.channelID && - // msgList[i].msg.channelType == msg.channelType) { - // msgList[i].msg = msg; - // msgList[i].lastContent = ''; - // isAdd = false; - // break; - // } - // } - // if (isAdd) { - // msgList.add(UIConversation(msg)); - // } - // if (isEnd && mounted) { - // setState(() {}); - // } - // }); + // 监听刷新channel资料事件 WKIM.shared.channelManager.addOnRefreshListener("cover_chat", (channel) { for (var i = 0; i < msgList.length; i++) { @@ -165,22 +148,24 @@ class ListViewShowDataState extends State { String getReminderText(UIConversation uiConversation) { String content = ""; - if (uiConversation.isMentionMe == 0) { + if (uiConversation.reminders == null) { uiConversation.msg.getReminderList().then((value) { - if (value != null && value.isNotEmpty) { - for (var i = 0; i < value.length; i++) { - if (value[i].type == WKMentionType.wkReminderTypeMentionMe && - value[i].done == 0) { - content = value[i].data; - uiConversation.isMentionMe = 1; - setState(() {}); - break; - } - } - } + Logs.debug('执行体系'); + uiConversation.reminders = value; + setState(() {}); }); - } else { - content = "[有人@你]"; + return content; + } + if (uiConversation.reminders!.isNotEmpty) { + for (var i = 0; i < uiConversation.reminders!.length; i++) { + if (uiConversation.reminders![i].type == + WKMentionType.wkReminderTypeMentionMe && + uiConversation.reminders![i].done == 0) { + content = uiConversation.reminders![i].data; + content = '[有人@你]'; + break; + } + } } return content; } @@ -310,7 +295,7 @@ class ListViewShowDataState extends State { Navigator.push( context, MaterialPageRoute( - builder: (context) => const ChatPage(), + builder: (_) => const ChatPage(), settings: RouteSettings( arguments: ChatChannel( msgList[pos].msg.channelID,