diff --git a/CHANGELOG.md b/CHANGELOG.md index f7b018a..269625c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,4 +69,6 @@ ### 1.3.4 * fix: Optimize connections ### 1.3.5 - * fix: Add clear channel messages method \ No newline at end of file + * fix: Add clear channel messages method + ### 1.3.6 + * fix: Add clear all channel red dots method \ No newline at end of file diff --git a/README.md b/README.md index ff0e814..892759c 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ #### 安装 ``` dependencies: - wukongimfluttersdk: ^1.3.5 + wukongimfluttersdk: ^1.3.6 ``` #### 引入 ```dart diff --git a/example/lib/home.dart b/example/lib/home.dart index 9721460..2a353ef 100644 --- a/example/lib/home.dart +++ b/example/lib/home.dart @@ -55,11 +55,20 @@ class ListViewShowDataState extends State { _connectionStatusStr = '同步消息中...'; } else if (status == WKConnectStatus.kicked) { _connectionStatusStr = '未连接,在其他设备登录'; + } else if (status == WKConnectStatus.fail) { + _connectionStatusStr = '未连接'; } if (mounted) { setState(() {}); } }); + WKIM.shared.conversationManager + .addOnClearAllRedDotListener("chat_conversation", () { + for (var i = 0; i < msgList.length; i++) { + msgList[i].msg.unreadCount = 0; + } + setState(() {}); + }); // 监听更新消息事件 WKIM.shared.conversationManager.addOnRefreshMsgListener('chat_conversation', (msg, isEnd) async { @@ -256,6 +265,44 @@ class ListViewShowDataState extends State { tooltip: 'Increment', child: const Icon(Icons.add), ), + persistentFooterButtons: [ + ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: const Color.fromARGB(255, 240, 117, 2), + ), + onPressed: () { + WKIM.shared.conversationManager.clearAllRedDot(); + }, + child: const Text( + '清除所有未读', + style: TextStyle(color: Colors.white), + ), + ), + ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: Colors.red, + ), + onPressed: () { + WKIM.shared.connectionManager.disconnect(false); + }, + child: const Text( + '断开连接', + style: TextStyle(color: Colors.white), + ), + ), + ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: const Color.fromARGB(255, 31, 27, 239), + ), + onPressed: () { + WKIM.shared.connectionManager.connect(); + }, + child: const Text( + '重连', + style: TextStyle(color: Colors.white), + ), + ), + ], ); } diff --git a/lib/db/conversation.dart b/lib/db/conversation.dart index ecf4194..8b130d5 100644 --- a/lib/db/conversation.dart +++ b/lib/db/conversation.dart @@ -191,6 +191,14 @@ class ConversationDB { return maxVersion; } + Future clearAllRedDot() async { + var map = {}; + map['unread_count'] = 0; + return await WKDBHelper.shared + .getDB() + .update(WKDBConst.tableConversation, map, where: "unread_count>0"); + } + Future updateWithField( dynamic map, String channelID, int channelType) async { return await WKDBHelper.shared.getDB().update( diff --git a/lib/manager/connect_manager.dart b/lib/manager/connect_manager.dart index 02f959b..c8e4fb0 100644 --- a/lib/manager/connect_manager.dart +++ b/lib/manager/connect_manager.dart @@ -135,6 +135,8 @@ class WKConnectionManager { WKDBHelper.shared.close(); } _closeAll(); + WKIM.shared.connectionManager + .setConnectionStatus(WKConnectStatus.fail, "Actively disconnect"); } _socketConnect(String addr) { diff --git a/lib/manager/conversation_manager.dart b/lib/manager/conversation_manager.dart index a309c37..109f625 100644 --- a/lib/manager/conversation_manager.dart +++ b/lib/manager/conversation_manager.dart @@ -17,6 +17,7 @@ class WKConversationManager { HashMap? _refeshMsgMap; HashMap? _deleteMsgMap; + HashMap? _clearAllRedDotMap; Function(String lastSsgSeqs, int msgCount, int version, Function(WKSyncConversation))? _syncConersationBack; @@ -74,6 +75,13 @@ class WKConversationManager { ConversationDB.shared.clearAll(); } + clearAllRedDot() async { + int row = await ConversationDB.shared.clearAllRedDot(); + if (row > 0) { + _setClearAllRedDot(); + } + } + updateRedDot(String channelID, int channelType, int redDot) async { var map = {}; map['unread_count'] = redDot; @@ -93,6 +101,25 @@ class WKConversationManager { } } + addOnClearAllRedDotListener(String key, Function() back) { + _clearAllRedDotMap ??= HashMap(); + _clearAllRedDotMap![key] = back; + } + + removeClearAllRedDotListener(String key) { + if (_clearAllRedDotMap != null) { + _clearAllRedDotMap!.remove(key); + } + } + + _setClearAllRedDot() { + if (_clearAllRedDotMap != null) { + _clearAllRedDotMap!.forEach((key, back) { + back(); + }); + } + } + addOnDeleteMsgListener(String key, Function(String, int) back) { _deleteMsgMap ??= HashMap(); _deleteMsgMap![key] = back; diff --git a/pubspec.yaml b/pubspec.yaml index 67e82b1..d43c083 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.5 +version: 1.3.6 homepage: https://github.com/WuKongIM/WuKongIMFlutterSDK environment: