From 53e7be54fcb555ff0b4271838b55d7ef2ba88fff Mon Sep 17 00:00:00 2001 From: SL Date: Wed, 29 May 2024 21:56:35 +0800 Subject: [PATCH] fix:Modify the import SDK method --- README.md | 9 ++++++-- example/lib/chat.dart | 18 ++++++++++----- example/lib/im.dart | 7 +++++- lib/db/channel.dart | 25 +++++---------------- lib/db/channel_member.dart | 30 +++---------------------- lib/manager/channel_member_manager.dart | 2 +- 6 files changed, 34 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index 8d3c50c..b47c45e 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,11 @@ ## 快速入门 #### 安装 +[![pub package](https://img.shields.io/pub/v/wukongimfluttersdk.svg)](https://pub.dartlang.org/packages/wukongimfluttersdk) + ``` dependencies: - wukongimfluttersdk: ^1.4.1 + wukongimfluttersdk: ^version // 版本号看上面 ``` #### 引入 ```dart @@ -84,4 +86,7 @@ WKIM.shared.cmdManager.addOnCmdListener('chat', (cmdMsg) { // todo 按需处理cmd消息 }); ``` -- 包含`key`的事件监听均有移除监听的方法,为了避免重复收到事件回掉,在退出或销毁页面时通过传入的`key`移除事件 \ No newline at end of file +- 包含`key`的事件监听均有移除监听的方法,为了避免重复收到事件回掉,在退出或销毁页面时通过传入的`key`移除事件 + +### 许可证 +悟空IM 使用 Apache 2.0 许可证。有关详情,请参阅 LICENSE 文件。 \ No newline at end of file diff --git a/example/lib/chat.dart b/example/lib/chat.dart index b22e802..5bd4190 100644 --- a/example/lib/chat.dart +++ b/example/lib/chat.dart @@ -45,11 +45,18 @@ class ChatListDataState extends State { final ScrollController _scrollController = ScrollController(); ChatListDataState(this.channelID, this.channelType) { - if (channelType == WKChannelType.group) { - title = '群聊【$channelID】'; - } else { - title = '单聊【$channelID】'; - } + WKIM.shared.channelManager + .getChannel(channelID, channelType) + .then((channel) { + print(channel?.localExtra); + print(channel?.remoteExtraMap); + WKIM.shared.channelManager.fetchChannelInfo(channelID, channelType); + if (channelType == WKChannelType.group) { + title = '${channel?.channelName}'; + } else { + title = '${channel?.channelName}'; + } + }); } List msgList = []; String title = ''; @@ -151,7 +158,6 @@ 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])); diff --git a/example/lib/im.dart b/example/lib/im.dart index 48d979c..aa92ab5 100644 --- a/example/lib/im.dart +++ b/example/lib/im.dart @@ -37,7 +37,7 @@ class IMUtils { "https://lmg.jj20.com/up/allimg/tx28/430423183653303.jpg", "https://lmg.jj20.com/up/allimg/tx23/520420024834916.jpg", "https://himg.bdimg.com/sys/portraitn/item/public.1.a535a65d.tJe8MgWmP8zJ456B73Kzfg", - "https://images.liqucn.com/img/h23/h07/img_localize_cb7b78b88d5b33e2ce8921221bf3deae_400x400.png", + "https://img2.baidu.com/it/u=3324164588,1070151830&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500", "https://img1.baidu.com/it/u=3916753633,2634890492&fm=253&fmt=auto&app=138&f=JPEG?w=400&h=400", "https://img0.baidu.com/it/u=4210586523,443489101&fm=253&fmt=auto&app=138&f=JPEG?w=304&h=304", "https://img2.baidu.com/it/u=2559320899,1546883787&fm=253&fmt=auto&app=138&f=JPEG?w=441&h=499", @@ -54,6 +54,7 @@ class IMUtils { // 获取channel资料 WKIM.shared.channelManager .addOnGetChannelListener((channelId, channelType, back) { + print('获取频道资料'); if (channelType == WKChannelType.personal) { // 获取个人资料 // 这里直接返回了 @@ -62,6 +63,8 @@ class IMUtils { channel.channelName = "【单聊】${channel.channelID}"; var index = channel.channelID.hashCode % imgs.length; channel.avatar = imgs[index]; + channel.remoteExtraMap = {'status': 1, 'notice': 'xx'}; + channel.localExtra = {'localStatus': 1, 'localNotice': 'nxx'}; back(channel); } else if (channelType == WKChannelType.group) { // 获取群资料 @@ -69,6 +72,8 @@ class IMUtils { channel.channelName = "【群聊】${channel.channelID}"; var index = channel.channelID.hashCode % imgs.length; channel.avatar = imgs[index]; + channel.remoteExtraMap = {'status': 2, 'notice': 'ss'}; + channel.localExtra = {'localStatus': 2, 'localNotice': 'nss'}; back(channel); } }); diff --git a/lib/db/channel.dart b/lib/db/channel.dart index 09a0d6a..3d17c3e 100644 --- a/lib/db/channel.dart +++ b/lib/db/channel.dart @@ -26,27 +26,17 @@ class ChannelDB { insertOrUpdateList(List list) async { List> addList = []; - List> updateList = []; for (WKChannel channel in list) { - bool bl = await isExist(channel.channelID, channel.channelType); - if (bl) { - updateList.add(getMap(channel)); - } else { + if (channel.channelID != '') { addList.add(getMap(channel)); } } - if (addList.isNotEmpty || updateList.isNotEmpty) { + if (addList.isNotEmpty) { WKDBHelper.shared.getDB().transaction((txn) async { if (addList.isNotEmpty) { for (Map value in addList) { - txn.insert(WKDBConst.tableChannel, value); - } - } - if (updateList.isNotEmpty) { - for (Map value in updateList) { - txn.update(WKDBConst.tableChannel, value, - where: "channel_id=? and channel_type=?", - whereArgs: [value['channel_id'], value['channel_type']]); + txn.insert(WKDBConst.tableChannel, value, + conflictAlgorithm: ConflictAlgorithm.replace); } } }); @@ -54,12 +44,7 @@ class ChannelDB { } saveOrUpdate(WKChannel channel) async { - bool bl = await isExist(channel.channelID, channel.channelType); - if (!bl) { - insert(channel); - } else { - update(channel); - } + insert(channel); } insert(WKChannel channel) { diff --git a/lib/db/channel_member.dart b/lib/db/channel_member.dart index d638f11..cd49831 100644 --- a/lib/db/channel_member.dart +++ b/lib/db/channel_member.dart @@ -96,24 +96,12 @@ class ChannelMemberDB { return list; } - insertOrUpdateList( - List allMemberList, List existList) { + insertList(List allMemberList) { List> insertCVList = []; - List> updateCVList = []; for (WKChannelMember channelMember in allMemberList) { - bool isAdd = true; - for (WKChannelMember cm in existList) { - if (channelMember.memberUID == cm.memberUID) { - isAdd = false; - updateCVList.add(getMap(channelMember)); - break; - } - } - if (isAdd) { - insertCVList.add(getMap(channelMember)); - } + insertCVList.add(getMap(channelMember)); } - if (insertCVList.isNotEmpty || updateCVList.isNotEmpty) { + if (insertCVList.isNotEmpty) { WKDBHelper.shared.getDB().transaction((txn) async { if (insertCVList.isNotEmpty) { for (Map value in insertCVList) { @@ -121,18 +109,6 @@ class ChannelMemberDB { conflictAlgorithm: ConflictAlgorithm.replace); } } - - if (updateCVList.isNotEmpty) { - for (Map value in updateCVList) { - txn.update(WKDBConst.tableChannelMember, value, - where: "channel_id=? and channel_type=? and member_uid=?", - whereArgs: [ - value['channel_id'], - value['channel_type'], - value['member_uid'] - ]); - } - } }); } } diff --git a/lib/manager/channel_member_manager.dart b/lib/manager/channel_member_manager.dart index 8202dca..9fdfe5c 100644 --- a/lib/manager/channel_member_manager.dart +++ b/lib/manager/channel_member_manager.dart @@ -87,7 +87,7 @@ class WKChannelMemberManager { } // 先保存或修改成员 - ChannelMemberDB.shared.insertOrUpdateList(list, existList); + ChannelMemberDB.shared.insertList(list); if (addList.isNotEmpty) { setOnNewChannelMember(addList);