From 87fb40796abedc7e5c9906912d5f58d534a618ae Mon Sep 17 00:00:00 2001 From: SL Date: Tue, 23 Apr 2024 21:49:22 +0800 Subject: [PATCH] fix:add clear channel message method --- CHANGELOG.md | 6 ++++-- README.md | 2 +- example/lib/chat.dart | 23 ++++++++++++----------- example/lib/http.dart | 1 - lib/db/message.dart | 14 ++++++++++++++ lib/manager/message_manager.dart | 30 +++++++++++++++++++++++++++++- pubspec.yaml | 2 +- 7 files changed, 61 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d307cd6..f7b018a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,5 +66,7 @@ * fix: Optimization of loading channel messages without the latest messages and multiple synchronization issues ### 1.3.3 * fix: Optimization of loading channel messages without the latest messages and multiple synchronization issues - ### 1.2.4 - * fix: Optimize connections \ No newline at end of file + ### 1.3.4 + * fix: Optimize connections + ### 1.3.5 + * fix: Add clear channel messages method \ No newline at end of file diff --git a/README.md b/README.md index e964713..ff0e814 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ #### 安装 ``` dependencies: - wukongimfluttersdk: ^1.3.4 + wukongimfluttersdk: ^1.3.5 ``` #### 引入 ```dart diff --git a/example/lib/chat.dart b/example/lib/chat.dart index 1de4115..f568bde 100644 --- a/example/lib/chat.dart +++ b/example/lib/chat.dart @@ -98,6 +98,14 @@ class ChatListDataState extends State { } setState(() {}); }); + // 清除聊天记录 + WKIM.shared.messageManager.addOnClearChannelMsgListener("chat", + (channelId, channelType) { + if (channelID == channelId) { + msgList.clear(); + setState(() {}); + } + }); } // 模拟同步消息扩展后保存到db @@ -304,20 +312,13 @@ class ChatListDataState extends State { actions: [ MaterialButton( child: const Text( - '断开', - style: TextStyle(color: Colors.white), + '清空记录', + style: TextStyle(color: Color.fromARGB(255, 4, 80, 194)), ), onPressed: () { - WKIM.shared.connectionManager.disconnect(false); + WKIM.shared.messageManager + .clearWithChannel(channelID, channelType); }), - MaterialButton( - child: const Text( - '重连', - style: TextStyle(color: Colors.white), - ), - onPressed: () { - WKIM.shared.connectionManager.connect(); - }) ], ), body: Container( diff --git a/example/lib/http.dart b/example/lib/http.dart index 650390c..26ec857 100644 --- a/example/lib/http.dart +++ b/example/lib/http.dart @@ -80,7 +80,6 @@ class HttpUtils { int pullMode, Function(WKSyncChannelMsg) back) async { final dio = Dio(); - print('同不消息'); final response = await dio.post('$apiURL/channel/messagesync', data: { "login_uid": UserInfo.uid, // 当前登录用户uid "channel_id": channelID, // 频道ID diff --git a/lib/db/message.dart b/lib/db/message.dart index e7d490c..9ab2df4 100644 --- a/lib/db/message.dart +++ b/lib/db/message.dart @@ -321,6 +321,12 @@ class MessageDB { //获取原始数据 List list = await getMessages( channelId, channelType, oldestOrderSeq, contain, pullMode, limit); + if (isMore == 0) { + iGetOrSyncHistoryMsgBack(list); + isMore = 1; + requestCount = 0; + return; + } //业务判断数据 List tempList = []; for (int i = 0, size = list.length; i < size; i++) { @@ -729,6 +735,14 @@ class MessageDB { return wkMsg; } + Future deleteWithChannel(String channelId, int channelType) async { + var map = {}; + map['is_deleted'] = 1; + return await WKDBHelper.shared.getDB().update(WKDBConst.tableMessage, map, + where: "channel_id=? and channel_type=?", + whereArgs: [channelId, channelType]); + } + dynamic getMap(WKMsg msg) { var map = {}; map['message_id'] = msg.messageID; diff --git a/lib/manager/message_manager.dart b/lib/manager/message_manager.dart index 6a1ce26..a8dd7e2 100644 --- a/lib/manager/message_manager.dart +++ b/lib/manager/message_manager.dart @@ -34,7 +34,7 @@ class WKMessageManager { HashMap)>? _newMsgBack; HashMap? _refreshMsgBack; HashMap? _deleteMsgBack; - + HashMap? _clearChannelMsgBack; Function( String channelID, int channelType, @@ -396,6 +396,27 @@ class WKMessageManager { } } + addOnClearChannelMsgListener(String key, Function(String, int) back) { + _clearChannelMsgBack ??= HashMap(); + if (key != '') { + _clearChannelMsgBack![key] = back; + } + } + + removeClearChannelMsgListener(String key) { + if (_clearChannelMsgBack != null) { + _clearChannelMsgBack!.remove(key); + } + } + + _setClearChannelMsg(String channelID, int channelType) { + if (_clearChannelMsgBack != null) { + _clearChannelMsgBack!.forEach((key, back) { + back(channelID, channelType); + }); + } + } + addOnDeleteMsgListener(String key, Function(String) back) { _deleteMsgBack ??= HashMap(); if (key != '') { @@ -688,6 +709,13 @@ class WKMessageManager { } } + clearWithChannel(String channelId, int channelType) async { + int row = await MessageDB.shared.deleteWithChannel(channelId, channelType); + if (row > 0) { + _setClearChannelMsg(channelId, channelType); + } + } + deleteWithClientMsgNo(String clientMsgNo) async { var map = {}; map['is_deleted'] = 1; diff --git a/pubspec.yaml b/pubspec.yaml index a66c994..67e82b1 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.4 +version: 1.3.5 homepage: https://github.com/WuKongIM/WuKongIMFlutterSDK environment: