fix:add clear channel message method

This commit is contained in:
SL 2024-04-23 21:49:22 +08:00
parent e2d170e9f0
commit 87fb40796a
7 changed files with 61 additions and 17 deletions

View File

@ -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
### 1.3.4
* fix: Optimize connections
### 1.3.5
* fix: Add clear channel messages method

View File

@ -9,7 +9,7 @@
#### 安装
```
dependencies:
wukongimfluttersdk: ^1.3.4
wukongimfluttersdk: ^1.3.5
```
#### 引入
```dart

View File

@ -98,6 +98,14 @@ class ChatListDataState extends State<ChatList> {
}
setState(() {});
});
//
WKIM.shared.messageManager.addOnClearChannelMsgListener("chat",
(channelId, channelType) {
if (channelID == channelId) {
msgList.clear();
setState(() {});
}
});
}
// db
@ -304,20 +312,13 @@ class ChatListDataState extends State<ChatList> {
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(

View File

@ -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

View File

@ -321,6 +321,12 @@ class MessageDB {
//
List<WKMsg> list = await getMessages(
channelId, channelType, oldestOrderSeq, contain, pullMode, limit);
if (isMore == 0) {
iGetOrSyncHistoryMsgBack(list);
isMore = 1;
requestCount = 0;
return;
}
//
List<WKMsg> tempList = [];
for (int i = 0, size = list.length; i < size; i++) {
@ -729,6 +735,14 @@ class MessageDB {
return wkMsg;
}
Future<int> deleteWithChannel(String channelId, int channelType) async {
var map = <String, Object>{};
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 = <String, Object>{};
map['message_id'] = msg.messageID;

View File

@ -34,7 +34,7 @@ class WKMessageManager {
HashMap<String, Function(List<WKMsg>)>? _newMsgBack;
HashMap<String, Function(WKMsg)>? _refreshMsgBack;
HashMap<String, Function(String)>? _deleteMsgBack;
HashMap<String, Function(String, int)>? _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 = <String, Object>{};
map['is_deleted'] = 1;

View File

@ -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: