From 0398d2b015a264c319f1098880ec06dd0946ec59 Mon Sep 17 00:00:00 2001 From: SL Date: Thu, 25 Apr 2024 21:48:29 +0800 Subject: [PATCH] fix:Add send message can reminder member method --- CHANGELOG.md | 4 +- README.md | 2 +- example/lib/chat.dart | 8 ++++ example/lib/contestation.dart | 1 + example/lib/home.dart | 64 +++++++++++++++++++++++++++++-- lib/db/const.dart | 2 +- lib/db/reminder.dart | 2 +- lib/entity/msg.dart | 6 +++ lib/entity/reminder.dart | 7 ++++ lib/manager/message_manager.dart | 38 ++++++++++++++++++ lib/model/wk_message_content.dart | 1 + pubspec.yaml | 2 +- 12 files changed, 129 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 269625c..56cfc4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,4 +71,6 @@ ### 1.3.5 * fix: Add clear channel messages method ### 1.3.6 - * fix: Add clear all channel red dots method \ No newline at end of file + * fix: Add clear all channel red dots method + ### 1.3.7 + * fix: Add send message can reminder member method \ No newline at end of file diff --git a/README.md b/README.md index 892759c..d15b2df 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ #### 安装 ``` dependencies: - wukongimfluttersdk: ^1.3.6 + wukongimfluttersdk: ^1.3.7 ``` #### 引入 ```dart diff --git a/example/lib/chat.dart b/example/lib/chat.dart index f568bde..b22e802 100644 --- a/example/lib/chat.dart +++ b/example/lib/chat.dart @@ -151,6 +151,7 @@ class ChatListDataState extends State { oldestOrderSeq, oldestOrderSeq == 0, pullMode, 10, 0, (list) { List uiList = []; for (int i = 0; i < list.length; i++) { + print(list[i].content); if (pullMode == 0 && !isReset) { uiList.add(UIMsg(list[i])); // msgList.insert(0, UIMsg(list[i])); @@ -368,6 +369,7 @@ class ChatListDataState extends State { _textEditingController.text = ''; Setting setting = Setting(); setting.receipt = 1; //开启回执 + // 回复 WKTextContent text = WKTextContent(content); WKReply reply = WKReply(); reply.messageId = "11"; @@ -377,6 +379,7 @@ class ChatListDataState extends State { WKTextContent payloadText = WKTextContent("dds"); reply.payload = payloadText; text.reply = reply; + // 标记 List list = []; WKMsgEntity entity = WKMsgEntity(); entity.offset = 0; @@ -384,6 +387,11 @@ class ChatListDataState extends State { entity.length = 1; list.add(entity); text.entities = list; + // 艾特 + WKMentionInfo mentionInfo = WKMentionInfo(); + mentionInfo.mentionAll = true; + mentionInfo.uids = ['uid_1', 'uid_2']; + text.mentionInfo = mentionInfo; // CustomMsg customMsg = CustomMsg(content); WKIM.shared.messageManager.sendMessageWithSetting( text, WKChannel(channelID, channelType), setting); diff --git a/example/lib/contestation.dart b/example/lib/contestation.dart index 7b96dfa..52ff0ad 100644 --- a/example/lib/contestation.dart +++ b/example/lib/contestation.dart @@ -4,6 +4,7 @@ class UIConversation { String lastContent = ''; String channelAvatar = ''; String channelName = ''; + int isMentionMe = 0; WKUIConversationMsg msg; UIConversation(this.msg); diff --git a/example/lib/home.dart b/example/lib/home.dart index 2a353ef..3cfdc7b 100644 --- a/example/lib/home.dart +++ b/example/lib/home.dart @@ -1,6 +1,7 @@ import 'package:example/const.dart'; import 'package:flutter/material.dart'; import 'package:wukongimfluttersdk/entity/conversation.dart'; +import 'package:wukongimfluttersdk/entity/reminder.dart'; import 'package:wukongimfluttersdk/type/const.dart'; import 'package:wukongimfluttersdk/wkim.dart'; @@ -127,6 +128,28 @@ class ListViewShowDataState extends State { return uiConversation.lastContent; } + String getReminderText(UIConversation uiConversation) { + String content = ""; + if (uiConversation.isMentionMe == 0) { + 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; + } + } + } + }); + } else { + content = "[有人@你]"; + } + return content; + } + String getChannelAvatarURL(UIConversation uiConversation) { if (uiConversation.channelAvatar == '') { uiConversation.msg.getWkChannel().then((channel) { @@ -207,6 +230,13 @@ class ListViewShowDataState extends State { ), Row( children: [ + Text( + getReminderText(uiMsg), + style: const TextStyle( + color: Color.fromARGB(255, 247, 2, 2), + fontSize: 14), + maxLines: 1, + ), Text( getShowContent(uiMsg), style: @@ -245,7 +275,7 @@ class ListViewShowDataState extends State { Navigator.push( context, MaterialPageRoute( - builder: (context) => ChatPage(), + builder: (context) => const ChatPage(), settings: RouteSettings( arguments: ChatChannel( msgList[pos].msg.channelID, @@ -274,7 +304,35 @@ class ListViewShowDataState extends State { WKIM.shared.conversationManager.clearAllRedDot(); }, child: const Text( - '清除所有未读', + '清除未读', + style: TextStyle(color: Colors.white), + ), + ), + ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: const Color.fromARGB(255, 240, 2, 133), + ), + onPressed: () { + if (msgList.isEmpty) { + return; + } + + List list = []; + WKReminder reminder = WKReminder(); + reminder.needUpload = 0; + reminder.type = WKMentionType.wkReminderTypeMentionMe; + reminder.data = '[有人@你]'; + reminder.done = 0; + reminder.reminderID = 11; + reminder.version = 1; + reminder.publisher = "uid_1"; + reminder.channelID = msgList[0].msg.channelID; + reminder.channelType = msgList[0].msg.channelType; + list.add(reminder); + WKIM.shared.reminderManager.saveOrUpdateReminders(list); + }, + child: const Text( + '提醒项', style: TextStyle(color: Colors.white), ), ), @@ -286,7 +344,7 @@ class ListViewShowDataState extends State { WKIM.shared.connectionManager.disconnect(false); }, child: const Text( - '断开连接', + '断开', style: TextStyle(color: Colors.white), ), ), diff --git a/lib/db/const.dart b/lib/db/const.dart index 4bff313..5fbe41e 100644 --- a/lib/db/const.dart +++ b/lib/db/const.dart @@ -225,7 +225,7 @@ class WKDBConst { reminder.version = readInt(data, 'version'); reminder.done = readInt(data, 'done'); String data1 = readString(data, 'data'); - reminder.needUpload = readInt(data, 'needUpload'); + reminder.needUpload = readInt(data, 'need_upload'); reminder.publisher = readString(data, 'publisher'); if (data1 != '') { reminder.data = jsonDecode(data1); diff --git a/lib/db/reminder.dart b/lib/db/reminder.dart index 0b57b22..71c6880 100644 --- a/lib/db/reminder.dart +++ b/lib/db/reminder.dart @@ -177,7 +177,7 @@ class ReminderDB { map['text'] = reminder.text; map['version'] = reminder.version; map['done'] = reminder.done; - map['needUpload'] = reminder.needUpload; + map['need_upload'] = reminder.needUpload; map['publisher'] = reminder.publisher; if (reminder.data != null) { map['data'] = jsonEncode(reminder.data); diff --git a/lib/entity/msg.dart b/lib/entity/msg.dart index f2e0953..3a6f990 100644 --- a/lib/entity/msg.dart +++ b/lib/entity/msg.dart @@ -286,3 +286,9 @@ class WKSyncChannelMsg { int more = 0; List? messages = []; } + +class WKMentionInfo { + bool isMentionMe = false; + bool mentionAll = false; + List? uids; +} diff --git a/lib/entity/reminder.dart b/lib/entity/reminder.dart index 3c1925e..c38f35f 100644 --- a/lib/entity/reminder.dart +++ b/lib/entity/reminder.dart @@ -14,3 +14,10 @@ class WKReminder { int needUpload = 0; String publisher = ''; } + +class WKMentionType { + //有人@我 + static const int wkReminderTypeMentionMe = 1; + //申请加群 + static const int wkApplyJoinGroupApprove = 2; +} diff --git a/lib/manager/message_manager.dart b/lib/manager/message_manager.dart index a8dd7e2..3e34ed4 100644 --- a/lib/manager/message_manager.dart +++ b/lib/manager/message_manager.dart @@ -81,6 +81,28 @@ class WKMessageManager { } content.entities = list; } + // 解析艾特 + var mentionJson = json['mention']; + if (mentionJson != null) { + var mentionInfo = WKMentionInfo(); + var mentionAll = WKDBConst.readInt(mentionJson, 'all'); + var uidList = mentionJson['uids']; + if (uidList != null) { + List uids = []; + for (var uid in uidList) { + uids.add(uid); + if (uid == WKIM.shared.options.uid) { + mentionInfo.isMentionMe = true; + } + } + mentionInfo.uids = uids; + } + if (mentionAll == 1) { + mentionInfo.mentionAll = true; + mentionInfo.isMentionMe = true; + } + content.mentionInfo = mentionInfo; + } return content; } @@ -617,6 +639,22 @@ class WKMessageManager { } json['entities'] = jsonArray; } + // 解析艾特 + if (wkMsg.messageContent!.mentionInfo != null) { + var mentionJson = {}; + if (wkMsg.messageContent!.mentionInfo!.mentionAll) { + mentionJson['all'] = 1; + } + if (wkMsg.messageContent!.mentionInfo!.uids != null && + wkMsg.messageContent!.mentionInfo!.uids!.isNotEmpty) { + var jsonArray = []; + for (String uid in wkMsg.messageContent!.mentionInfo!.uids!) { + jsonArray.add(uid); + } + mentionJson['uids'] = jsonArray; + } + json['mention'] = mentionJson; + } return jsonEncode(json); } diff --git a/lib/model/wk_message_content.dart b/lib/model/wk_message_content.dart index d4564a6..a7bc331 100644 --- a/lib/model/wk_message_content.dart +++ b/lib/model/wk_message_content.dart @@ -6,6 +6,7 @@ class WKMessageContent { String topicId = ""; WKReply? reply; List? entities; + WKMentionInfo? mentionInfo; Map encodeJson() { return {}; } diff --git a/pubspec.yaml b/pubspec.yaml index d43c083..2487bcc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ description: wukong IM flutter sdk # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.3.6 +version: 1.3.7 homepage: https://github.com/WuKongIM/WuKongIMFlutterSDK environment: