From a75887adba376165385ea409bf73992ac1547106 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Wed, 23 Mar 2022 12:04:07 +0800 Subject: [PATCH 01/56] change files. --- example/lib/pages/chat/chat_input_bar.dart | 4 +++- example/lib/pages/chat/chat_items/chat_item.dart | 14 +++++++++----- example/lib/pages/chat/chat_page.dart | 12 +++++++++--- .../lib/pages/chatroom/chat_room_list_page.dart | 13 ++++++++++--- .../contacts/contact_friends_request_page.dart | 16 ++++++++++++---- example/lib/pages/contacts/contacts_page.dart | 16 ++++++++++++---- .../pages/conversations/conversations_page.dart | 8 ++++++-- example/lib/pages/group/group_info_page.dart | 9 ++++++--- example/lib/pages/group/joined_groups_page.dart | 14 ++++++++++---- example/lib/pages/group/public_groups_page.dart | 16 ++++++++++++---- 10 files changed, 89 insertions(+), 33 deletions(-) diff --git a/example/lib/pages/chat/chat_input_bar.dart b/example/lib/pages/chat/chat_input_bar.dart index 67b865da..f52b2c3a 100644 --- a/example/lib/pages/chat/chat_input_bar.dart +++ b/example/lib/pages/chat/chat_input_bar.dart @@ -405,7 +405,9 @@ class _ChatInputBarState extends State { void _updateInputBarType() { _showSendBtn = widget.textController?.text.length != 0; - setState(() {}); + if (mounted) { + setState(() {}); + } } } diff --git a/example/lib/pages/chat/chat_items/chat_item.dart b/example/lib/pages/chat/chat_items/chat_item.dart index 71ffe9af..848a1f18 100644 --- a/example/lib/pages/chat/chat_items/chat_item.dart +++ b/example/lib/pages/chat/chat_items/chat_item.dart @@ -230,7 +230,9 @@ class ChatItemState extends State implements EMMessageStatusListener { @override void onError(EMError error) { - setState(() {}); + if (mounted) { + setState(() {}); + } print('发送失败'); } @@ -241,8 +243,9 @@ class ChatItemState extends State implements EMMessageStatusListener { @override void onReadAck() { - setState(() {}); - print('收到已读回调'); + if (mounted) { + setState(() {}); + } } @override @@ -250,8 +253,9 @@ class ChatItemState extends State implements EMMessageStatusListener { @override void onSuccess() { - setState(() {}); - print('发送成功'); + if (mounted) { + setState(() {}); + } } _messageBubble() { diff --git a/example/lib/pages/chat/chat_page.dart b/example/lib/pages/chat/chat_page.dart index f752b4ac..6e3248ec 100644 --- a/example/lib/pages/chat/chat_page.dart +++ b/example/lib/pages/chat/chat_page.dart @@ -130,7 +130,9 @@ class _ChatPageState extends State if (_keyboardVisible) { _inputBarType = ChatInputBarType.normal; SystemChannels.textInput.invokeMethod('TextInput.hide'); - setState(() {}); + if (mounted) { + setState(() {}); + } } }, child: SafeArea( @@ -261,7 +263,9 @@ class _ChatPageState extends State onFaceTap: (expression) { _inputBarEditingController.text = _inputBarEditingController.text + '[${expression.name}]'; - setState(() {}); + if (mounted) { + setState(() {}); + } }, onDeleteTap: () { if (_inputBarEditingController.text.length > 0) { @@ -296,7 +300,9 @@ class _ChatPageState extends State /// 刷新View并滑动到最底部 _setStateAndMoreToListViewEnd() { - setState(() {}); + if (mounted) { + setState(() {}); + } Future.delayed(Duration(milliseconds: 100), () { _scrollController.jumpTo(_scrollController.position.maxScrollExtent); }); diff --git a/example/lib/pages/chatroom/chat_room_list_page.dart b/example/lib/pages/chatroom/chat_room_list_page.dart index 0748e40c..fcc51f02 100644 --- a/example/lib/pages/chatroom/chat_room_list_page.dart +++ b/example/lib/pages/chatroom/chat_room_list_page.dart @@ -43,7 +43,9 @@ class ChatRoomsListPagesState extends State { _searchName = text; if (_searchName.length == 0) { _searchedRoom = null; - setState(() {}); + if (mounted) { + setState(() {}); + } } }, style: TextStyle( @@ -162,11 +164,14 @@ class ChatRoomsListPagesState extends State { _isEnd = false; } } - setState(() {}); + SmartDialog.showToast('获取成功'); isMore ? _refreshController.loadComplete() : _refreshController.refreshCompleted(); + if (mounted) { + setState(() {}); + } } on EMError catch (e) { SmartDialog.showToast('获取失败$e'); isMore @@ -203,7 +208,9 @@ class ChatRoomsListPagesState extends State { SmartDialog.showToast('搜索失败: $e'); } finally { SmartDialog.dismiss(); - setState(() {}); + if (mounted) { + setState(() {}); + } } } } diff --git a/example/lib/pages/contacts/contact_friends_request_page.dart b/example/lib/pages/contacts/contact_friends_request_page.dart index ed0d4eb3..ee97c4f1 100644 --- a/example/lib/pages/contacts/contact_friends_request_page.dart +++ b/example/lib/pages/contacts/contact_friends_request_page.dart @@ -19,7 +19,9 @@ class ContactFriendsRequestPageState extends State { String? currentUser = EMClient.getInstance.currentUsername; if (currentUser != null) { SharePreferenceManager.load(currentUser, callback: () { - setState(() {}); + if (mounted) { + setState(() {}); + } }); } } @@ -39,7 +41,9 @@ class ContactFriendsRequestPageState extends State { TextButton( onPressed: () { SharePreferenceManager.removeAllRequest(); - setState(() {}); + if (mounted) { + setState(() {}); + } }, child: Text( '清空', @@ -104,7 +108,9 @@ class ContactFriendsRequestPageState extends State { reqestId, true, ); - setState(() {}); + if (mounted) { + setState(() {}); + } }, ), TextButton( @@ -121,7 +127,9 @@ class ContactFriendsRequestPageState extends State { reqestId, false, ); - setState(() {}); + if (mounted) { + setState(() {}); + } }, ), ], diff --git a/example/lib/pages/contacts/contacts_page.dart b/example/lib/pages/contacts/contacts_page.dart index fd95c197..fc6ccf7b 100644 --- a/example/lib/pages/contacts/contacts_page.dart +++ b/example/lib/pages/contacts/contacts_page.dart @@ -35,7 +35,9 @@ class ContactsPageState extends State String? currentUser = EMClient.getInstance.currentUsername; if (currentUser != null) { SharePreferenceManager.load(currentUser, callback: () { - setState(() {}); + if (mounted) { + setState(() {}); + } }); } } @@ -253,7 +255,9 @@ class ContactsPageState extends State SuspensionUtil.sortListBySuspensionTag(_contactList); SuspensionUtil.setShowSuspensionStatus(_contactList); _contactList.insertAll(0, _topList); - setState(() {}); + if (mounted) { + setState(() {}); + } } } @@ -274,7 +278,9 @@ class ContactsPageState extends State SuspensionUtil.sortListBySuspensionTag(_contactList); SuspensionUtil.setShowSuspensionStatus(_contactList); _contactList.insertAll(0, _topList); - setState(() {}); + if (mounted) { + setState(() {}); + } Future.delayed(Duration(seconds: 3)).then((value) { _fetchContactsFromServer(count); }); @@ -320,7 +326,9 @@ class ContactsPageState extends State void onContactInvited(String? userName, String? reason) { SharePreferenceManager.addRequest(userName!); _friendRequestCount = SharePreferenceManager.loadUnreadCount(); - setState(() {}); + if (mounted) { + setState(() {}); + } } @override diff --git a/example/lib/pages/conversations/conversations_page.dart b/example/lib/pages/conversations/conversations_page.dart index 2bdb313c..43cf0543 100644 --- a/example/lib/pages/conversations/conversations_page.dart +++ b/example/lib/pages/conversations/conversations_page.dart @@ -166,7 +166,9 @@ class ConversationPageState extends State } on Error { _refreshController.refreshFailed(); } finally { - setState(() {}); + if (mounted) { + setState(() {}); + } } } @@ -191,7 +193,9 @@ class ConversationPageState extends State _conversationsList.removeAt(index); } on Error { } finally { - setState(() {}); + if (mounted) { + setState(() {}); + } } } diff --git a/example/lib/pages/group/group_info_page.dart b/example/lib/pages/group/group_info_page.dart index d69b2dc1..8e33f352 100644 --- a/example/lib/pages/group/group_info_page.dart +++ b/example/lib/pages/group/group_info_page.dart @@ -164,10 +164,10 @@ class GroupInfoPageState extends State { ); } - _joinPublicGroup() { + _joinPublicGroup() async { try { SmartDialog.showLoading(msg: '加入中...'); - EMClient.getInstance.groupManager.joinPublicGroup(_group!.groupId); + await EMClient.getInstance.groupManager.joinPublicGroup(_group!.groupId); SmartDialog.showToast('加入成功'); } on EMError catch (e) { SmartDialog.showToast('加入失败: $e'); @@ -199,8 +199,11 @@ class GroupInfoPageState extends State { .getGroupSpecificationFromServer( widget.group.groupId, ); - setState(() {}); + SmartDialog.showToast('获取成功'); + if (mounted) { + setState(() {}); + } } on EMError catch (e) { SmartDialog.showToast('获取失败: $e'); } finally { diff --git a/example/lib/pages/group/joined_groups_page.dart b/example/lib/pages/group/joined_groups_page.dart index e1a9e232..0eaca992 100644 --- a/example/lib/pages/group/joined_groups_page.dart +++ b/example/lib/pages/group/joined_groups_page.dart @@ -232,7 +232,7 @@ class JoinedGroupsPageState extends State { } _loadJoinedGroups([bool isMore = false]) async { - print('_loadJoinedGroups'); + debugPrint('_loadJoinedGroups'); try { if (!isMore) { _pageNumber = 0; @@ -255,7 +255,9 @@ class JoinedGroupsPageState extends State { _groupsList.clear(); } _groupsList.addAll(groups); - setState(() {}); + if (mounted) { + setState(() {}); + } SmartDialog.showToast('获取成功'); isMore ? _refreshController.loadComplete() @@ -291,7 +293,9 @@ class JoinedGroupsPageState extends State { _searchName = std; if (std.length == 0) { _searchedGroups.clear(); - setState(() {}); + if (mounted) { + setState(() {}); + } return; } _searchedGroups.clear(); @@ -305,6 +309,8 @@ class JoinedGroupsPageState extends State { continue; } } - setState(() {}); + if (mounted) { + setState(() {}); + } } } diff --git a/example/lib/pages/group/public_groups_page.dart b/example/lib/pages/group/public_groups_page.dart index 4621dd10..f889bc2e 100644 --- a/example/lib/pages/group/public_groups_page.dart +++ b/example/lib/pages/group/public_groups_page.dart @@ -43,7 +43,9 @@ class PublicGroupsPageState extends State { _searchName = text; if (_searchName.length == 0) { _searchedGroup = null; - setState(() {}); + if (mounted) { + setState(() {}); + } } }, style: TextStyle( @@ -154,7 +156,9 @@ class PublicGroupsPageState extends State { // 返回数据小于pageSize,说明是最后一页 if (_pageSize > cursor.data!.length) { _isEnd = true; - setState(() {}); + if (mounted) { + setState(() {}); + } } } } on EMError catch (e) { @@ -178,8 +182,10 @@ class PublicGroupsPageState extends State { _cursor = cursor.cursor; _groupsList.clear(); _groupsList.addAll(cursor.data!); - setState(() {}); SmartDialog.showToast('获取成功'); + if (mounted) { + setState(() {}); + } } on EMError catch (e) { SmartDialog.showToast('获取失败$e'); _refreshController.refreshFailed(); @@ -203,7 +209,9 @@ class PublicGroupsPageState extends State { SmartDialog.showToast('搜索失败: $e'); } finally { SmartDialog.dismiss(); - setState(() {}); + if (mounted) { + setState(() {}); + } } } } From 12f09c0db5f8bdb3801f79f53244d8fc31e567f9 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Wed, 23 Mar 2022 12:16:10 +0800 Subject: [PATCH 02/56] update change file. --- CHANGELOG.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2580dfce..b7c3b919 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,16 @@ - 修改EMImPushConfig为EMPushConfigs; - 删除EMOptions中的EMPushConfig.设置推送证书时直接调用EMOptions即可; - EMGroup中移除ShareFiles,如果需要获取共享文件,请调用Api: - `EMClient.getInstance.groupManager.getGroupFileListFromServer(groupId)` + `EMClient.getInstance.groupManager.getGroupFileListFromServer(groupId)` +- 将isConnected和isLoginBefore、Token改为从原生获取; +- 修复安卓设置群组免打扰失效的问题; +- 修复获取公开群crash的问题; +- 修改throw error的逻辑; +- 修改构造文本消息时的方法,需要传入参数名; +- 修改部分原生方法逻辑; +- 调整项目目录结构; +- 将`onConversationRead`回调方法参数改为必选; +- ## 3.8.3+5 From ed489823a74748d9dbdaab3daa9ac946f2ebf4aa Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Wed, 23 Mar 2022 15:59:04 +0800 Subject: [PATCH 03/56] update --- example/lib/main.dart | 2 ++ example/lib/pages/group/group_info_page.dart | 2 +- ios/Classes/EMGroup+Flutter.m | 2 +- lib/src/models/em_message.dart | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 966dfb52..18edb6dc 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -28,6 +28,8 @@ void main() { void initSDK() async { var options = EMOptions(appKey: 'easemob-demo#easeim'); + options.deleteMessagesAsExitGroup = false; + options.deleteMessagesAsExitChatRoom = false; options.debugModel = true; options.enableAPNs("EaseIM_APNS_Product"); diff --git a/example/lib/pages/group/group_info_page.dart b/example/lib/pages/group/group_info_page.dart index 8e33f352..5bf613bd 100644 --- a/example/lib/pages/group/group_info_page.dart +++ b/example/lib/pages/group/group_info_page.dart @@ -180,7 +180,7 @@ class GroupInfoPageState extends State { try { SmartDialog.showLoading(msg: '申请中...'); if (_group != null) { - EMClient.getInstance.groupManager.requestToJoinPublicGroup( + await EMClient.getInstance.groupManager.requestToJoinPublicGroup( _group!.groupId, ); } diff --git a/ios/Classes/EMGroup+Flutter.m b/ios/Classes/EMGroup+Flutter.m index b4b264c5..251a6028 100644 --- a/ios/Classes/EMGroup+Flutter.m +++ b/ios/Classes/EMGroup+Flutter.m @@ -27,7 +27,7 @@ - (NSDictionary *)toJson { ret[@"isAllMemberMuted"] = @(self.isMuteAllMembers); ret[@"options"] = [self.setting toJson]; ret[@"permissionType"] = @([EMGroup premissionTypeToInt:self.permissionType]); - + return ret; } diff --git a/lib/src/models/em_message.dart b/lib/src/models/em_message.dart index a4f81588..5d38a2d3 100644 --- a/lib/src/models/em_message.dart +++ b/lib/src/models/em_message.dart @@ -636,7 +636,7 @@ class EMFileMessageBody extends EMMessageBody { EMDownloadStatus fileStatus = EMDownloadStatus.PENDING; /// 文件大小 - int? fileSize = 0; + int fileSize = 0; /// 文件名称 String? displayName = ''; From 9c35bf0c92bc5ae312a21830f15a941328ee0755 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Thu, 24 Mar 2022 15:16:56 +0800 Subject: [PATCH 04/56] change message callback methods. --- README.md | 10 +- lib/src/em_chat_manager.dart | 28 +--- lib/src/em_push_manager.dart | 49 ++++--- lib/src/models/em_chat_enums.dart | 5 + lib/src/models/em_message.dart | 130 +++++++----------- lib/src/models/em_message_state_handle.dart | 19 +++ lib/src/models/em_push_configs.dart | 73 +++++----- .../tools/em_message_callback_manager.dart | 49 +++++++ 8 files changed, 197 insertions(+), 166 deletions(-) create mode 100644 lib/src/models/em_message_state_handle.dart create mode 100644 lib/src/tools/em_message_callback_manager.dart diff --git a/README.md b/README.md index cb48fb32..dbc9875f 100644 --- a/README.md +++ b/README.md @@ -75,15 +75,7 @@ import 'package:im_flutter_sdk/im_flutter_sdk.dart' ```dart EMOptions options = EMOptions(appKey: 'easemob-demo#chatdemoui'); -EMPushConfig config = EMPushConfig(); -// 配置推送信息 -config - ..enableAPNs("chatdemoui_dev") - ..enableHWPush() - ..enableFCM('') - ..enableMeiZuPush('', '') - ..enableMiPush('', ''); -options.pushConfig = config; +options.enableAPNs("chatdemoui_dev"); await EMClient.getInstance.init(options); ``` diff --git a/lib/src/em_chat_manager.dart b/lib/src/em_chat_manager.dart index e41ad213..6f850c6a 100644 --- a/lib/src/em_chat_manager.dart +++ b/lib/src/em_chat_manager.dart @@ -4,8 +4,9 @@ import 'package:flutter/services.dart'; import 'tools/em_extension.dart'; import '../im_flutter_sdk.dart'; import 'chat_method_keys.dart'; +import 'tools/em_message_callback_manager.dart'; -class EMChatManager implements EMMessageStatusListener { +class EMChatManager { static const _channelPrefix = 'com.chat.im'; static const MethodChannel _channel = const MethodChannel('$_channelPrefix/chat_manager', JSONMethodCodec()); @@ -13,6 +14,7 @@ class EMChatManager implements EMMessageStatusListener { final List _messageListeners = []; EMChatManager() { + MessageCallBackManager.getInstance; _channel.setMethodCallHandler((MethodCall call) async { if (call.method == ChatMethodKeys.onMessagesReceived) { return _onMessagesReceived(call.arguments); @@ -37,9 +39,6 @@ class EMChatManager implements EMMessageStatusListener { /// 发送消息 [message]. Future sendMessage(EMMessage message) async { - if (message.listener == null) { - message.listener = this; - } message.status = EMMessageStatus.PROGRESS; Map result = await _channel.invokeMethod( ChatMethodKeys.sendMessage, message.toJson()); @@ -57,9 +56,6 @@ class EMChatManager implements EMMessageStatusListener { /// 重发消息 [message]. Future resendMessage(EMMessage message) async { - if (message.listener == null) { - message.listener = this; - } message.status = EMMessageStatus.PROGRESS; Map result = await _channel.invokeMethod( ChatMethodKeys.resendMessage, message.toJson()); @@ -488,22 +484,4 @@ class EMChatManager implements EMMessageStatusListener { listener.onConversationRead(from, to); } } - - @override - void onDeliveryAck() {} - - @override - void onError(EMError error) {} - - @override - void onProgress(int progress) {} - - @override - void onReadAck() {} - - @override - void onStatusChanged() {} - - @override - void onSuccess() {} } diff --git a/lib/src/em_push_manager.dart b/lib/src/em_push_manager.dart index cfc11566..efd0488d 100644 --- a/lib/src/em_push_manager.dart +++ b/lib/src/em_push_manager.dart @@ -1,8 +1,6 @@ import 'dart:io'; import 'package:flutter/services.dart'; - -import 'tools/em_extension.dart'; import 'chat_method_keys.dart'; import 'models/em_error.dart'; import 'models/em_push_configs.dart'; @@ -12,8 +10,7 @@ class EMPushManager { static const MethodChannel _channel = const MethodChannel( '$_channelPrefix/chat_push_manager', JSONMethodCodec()); - /// 从本地获取ImPushConfig - Future getImPushConfig() async { + Future getPushConfigsFromCache() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getImPushConfig); try { EMError.hasErrorFromResult(result); @@ -23,8 +20,7 @@ class EMPushManager { } } - /// 从服务器获取ImPushConfig - Future getImPushConfigFromServer() async { + Future getPushConfigsFromServer() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getImPushConfigFromServer); try { @@ -37,63 +33,82 @@ class EMPushManager { } /// 更新当前用户的[nickname],这样离线消息推送的时候可以显示用户昵称而不是id,需要登录环信服务器成功后调用才生效 - Future updatePushNickname(String nickname) async { + Future updatePushNickname(String nickname) async { Map req = {'nickname': nickname}; Map result = await _channel.invokeMethod(ChatMethodKeys.updatePushNickname, req); try { EMError.hasErrorFromResult(result); - return result.boolValue(ChatMethodKeys.updatePushNickname); } on EMError catch (e) { throw e; } } /// 上传华为推送token, 需要确保登录成功后再调用(可以是进入home页面后) - Future updateHMSPushToken(String token) async { + Future updateHMSPushToken(String token) async { if (Platform.isAndroid) { Map req = {'token': token}; Map result = await _channel.invokeMethod(ChatMethodKeys.updateHMSPushToken, req); try { EMError.hasErrorFromResult(result); - return result.boolValue(ChatMethodKeys.updateHMSPushToken); } on EMError catch (e) { throw e; } } - return true; } /// 上传FCM推送token, 需要确保登录成功后再调用(可以是进入home页面后) - Future updateFCMPushToken(String token) async { + Future updateFCMPushToken(String token) async { if (Platform.isAndroid) { Map req = {'token': token}; Map result = await _channel.invokeMethod(ChatMethodKeys.updateFCMPushToken, req); try { EMError.hasErrorFromResult(result); - return result.boolValue(ChatMethodKeys.updateFCMPushToken); } on EMError catch (e) { throw e; } } - return true; } /// 上传iOS推送deviceToken - Future updateAPNsDeviceToken(String token) async { + Future updateAPNsDeviceToken(String token) async { if (Platform.isIOS) { Map req = {'token': token}; Map result = await _channel.invokeMethod(ChatMethodKeys.updateAPNsPushToken, req); try { EMError.hasErrorFromResult(result); - return true; } on EMError catch (e) { throw e; } } - return true; + } + + /// 从本地获取ImPushConfig + @Deprecated('use - getPushConfigsFromCache method instead.') + Future getImPushConfig() async { + Map result = await _channel.invokeMethod(ChatMethodKeys.getImPushConfig); + try { + EMError.hasErrorFromResult(result); + return EMPushConfigs.fromJson(result[ChatMethodKeys.getImPushConfig]); + } on EMError catch (e) { + throw e; + } + } + + /// 从服务器获取ImPushConfig + @Deprecated('use - getPushConfigsFromServer method instead.') + Future getImPushConfigFromServer() async { + Map result = + await _channel.invokeMethod(ChatMethodKeys.getImPushConfigFromServer); + try { + EMError.hasErrorFromResult(result); + return EMPushConfigs.fromJson( + result[ChatMethodKeys.getImPushConfigFromServer]); + } on EMError catch (e) { + throw e; + } } } diff --git a/lib/src/models/em_chat_enums.dart b/lib/src/models/em_chat_enums.dart index fe52229a..0cc680ed 100644 --- a/lib/src/models/em_chat_enums.dart +++ b/lib/src/models/em_chat_enums.dart @@ -16,3 +16,8 @@ enum EMConversationType { GroupChat, // 群聊消息 ChatRoom, // 聊天室消息 } + +enum EMPushStyle { + Simple, + Summary, +} diff --git a/lib/src/models/em_message.dart b/lib/src/models/em_message.dart index 5d38a2d3..845d9d0d 100644 --- a/lib/src/models/em_message.dart +++ b/lib/src/models/em_message.dart @@ -1,9 +1,9 @@ import 'dart:math'; -import 'package:flutter/services.dart'; +import '../tools/em_message_callback_manager.dart'; import '../tools/em_extension.dart'; import '../../im_flutter_sdk.dart'; -import '../chat_method_keys.dart'; +import 'em_message_state_handle.dart'; // 消息类型 enum EMMessageChatType { @@ -66,58 +66,30 @@ abstract class EMMessageStatusListener { void onStatusChanged() {} } -class MessageCallBackManager { - static const _channelPrefix = 'com.chat.im'; - static const MethodChannel _emMessageChannel = - const MethodChannel('$_channelPrefix/chat_message', JSONMethodCodec()); - Map cacheMessageMap = {}; - static MessageCallBackManager? _instance; - static MessageCallBackManager get getInstance => - _instance = _instance ?? MessageCallBackManager._internal(); - MessageCallBackManager._internal() { - _emMessageChannel.setMethodCallHandler((MethodCall call) async { - Map argMap = call.arguments; - int? localTime = argMap['localTime']; - EMMessage? msg = cacheMessageMap[localTime.toString()]; - if (msg == null) { - return null; - } - if (call.method == ChatMethodKeys.onMessageProgressUpdate) { - return msg._onMessageProgressChanged(argMap); - } else if (call.method == ChatMethodKeys.onMessageError) { - return msg._onMessageError(argMap); - } else if (call.method == ChatMethodKeys.onMessageSuccess) { - return msg._onMessageSuccess(argMap); - } else if (call.method == ChatMethodKeys.onMessageReadAck) { - return msg._onMessageReadAck(argMap); - } else if (call.method == ChatMethodKeys.onMessageDeliveryAck) { - return msg._onMessageDeliveryAck(argMap); - } else if (call.method == ChatMethodKeys.onMessageStatusChanged) { - return msg._onMessageStatusChanged(argMap); - } - return null; - }); - } - - addMessage(EMMessage message) { - cacheMessageMap[message.localTime.toString()] = message; - } - - removeMessage(EMMessage message) { - if (cacheMessageMap.containsKey(message.localTime.toString())) { - cacheMessageMap.remove(message.localTime.toString()); - } +class EMMessage { + EMMessage._private() { + _tmpKey = localTime.toString(); } -} -class EMMessage { - EMMessage._private(); + late EMMessageStateHandle _handle; /// 构造接收的消息 EMMessage.createReceiveMessage({ required this.body, this.direction = EMMessageDirection.RECEIVE, - }); + }) { + _tmpKey = localTime.toString(); + _handle = EMMessageStateHandle( + _tmpKey, + onMessageDeliveryAck: _onMessageDeliveryAck, + onMessageError: _onMessageError, + onMessageProgressChanged: _onMessageProgressChanged, + onMessageReadAck: _onMessageReadAck, + onMessageSuccess: _onMessageSuccess, + onMessageStatusChanged: _onMessageStatusChanged, + ); + MessageCallBackManager.getInstance.addMessage(_tmpKey, _handle); + } /// 构造发送的消息 EMMessage.createSendMessage({ @@ -126,75 +98,74 @@ class EMMessage { this.to, this.hasRead = true, }) : this.from = EMClient.getInstance.currentUsername, - this.conversationId = to; + this.conversationId = to { + _tmpKey = localTime.toString(); + _handle = EMMessageStateHandle( + _tmpKey, + onMessageDeliveryAck: _onMessageDeliveryAck, + onMessageError: _onMessageError, + onMessageProgressChanged: _onMessageProgressChanged, + onMessageReadAck: _onMessageReadAck, + onMessageSuccess: _onMessageSuccess, + onMessageStatusChanged: _onMessageStatusChanged, + ); + MessageCallBackManager.getInstance.addMessage(_tmpKey, _handle); + } void dispose() { - MessageCallBackManager.getInstance.removeMessage(this); + MessageCallBackManager.getInstance.removeMessage(_tmpKey); + // listener = null; } - Future? _onMessageError(Map map) { + void _onMessageError(Map map) { EMLog.v('发送失败 -- ' + map.toString()); EMMessage msg = EMMessage.fromJson(map['message']); this._msgId = msg.msgId; this.status = msg.status; this.body = msg.body; - if (listener != null) { - listener!.onError(EMError.fromJson(map['error'])); - } + listener?.onError(EMError.fromJson(map['error'])); return null; } - Future? _onMessageProgressChanged(Map map) { + void _onMessageProgressChanged(Map map) { EMLog.v( '发送 -- ' + ' msg_id: ' + this.msgId! + ' ' + map['progress'].toString(), ); - if (this.listener != null) { - int progress = map['progress']; - listener!.onProgress(progress); - } + int progress = map['progress']; + listener?.onProgress(progress); return null; } - Future? _onMessageSuccess(Map map) { + void _onMessageSuccess(Map map) { EMMessage msg = EMMessage.fromJson(map['message']); this._msgId = msg.msgId; this.status = msg.status; this.body = msg.body; - if (listener != null) { - listener!.onSuccess(); - } + listener?.onSuccess(); EMLog.v('发送成功 -- ' + this.toString()); return null; } - Future? _onMessageReadAck(Map map) { + void _onMessageReadAck(Map map) { EMLog.v('消息已读 -- ' + ' msg_id: ' + this.msgId!); EMMessage msg = EMMessage.fromJson(map); this.hasReadAck = msg.hasReadAck; + listener?.onReadAck(); - if (listener != null) { - listener!.onReadAck(); - } return null; } - Future? _onMessageDeliveryAck(Map map) { + void _onMessageDeliveryAck(Map map) { EMMessage msg = EMMessage.fromJson(map); this.hasDeliverAck = msg.hasDeliverAck; - - if (listener != null) { - listener!.onDeliveryAck(); - } + listener?.onDeliveryAck(); return null; } - Future? _onMessageStatusChanged(Map map) { + void _onMessageStatusChanged(Map map) { EMMessage msg = EMMessage.fromJson(map); this.status = msg.status; - - if (listener != null) { - listener!.onStatusChanged(); - } + listener?.onStatusChanged(); return null; } @@ -306,13 +277,10 @@ class EMMessage { void setMessageListener(EMMessageStatusListener? listener) { this.listener = listener; - if (listener != null) { - MessageCallBackManager.getInstance.addMessage(this); - } else { - MessageCallBackManager.getInstance.removeMessage(this); - } } + late String _tmpKey; + /// 消息id String? _msgId, msgLocalId = DateTime.now().millisecondsSinceEpoch.toString() + diff --git a/lib/src/models/em_message_state_handle.dart b/lib/src/models/em_message_state_handle.dart new file mode 100644 index 00000000..528107ea --- /dev/null +++ b/lib/src/models/em_message_state_handle.dart @@ -0,0 +1,19 @@ +class EMMessageStateHandle { + final String messageKey; + final void Function(Map)? onMessageError; + final void Function(Map)? onMessageProgressChanged; + final void Function(Map)? onMessageSuccess; + final void Function(Map)? onMessageReadAck; + final void Function(Map)? onMessageDeliveryAck; + final void Function(Map)? onMessageStatusChanged; + + EMMessageStateHandle( + this.messageKey, { + this.onMessageError, + this.onMessageProgressChanged, + this.onMessageSuccess, + this.onMessageReadAck, + this.onMessageDeliveryAck, + this.onMessageStatusChanged, + }); +} diff --git a/lib/src/models/em_push_configs.dart b/lib/src/models/em_push_configs.dart index 1bd7d104..fbd82637 100644 --- a/lib/src/models/em_push_configs.dart +++ b/lib/src/models/em_push_configs.dart @@ -1,20 +1,20 @@ import 'package:flutter/services.dart'; -import '../../im_flutter_sdk.dart'; + import '../chat_method_keys.dart'; import '../tools/em_extension.dart'; - -enum EMImPushStyle { Simple, Summary } +import 'em_chat_enums.dart'; +import 'em_error.dart'; class EMPushConfigs { EMPushConfigs._private(); - EMImPushStyle? _pushStyle; + EMPushStyle? _pushStyle; bool? _noDisturb; int? _noDisturbStartHour; int? _noDisturbEndHour; List? _noDisturbGroups = []; - EMImPushStyle? get pushStyle => _pushStyle; + EMPushStyle? get pushStyle => _pushStyle; bool? get noDisturb => _noDisturb; int? get noDisturbStartHour => _noDisturbStartHour; int? get noDisturbEndHour => _noDisturbEndHour; @@ -23,7 +23,7 @@ class EMPushConfigs { factory EMPushConfigs.fromJson(Map map) { return EMPushConfigs._private() .._pushStyle = - map['pushStyle'] == 0 ? EMImPushStyle.Simple : EMImPushStyle.Summary + map['pushStyle'] == 0 ? EMPushStyle.Simple : EMPushStyle.Summary .._noDisturb = map.boolValue('noDisturb') .._noDisturbStartHour = map['noDisturbStartHour'] .._noDisturbEndHour = map['noDisturbEndHour']; @@ -31,7 +31,7 @@ class EMPushConfigs { Map toJson() { Map data = Map(); - data['pushStyle'] = _pushStyle == EMImPushStyle.Simple; + data['pushStyle'] = _pushStyle == EMPushStyle.Simple; data['noDisturb'] = _noDisturb; data['noDisturbStartHour'] = _noDisturbStartHour; data['noDisturbEndHour'] = _noDisturbEndHour; @@ -45,7 +45,7 @@ extension EMPushConfigsExtension on EMPushConfigs { const MethodChannel('com.chat.im/chat_push_manager', JSONMethodCodec()); /// 设置是否免打扰[isNoDisturb], [startTime], [endTime] - Future setNoDisturb( + Future setNoDisturb( bool isNoDisturb, [ int startTime = 0, int endTime = 24, @@ -59,51 +59,56 @@ extension EMPushConfigsExtension on EMPushConfigs { }; Map result = await _channel.invokeMethod(ChatMethodKeys.imPushNoDisturb, req); - EMError.hasErrorFromResult(result); - bool success = result.boolValue(ChatMethodKeys.imPushNoDisturb); - if (success) { - _noDisturb = isNoDisturb; - _noDisturbStartHour = startTime; - _noDisturbEndHour = endTime; + try { + EMError.hasErrorFromResult(result); + bool success = result.boolValue(ChatMethodKeys.imPushNoDisturb); + if (success) { + _noDisturb = isNoDisturb; + _noDisturbStartHour = startTime; + _noDisturbEndHour = endTime; + } + } on EMError catch (e) { + throw e; } - return success; } /// 设置消息推送显示样式[pushStyle] - Future setPushStyle(EMImPushStyle pushStyle) async { - EMLog.v('setPushStyle: ' + pushStyle.toString()); - Map req = {'pushStyle': pushStyle == EMImPushStyle.Simple ? 0 : 1}; + Future setPushStyle(EMPushStyle pushStyle) async { + Map req = {'pushStyle': pushStyle == EMPushStyle.Simple ? 0 : 1}; Map result = await _channel.invokeMethod(ChatMethodKeys.updateImPushStyle, req); - EMError.hasErrorFromResult(result); - bool success = result.boolValue(ChatMethodKeys.updateImPushStyle); - if (success) _pushStyle = pushStyle; - return success; + try { + EMError.hasErrorFromResult(result); + } on EMError catch (e) { + throw e; + } } /// 通过群id[groupId]设置群组是否免打扰[isNoDisturb] - Future setGroupToDisturb( + Future setGroupToDisturb( String groupId, bool isNoDisturb, ) async { Map req = {'noDisturb': isNoDisturb, 'group_id': groupId}; - EMLog.v('setGroupToDisturb: ' + req.toString()); Map result = await _channel.invokeMethod(ChatMethodKeys.updateGroupPushService, req); - EMError.hasErrorFromResult(result); - EMGroup group = - EMGroup.fromJson(result[ChatMethodKeys.updateGroupPushService]); - _noDisturbGroups!.removeWhere((e) => e == group.groupId); - if (isNoDisturb) _noDisturbGroups!.add(group.groupId); - return group; + try { + EMError.hasErrorFromResult(result); + } on EMError catch (e) { + throw e; + } } /// 获取免打扰群组列表 Future?> noDisturbGroupsFromServer() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getNoDisturbGroups); - EMError.hasErrorFromResult(result); - _noDisturbGroups = - result[ChatMethodKeys.getNoDisturbGroups]?.cast(); - return _noDisturbGroups; + try { + EMError.hasErrorFromResult(result); + _noDisturbGroups = + result[ChatMethodKeys.getNoDisturbGroups]?.cast(); + return _noDisturbGroups; + } on EMError catch (e) { + throw e; + } } } diff --git a/lib/src/tools/em_message_callback_manager.dart b/lib/src/tools/em_message_callback_manager.dart new file mode 100644 index 00000000..7cc483f9 --- /dev/null +++ b/lib/src/tools/em_message_callback_manager.dart @@ -0,0 +1,49 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:im_flutter_sdk/src/models/em_message_state_handle.dart'; + +import '../chat_method_keys.dart'; + +class MessageCallBackManager { + static const _channelPrefix = 'com.chat.im'; + static const MethodChannel _emMessageChannel = + const MethodChannel('$_channelPrefix/chat_message', JSONMethodCodec()); + Map cacheHandleMap = {}; + static MessageCallBackManager? _instance; + static MessageCallBackManager get getInstance => + _instance = _instance ?? MessageCallBackManager._internal(); + + MessageCallBackManager._internal() { + _emMessageChannel.setMethodCallHandler((MethodCall call) async { + Map argMap = call.arguments; + int? localTime = argMap['localTime']; + debugPrint("------- handle: $localTime"); + EMMessageStateHandle? handle = cacheHandleMap[localTime.toString()]; + + if (call.method == ChatMethodKeys.onMessageProgressUpdate) { + return handle?.onMessageProgressChanged?.call(argMap); + } else if (call.method == ChatMethodKeys.onMessageError) { + return handle?.onMessageError?.call(argMap); + } else if (call.method == ChatMethodKeys.onMessageSuccess) { + return handle?.onMessageSuccess?.call(argMap); + } else if (call.method == ChatMethodKeys.onMessageReadAck) { + return handle?.onMessageReadAck?.call(argMap); + } else if (call.method == ChatMethodKeys.onMessageDeliveryAck) { + return handle?.onMessageDeliveryAck?.call(argMap); + } else if (call.method == ChatMethodKeys.onMessageStatusChanged) { + return handle?.onMessageStatusChanged?.call(argMap); + } + return null; + }); + } + + addMessage(String key, EMMessageStateHandle message) { + debugPrint("----- flutter 添加: " + key); + cacheHandleMap[key] = message; + } + + removeMessage(String key) { + debugPrint("----- flutter 删除: " + key); + cacheHandleMap.remove(key); + } +} From b4bf5696b8706902b2371f5b9d1ee6985a756164 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Fri, 25 Mar 2022 18:10:28 +0800 Subject: [PATCH 05/56] fix ios use token login error. --- CHANGELOG.md | 4 ++++ README.md | 2 +- ios/Classes/EMClientWrapper.m | 5 +---- lib/im_flutter_sdk.dart | 9 ++++++++- lib/src/em_chat_manager.dart | 2 +- lib/src/em_chat_room_manager.dart | 2 +- lib/src/em_client.dart | 10 +++------- lib/src/em_contact_manager.dart | 2 +- lib/src/em_group_manager.dart | 2 +- lib/src/em_push_manager.dart | 2 +- lib/src/em_userInfo_manager.dart | 2 +- lib/src/{ => internal}/chat_method_keys.dart | 0 lib/src/internal/em_event_keys.dart | 7 +++++++ .../{models => internal}/em_message_state_handle.dart | 0 lib/src/models/em_conversation.dart | 2 +- lib/src/models/em_message.dart | 4 +++- lib/src/models/em_push_configs.dart | 2 +- lib/src/tools/em_message_callback_manager.dart | 4 ++-- pubspec.yaml | 2 +- 19 files changed, 38 insertions(+), 25 deletions(-) rename lib/src/{ => internal}/chat_method_keys.dart (100%) create mode 100644 lib/src/internal/em_event_keys.dart rename lib/src/{models => internal}/em_message_state_handle.dart (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7c3b919..1200b4b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## NEXT +## 3.8.3+7 + +- 修复ios使用token登录失败; +- 修改Login方法和Logout方法返回值; ## 3.8.3+6 diff --git a/README.md b/README.md index dbc9875f..2f7367cd 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Demo中使用的音视频是针对声网音视频封装的[EaseCallKit](https:// ```dart dependencies: - im_flutter_sdk: ^3.8.3+5 + im_flutter_sdk: ^3.8.3+7 ``` 2. 执行`flutter pub get`; diff --git a/ios/Classes/EMClientWrapper.m b/ios/Classes/EMClientWrapper.m index cfdc73e8..89318bd2 100644 --- a/ios/Classes/EMClientWrapper.m +++ b/ios/Classes/EMClientWrapper.m @@ -241,10 +241,7 @@ - (void)login:(NSDictionary *)param channelName:(NSString *)aChannelName result: [weakSelf wrapperCallBack:result channelName:aChannelName error:aError - object:@{ - @"username": aUsername, - @"token": EMClient.sharedClient.accessUserToken - }]; + object:EMClient.sharedClient.accessUserToken]; }]; } } diff --git a/lib/im_flutter_sdk.dart b/lib/im_flutter_sdk.dart index 285793c6..ff90ba62 100644 --- a/lib/im_flutter_sdk.dart +++ b/lib/im_flutter_sdk.dart @@ -4,7 +4,7 @@ export 'src/em_client.dart'; export 'src/models/em_message.dart'; export 'src/models/em_group_message_ack.dart'; -export 'src/tools/em_log.dart'; +// export 'src/tools/em_log.dart'; export 'src/em_listeners.dart'; export 'src/models/em_chat_room.dart'; export 'src/models/em_conversation.dart'; @@ -20,3 +20,10 @@ export 'src/models/em_userInfo.dart'; export 'src/models/em_group_shared_file.dart'; export 'src/models/em_group_options.dart'; export 'src/models/em_chat_enums.dart'; + +export 'src/em_chat_manager.dart'; +export 'src/em_contact_manager.dart'; +export 'src/em_group_manager.dart'; +export 'src/em_chat_room_manager.dart'; +export 'src/em_push_manager.dart'; +export 'src/em_userInfo_manager.dart'; diff --git a/lib/src/em_chat_manager.dart b/lib/src/em_chat_manager.dart index 6f850c6a..206e3956 100644 --- a/lib/src/em_chat_manager.dart +++ b/lib/src/em_chat_manager.dart @@ -3,7 +3,7 @@ import "dart:async"; import 'package:flutter/services.dart'; import 'tools/em_extension.dart'; import '../im_flutter_sdk.dart'; -import 'chat_method_keys.dart'; +import 'internal/chat_method_keys.dart'; import 'tools/em_message_callback_manager.dart'; class EMChatManager { diff --git a/lib/src/em_chat_room_manager.dart b/lib/src/em_chat_room_manager.dart index c61bf5b8..05c3be9a 100644 --- a/lib/src/em_chat_room_manager.dart +++ b/lib/src/em_chat_room_manager.dart @@ -1,7 +1,7 @@ import "dart:async"; import 'package:flutter/services.dart'; -import 'chat_method_keys.dart'; +import 'internal/chat_method_keys.dart'; import '../im_flutter_sdk.dart'; class EMChatRoomManager { diff --git a/lib/src/em_client.dart b/lib/src/em_client.dart index a41563b6..2fd7b6ef 100644 --- a/lib/src/em_client.dart +++ b/lib/src/em_client.dart @@ -1,15 +1,11 @@ import 'dart:async'; import 'package:flutter/services.dart'; -import 'em_chat_manager.dart'; -import 'em_contact_manager.dart'; -import 'em_group_manager.dart'; -import 'em_push_manager.dart'; -import 'em_userInfo_manager.dart'; + +import 'internal/chat_method_keys.dart'; import 'tools/em_extension.dart'; import '../im_flutter_sdk.dart'; -import 'chat_method_keys.dart'; -import 'em_chat_room_manager.dart'; +import 'tools/em_log.dart'; class EMClient { static const _channelPrefix = 'com.chat.im'; diff --git a/lib/src/em_contact_manager.dart b/lib/src/em_contact_manager.dart index ddd4e30d..415b710a 100644 --- a/lib/src/em_contact_manager.dart +++ b/lib/src/em_contact_manager.dart @@ -3,7 +3,7 @@ import 'dart:async'; import 'package:flutter/services.dart'; import '../im_flutter_sdk.dart'; -import 'chat_method_keys.dart'; +import 'internal/chat_method_keys.dart'; class EMContactManager { static const _channelPrefix = 'com.chat.im'; diff --git a/lib/src/em_group_manager.dart b/lib/src/em_group_manager.dart index b47c6ecd..33b76b53 100644 --- a/lib/src/em_group_manager.dart +++ b/lib/src/em_group_manager.dart @@ -9,7 +9,7 @@ import 'models/em_group_options.dart'; import 'models/em_group_shared_file.dart'; import 'tools/em_extension.dart'; -import 'chat_method_keys.dart'; +import 'internal/chat_method_keys.dart'; class EMGroupManager { static const _channelPrefix = 'com.chat.im'; diff --git a/lib/src/em_push_manager.dart b/lib/src/em_push_manager.dart index efd0488d..1e5e48fa 100644 --- a/lib/src/em_push_manager.dart +++ b/lib/src/em_push_manager.dart @@ -1,7 +1,7 @@ import 'dart:io'; import 'package:flutter/services.dart'; -import 'chat_method_keys.dart'; +import 'internal/chat_method_keys.dart'; import 'models/em_error.dart'; import 'models/em_push_configs.dart'; diff --git a/lib/src/em_userInfo_manager.dart b/lib/src/em_userInfo_manager.dart index 0cdc9922..adce64ea 100644 --- a/lib/src/em_userInfo_manager.dart +++ b/lib/src/em_userInfo_manager.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'package:flutter/services.dart'; -import 'chat_method_keys.dart'; +import 'internal/chat_method_keys.dart'; import 'em_client.dart'; import 'models/em_error.dart'; import 'models/em_userInfo.dart'; diff --git a/lib/src/chat_method_keys.dart b/lib/src/internal/chat_method_keys.dart similarity index 100% rename from lib/src/chat_method_keys.dart rename to lib/src/internal/chat_method_keys.dart diff --git a/lib/src/internal/em_event_keys.dart b/lib/src/internal/em_event_keys.dart new file mode 100644 index 00000000..711a61dd --- /dev/null +++ b/lib/src/internal/em_event_keys.dart @@ -0,0 +1,7 @@ +class EMContactChangeEvent { + static const String CONTACT_ADD = 'onContactAdded'; + static const String CONTACT_DELETE = 'onContactDeleted'; + static const String INVITED = 'onContactInvited'; + static const String INVITATION_ACCEPTED = 'onFriendRequestAccepted'; + static const String INVITATION_DECLINED = 'onFriendRequestDeclined'; +} diff --git a/lib/src/models/em_message_state_handle.dart b/lib/src/internal/em_message_state_handle.dart similarity index 100% rename from lib/src/models/em_message_state_handle.dart rename to lib/src/internal/em_message_state_handle.dart diff --git a/lib/src/models/em_conversation.dart b/lib/src/models/em_conversation.dart index db35b30a..b5fddde5 100644 --- a/lib/src/models/em_conversation.dart +++ b/lib/src/models/em_conversation.dart @@ -3,7 +3,7 @@ import 'package:flutter/services.dart'; import '../tools/em_extension.dart'; import '../../im_flutter_sdk.dart'; -import '../chat_method_keys.dart'; +import '../internal/chat_method_keys.dart'; enum EMMessageSearchDirection { Up, Down } diff --git a/lib/src/models/em_message.dart b/lib/src/models/em_message.dart index 845d9d0d..70411105 100644 --- a/lib/src/models/em_message.dart +++ b/lib/src/models/em_message.dart @@ -1,9 +1,11 @@ import 'dart:math'; +import '../tools/em_log.dart'; + import '../tools/em_message_callback_manager.dart'; import '../tools/em_extension.dart'; import '../../im_flutter_sdk.dart'; -import 'em_message_state_handle.dart'; +import '../internal/em_message_state_handle.dart'; // 消息类型 enum EMMessageChatType { diff --git a/lib/src/models/em_push_configs.dart b/lib/src/models/em_push_configs.dart index fbd82637..7bc66a65 100644 --- a/lib/src/models/em_push_configs.dart +++ b/lib/src/models/em_push_configs.dart @@ -1,6 +1,6 @@ import 'package:flutter/services.dart'; -import '../chat_method_keys.dart'; +import '../internal/chat_method_keys.dart'; import '../tools/em_extension.dart'; import 'em_chat_enums.dart'; import 'em_error.dart'; diff --git a/lib/src/tools/em_message_callback_manager.dart b/lib/src/tools/em_message_callback_manager.dart index 7cc483f9..988eb5d7 100644 --- a/lib/src/tools/em_message_callback_manager.dart +++ b/lib/src/tools/em_message_callback_manager.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:im_flutter_sdk/src/models/em_message_state_handle.dart'; +import 'package:im_flutter_sdk/src/internal/em_message_state_handle.dart'; -import '../chat_method_keys.dart'; +import '../internal/chat_method_keys.dart'; class MessageCallBackManager { static const _channelPrefix = 'com.chat.im'; diff --git a/pubspec.yaml b/pubspec.yaml index e91ab8d7..cb7bf69d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: im_flutter_sdk description: Easemob IM flutter SDK. -version: 3.8.3+6 +version: 3.8.3+7 homepage: http://www.easemob.com/product/im environment: From dd0fd89f6e8f5e7ae6647ad079031cea510de83f Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Fri, 25 Mar 2022 18:20:06 +0800 Subject: [PATCH 06/56] update --- lib/src/tools/em_message_callback_manager.dart | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/src/tools/em_message_callback_manager.dart b/lib/src/tools/em_message_callback_manager.dart index 988eb5d7..2dff6390 100644 --- a/lib/src/tools/em_message_callback_manager.dart +++ b/lib/src/tools/em_message_callback_manager.dart @@ -1,6 +1,5 @@ -import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:im_flutter_sdk/src/internal/em_message_state_handle.dart'; +import '../internal/em_message_state_handle.dart'; import '../internal/chat_method_keys.dart'; @@ -17,7 +16,6 @@ class MessageCallBackManager { _emMessageChannel.setMethodCallHandler((MethodCall call) async { Map argMap = call.arguments; int? localTime = argMap['localTime']; - debugPrint("------- handle: $localTime"); EMMessageStateHandle? handle = cacheHandleMap[localTime.toString()]; if (call.method == ChatMethodKeys.onMessageProgressUpdate) { @@ -38,12 +36,10 @@ class MessageCallBackManager { } addMessage(String key, EMMessageStateHandle message) { - debugPrint("----- flutter 添加: " + key); cacheHandleMap[key] = message; } removeMessage(String key) { - debugPrint("----- flutter 删除: " + key); cacheHandleMap.remove(key); } } From 8dc1acf8a2d6ebe386c30ca7355a14a0fb0d1dc1 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Sun, 27 Mar 2022 10:08:01 +0800 Subject: [PATCH 07/56] update api referance. --- lib/src/em_client.dart | 61 +++++++++---- lib/src/em_contact_manager.dart | 151 +++++++++++++++++++++++--------- 2 files changed, 156 insertions(+), 56 deletions(-) diff --git a/lib/src/em_client.dart b/lib/src/em_client.dart index 2fd7b6ef..3779a12f 100644 --- a/lib/src/em_client.dart +++ b/lib/src/em_client.dart @@ -2,11 +2,14 @@ import 'dart:async'; import 'package:flutter/services.dart'; -import 'internal/chat_method_keys.dart'; import 'tools/em_extension.dart'; import '../im_flutter_sdk.dart'; +import 'internal/chat_method_keys.dart'; import 'tools/em_log.dart'; +/// +/// The EMClient, which is the entry point of the Chat SDK. You can log in, log out, and access other functionalities such as group and chatroom with this class. +/// class EMClient { static const _channelPrefix = 'com.chat.im'; static const MethodChannel _channel = @@ -35,7 +38,6 @@ class EMClient { static EMClient get getInstance => _instance = _instance ?? EMClient._internal(); - /// @nodoc private constructor EMClient._internal() { _addNativeMethodCallHandler(); } @@ -103,7 +105,11 @@ class EMClient { } } - /// 初始化SDK 指定[options]. + /// + /// Initializes the SDK. + /// + /// Param [options] The configurations. Make sure to set the param. + /// Future init(EMOptions options) async { _options = options; EMLog.v('init: $options'); @@ -111,23 +117,42 @@ class EMClient { _currentUsername = await getCurrentUsername(); } - /// 注册环信id,[username],[password], - /// 需要在环信后台的console中设置为开放注册才能通过sdk注册,否则只能使用rest api注册。 - /// 返回注册成功的环信id - Future createAccount(String username, String password) async { + /// + /// Register a new user with your chat network. + /// + /// Param [username] The username. The maximum length is 64 characters. Ensure that you set this parameter. + /// Supported characters include the 26 English letters (a-z), the ten numbers (0-9), the underscore (_), the hyphen (-), + /// and the English period (.). This parameter is case insensitive, and upper-case letters are automatically changed to low-case ones. + /// If you want to set this parameter as a regular expression, set it as ^[a-zA-Z0-9_-]+$. + /// + /// Param [password] The password. The maximum length is 64 characters. Ensure that you set this parameter. + /// + /// **Throws** [EMError] A description of the issue that caused this error. + /// + Future createAccount(String username, String password) async { EMLog.v('create account: $username : $password'); Map req = {'username': username, 'password': password}; Map result = await _channel.invokeMethod(ChatMethodKeys.createAccount, req); try { EMError.hasErrorFromResult(result); - return result[ChatMethodKeys.createAccount]; } on EMError catch (e) { throw e; } } - /// 使用用户名(环信id)和密码(或token)登录,[username], [pwdOrToken] - /// 返回登录成功的id(环信id) + /// + /// An app user logs in to the chat server with a password or token + /// + /// Param [username] The unique chat user ID, the same as username. + /// + /// Param [pwdOrToken] The password or token. + /// + /// Param [isPassword] login With password or token. + /// `true`: (default) login with password. + /// `false`: login with token. + /// + /// **Throws** [EMError] A description of the issue that caused this error. + /// Future login(String username, String pwdOrToken, [bool isPassword = true]) async { EMLog.v('login: $username : $pwdOrToken, isPassword: $isPassword'); @@ -139,15 +164,22 @@ class EMClient { Map result = await _channel.invokeMethod(ChatMethodKeys.login, req); try { EMError.hasErrorFromResult(result); - _currentUsername = result[ChatMethodKeys.login]; + _currentUsername = username; } on EMError catch (e) { throw e; } } - /// 退出登录,是否解除deviceToken绑定[unbindDeviceToken] - /// 返回退出是否成功 - Future logout([ + /// + /// An app user logs out. + /// + /// Param [unbindDeviceToken] Whether to unbind the token. + /// `true`: (default) unbind the device token when logout. + /// `false`: not unbind the device token when logout. + /// + /// **Throws** [EMError] A description of the issue that caused this error. + /// + Future logout([ bool unbindDeviceToken = true, ]) async { EMLog.v('logout unbindDeviceToken: $unbindDeviceToken'); @@ -156,7 +188,6 @@ class EMClient { try { EMError.hasErrorFromResult(result); _clearAllInfo(); - return result.boolValue(ChatMethodKeys.logout); } on EMError catch (e) { throw e; } diff --git a/lib/src/em_contact_manager.dart b/lib/src/em_contact_manager.dart index 415b710a..d9aedee3 100644 --- a/lib/src/em_contact_manager.dart +++ b/lib/src/em_contact_manager.dart @@ -2,9 +2,14 @@ import 'dart:async'; import 'package:flutter/services.dart'; -import '../im_flutter_sdk.dart'; +import 'em_listeners.dart'; import 'internal/chat_method_keys.dart'; +import 'internal/em_event_keys.dart'; +import 'models/em_error.dart'; +/// +/// The `EMContactManager` is used to record, query, and modify contacts. +/// class EMContactManager { static const _channelPrefix = 'com.chat.im'; static const MethodChannel _channel = const MethodChannel( @@ -23,7 +28,6 @@ class EMContactManager { final List _contactChangeEventListeners = []; - /// @nodoc Future _onContactChanged(Map event) async { var type = event['type']; String? username = event['username']; @@ -50,8 +54,16 @@ class EMContactManager { } } - /// 添加联系人[username] with [reason]. - Future addContact( + /// + /// Adds a new contact. + /// + /// Param [username] The user to be added. + /// + /// Param [reason] (optional) The invitation message. Set the parameter as null if you want to ignore the information. + /// + /// **Throws** [EMError] A description of the issue that caused this error. + /// + Future addContact( String username, [ String reason = '', ]) async { @@ -59,15 +71,23 @@ class EMContactManager { Map result = await _channel.invokeMethod(ChatMethodKeys.addContact, req); try { EMError.hasErrorFromResult(result); - return result[ChatMethodKeys.addContact]; } on EMError catch (e) { throw e; } } - /// 删除联系人 [username] - /// [keepConversation] true 保留会话和消息 false 不保留, 默认为false - Future deleteContact( + /// + /// Deletes a contact and all the conversations associated. + /// + /// Param [username] The contact to be deleted. + /// + /// Param [keepConversation] Whether to keep the associated conversation and messages. + /// `true`: keep conversation and messages. + /// `false`: (default) delete conversation and messages. + /// + /// **Throws** [EMError] A description of the issue that caused this error. + /// + Future deleteContact( String username, [ bool keepConversation = false, ]) async { @@ -75,13 +95,18 @@ class EMContactManager { Map result = await _channel.invokeMethod(ChatMethodKeys.deleteContact, req); try { EMError.hasErrorFromResult(result); - return result[ChatMethodKeys.deleteContact]; } on EMError catch (e) { throw e; } } - /// 从服务器获取所有的好友 + /// + /// Get all contacts from the server. + /// + /// **return** The list of contacts. + /// + /// **Throws** [EMError] A description of the issue that caused this error. + /// Future> getAllContactsFromServer() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getAllContactsFromServer); @@ -89,7 +114,6 @@ class EMContactManager { EMError.hasErrorFromResult(result); List contacts = []; result[ChatMethodKeys.getAllContactsFromServer]?.forEach((element) { - // 此处做了一个适配,目前native 返回的都是String, 为了避免以后出现进一步扩展,flutter直接返回contact对象 contacts.add(element); }); return contacts; @@ -98,7 +122,13 @@ class EMContactManager { } } - /// 从本地获取所有的好友 + /// + /// Gets the contact list from the local database. + /// + /// **return** The contact list. + /// + /// **Throws** [EMError] A description of the issue that caused this error. + /// Future> getAllContactsFromDB() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getAllContactsFromDB); @@ -106,7 +136,6 @@ class EMContactManager { EMError.hasErrorFromResult(result); List contacts = []; result[ChatMethodKeys.getAllContactsFromDB]?.forEach((element) { - // 此处做了一个适配,目前native 返回的都是String, 为了避免以后出现进一步扩展,flutter直接返回contact对象 contacts.add(element); }); @@ -116,35 +145,54 @@ class EMContactManager { } } - /// 把指定用户加入到黑名单中 [username] . - Future addUserToBlockList( + /// + /// Adds a user to block list. + /// You can send message to the user in block list, but you can not receive the message sent by the other. + /// + /// Param [username] The user to be blocked. + /// + /// **Throws** [EMError] A description of the issue that caused this error. + /// + Future addUserToBlockList( String username, ) async { Map req = {'username': username}; - Map result = - await _channel.invokeMethod(ChatMethodKeys.addUserToBlockList, req); + Map result = await _channel.invokeMethod( + ChatMethodKeys.addUserToBlockList, + req, + ); try { EMError.hasErrorFromResult(result); - return result[ChatMethodKeys.addUserToBlockList]; } on EMError catch (e) { throw e; } } - /// 把用户从黑名单中移除 [username]. - Future removeUserFromBlockList(String username) async { + /// + /// Removes the contact from the block list. + /// + /// Param [username] The user to be removed from the block list. + /// + /// **Throws** [EMError] A description of the issue that caused this error. + /// + Future removeUserFromBlockList(String username) async { Map req = {'username': username}; Map result = await _channel.invokeMethod( ChatMethodKeys.removeUserFromBlockList, req); try { EMError.hasErrorFromResult(result); - return result[ChatMethodKeys.removeUserFromBlockList]; } on EMError catch (e) { throw e; } } - /// 从服务器获取黑名单列表 + /// + /// Get all block list from the server. + /// + /// **return** The block list from the server. + /// + /// **Throws** [EMError] A description of the issue that caused this error. + /// Future> getBlockListFromServer() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getBlockListFromServer); @@ -152,7 +200,6 @@ class EMContactManager { EMError.hasErrorFromResult(result); List blockList = []; result[ChatMethodKeys.getBlockListFromServer]?.forEach((element) { - // 此处做了一个适配,目前native 返回的都是String, 为了避免以后出现进一步扩展,flutter直接返回contact对象 blockList.add(element); }); return blockList; @@ -161,7 +208,13 @@ class EMContactManager { } } - /// 从本地数据库中获取黑名单列表 + /// + /// Gets the local database block list. + /// + /// **return** The block list. + /// + /// **Throws** [EMError] A description of the issue that caused this error. + /// Future> getBlockListFromDB() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getBlockListFromDB); try { @@ -176,33 +229,49 @@ class EMContactManager { } } - /// 接受加好友的邀请[username]. - Future acceptInvitation(String username) async { + /// + /// Accepts a friend invitation。 + /// + /// Param [username] The user who initiates the friend request. + /// + /// **Throws** [EMError] A description of the issue that caused this error. + /// + Future acceptInvitation(String username) async { Map req = {'username': username}; Map result = await _channel.invokeMethod(ChatMethodKeys.acceptInvitation, req); try { EMError.hasErrorFromResult(result); - return result[ChatMethodKeys.acceptInvitation]; } on EMError catch (e) { throw e; } } - /// 拒绝加好友的邀请 [username]. - Future declineInvitation(String username) async { + /// + /// Declines a friend invitation. + /// + /// Param [username] The user who initiates the invitation. + /// + /// **Throws** [EMError] A description of the issue that caused this error. + /// + Future declineInvitation(String username) async { Map req = {'username': username}; Map result = await _channel.invokeMethod(ChatMethodKeys.declineInvitation, req); try { EMError.hasErrorFromResult(result); - return result[ChatMethodKeys.declineInvitation]; } on EMError catch (e) { throw e; } } - /// 从服务器获取登录用户在其他设备上登录的ID + /// + /// Get the unique IDs of current user on the other devices. The ID is username + "/" + resource. + /// + /// **return** The unique device ID list on the other devices if the method succeeds. + /// + /// **Throws** [EMError] A description of the issue that caused this error. + /// Future?> getSelfIdsOnOtherPlatform() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getSelfIdsOnOtherPlatform); @@ -216,23 +285,23 @@ class EMContactManager { } } - /// 设置好友监听器 [contactListener] + /// + /// Registers a new contact listener. + /// + /// Param [contactListener] The contact listener to be registered. + /// void addContactListener(EMContactEventListener contactListener) { _contactChangeEventListeners.add(contactListener); } - /// 移除好友监听器 [contactListener] + /// + /// Removes the contact listener. + /// + /// Param [contactListener] The contact listener to be removed. + /// void removeContactListener(EMContactEventListener contactListener) { if (_contactChangeEventListeners.contains(contactListener)) { _contactChangeEventListeners.remove(contactListener); } } } - -class EMContactChangeEvent { - static const String CONTACT_ADD = 'onContactAdded'; - static const String CONTACT_DELETE = 'onContactDeleted'; - static const String INVITED = 'onContactInvited'; - static const String INVITATION_ACCEPTED = 'onFriendRequestAccepted'; - static const String INVITATION_DECLINED = 'onFriendRequestDeclined'; -} From b1564ef24c9ec8a5a004879b3e1a68a05d6d9c0c Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Sun, 27 Mar 2022 10:21:05 +0800 Subject: [PATCH 08/56] update --- CHANGELOG.md | 2 +- ios/Classes/EMClientWrapper.m | 2 +- pubspec.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1200b4b4..a5d3c7b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## NEXT -## 3.8.3+7 +## 3.8.3+8` - 修复ios使用token登录失败; - 修改Login方法和Logout方法返回值; diff --git a/ios/Classes/EMClientWrapper.m b/ios/Classes/EMClientWrapper.m index 89318bd2..997cf8ba 100644 --- a/ios/Classes/EMClientWrapper.m +++ b/ios/Classes/EMClientWrapper.m @@ -241,7 +241,7 @@ - (void)login:(NSDictionary *)param channelName:(NSString *)aChannelName result: [weakSelf wrapperCallBack:result channelName:aChannelName error:aError - object:EMClient.sharedClient.accessUserToken]; + object:EMClient.sharedClient.currentUsername]; }]; } } diff --git a/pubspec.yaml b/pubspec.yaml index cb7bf69d..469f87cd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: im_flutter_sdk description: Easemob IM flutter SDK. -version: 3.8.3+7 +version: 3.8.3+8 homepage: http://www.easemob.com/product/im environment: From 103ee55e2a62d531fe79dfbb75d194f7cce21e4c Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Sun, 27 Mar 2022 10:22:30 +0800 Subject: [PATCH 09/56] update --- CHANGELOG.md | 2 +- ios/Classes/EMClientWrapper.m | 3 +-- pubspec.yaml | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1200b4b4..a86947fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## NEXT -## 3.8.3+7 +## 3.8.3+8 - 修复ios使用token登录失败; - 修改Login方法和Logout方法返回值; diff --git a/ios/Classes/EMClientWrapper.m b/ios/Classes/EMClientWrapper.m index 89318bd2..5519db3c 100644 --- a/ios/Classes/EMClientWrapper.m +++ b/ios/Classes/EMClientWrapper.m @@ -227,7 +227,6 @@ - (void)login:(NSDictionary *)param channelName:(NSString *)aChannelName result: password:pwdOrToken completion:^(NSString *aUsername, EMError *aError) { - [weakSelf wrapperCallBack:result channelName:aChannelName error:aError @@ -241,7 +240,7 @@ - (void)login:(NSDictionary *)param channelName:(NSString *)aChannelName result: [weakSelf wrapperCallBack:result channelName:aChannelName error:aError - object:EMClient.sharedClient.accessUserToken]; + object:EMClient.sharedClient.currentUsername]; }]; } } diff --git a/pubspec.yaml b/pubspec.yaml index cb7bf69d..469f87cd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: im_flutter_sdk description: Easemob IM flutter SDK. -version: 3.8.3+7 +version: 3.8.3+8 homepage: http://www.easemob.com/product/im environment: From 1596c83b6345e6b8a0f78e5cae490ef7e4f652f0 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Mon, 28 Mar 2022 10:34:41 +0800 Subject: [PATCH 10/56] update doc --- lib/src/em_chat_manager.dart | 13 ++ lib/src/em_client.dart | 193 +++++++++++------- lib/src/internal/em_enum_transform_tools.dart | 58 ++++++ 3 files changed, 185 insertions(+), 79 deletions(-) create mode 100644 lib/src/internal/em_enum_transform_tools.dart diff --git a/lib/src/em_chat_manager.dart b/lib/src/em_chat_manager.dart index 206e3956..b9619f17 100644 --- a/lib/src/em_chat_manager.dart +++ b/lib/src/em_chat_manager.dart @@ -6,6 +6,18 @@ import '../im_flutter_sdk.dart'; import 'internal/chat_method_keys.dart'; import 'tools/em_message_callback_manager.dart'; +/// +/// The chat manager. This class is responsible for managing conversations. +/// (such as: load, delete), sending messages, downloading attachments and so on. +/// +/// Such as, send a text message: +/// +/// ```dart +/// EMMessage msg = EMMessage.createTxtSendMessage( +/// username: toChatUsername, content: content); +/// await EMClient.getInstance.chatManager.sendMessage(msg); +/// ``` +/// class EMChatManager { static const _channelPrefix = 'com.chat.im'; static const MethodChannel _channel = @@ -13,6 +25,7 @@ class EMChatManager { final List _messageListeners = []; + /// @nodoc EMChatManager() { MessageCallBackManager.getInstance; _channel.setMethodCallHandler((MethodCall call) async { diff --git a/lib/src/em_client.dart b/lib/src/em_client.dart index 3779a12f..f7a9ba86 100644 --- a/lib/src/em_client.dart +++ b/lib/src/em_client.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:flutter/services.dart'; +import 'internal/em_enum_transform_tools.dart'; import 'tools/em_extension.dart'; import '../im_flutter_sdk.dart'; import 'internal/chat_method_keys.dart'; @@ -193,7 +194,16 @@ class EMClient { } } - /// 修改appKey [newAppKey]. + /// + /// Update the App Key, which is the unique identifier used to access Agora Chat. + /// + /// You retrieve the new App Key from Agora Console. + /// + /// As this key controls all access to Agora Chat for your app, you can only update the key when the current user is logged out. + /// + /// + /// Param [newAppKey] The App Key, make sure to set the param. + /// Future changeAppKey({required String newAppKey}) async { EMLog.v('changeAppKey: $newAppKey'); Map req = {'appKey': newAppKey}; @@ -206,15 +216,15 @@ class EMClient { } } - // /// @nodoc 上传日志到环信, 不对外暴露 - // Future _uploadLog() async { - // Map result = await _channel.invokeMethod(ChatMethodKeys.uploadLog); - // EMError.hasErrorFromResult(result); - // return true; - // } - - /// 压缩环信日志 - /// 返回日志路径 + /// + /// Compresses the debug log into a gzip archive. + /// + /// Best practice is to delete this debug archive as soon as it is no longer used. + /// + /// **return** The path of the compressed gz file. + /// + /// **Throws** [EMError] A description of the issue that caused this error. + /// Future compressLogs() async { EMLog.v('compressLogs:'); Map result = await _channel.invokeMethod(ChatMethodKeys.compressLogs); @@ -226,8 +236,17 @@ class EMClient { } } - /// 获取账号名下登陆的在线设备列表 - /// 当前登录账号和密码 [username]/[password]. + /// + /// Gets all the information about the logged in devices under the specified account. + /// + /// Param [username] The user ID you want to get the device information. + /// + /// Param [password] The password. + /// + /// **return** The list of the online devices. + /// + /// **Throws** [EMError] A description of the issue that caused this error. + /// Future> getLoggedInDevicesFromServer( {required String username, required String password}) async { EMLog.v('getLoggedInDevicesFromServer: $username, "******"'); @@ -246,8 +265,17 @@ class EMClient { } } - /// 根据设备ID,将该设备下线, - /// 账号和密码 [username]/[password] 设备ID[resource]. + /// + /// Force the specified account to logout from the specified device, to fetch the device ID: {@link EMDeviceInfo#resource}. + /// + /// Param [username] The account you want to force logout. + /// + /// Param [password] The account's password. + /// + /// Param [resource] The device ID, see {@link EMDeviceInfo#resource}. + /// + /// **Throws** [EMError] A description of the issue that caused this error. + /// Future kickDevice( {required String username, required String password, @@ -267,9 +295,16 @@ class EMClient { } } - /// 将该账号下的所有设备都踢下线 - /// 账号和密码 [username]/[password]. - Future kickAllDevices( + /// + /// Kicks out all the devices logged in under the specified account. + /// + /// Param [username] The account you want to log out from all the devices. + /// + /// Param [password] The account's password. + /// + /// **Throws** [EMError] A description of the issue that caused this error. + /// + Future kickAllDevices( {required String username, required String password}) async { EMLog.v('kickAllDevices: $username, "******"'); Map req = {'username': username, 'password': password}; @@ -277,7 +312,6 @@ class EMClient { await _channel.invokeMethod(ChatMethodKeys.kickAllDevices, req); try { EMError.hasErrorFromResult(result); - return result.boolValue(ChatMethodKeys.kickAllDevices); } on EMError catch (e) { throw e; } @@ -285,34 +319,62 @@ class EMClient { /* Listeners*/ - /// @nodoc 添加多设备监听的接口 [listener]. + /// + /// Adds the multi-device listener. + /// + /// Param [listener] See {EMMultiDeviceListener} + /// void addMultiDeviceListener(EMMultiDeviceListener listener) { _multiDeviceListeners.add(listener); } - /// @nodoc 移除多设备监听的接口[listener]. + /// + /// Removes the multi-device listener. + /// + /// Param [listener] See {EMMultiDeviceListener} + /// void removeMultiDeviceListener(EMMultiDeviceListener listener) { if (_multiDeviceListeners.contains(listener)) { _multiDeviceListeners.remove(listener); } } - /// 添加链接状态监听的接口[listener]. + /// + /// Adds the connection listener of chat server. + /// + /// Param [listener] The chat server connection listener. + /// void addConnectionListener(EMConnectionListener listener) { _connectionListeners.add(listener); } - /// 移除链接状态监听的接口[listener]. + /// + /// Removes the chat server connection listener. + /// + /// Param [listener] The chat server connection listener. + /// void removeConnectionListener(EMConnectionListener listener) { if (_connectionListeners.contains(listener)) { _connectionListeners.remove(listener); } } + /// + /// Adds the custom listener of native. + /// + /// 你可以从原生发送数据到flutter. + /// + /// Param [listener] The custom native listener. + /// void addCustomListener(EMCustomListener listener) { _customListeners.add(listener); } + /// + /// Removes the custom listener. + /// + /// Param [listener] The custom native listener. + /// void removeCustomListener(EMCustomListener listener) { if (_customListeners.contains(listener)) { _customListeners.remove(listener); @@ -351,87 +413,60 @@ class EMClient { } } + /// + /// Gets the `EMChatManager` class. Make sure to call it after EMClient has been initialized, see {@link EMClient#init(EMOptions)} + /// + /// **return** The `EMChatManager` class. + /// EMChatManager get chatManager { return _chatManager; } + /// + /// Gets the `EMContactManager` class. Make sure to call it after the EMClient has been initialized, see {@link EMClient#init(EMOptions)} + /// + /// **return** The `EMContactManager` class. + /// EMContactManager get contactManager { return _contactManager; } + /// + /// Gets the `ChatRoomManager` class. Make sure to call it after the EMClient has been initialized, see {@link EMClient#init(EMOptions)} + /// + /// **return** The `EMChatRoomManager` class. + /// EMChatRoomManager get chatRoomManager { return _chatRoomManager; } + /// + /// Gets the `EMGroupManager` class. Make sure to call it after the EMClient has been initialized, see {@link EMClient#init(EMOptions)} + /// + /// **return** The `EMGroupManager` class. + /// EMGroupManager get groupManager { return _groupManager; } + /// + /// Gets the `EMPushManager` class. Make sure to call it after the EMClient has been initialized, see {@link EMClient#init(EMOptions)} + /// + /// **return** The `EMPushManager` class. + /// EMPushManager get pushManager { return _pushManager; } + /// + /// Gets the `EMUserInfoManager` class. Make sure to call it after the EMClient has been initialized, see {@link EMClient#init(EMOptions)} + /// + /// **return** The `EMUserInfoManager` class. + /// EMUserInfoManager get userInfoManager { return _userInfoManager; } - EMContactGroupEvent? convertIntToEMContactGroupEvent(int? i) { - switch (i) { - case 2: - return EMContactGroupEvent.CONTACT_REMOVE; - case 3: - return EMContactGroupEvent.CONTACT_ACCEPT; - case 4: - return EMContactGroupEvent.CONTACT_DECLINE; - case 5: - return EMContactGroupEvent.CONTACT_BAN; - case 6: - return EMContactGroupEvent.CONTACT_ALLOW; - case 10: - return EMContactGroupEvent.GROUP_CREATE; - case 11: - return EMContactGroupEvent.GROUP_DESTROY; - case 12: - return EMContactGroupEvent.GROUP_JOIN; - case 13: - return EMContactGroupEvent.GROUP_LEAVE; - case 14: - return EMContactGroupEvent.GROUP_APPLY; - case 15: - return EMContactGroupEvent.GROUP_APPLY_ACCEPT; - case 16: - return EMContactGroupEvent.GROUP_APPLY_DECLINE; - case 17: - return EMContactGroupEvent.GROUP_INVITE; - case 18: - return EMContactGroupEvent.GROUP_INVITE_ACCEPT; - case 19: - return EMContactGroupEvent.GROUP_INVITE_DECLINE; - case 20: - return EMContactGroupEvent.GROUP_KICK; - case 21: - return EMContactGroupEvent.GROUP_BAN; - case 22: - return EMContactGroupEvent.GROUP_ALLOW; - case 23: - return EMContactGroupEvent.GROUP_BLOCK; - case 24: - return EMContactGroupEvent.GROUP_UNBLOCK; - case 25: - return EMContactGroupEvent.GROUP_ASSIGN_OWNER; - case 26: - return EMContactGroupEvent.GROUP_ADD_ADMIN; - case 27: - return EMContactGroupEvent.GROUP_REMOVE_ADMIN; - case 28: - return EMContactGroupEvent.GROUP_ADD_MUTE; - case 29: - return EMContactGroupEvent.GROUP_REMOVE_MUTE; - default: - return null; - } - } - void _clearAllInfo() { _currentUsername = null; _userInfoManager.clearUserInfoCache(); diff --git a/lib/src/internal/em_enum_transform_tools.dart b/lib/src/internal/em_enum_transform_tools.dart new file mode 100644 index 00000000..d7a29db4 --- /dev/null +++ b/lib/src/internal/em_enum_transform_tools.dart @@ -0,0 +1,58 @@ +import '../em_listeners.dart'; + +EMContactGroupEvent? convertIntToEMContactGroupEvent(int? i) { + switch (i) { + case 2: + return EMContactGroupEvent.CONTACT_REMOVE; + case 3: + return EMContactGroupEvent.CONTACT_ACCEPT; + case 4: + return EMContactGroupEvent.CONTACT_DECLINE; + case 5: + return EMContactGroupEvent.CONTACT_BAN; + case 6: + return EMContactGroupEvent.CONTACT_ALLOW; + case 10: + return EMContactGroupEvent.GROUP_CREATE; + case 11: + return EMContactGroupEvent.GROUP_DESTROY; + case 12: + return EMContactGroupEvent.GROUP_JOIN; + case 13: + return EMContactGroupEvent.GROUP_LEAVE; + case 14: + return EMContactGroupEvent.GROUP_APPLY; + case 15: + return EMContactGroupEvent.GROUP_APPLY_ACCEPT; + case 16: + return EMContactGroupEvent.GROUP_APPLY_DECLINE; + case 17: + return EMContactGroupEvent.GROUP_INVITE; + case 18: + return EMContactGroupEvent.GROUP_INVITE_ACCEPT; + case 19: + return EMContactGroupEvent.GROUP_INVITE_DECLINE; + case 20: + return EMContactGroupEvent.GROUP_KICK; + case 21: + return EMContactGroupEvent.GROUP_BAN; + case 22: + return EMContactGroupEvent.GROUP_ALLOW; + case 23: + return EMContactGroupEvent.GROUP_BLOCK; + case 24: + return EMContactGroupEvent.GROUP_UNBLOCK; + case 25: + return EMContactGroupEvent.GROUP_ASSIGN_OWNER; + case 26: + return EMContactGroupEvent.GROUP_ADD_ADMIN; + case 27: + return EMContactGroupEvent.GROUP_REMOVE_ADMIN; + case 28: + return EMContactGroupEvent.GROUP_ADD_MUTE; + case 29: + return EMContactGroupEvent.GROUP_REMOVE_MUTE; + default: + return null; + } +} From 978c3cfd5e7acb91acc26abb63ad60496d17765d Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Tue, 29 Mar 2022 15:43:50 +0800 Subject: [PATCH 11/56] update api referance. --- .../im_flutter_sdk/EMGroupManagerWrapper.java | 79 +- .../lib/pages/chat/chat_items/chat_item.dart | 2 +- example/lib/pages/chat/chat_page.dart | 6 +- .../conversations/conversations_page.dart | 4 +- .../lib/pages/group/joined_groups_page.dart | 6 + lib/src/em_chat_manager.dart | 332 ++++++-- lib/src/em_chat_room_manager.dart | 409 ++++++++-- lib/src/em_client.dart | 58 +- lib/src/em_contact_manager.dart | 22 +- lib/src/em_group_manager.dart | 733 ++++++++++++++---- lib/src/em_push_manager.dart | 3 + lib/src/em_userInfo_manager.dart | 106 +-- lib/src/internal/chat_method_keys.dart | 1 + lib/src/models/em_group_options.dart | 13 +- lib/src/models/em_message.dart | 5 +- 15 files changed, 1426 insertions(+), 353 deletions(-) diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMGroupManagerWrapper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMGroupManagerWrapper.java index add90788..9ba82fc3 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMGroupManagerWrapper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMGroupManagerWrapper.java @@ -152,6 +152,7 @@ private void getGroupWithId(JSONObject param, String channelName, Result result) } private void getJoinedGroups(JSONObject param, String channelName, Result result) throws JSONException { + EMClient.getInstance().groupManager().loadAllGroups(); List groups = EMClient.getInstance().groupManager().getAllGroups(); List groupList = new ArrayList<>(); for (EMGroup group : groups) { @@ -190,8 +191,10 @@ public void onSuccess(List object) { private void getPublicGroupsFromServer(JSONObject param, String channelName, Result result) throws JSONException { int pageSize = param.getInt("pageSize"); - String cursor = param.getString("cursor"); - + String cursor = null; + if (param.has("cursor")){ + cursor = param.getString("cursor"); + } EMValueWrapperCallBack> callBack = new EMValueWrapperCallBack>( result, channelName) { @Override @@ -204,14 +207,34 @@ public void onSuccess(EMCursorResult object) { } private void createGroup(JSONObject param, String channelName, Result result) throws JSONException { - String groupName = param.getString("groupName"); - String desc = param.getString("desc"); - JSONArray inviteMembers = param.getJSONArray("inviteMembers"); - String[] members = new String[inviteMembers.length()]; - for (int i = 0; i < inviteMembers.length(); i++) { - members[i] = inviteMembers.getString(i); + String groupName = null; + + if (param.has("groupName")){ + groupName = param.getString("groupName"); + } + + String desc = null; + if(param.has("desc")){ + desc = param.getString("desc"); + } + + String[] members = null; + if(param.has("inviteMembers")){ + JSONArray inviteMembers = param.getJSONArray("inviteMembers"); + members = new String[inviteMembers.length()]; + for (int i = 0; i < inviteMembers.length(); i++) { + members[i] = inviteMembers.getString(i); + } } - String inviteReason = param.getString("inviteReason"); + if (members == null) { + members = new String[0]; + } + String inviteReason = null; + + if (param.has("inviteReason")){ + inviteReason = param.getString("inviteReason"); + } + EMGroupOptions options = EMGroupOptionsHelper.fromJson(param.getJSONObject("options")); EMValueWrapperCallBack callBack = new EMValueWrapperCallBack(result, channelName) { @@ -242,7 +265,10 @@ public void onSuccess(EMGroup object) { private void getGroupMemberListFromServer(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - String cursor = param.getString("cursor"); + String cursor = null; + if(param.has("cursor")){ + cursor = param.getString("cursor"); + } int pageSize = param.getInt("pageSize"); EMValueWrapperCallBack> callBack = new EMValueWrapperCallBack>( @@ -347,9 +373,19 @@ private void addMembers(JSONObject param, String channelName, Result result) thr members[i] = array.getString(i); } - - EMClient.getInstance().groupManager().asyncAddUsersToGroup(groupId, members, - new EMWrapperCallBack(result, channelName, true)); + String welcome = null; + if (param.has("welcome")){ + welcome = param.getString("welcome"); + } + String finalWelcome = welcome; + asyncRunnable(() -> { + try { + EMClient.getInstance().groupManager().addUsersToGroup(groupId, members, finalWelcome); + onSuccess(result, channelName, true); + } catch (HyphenateException e) { + onError(result, e); + } + }); } private void removeMembers(JSONObject param, String channelName, Result result) throws JSONException { @@ -664,7 +700,10 @@ public void onSuccess() { private void requestToJoinPublicGroup(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - + String reason = null; + if (param.has("reason")){ + reason = param.getString("reason"); + } EMWrapperCallBack callBack = new EMWrapperCallBack(result, channelName, null) { @Override public void onSuccess() { @@ -674,7 +713,7 @@ public void onSuccess() { } }; - EMClient.getInstance().groupManager().asyncJoinGroup(groupId, callBack); + EMClient.getInstance().groupManager().asyncApplyJoinToGroup(groupId, reason, callBack); } private void acceptJoinApplication(JSONObject param, String channelName, Result result) throws JSONException { @@ -696,7 +735,10 @@ public void onSuccess() { private void declineJoinApplication(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); String username = param.getString("username"); - String reason = param.getString("reason"); + String reason = null; + if (param.has("reason")){ + reason = param.getString("reason"); + } EMWrapperCallBack callBack = new EMWrapperCallBack(result, channelName, null) { @Override @@ -727,7 +769,10 @@ public void onSuccess(EMGroup object) { private void declineInvitationFromGroup(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); String username = param.getString("username"); - String reason = param.getString("reason"); + String reason = null; + if (param.has("reason")){ + reason = param.getString("reason"); + } EMWrapperCallBack callBack = new EMWrapperCallBack(result, channelName, null) { @Override diff --git a/example/lib/pages/chat/chat_items/chat_item.dart b/example/lib/pages/chat/chat_items/chat_item.dart index 848a1f18..e597779f 100644 --- a/example/lib/pages/chat/chat_items/chat_item.dart +++ b/example/lib/pages/chat/chat_items/chat_item.dart @@ -44,7 +44,7 @@ class ChatItem extends StatefulWidget { class ChatItemState extends State implements EMMessageStatusListener { void initState() { super.initState(); - widget.msg.setMessageListener(this); + widget.msg.setMessageStatusListener(this); } @override diff --git a/example/lib/pages/chat/chat_page.dart b/example/lib/pages/chat/chat_page.dart index 5599d9d9..dc9279df 100644 --- a/example/lib/pages/chat/chat_page.dart +++ b/example/lib/pages/chat/chat_page.dart @@ -71,7 +71,7 @@ class _ChatPageState extends State _moreView = ChatMoreView(items); // 添加环信回调监听 - EMClient.getInstance.chatManager.addListener(this); + EMClient.getInstance.chatManager.addChatManagerListener(this); EMClient.getInstance.chatRoomManager.addChatRoomChangeListener(this); // 设置所有消息已读 widget.conversation.markAllMessagesAsRead(); @@ -95,13 +95,13 @@ class _ChatPageState extends State .joinChatRoom(widget.conversation.id); _loadMessages(); } on EMError catch (e) { - print("加入房间失败 -- " + e.toString()); + debugPrint("加入房间失败 -- " + e.toString()); } } void dispose() { // 移除环信回调监听 - EMClient.getInstance.chatManager.removeListener(this); + EMClient.getInstance.chatManager.removeChatManagerListener(this); _scrollController.dispose(); _inputBarEditingController.dispose(); if (widget.conversation.type == EMConversationType.ChatRoom) { diff --git a/example/lib/pages/conversations/conversations_page.dart b/example/lib/pages/conversations/conversations_page.dart index 4bc00a64..37ed4b87 100644 --- a/example/lib/pages/conversations/conversations_page.dart +++ b/example/lib/pages/conversations/conversations_page.dart @@ -33,7 +33,7 @@ class ConversationPageState extends State void initState() { super.initState(); // 添加环信回调监听 - EMClient.getInstance.chatManager.addListener(this); + EMClient.getInstance.chatManager.addChatManagerListener(this); notifier = eventBus.on().listen((event) { if (event.eventKey == EventBusManager.updateConversationsList) { _reLoadAllConversations(); @@ -44,7 +44,7 @@ class ConversationPageState extends State void dispose() { _refreshController.dispose(); // 移除环信回调监听 - EMClient.getInstance.chatManager.removeListener(this); + EMClient.getInstance.chatManager.removeChatManagerListener(this); notifier.cancel(); super.dispose(); } diff --git a/example/lib/pages/group/joined_groups_page.dart b/example/lib/pages/group/joined_groups_page.dart index 0eaca992..cb4a1ca8 100644 --- a/example/lib/pages/group/joined_groups_page.dart +++ b/example/lib/pages/group/joined_groups_page.dart @@ -271,6 +271,12 @@ class JoinedGroupsPageState extends State { } _chat(EMGroup group) async { + EMCursorResult result = await EMClient.getInstance.groupManager + .getGroupMemberListFromServer("groupId", cursor: null); + + result = await EMClient.getInstance.groupManager + .getGroupMemberListFromServer("groupId", cursor: result.cursor); + EMConversation? con = await EMClient.getInstance.chatManager.getConversation( group.groupId, diff --git a/lib/src/em_chat_manager.dart b/lib/src/em_chat_manager.dart index a24df1fc..aedeeeba 100644 --- a/lib/src/em_chat_manager.dart +++ b/lib/src/em_chat_manager.dart @@ -50,7 +50,19 @@ class EMChatManager { }); } - /// 发送消息 [message]. + /// + /// Sends a message. + /// + /// Reference: + /// If the message is voice, picture and other message with attachment, the SDK will automatically upload the attachment. + /// You can set whether to upload the attachment to the chat sever by {@link EMOptions#serverTransfer(boolean)}. + /// + /// To listen for the status of sending messages, call {@link EMMessage#setMessageStatusListener(EMMessageStatusListener)}. + /// + /// Param [message] The message object to be sent + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future sendMessage(EMMessage message) async { message.status = EMMessageStatus.PROGRESS; Map result = await _channel.invokeMethod( @@ -84,7 +96,22 @@ class EMChatManager { } } - /// 发送消息已读 [message]. + /// + /// Sends the read receipt to the server. + /// + /// This method applies to one-to-one chats only. + /// + /// Precondition: set {@link EMOptions#requireAck(bool)}. + /// + /// Reference: + /// To send the group message read receipt, call {@link #sendGroupMessageReadAck(String, String, String)}. + /// + /// We recommend that you call {@link #sendConversationReadAck(String)} when entering a chat page, and call this method in other cases to reduce the number of method calls. + /// + /// Param [message] The message. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future sendMessageReadAck(EMMessage message) async { Map req = {"to": message.from, "msg_id": message.msgId}; Map result = @@ -97,6 +124,23 @@ class EMChatManager { } } + /// + /// Sends the group message receipt to the server. + /// + /// You can only call the method after setting the following method: {@link EMOptions#requireAck(bool)} and {@link EMMessage#needGroupAck(bool)}. + /// + /// Reference: + /// To send the one-to-one chat message receipt to server, call {@link #sendMessageReadAck(EMMessage)}; + /// To send the conversation receipt to the server, call {@link #sendConversationReadAck(String)}. + /// + /// Param [msgId] The message ID. + /// + /// Param [groupId] The group ID. + /// + /// Param [content] The extension information. Developer self-defined command string that can be used for specifying custom action/command. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future sendGroupMessageReadAck( String msgId, String groupId, { @@ -119,7 +163,19 @@ class EMChatManager { } } - /// 发送会话已读 [conversationId]为会话Id + /// + /// Sends the conversation read receipt to the server. This method is only for one-to-one chat conversation. + /// + /// This method will inform the sever to set the unread message count of the conversation to 0, and conversation list (with multiple devices) will receive + /// a callback method from {@link EMChatManagerListener#onConversationRead(String, String)}. + /// + /// Reference: + /// To send the group message read receipt, call {@link #sendGroupMessageReadAck(String, String, String)}. + /// + /// Param [conversationId] The conversation ID. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future sendConversationReadAck(String conversationId) async { Map req = {"con_id": conversationId}; Map result = @@ -132,7 +188,13 @@ class EMChatManager { } } - /// 撤回发送的消息(增值服务), 默认时效为2分钟,超过2分钟无法撤回. + /// + /// Recalls the sent message. + /// + /// Param [messageId] The message id. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future recallMessage(String messageId) async { Map req = {"msg_id": messageId}; Map result = await _channel.invokeMethod(ChatMethodKeys.recallMessage, req); @@ -144,20 +206,49 @@ class EMChatManager { } } - /// 通过[messageId]从db获取消息. - Future loadMessage(String messageId) async { + /// + /// Fetches message for local database by message ID. + /// + /// Param [messageId] The message ID. + /// + /// **return** The message object obtained by the specified ID. Returns null if the message doesn't exist. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future loadMessage(String messageId) async { Map req = {"msg_id": messageId}; Map result = await _channel.invokeMethod(ChatMethodKeys.getMessage, req); try { EMError.hasErrorFromResult(result); - return EMMessage.fromJson(result[ChatMethodKeys.getMessage]); + if (result.containsKey(ChatMethodKeys.getMessage)) { + return EMMessage.fromJson(result[ChatMethodKeys.getMessage]); + } else { + return null; + } } on EMError catch (e) { throw e; } } - /// 通过会话[conversationId], 会话类型[type]获取会话. + /// + /// Gets the conversation by conversation ID and conversation type. + /// + /// The SDK wil return null if the conversation is not found. + /// + /// Param [conversationId] The conversation ID. + /// + /// Param [type] The conversation type, see {@link EMConversationType}. + /// + /// Param [createIfNeed] Whether to create a conversation if not find the specified conversation. + /// + /// `true` (default) means create one. + /// `false` means not. + /// + /// **return** The conversation object found according to the ID and type. Returns null if the conversation is not found. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future getConversation( String conversationId, [ EMConversationType type = EMConversationType.Chat, @@ -182,45 +273,74 @@ class EMChatManager { } } - /// 将所有对话标记为已读. - Future markAllConversationsAsRead() async { + /// Marks all messages as read. + /// + /// This method is for the local conversations only. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future markAllConversationsAsRead() async { Map result = await _channel.invokeMethod(ChatMethodKeys.markAllChatMsgAsRead); try { EMError.hasErrorFromResult(result); - return result.boolValue(ChatMethodKeys.markAllChatMsgAsRead); } on EMError catch (e) { throw e; } } - /// 获取未读消息的计数. - Future getUnreadMessageCount() async { + /// + /// Gets the unread message count. + /// + /// **return** The count of unread messages. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future getUnreadMessageCount() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getUnreadMessageCount); try { + int ret = 0; EMError.hasErrorFromResult(result); - return result[ChatMethodKeys.getUnreadMessageCount] as int?; + if (result.containsKey(ChatMethodKeys.getUnreadMessageCount)) { + ret = result[ChatMethodKeys.getUnreadMessageCount] as int; + } + return ret; } on EMError catch (e) { throw e; } } - /// 更新消息[message]. - Future updateMessage(EMMessage message) async { + /// + /// Updates the local message. + /// + /// Will update the memory and the local database at the same time. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future updateMessage(EMMessage message) async { Map req = {"message": message.toJson()}; Map result = await _channel.invokeMethod(ChatMethodKeys.updateChatMessage, req); try { EMError.hasErrorFromResult(result); - return EMMessage.fromJson(result[ChatMethodKeys.updateChatMessage]); } on EMError catch (e) { throw e; } } - /// 导入消息 [messages]. - Future importMessages(List messages) async { + /// + /// Imports messages to the local database. + /// + /// Make sure the message's sender or receiver is the current user before option. + /// + /// Recommends import less than 1,000 messages per operation. + /// + /// Param [messages] The message list. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future importMessages(List messages) async { List list = []; messages.forEach((element) { list.add(element.toJson()); @@ -230,37 +350,56 @@ class EMChatManager { await _channel.invokeMethod(ChatMethodKeys.importMessages, req); try { EMError.hasErrorFromResult(result); - return result.boolValue(ChatMethodKeys.importMessages); } on EMError catch (e) { throw e; } } - /// 下载附件 [message]. - Future downloadAttachment(EMMessage message) async { + /// + /// Downloads the attachment files from the server. + /// + /// You can call the method again if the attachment download fails. + /// + /// Param [message] The message to be download the attachment. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future downloadAttachment(EMMessage message) async { Map result = await _channel.invokeMethod( ChatMethodKeys.downloadAttachment, {"message": message.toJson()}); try { EMError.hasErrorFromResult(result); - return EMMessage.fromJson(result[ChatMethodKeys.downloadAttachment]); } on EMError catch (e) { throw e; } } - /// 下载缩略图 [message]. - Future downloadThumbnail(EMMessage message) async { + /// + /// Downloads the thumbnail if the msg is not downloaded before or the download failed. + /// + /// Param [message] The message object. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future downloadThumbnail(EMMessage message) async { Map result = await _channel.invokeMethod( ChatMethodKeys.downloadThumbnail, {"message": message.toJson()}); try { EMError.hasErrorFromResult(result); - return EMMessage.fromJson(result[ChatMethodKeys.downloadThumbnail]); } on EMError catch (e) { throw e; } } - /// 获取所有会话 + /// + /// Gets all conversations from the local database. + /// + /// Conversations will be loaded from memory first, if no conversation is found then the SDk loads from the local database. + /// + /// **return** Returns all the conversations from the memory or local database. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future> loadAllConversations() async { Map result = await _channel.invokeMethod(ChatMethodKeys.loadAllConversations); @@ -276,7 +415,15 @@ class EMChatManager { } } - /// 从服务器获取会话 + /// + /// Fetches the conversation list from the server. + /// + /// The default maximum return is 100. + /// + /// **return** Returns the conversation list of the current user. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future> getConversationsFromServer() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getConversationsFromServer); @@ -292,16 +439,22 @@ class EMChatManager { } } - // 批量更新一组会话显示名称`Map`,`key`会话id, `value`对应名称,既conversation.name属性。 - // Future updateConversationsName(Map nameMap) async { - // Map req = {"name_map": nameMap}; - // Map result = - // await _channel.invokeMethod(ChatMethodKeys.updateConversationsName, req); - // EMError.hasErrorFromResult(result); - // return result.boolValue(ChatMethodKeys.updateConversationsName); - // } - - /// 删除会话, 如果[deleteMessages]设置为true,则同时删除消息。 + /// + /// Deletes conversation and messages from the local database. + /// + /// If you set `deleteMessages` to `true`, delete the local chat history when delete the conversation. + /// + /// Param [conversationId] The conversation ID. + /// + /// Param [deleteMessages] Whether to delete the chat history when delete the conversation. + /// + /// `true`: (default) means delete the chat history when delete the conversation. + /// `false`: means not. + /// + /// **return** The result of deleting. `True` means success, `false` means failure. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future deleteConversation( String conversationId, [ bool deleteMessages = true, @@ -317,20 +470,47 @@ class EMChatManager { } } - /// 添加消息监听 [listener] - void addListener(EMChatManagerListener listener) { + /// + /// Adds the message listener. + /// + /// Receives new messages and so on can set the method to listen, see {@link EMChatManagerListener}. + /// + /// Param [listener] The message listener which is used to listen the incoming messages, see {@link EMChatManagerListener} + /// + void addChatManagerListener(EMChatManagerListener listener) { _messageListeners.add(listener); } - /// 移除消息监听[listener] - void removeListener(EMChatManagerListener listener) { + /// + /// Removes the message listener. + /// + /// You should call this method after set {@link #addMessageListener(addChatManagerListener)} . + /// + /// Param [listener] The message listener to be removed. + /// + void removeChatManagerListener(EMChatManagerListener listener) { if (_messageListeners.contains(listener)) { _messageListeners.remove(listener); } } - /// 在会话[conversationId]中提取历史消息,按[type]筛选。 - /// 结果按每页[pageSize]分页,从[startMsgId]开始。 + /// + /// Fetches history messages of the conversation from the server. + /// + /// Fetches by page. + /// + /// Param [conversationId] The conversation ID. + /// + /// Param [type] The conversation type which select to fetch roam message, see {@link EMConversationType} + /// + /// Param [pageSize] The number of records per page. + /// + /// Param [startMsgId] The start search roam message, if the param is empty, fetches from the server latest message. + /// + /// **return** Returns the messages and the cursor for next fetch action. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future> fetchHistoryMessages( String conversationId, { EMConversationType type = EMConversationType.Chat, @@ -356,7 +536,23 @@ class EMChatManager { } } - /// 搜索包含[keywords]的消息,消息类型为[type],起始时间[timeStamp],条数[maxCount], 消息发送方[from],方向[direction]。 + /// + /// Searches messages from the database according to the parameters. + /// + /// Note: Cautious about the memory usage when the maxCount is large, currently the limited number is 400 entries at a time. + /// + /// Param [keywords] The keywords in message. + /// + /// Param [timeStamp] The timestamp for search, Unix timestamp, in milliseconds. + /// + /// Param [maxCount] The max number of message to search at a time. + /// + /// Param [from] A user ID or a group ID searches for messages, usually refers to the conversation ID. + /// + /// **return** The list of messages. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future> searchMsgFromDB( String keywords, { int timeStamp = -1, @@ -385,11 +581,25 @@ class EMChatManager { } } - /// 从服务器获取群组已读回执。 - /// [msgId], 需要获取的群消息id。 - /// [startAckId], 起始的ackId, 用于分页。 - /// [pageSize], 返回的数量。 - Future> asyncFetchGroupAcks( + /// + /// Fetches the ack details for group messages from server. + /// + /// Fetches by page. + /// + /// Reference: + /// If you want to send group message receipt, see {@link {@link #sendConversationReadAck(String)}. + /// + /// Param [msgId] The message ID. + /// + /// Param [startAckId] The start ID for fetch receipts, can be null. If you set it as null, the SDK will start from the server's latest receipt. + /// + /// Param [pageSize] The number of records per page. + /// + /// **return** The group acks cursor result. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future> fetchGroupAcks( String msgId, { String? startAckId, int pageSize = 0, @@ -419,8 +629,21 @@ class EMChatManager { } } - /// 删除远程会话列表 - Future asyncDeleteRemoteConversation( + /// + /// Deletes the conversation of a specified ID and it's chat records on the server. + /// + /// Param [conversationId] Conversation ID. + /// + /// Param [conversationType] Conversation type {@link EMConversationType} + /// + /// Param [isDeleteMessage] Whether to delete the server chat records when delete conversation. + /// + /// `true`:(default) means to delete the chat history when delete the conversation; + /// `false`: means not. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future deleteRemoteConversation( String conversationId, { EMConversationType conversationType = EMConversationType.Chat, bool isDeleteMessage = true, @@ -442,7 +665,6 @@ class EMChatManager { EMError.hasErrorFromResult(data); } - /// @nodoc Future _onMessagesReceived(List messages) async { List messageList = []; for (var message in messages) { @@ -453,7 +675,6 @@ class EMChatManager { } } - /// @nodoc Future _onCmdMessagesReceived(List messages) async { List list = []; for (var message in messages) { @@ -464,7 +685,6 @@ class EMChatManager { } } - /// @nodoc Future _onMessagesRead(List messages) async { List list = []; for (var message in messages) { @@ -475,7 +695,6 @@ class EMChatManager { } } - /// @nodoc Future _onGroupMessageRead(List messages) async { List list = []; for (var message in messages) { @@ -486,7 +705,6 @@ class EMChatManager { } } - /// @nodoc Future _onMessagesDelivered(List messages) async { List list = []; for (var message in messages) { diff --git a/lib/src/em_chat_room_manager.dart b/lib/src/em_chat_room_manager.dart index be5c9630..a2586aa0 100644 --- a/lib/src/em_chat_room_manager.dart +++ b/lib/src/em_chat_room_manager.dart @@ -5,11 +5,22 @@ import 'tools/em_extension.dart'; import 'internal/chat_method_keys.dart'; import '../im_flutter_sdk.dart'; +/// +/// The chat room manager, which manages users joining and existing the chat room and getting the chat room list, and manages member privileges. +/// For example, joining a chat room: +/// ```dart +/// try { +/// await EMClient.getInstance.chatRoomManager.joinChatRoom(chatRoomId); +/// } on EMError catch (e) { +/// debugPrint(e.toString()); +/// } +/// ``` class EMChatRoomManager { static const _channelPrefix = 'com.chat.im'; static const MethodChannel _channel = const MethodChannel( '$_channelPrefix/chat_room_manager', JSONMethodCodec()); + /// @nodoc EMChatRoomManager() { _channel.setMethodCallHandler((MethodCall call) async { Map? argMap = call.arguments; @@ -22,19 +33,31 @@ class EMChatRoomManager { final List _chatRoomEventListeners = []; - /// 添加聊天室监听器 + /// + /// Registers a chat room event listener. + /// Chat room destruction, member entry and exit, mute, and allowlist entry addition among other operations can be listened by setting + /// {@link EMChatRoomEventListener}. + /// + /// Chat room event listeners registered with this method can be removed by calling {@link #removeChatRoomListener(EMChatRoomEventListener)}. + /// + /// Param [listener] A chat room listener. See {@link EMChatRoomEventListener}. + /// void addChatRoomChangeListener(EMChatRoomEventListener listener) { _chatRoomEventListeners.add(listener); } - /// 移除聊天室监听器 + /// + /// Removes a chat room event listener. + /// This method removes the chat room event listener registered with {@link #addChatRoomChangeListener(EMChatRoomEventListener)}. + /// + /// Param [listener] The chat room event listener to be removed. + /// void removeChatRoomListener(EMChatRoomEventListener listener) { if (_chatRoomEventListeners.contains(listener)) { _chatRoomEventListeners.remove(listener); } } - /// @nodoc Future _chatRoomChange(Map event) async { String? type = event['type']; for (EMChatRoomEventListener listener in _chatRoomEventListeners) { @@ -112,7 +135,15 @@ class EMChatRoomManager { } } - /// 加入聊天室[roomId]. + /// + /// Joins the chat room. + /// + /// To exit the chat room, call {@link #leaveChatRoom(String)}. + /// + /// Param [roomId] The ID of the chat room to join. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future joinChatRoom(String roomId) async { Map result = await _channel .invokeMethod(ChatMethodKeys.joinChatRoom, {"roomId": roomId}); @@ -123,7 +154,13 @@ class EMChatRoomManager { } } - /// 离开聊天室[roomId]. + /// + /// Leaves a chat room. + /// + /// Param [roomId] The ID of the chat room to leave. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future leaveChatRoom(String roomId) async { Map result = await _channel .invokeMethod(ChatMethodKeys.leaveChatRoom, {"roomId": roomId}); @@ -134,7 +171,17 @@ class EMChatRoomManager { } } - /// 翻页从服务器获取聊天室 [pageNum] and [pageSize] + /// + /// Gets chat room data from the server with pagination. + /// + /// Param [pageNum] The page number, starting from 1. + /// + /// Param [pageSize] The number of records per page. + /// + /// **return** Chat room data. See {@link EMPageResult}. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future> fetchPublicChatRoomsFromServer({ int pageNum = 1, int pageSize = 200, @@ -154,7 +201,15 @@ class EMChatRoomManager { } } - /// 获取聊天室详情[roomId]. + /// + /// Gets details of a chat room from the server, excluding the member list by default. + /// + /// Param [roomId] The chat room ID. + /// + /// **return** The chat room instance. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future fetchChatRoomInfoFromServer(String roomId) async { Map result = await _channel.invokeMethod( ChatMethodKeys.fetchChatRoomInfoFromServer, {"roomId": roomId}); @@ -167,20 +222,36 @@ class EMChatRoomManager { } } - /// 从本地获取聊天室 [roomId]. - Future getChatRoomWithId(String roomId) async { + /// + /// Gets the chat room in the cache. + /// + /// Param [roomId] The chat room ID. + /// + /// **return** The chat room instance. Returns null if the chat room is not found in the cache. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future getChatRoomWithId(String roomId) async { Map result = await _channel .invokeMethod(ChatMethodKeys.getChatRoom, {"roomId": roomId}); try { EMError.hasErrorFromResult(result); - return EMChatRoom.fromJson( - result[ChatMethodKeys.fetchChatRoomInfoFromServer]); + if (result.containsKey(ChatMethodKeys.fetchChatRoomInfoFromServer)) { + return EMChatRoom.fromJson( + result[ChatMethodKeys.fetchChatRoomInfoFromServer]); + } else { + return null; + } } on EMError catch (e) { throw e; } } - /// 获取所有聊天室 + /// + /// Gets the list of chat rooms in the cache. + /// + /// **return** The list of chat rooms maintained by EMChatRoomManager. + @Deprecated("") Future> getAllChatRooms() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getAllChatRooms); try { @@ -194,6 +265,23 @@ class EMChatRoomManager { } } + /// + /// Creates a chat room. + /// + /// Param [subject] The chat room subject. + /// + /// Param [desc] The chat room description. + /// + /// Param [welcomeMsg] A welcome message inviting members to join the chat room. + /// + /// Param [maxUserCount] The maximum number of members allowed to join the chat room. + /// + /// Param [members] The list of members invited to join the chat room. + /// + /// **return** The chat room instance created successfully. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future createChatRoom( String subject, { String? desc, @@ -217,7 +305,15 @@ class EMChatRoomManager { } } - /// @nodoc 销毁聊天室,需要owner权限 [roomId] + /// + /// Destroys a chat room. + /// + /// Only the chat room owner can call this method. + /// + /// Param [roomId] The chat room ID. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future destroyChatRoom( String roomId, ) async { @@ -231,7 +327,17 @@ class EMChatRoomManager { } } - /// @nodoc 修改聊天室标题,需要owner权限[roomId] [subject] + /// + /// Changes the chat room subject. + /// + /// Only the chat room owner can call this method. + /// + /// Param [roomId] The chat room ID. + /// + /// Param [subject] The new subject of the chat room. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future changeChatRoomSubject( String roomId, String subject, @@ -246,7 +352,17 @@ class EMChatRoomManager { } } - /// @nodoc 修改聊天室描述信息,需要owner权限 [roomId] .[description] + /// + /// Modifies the chat room description. + /// + /// Only the chat room owner can call this method. + /// + /// Param [roomId] The chat room ID. + /// + /// Param [description] The new description of the chat room. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future changeChatRoomDescription( String roomId, String description, @@ -261,7 +377,21 @@ class EMChatRoomManager { } } - /// @nodoc 获取聊天室成员列表,[roomId] [cursor] [pageSize] + /// + /// Gets the chat room member list. + /// + /// When EMCursorResult.cursor is an empty string ("") amid the result, all data is fetched. + /// + /// Param [roomId] The chat room ID. + /// + /// Param [cursor] The cursor position from which to start getting data. + /// + /// Param [pageSize] The number of members per page. + /// + /// **return** The list of chat room members. See {@link EMCursorResult}. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future> fetchChatRoomMembers( String roomId, { String cursor = '', @@ -280,11 +410,22 @@ class EMChatRoomManager { } } - /// @nodoc 禁止聊天室成员发言,需要聊天室拥有者或者管理员权限 - /// [roomId] 聊天室ID [duration] 禁言的时间,单位是毫秒 [muteMembers] 禁言的用户列表 + /// + /// Mutes members in a chat room. + /// + /// Only the chat room owner or admin can call this method. + /// + /// Param [roomId] The chat room ID. + /// + /// Param [muteMembers] The list of members to be muted. + /// + /// Param [duration] The mute duration in milliseconds. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future muteChatRoomMembers( String roomId, - List muteMembers, { + List muteMembers, { int duration = -1, }) async { Map req = { @@ -301,10 +442,20 @@ class EMChatRoomManager { } } - /// @nodoc 取消禁言,需要聊天室拥有者或者管理员权限 [roomId].[muteMembers] + /// + /// Unmutes members in a chat room. + /// + /// Only the chat room owner or admin can call this method. + /// + /// Param [roomId] The chat room ID. + /// + /// Param [unMuteMembers] The list of members to be unmuted. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future unMuteChatRoomMembers( String roomId, - List unMuteMembers, + List unMuteMembers, ) async { Map req = {"roomId": roomId, "unMuteMembers": unMuteMembers}; Map result = @@ -316,8 +467,17 @@ class EMChatRoomManager { } } - /// @nodoc 转移聊天室的所有权,需要聊天室拥有者权限 [roomId] .[newOwner] - /// @nodoc 如果转移成功,请调用[onSuccess],如果出现错误,请调用[onError]。 + /// + /// Transfers the chat room ownership. + /// + /// Only the chat room owner can call this method. + /// + /// Param [roomId] A chat room ID. + /// + /// Param [newOwner] The ID of the new chat room owner. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future changeOwner( String roomId, String newOwner, @@ -332,8 +492,17 @@ class EMChatRoomManager { } } - /// 为聊天室添加管理员,需要拥有者权限 [roomId].[admin] - /// 如果添加成功,请调用[onSuccess],如果出现错误,请调用[onError]。 + /// + /// Adds a chat room admin. + /// + /// Only the chat room owner can call this method. + /// + /// Param [roomId] A chat room ID. + /// + /// Param [admin] The ID of the chat room admin to be added. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future addChatRoomAdmin( String roomId, String admin, @@ -348,8 +517,15 @@ class EMChatRoomManager { } } - /// 删除聊天室管理员,需要拥有着权限[roomId].[admin] - /// 如果删除成功,请调用[onSuccess],如果出现错误,请调用[onError]。 + /// + /// Removes privileges of a chat room admin. + /// + /// Param [roomId] The chat room ID. + /// + /// Param [admin] The ID of admin whose privileges are to be removed. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future removeChatRoomAdmin( String roomId, String admin, @@ -364,7 +540,21 @@ class EMChatRoomManager { } } - /// @nodoc 获取聊天室的禁言列表,需要拥有者或者管理员权限 [roomId].[pageNum].[pageSize] + /// + /// Gets the list of members who are muted in the chat room from the server. + /// + /// Only the chat room owner or admin can call this method. + /// + /// Param [roomId] The chat room ID + /// + /// Param [pageNum] The page number, starting from 1. + /// + /// Param [pageSize] The number of muted members per page. + /// + /// **return** The muted member list. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future?> fetchChatRoomMuteList( String roomId, { int pageNum = 1, @@ -381,10 +571,20 @@ class EMChatRoomManager { } } - /// @nodoc 删除聊天室成员,需要拥有者或者管理员权限[roomId].[members]. + /// + /// Removes members from a chat room. + /// + /// Only the chat room owner or admin can call this method. + /// + /// Param [roomId] The chat room ID + /// + /// Param [members] The members list to be removed. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future removeChatRoomMembers( String roomId, - List members, + List members, ) async { Map req = {"roomId": roomId, "members": members}; Map result = @@ -396,7 +596,22 @@ class EMChatRoomManager { } } - /// @nodoc 添加成员到黑名单,禁止成员继续加入聊天室,需要拥有者或者管理员权限[roomId].[members]. + /// + /// Adds members to the chat room's block list. + /// + /// Only the chat room owner or admin can call this method. + /// + /// For members added to block list, note the following: + /// 1. A member, once added to the chat room block list, will be removed from the chat room by the server. + /// 2. The method {@link EMChatRoomEventListener#onRemovedFromChatRoom(String, String?, String?)} occurs. + /// 3. Members added to the block list are banned from rejoining the chat room. + /// + /// Param [roomId] The chat room ID. + /// + /// Param [members] The list of members to be added to block list. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future blockChatRoomMembers( String roomId, List members, @@ -411,7 +626,17 @@ class EMChatRoomManager { } } - /// @nodoc 将成员从黑名单种移除,需要拥有者或者管理员权限[roomId].[members]. + /// + /// Removes members from the chat room's block list. + /// + /// Only the chat room owner or admin can call this method. + /// + /// Param [roomId] The chat room ID. + /// + /// Param [members] The list of members to be removed from the block list. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future unBlockChatRoomMembers( String roomId, List members, @@ -426,7 +651,21 @@ class EMChatRoomManager { } } - /// @nodoc 获取群组黑名单列表,分页显示,需要拥有者或者管理员权限 [roomId].[pageNum].[pageSize] + /// + /// Gets the chat room block list with pagination. + /// + /// Only the chat room owner or admin can call this method. + /// + /// Param [roomId] The chat room ID. + /// + /// Param [pageNum] The page number, starting from 1. + /// + /// Param [pageSize] The number of users on the block list per page. + /// + /// **return** The chat room's block list. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future?> fetchChatRoomBlockList( String roomId, [ int pageNum = 1, @@ -443,7 +682,17 @@ class EMChatRoomManager { } } - /// 更新聊天室公告[roomId].[announcement] + /// + /// Updates the chat room announcement. + /// + /// Only the chat room owner or admin can call this method. + /// + /// Param [roomId] The chat room ID. + /// + /// Param [announcement] The announcement content. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future updateChatRoomAnnouncement( String roomId, String announcement, @@ -458,7 +707,15 @@ class EMChatRoomManager { } } - /// 从服务器获取聊天室公告内容[roomId] + /// + /// Gets the chat room announcement from the server. + /// + /// Param [roomId] The chat room ID. + /// + /// **return** The chat room announcement. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future fetchChatRoomAnnouncement( String roomId, ) async { @@ -473,8 +730,18 @@ class EMChatRoomManager { } } - /// 从服务器获取聊天室白名单列表 [roomId]: 聊天室id - Future> fetchChatRoomWhiteListFromServer(String roomId) async { + /// + /// Gets the while list from the server. + /// + /// Only the chat room owner or admin can call this method. + /// + /// Param [roomId] The chat room ID. + /// + /// **return** The chat room while list. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future?> fetchChatRoomWhiteListFromServer(String roomId) async { Map req = {"roomId": roomId}; Map result = await _channel.invokeMethod( ChatMethodKeys.fetchChatRoomWhiteListFromServer, req); @@ -486,7 +753,15 @@ class EMChatRoomManager { return contacts; } - /// 判断当前登录账号是否在聊天室白名单中 [roomId]: 聊天室id + /// + /// Checks whether the member is on the while list. + /// + /// Param [roomId] The chat room ID. + /// + /// **return** Current member is in while list. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future isMemberInChatRoomWhiteList(String roomId) async { Map req = {"roomId": roomId}; Map result = await _channel.invokeMethod( @@ -496,9 +771,21 @@ class EMChatRoomManager { .boolValue(ChatMethodKeys.isMemberInChatRoomWhiteListFromServer); } - /// 向聊天室白名单中添加用户[roomId]: 聊天室id, [members]: 需要添加到聊天室的用户id。 + /// + /// Adds members to the allowlist. + /// + /// Only the chat room owner or admin can call this method. + /// + /// Param [roomId] The chat room ID. + /// + /// Param [members] The list of members to be added to the while list. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future addMembersToChatRoomWhiteList( - String roomId, List members) async { + String roomId, + List members, + ) async { Map req = { "roomId": roomId, "members": members, @@ -511,7 +798,17 @@ class EMChatRoomManager { EMError.hasErrorFromResult(result); } - /// 从聊天室中移除白名单成员,[roomId]: 聊天室id, [members]: 需要移除的用户列表。 + /// + /// Removes members from the while list. + /// + /// Only the chat room owner or admin can call this method. + /// + /// Param [roomId] The chat room ID. + /// + /// Param [members] The list of members to be removed from the while list. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future removeMembersFromChatRoomWhiteList( String roomId, List members, @@ -527,27 +824,41 @@ class EMChatRoomManager { EMError.hasErrorFromResult(result); } - Future muteAllChatRoomMembers(String roomId) async { + /// + /// Mutes all members. + /// + /// Only the chat room owner or admin can call this method. + /// + /// This method does not work for the chat room owner, admin, and members added to the block list. + /// + /// Param [roomId] The chat room ID. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future muteAllChatRoomMembers(String roomId) async { Map req = {"roomId": roomId}; Map result = await _channel.invokeMethod( ChatMethodKeys.muteAllChatRoomMembers, req, ); EMError.hasErrorFromResult(result); - return result.boolValue( - ChatMethodKeys.muteAllChatRoomMembers, - ); } - Future unMuteAllChatRoomMembers(String roomId) async { + /// + /// Unmutes all members. + /// + /// Only the chat room owner or admin can call this method. + /// + /// Param [roomId] The chat room ID. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future unMuteAllChatRoomMembers(String roomId) async { Map req = {"roomId": roomId}; Map result = await _channel.invokeMethod( ChatMethodKeys.unMuteAllChatRoomMembers, req, ); EMError.hasErrorFromResult(result); - return result.boolValue( - ChatMethodKeys.unMuteAllChatRoomMembers, - ); } } diff --git a/lib/src/em_client.dart b/lib/src/em_client.dart index 9eb70e24..66e22d7b 100644 --- a/lib/src/em_client.dart +++ b/lib/src/em_client.dart @@ -133,7 +133,7 @@ class EMClient { /// /// Param [password] The password. The maximum length is 64 characters. Ensure that you set this parameter. /// - /// **Throws** [EMError] A description of the issue that caused this error. + /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// Future createAccount(String username, String password) async { EMLog.v('create account: $username : $password'); @@ -157,7 +157,7 @@ class EMClient { /// `true`: (default) login with password. /// `false`: login with token. /// - /// **Throws** [EMError] A description of the issue that caused this error. + /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// Future login(String username, String pwdOrToken, [bool isPassword = true]) async { @@ -176,6 +176,17 @@ class EMClient { } } + /// + /// An app user logs in to the chat server by user ID and Agora token. This method supports automatic login. + /// + /// Reference: Another method to login to chat server is to login with user ID and token, see {@link #login(String, String, bool)}. + /// + /// Param [username] The user ID. + /// + /// Param [agoraToken] The Agora token. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future loginWithAgoraToken(String username, String agoraToken) async { Map req = { "username": username, @@ -192,8 +203,36 @@ class EMClient { } } - /// 退出登录,是否解除deviceToken绑定[unbindDeviceToken] - /// 返回退出是否成功 + /// + /// When a user is in the Agora token login state and receives a callback notification of the token is to be expired + /// in the {@link EMConnectionListener} implementation class, + /// this API can be called to update the token to avoid unknown problems caused by the token invalidation. + /// + /// Param [agoraToken] The new token. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future renewAgoraToken(String agoraToken) async { + Map req = {"agora_token": agoraToken}; + + Map result = await _channel.invokeMethod(ChatMethodKeys.renewToken, req); + try { + EMError.hasErrorFromResult(result); + } on EMError catch (e) { + throw e; + } + } + + /// + /// An app user logs out and returns the result. + /// + /// Param [unbindDeviceToken] Whether to unbind the token. + /// + /// `true` (default) means to unbind the device token when logout. + /// `false` means to not unbind the device token when logout. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future logout([ bool unbindDeviceToken = true, ]) async { @@ -215,9 +254,10 @@ class EMClient { /// /// As this key controls all access to Agora Chat for your app, you can only update the key when the current user is logged out. /// - /// /// Param [newAppKey] The App Key, make sure to set the param. /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future changeAppKey({required String newAppKey}) async { EMLog.v('changeAppKey: $newAppKey'); Map req = {'appKey': newAppKey}; @@ -237,7 +277,7 @@ class EMClient { /// /// **return** The path of the compressed gz file. /// - /// **Throws** [EMError] A description of the issue that caused this error. + /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// Future compressLogs() async { EMLog.v('compressLogs:'); @@ -259,7 +299,7 @@ class EMClient { /// /// **return** The list of the online devices. /// - /// **Throws** [EMError] A description of the issue that caused this error. + /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// Future> getLoggedInDevicesFromServer( {required String username, required String password}) async { @@ -288,7 +328,7 @@ class EMClient { /// /// Param [resource] The device ID, see {@link EMDeviceInfo#resource}. /// - /// **Throws** [EMError] A description of the issue that caused this error. + /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// Future kickDevice( {required String username, @@ -316,7 +356,7 @@ class EMClient { /// /// Param [password] The account's password. /// - /// **Throws** [EMError] A description of the issue that caused this error. + /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// Future kickAllDevices( {required String username, required String password}) async { diff --git a/lib/src/em_contact_manager.dart b/lib/src/em_contact_manager.dart index d9aedee3..d23df700 100644 --- a/lib/src/em_contact_manager.dart +++ b/lib/src/em_contact_manager.dart @@ -61,7 +61,7 @@ class EMContactManager { /// /// Param [reason] (optional) The invitation message. Set the parameter as null if you want to ignore the information. /// - /// **Throws** [EMError] A description of the issue that caused this error. + /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// Future addContact( String username, [ @@ -85,7 +85,7 @@ class EMContactManager { /// `true`: keep conversation and messages. /// `false`: (default) delete conversation and messages. /// - /// **Throws** [EMError] A description of the issue that caused this error. + /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// Future deleteContact( String username, [ @@ -105,7 +105,7 @@ class EMContactManager { /// /// **return** The list of contacts. /// - /// **Throws** [EMError] A description of the issue that caused this error. + /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// Future> getAllContactsFromServer() async { Map result = @@ -127,7 +127,7 @@ class EMContactManager { /// /// **return** The contact list. /// - /// **Throws** [EMError] A description of the issue that caused this error. + /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// Future> getAllContactsFromDB() async { Map result = @@ -151,7 +151,7 @@ class EMContactManager { /// /// Param [username] The user to be blocked. /// - /// **Throws** [EMError] A description of the issue that caused this error. + /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// Future addUserToBlockList( String username, @@ -173,7 +173,7 @@ class EMContactManager { /// /// Param [username] The user to be removed from the block list. /// - /// **Throws** [EMError] A description of the issue that caused this error. + /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// Future removeUserFromBlockList(String username) async { Map req = {'username': username}; @@ -191,7 +191,7 @@ class EMContactManager { /// /// **return** The block list from the server. /// - /// **Throws** [EMError] A description of the issue that caused this error. + /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// Future> getBlockListFromServer() async { Map result = @@ -213,7 +213,7 @@ class EMContactManager { /// /// **return** The block list. /// - /// **Throws** [EMError] A description of the issue that caused this error. + /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// Future> getBlockListFromDB() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getBlockListFromDB); @@ -234,7 +234,7 @@ class EMContactManager { /// /// Param [username] The user who initiates the friend request. /// - /// **Throws** [EMError] A description of the issue that caused this error. + /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// Future acceptInvitation(String username) async { Map req = {'username': username}; @@ -252,7 +252,7 @@ class EMContactManager { /// /// Param [username] The user who initiates the invitation. /// - /// **Throws** [EMError] A description of the issue that caused this error. + /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// Future declineInvitation(String username) async { Map req = {'username': username}; @@ -270,7 +270,7 @@ class EMContactManager { /// /// **return** The unique device ID list on the other devices if the method succeeds. /// - /// **Throws** [EMError] A description of the issue that caused this error. + /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// Future?> getSelfIdsOnOtherPlatform() async { Map result = diff --git a/lib/src/em_group_manager.dart b/lib/src/em_group_manager.dart index 33b76b53..1ab804dd 100644 --- a/lib/src/em_group_manager.dart +++ b/lib/src/em_group_manager.dart @@ -11,11 +11,15 @@ import 'tools/em_extension.dart'; import 'internal/chat_method_keys.dart'; +/// +/// The group manager for management of group creation and deletion and member management. +/// class EMGroupManager { static const _channelPrefix = 'com.chat.im'; static const MethodChannel _channel = const MethodChannel( '$_channelPrefix/chat_group_manager', JSONMethodCodec()); + /// @nodoc EMGroupManager() { _channel.setMethodCallHandler((MethodCall call) async { Map? argMap = call.arguments; @@ -29,16 +33,38 @@ class EMGroupManager { final _groupChangeListeners = []; - /// 根据群组id获取群实例 - Future getGroupWithId(String groupId) async { + /// + /// Gets the group instance from the cache by group ID. + /// + /// Param [groupId] The group ID. + /// + /// **return** The group instance. Returns null if the group does not exist. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future getGroupWithId(String groupId) async { Map req = {'groupId': groupId}; Map result = await _channel.invokeMethod(ChatMethodKeys.getGroupWithId, req); - EMError.hasErrorFromResult(result); - return EMGroup.fromJson(result[ChatMethodKeys.getGroupWithId]); + try { + EMError.hasErrorFromResult(result); + if (result.containsKey(ChatMethodKeys.getGroupWithId)) { + return EMGroup.fromJson(result[ChatMethodKeys.getGroupWithId]); + } else { + return null; + } + } on EMError catch (e) { + throw e; + } } - /// 从本地缓存中获取已加入的群组列表 + /// + /// Gets all groups of the current user (from the cache). + /// + /// **return** The group list. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future> getJoinedGroups() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getJoinedGroups); EMError.hasErrorFromResult(result); @@ -48,7 +74,7 @@ class EMGroupManager { return list; } - /// 获取免打扰的群组列表id + @Deprecated("Switch to using EMPushConfig#noDisturbGroupsFromServer instead.") Future?> getGroupsWithoutNotice() async { Map result = await _channel .invokeMethod(ChatMethodKeys.getGroupsWithoutPushNotification); @@ -58,7 +84,15 @@ class EMGroupManager { return list; } - /// 从服务器获取已加入的群组列表 + /// + /// Gets all groups of the current user from the server. + /// + /// This method returns a group list which does not contain member information. If you want to update information of a group to include its member information, call {@link #getGroupSpecificationFromServer(String groupId)}. + /// + /// **return** The list of groups that the current user joins. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future> getJoinedGroupsFromServer({ int pageSize = 200, int pageNum = 1, @@ -73,12 +107,25 @@ class EMGroupManager { return list; } - /// 从服务器获取公开群组列表 + /// + /// Gets public groups from the server with pagination. + /// + /// + /// Param [pageSize] The number of public groups per page. + /// + /// Param [cursor] The cursor position from which to start to get data next time. Sets the parameter as null for the first time. + /// + /// **return** The result of {@link EMCursorResult}, including the cursor for getting data next time and the group list. + /// For the last page, the return value of cursor is an empty string. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future> getPublicGroupsFromServer({ int pageSize = 200, - String cursor = '', + String? cursor, }) async { - Map req = {'pageSize': pageSize, 'cursor': cursor}; + Map req = {'pageSize': pageSize}; + req.setValueWithOutNull("cursor", cursor); Map result = await _channel.invokeMethod( ChatMethodKeys.getPublicGroupsFromServer, req); try { @@ -93,19 +140,47 @@ class EMGroupManager { } } - /// 创建群组 - Future createGroup(String groupName, - {required EMGroupOptions settings, - String desc = '', - List? inviteMembers, - String inviteReason = ''}) async { - Map req = { - 'groupName': groupName, - 'desc': desc, - 'inviteMembers': inviteMembers ?? [], - 'inviteReason': inviteReason, - 'options': settings.toJson() - }; + /// + /// Creates a group instance. + /// + /// After the group is created, the data in the cache and database will be updated and multiple devices will receive the notification event and + /// update the group to the cache and database. + /// You can set {@link com.hyphenate.EMMultiDeviceListener} to listen on the event. The event callback function + /// is {@link EMMultiDeviceListener#onGroupEvent(int, String, List)}, where the first parameter is the event, + /// for example, {@link EMContactGroupEvent#GROUP_CREATE} for the group creation event. + /// + /// Param [groupName] The group name. + /// + /// Param [desc] The group description. + /// + /// Param [inviteMembers] The group member array. The group owner ID is optional. + /// + /// Param [inviteReason] The group joining invitation. + /// + /// Param [options] The options for creating a group. See {@link EMGroupOptions}. + /// The options are as follows: + /// - The maximum number of group members. The default value is 200. + /// - The group style. See {@link EMGroupManager.EMGroupStyle}. The default value is {@link EMGroupStyle#PrivateOnlyOwnerInvite}. + /// - Whether to ask for permission when inviting a user to join the group. The default value is false, indicating that invitees are automaticall added to the group without their permission. + /// - The group detail extensions. + /// + /// **return** The created group instance. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future createGroup({ + String? groupName, + String? desc, + List? inviteMembers, + String? inviteReason, + required EMGroupOptions options, + }) async { + Map req = {'options': options.toJson()}; + req.setValueWithOutNull("groupName", groupName); + req.setValueWithOutNull("desc", desc); + req.setValueWithOutNull("inviteMembers", inviteMembers); + req.setValueWithOutNull("inviteReason", inviteReason); + Map result = await _channel.invokeMethod(ChatMethodKeys.createGroup, req); try { EMError.hasErrorFromResult(result); @@ -115,7 +190,17 @@ class EMGroupManager { } } - /// 获取群组详情 + /// + /// Gets group information from the server. + /// + /// This method does not get member information. If member information is required, call {@link #getGroupMemberListFromServer(String, int?, String?)}. + /// + /// Param [groupId] The group ID. + /// + /// **return** The group instance. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future getGroupSpecificationFromServer(String groupId) async { Map req = {'groupId': groupId}; Map result = await _channel.invokeMethod( @@ -129,17 +214,38 @@ class EMGroupManager { } } - /// 获取群组成员列表 + /// + /// Gets a group's member list with pagination. + /// + /// When EMCursorResult.cursor is an empty string ("") in the result, there is no more data. + /// + /// For example: + /// ```dart + /// EMCursorResult result = await EMClient.getInstance.groupManager.getGroupMemberListFromServer(groupId); // search 1 + /// result = await EMClient.getInstance.groupManager.getGroupMemberListFromServer(groupId, cursor: result.cursor); // search 2 + /// ``` + /// + /// Param [groupId] The group ID. + /// + /// Param [pageSize] The number of group members per page. + /// + /// Param [cursor] The cursor position from which to start to get data next time. Sets the parameter as null for the first time. + /// + /// **return** The result of {@link EMCursorResult}, including the cursor for getting data next time and the group member list. + /// For the last page, the return value of cursor is an empty string. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future> getGroupMemberListFromServer( String groupId, { int pageSize = 200, - String cursor = '', + String? cursor, }) async { Map req = { 'groupId': groupId, - 'cursor': cursor, 'pageSize': pageSize, }; + req.setValueWithOutNull("cursor", cursor); Map result = await _channel.invokeMethod( ChatMethodKeys.getGroupMemberListFromServer, req, @@ -154,8 +260,22 @@ class EMGroupManager { } } - /// 获取黑名单列表 - Future?> getGroupBlockListFromServer( + /// + /// Gets the group block list from server with pagination. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// Param [pageSize] The number of groups per page. + /// + /// Param [pageNum] The page number, starting from 1. + /// + /// **return** The group block list. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future?> getBlockListFromServer( String groupId, { int pageSize = 200, int pageNum = 1, @@ -171,8 +291,22 @@ class EMGroupManager { } } - /// 获取禁言列表 - Future?> getGroupMuteListFromServer( + /// + /// Gets the mute list of the group from the server. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// Param [pageSize] The number of groups per page. + /// + /// Param [pageNum] The page number, starting from 1. + /// + /// **return** The group mute list. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future?> getMuteListFromServer( String groupId, { int pageSize = 200, int pageNum = 1, @@ -188,8 +322,18 @@ class EMGroupManager { } } - /// 获取白名单列表 - Future?> getGroupWhiteListFromServer(String groupId) async { + /// + /// Gets the allow list of group from the server. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// **return** return the group allow list. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future?> getWhiteListFromServer(String groupId) async { Map req = {'groupId': groupId}; Map result = await _channel.invokeMethod( ChatMethodKeys.getGroupWhiteListFromServer, req); @@ -201,7 +345,15 @@ class EMGroupManager { } } - /// 判断自己是否在白名单中 + /// + /// Gets whether the member is on the allow list. + /// + /// Param [groupId] The group ID. + /// + /// **return** returns a Boolean value to indicate whether the current user is on the group allow list; + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future isMemberInWhiteListFromServer(String groupId) async { Map req = {'groupId': groupId}; Map result = await _channel.invokeMethod( @@ -214,8 +366,20 @@ class EMGroupManager { } } - /// 获取群共享文件列表 - Future> getGroupFileListFromServer( + /// + /// Gets the shared files of group from the server. + /// + /// Param [groupId] The group ID. + /// + /// Param [pageSize] The number of groups per page. + /// + /// Param [pageNum] The page number, starting from 1. + /// + /// **return** The shared files. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future?> getGroupFileListFromServer( String groupId, { int pageSize = 200, int pageNum = 1, @@ -235,7 +399,17 @@ class EMGroupManager { } } - /// 从服务器获取群公告 + /// + /// Gets the group announcement from the server. + /// + /// Group members can call this method. + /// + /// Param [groupId] The group ID. + /// + /// **return** The group announcement. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future getGroupAnnouncementFromServer(String groupId) async { Map req = {'groupId': groupId}; Map result = await _channel.invokeMethod( @@ -248,13 +422,26 @@ class EMGroupManager { } } - /// 邀请用户加入私有群,用于公开群: PublicJoinNeedApproval / PublicOpenJoin + /// + /// Adds users to the group. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// Param [members] The array of new members to add. + /// + /// Param [welcome] The welcome message. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future addMembers( String groupId, List members, [ - String welcome = '', + String? welcome, ]) async { - Map req = {'welcome': welcome, 'groupId': groupId, 'members': members}; + Map req = {'groupId': groupId, 'members': members}; + req.setValueWithOutNull("welcome", welcome); Map result = await _channel.invokeMethod(ChatMethodKeys.addMembers, req); try { EMError.hasErrorFromResult(result); @@ -263,7 +450,20 @@ class EMGroupManager { } } - /// 邀请用户加入私有群,用于私有群: PrivateOnlyOwnerInvite / PrivateMemberCanInvite + /// + /// Adds users to the group. + /// + /// Only the group owner or admin can call this method. + /// 邀请用户加入私有群,用于私有群: PrivateOnlyOwnerInvite / PrivateMemberCanInvite ???? + /// + /// Param [groupId] The group ID. + /// + /// Param [members] The array of new members to invite. + /// + /// Param [reason] The invite reason. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future inviterUser( String groupId, List members, [ @@ -289,7 +489,17 @@ class EMGroupManager { } } - /// 从群组中移除用户 + /// + /// Removes a member from the group. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// Param [members] The user IDs of members to be removed. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future removeMembers( String groupId, List members, @@ -303,7 +513,19 @@ class EMGroupManager { } } - /// 将用户加入到群组黑名单中 + /// + /// Adds the user to the group block list. + /// + /// Users will be first removed from the group they have joined before being added to the group block list. The users on the group block list can not join the group again. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// Param [members] The list of users to be added to the block list. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future blockMembers( String groupId, List members, @@ -317,7 +539,17 @@ class EMGroupManager { } } - /// 将用户从黑名单中移除 + /// + /// Removes users from the group block list. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// Param [members] The users to be removed from the group block list. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future unblockMembers( String groupId, List members, @@ -332,8 +564,18 @@ class EMGroupManager { } } - /// 更新群组名称 - Future changeGroupName( + /// + /// Changes the group name. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// Param [name] The new group name. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future changeGroupName( String groupId, String name, ) async { @@ -342,14 +584,23 @@ class EMGroupManager { await _channel.invokeMethod(ChatMethodKeys.updateGroupSubject, req); try { EMError.hasErrorFromResult(result); - return EMGroup.fromJson(result[ChatMethodKeys.updateGroupSubject]); } on EMError catch (e) { throw e; } } - /// 更新群描述 - Future changeGroupDescription( + /// + /// Changes the group description. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// Param [desc] The new group description. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future changeGroupDescription( String groupId, String desc, ) async { @@ -358,13 +609,18 @@ class EMGroupManager { await _channel.invokeMethod(ChatMethodKeys.updateDescription, req); try { EMError.hasErrorFromResult(result); - return EMGroup.fromJson(result[ChatMethodKeys.updateDescription]); } on EMError catch (e) { throw e; } } - /// 退出群组 + /// + /// Leaves a group. + /// + /// Param [groupId] The group ID. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future leaveGroup(String groupId) async { Map req = {'groupId': groupId}; Map result = await _channel.invokeMethod(ChatMethodKeys.leaveGroup, req); @@ -375,7 +631,15 @@ class EMGroupManager { } } - /// 解散群组 + /// + /// Destroys the group instance. + /// + /// Only the group owner can call this method. + /// + /// Param [groupId] The group ID. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future destroyGroup(String groupId) async { Map req = {'groupId': groupId}; Map result = await _channel.invokeMethod(ChatMethodKeys.destroyGroup, req); @@ -386,7 +650,15 @@ class EMGroupManager { } } - /// 不接收群消息 + /// + /// Blocks group messages. + /// + /// The user that blocks group messages is still a group member, but can't receive group messages. + /// + /// Param [groupId] The group ID. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future blockGroup(String groupId) async { Map req = {'groupId': groupId}; Map result = await _channel.invokeMethod(ChatMethodKeys.blockGroup, req); @@ -397,7 +669,13 @@ class EMGroupManager { } } - /// 恢复接收群消息 + /// + /// Unblocks group messages. + /// + /// Param [groupId] The group ID. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future unblockGroup(String groupId) async { Map req = {'groupId': groupId}; Map result = await _channel.invokeMethod(ChatMethodKeys.unblockGroup, req); @@ -408,8 +686,20 @@ class EMGroupManager { } } - /// 将群转给其他人,需要群主调用 - Future changeGroupOwner( + /// + /// Transfers the group ownership. + /// + /// Only the group owner can call this method. + /// + /// Param [groupId] The group ID. + /// + /// Param [newOwner] The new owner ID. + /// + /// **return** The updated group instance. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future changeOwner( String groupId, String newOwner, ) async { @@ -424,7 +714,19 @@ class EMGroupManager { } } - /// 添加管理员 + /// + /// Adds a group admin. + /// + /// Only the group owner can call this method and admin can not. + /// + /// Param [groupId] The group ID. + /// + /// Param [memberId] The admin ID to add. + /// + /// **return** The updated group instance. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future addAdmin( String groupId, String memberId, @@ -439,7 +741,19 @@ class EMGroupManager { } } - /// 移除管理员 + /// + /// Removes a group admin. + /// + /// Only the group owner can call this method. + /// + /// Param [groupId] The group ID. + /// + /// Param [adminId] The admin ID to remove. + /// + /// **return** The updated group instance. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future removeAdmin( String groupId, String adminId, @@ -454,7 +768,21 @@ class EMGroupManager { } } - /// 对群成员禁言,白名单中的用户不会被限制 + /// + /// Mutes group members. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// Param [members] The list of members to be muted. + /// + /// Param [duration] The mute duration in milliseconds. + /// + /// **return** The updated group instance. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future muteMembers( String groupId, List members, { @@ -470,8 +798,18 @@ class EMGroupManager { } } - /// 对群成员取消禁言 - Future unMuteMembers( + /// + /// Unmutes group members. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// Param [members] The list of members to be muted. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future unMuteMembers( String groupId, List members, ) async { @@ -479,13 +817,20 @@ class EMGroupManager { Map result = await _channel.invokeMethod(ChatMethodKeys.unMuteMembers, req); try { EMError.hasErrorFromResult(result); - return EMGroup.fromJson(result[ChatMethodKeys.unMuteMembers]); } on EMError catch (e) { throw e; } } - /// 对所有群成员禁言,白名单中的用户不会被限制 + /// + /// Mutes all members. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future muteAllMembers(String groupId) async { Map req = {'groupId': groupId}; Map result = @@ -497,7 +842,15 @@ class EMGroupManager { } } - /// 取消对所有群成员禁言 + /// + /// Unmutes all members. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future unMuteAllMembers(String groupId) async { Map req = {'groupId': groupId}; Map result = @@ -509,8 +862,18 @@ class EMGroupManager { } } - /// 将用户添加到白名单 - Future addWhiteList( + /// + /// Adds members to the allowlist. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// Param [members] The members to be added to the allowlist. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future addWhiteList( String groupId, List members, ) async { @@ -518,14 +881,23 @@ class EMGroupManager { Map result = await _channel.invokeMethod(ChatMethodKeys.addWhiteList, req); try { EMError.hasErrorFromResult(result); - return EMGroup.fromJson(result[ChatMethodKeys.addWhiteList]); } on EMError catch (e) { throw e; } } - /// 将用户移出白名单 - Future removeWhiteList( + /// + /// Removes members from the allowlist. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// Param [members] The members to be removed from the allowlist. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future removeWhiteList( String groupId, List members, ) async { @@ -534,14 +906,23 @@ class EMGroupManager { await _channel.invokeMethod(ChatMethodKeys.removeWhiteList, req); try { EMError.hasErrorFromResult(result); - return EMGroup.fromJson(result[ChatMethodKeys.removeWhiteList]); } on EMError catch (e) { throw e; } } - /// 上传群共享文件 - Future uploadGroupSharedFile( + /// + /// Uploads the shared file to the group. + /// + /// Note: The callback is only used for progress callback. + /// + /// Param [groupId] The group ID. + /// + /// Param [filePath] The local file path. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future uploadGroupSharedFile( String groupId, String filePath, ) async { @@ -550,14 +931,25 @@ class EMGroupManager { await _channel.invokeMethod(ChatMethodKeys.uploadGroupSharedFile, req); try { EMError.hasErrorFromResult(result); - return result.boolValue(ChatMethodKeys.uploadGroupSharedFile); } on EMError catch (e) { throw e; } } - /// 下载群共享文件 - Future downloadGroupSharedFile( + /// + /// Downloads the shared file of the group. + /// + /// Note: The callback is only used for progress callback. + /// + /// Param [groupId] The group ID. + /// + /// Param [fileId] The ID of the shared file. + /// + /// Param [savePath] The local file path. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future downloadGroupSharedFile( String groupId, String fileId, String savePath, @@ -567,14 +959,23 @@ class EMGroupManager { ChatMethodKeys.downloadGroupSharedFile, req); try { EMError.hasErrorFromResult(result); - return result.boolValue(ChatMethodKeys.downloadGroupSharedFile); } on EMError catch (e) { throw e; } } - /// 删除群共享文件 - Future removeGroupSharedFile( + /// + /// Removes a shared file of the group. + /// + /// Group members can delete their own uploaded files. The group owner or admin can delete all shared files. + /// + /// Param [groupId] The group ID. + /// + /// Param [fileId] The shared file ID. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future removeGroupSharedFile( String groupId, String fileId, ) async { @@ -583,13 +984,22 @@ class EMGroupManager { await _channel.invokeMethod(ChatMethodKeys.removeGroupSharedFile, req); try { EMError.hasErrorFromResult(result); - return EMGroup.fromJson(result[ChatMethodKeys.removeGroupSharedFile]); } on EMError catch (e) { throw e; } } - /// 更新群公告 + /// + /// Updates the group announcement. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// Param [announcement] The group announcement. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future updateGroupAnnouncement( String groupId, String announcement, @@ -605,24 +1015,42 @@ class EMGroupManager { } } - /// 更新群扩展 - Future updateGroupExt( + /// + /// Updates the group extension field. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// Param [extension] The group extension field. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future updateGroupExtension( String groupId, - String ext, + String extension, ) async { - Map req = {'groupId': groupId, 'ext': ext}; + Map req = {'groupId': groupId, 'ext': extension}; Map result = await _channel.invokeMethod(ChatMethodKeys.updateGroupExt, req); try { EMError.hasErrorFromResult(result); - return EMGroup.fromJson(result[ChatMethodKeys.updateGroupExt]); } on EMError catch (e) { throw e; } } - /// 加入公开群,用于加入不需要群主/管理员同意的公开群: EMGroupStyle.PublicOpenJoin - Future joinPublicGroup( + /// + /// Joins a public group. + /// + /// For a group that requires no authentication,users can join it freely without the need of having permission. + /// For a group that requires authentication, users need to wait for the owner to agree before joining the group. For details, see {@link EMGroupStyle}. + /// + ///Param [groupId] The group ID. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future joinPublicGroup( String groupId, ) async { Map req = {'groupId': groupId}; @@ -630,31 +1058,50 @@ class EMGroupManager { await _channel.invokeMethod(ChatMethodKeys.joinPublicGroup, req); try { EMError.hasErrorFromResult(result); - return EMGroup.fromJson(result[ChatMethodKeys.joinPublicGroup]); } on EMError catch (e) { throw e; } } - /// 申请加入公开群,用于加入需要群主/管理员同意的公开群: EMGroupStyle.PublicJoinNeedApproval - Future requestToJoinPublicGroup( + /// + /// Requests to join a group. + /// + /// Note: The group style is {@link EMGroupStyle#PublicJoinNeedApproval}, which is a public group + /// requiring authentication. + /// + /// Param [groupId] The group ID. + /// + /// Param [reason] The reason for requesting to join the group. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future requestToJoinPublicGroup( String groupId, [ - String reason = '', + String? reason, ]) async { - Map req = {'groupId': groupId, 'reason': reason}; + Map req = {'groupId': groupId}; + req.setValueWithOutNull('reason', reason); Map result = await _channel.invokeMethod( ChatMethodKeys.requestToJoinPublicGroup, req); try { EMError.hasErrorFromResult(result); - return EMGroup.fromJson(result[ChatMethodKeys.requestToJoinPublicGroup]); } on EMError catch (e) { throw e; } } - /// 同意公开群组申请,当群类型是EMGroupStyle.PublicJoinNeedApproval, - /// 有人申请进群时,管理员和群主会收到申请,用该方法同意申请 - Future acceptJoinApplication( + /// + /// Approves a group request. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// Param [username] The ID of the user who sends a request to join the group. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future acceptJoinApplication( String groupId, String username, ) async { @@ -663,33 +1110,53 @@ class EMGroupManager { await _channel.invokeMethod(ChatMethodKeys.acceptJoinApplication, req); try { EMError.hasErrorFromResult(result); - return EMGroup.fromJson(result[ChatMethodKeys.acceptJoinApplication]); } on EMError catch (e) { throw e; } } - /// 拒绝公开群组申请,当群类型是EMGroupStyle.PublicJoinNeedApproval, - /// 有人申请进群时,管理员和群主会收到申请,用该方法拒绝申请 - Future declineJoinApplication( + /// + /// Declines a group request. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// Param [username] The ID of the user who sends a request to join the group. + /// + /// Param [reason] The reason of declining. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future declineJoinApplication( String groupId, String username, [ - String reason = '', + String? reason, ]) async { - Map req = {'groupId': groupId, 'username': username, 'reason': reason}; + Map req = {'groupId': groupId, 'username': username}; + req.setValueWithOutNull('reason', reason); + Map result = await _channel.invokeMethod(ChatMethodKeys.declineJoinApplication, req); try { EMError.hasErrorFromResult(result); - return EMGroup.fromJson(result[ChatMethodKeys.declineJoinApplication]); } on EMError catch (e) { throw e; } } - /// 同意群邀请,当群组是PrivateOnlyOwnerInvite / PrivateMemberCanInvite时, - /// 有人添加您入群时您会收到群邀请,用该方法同意群邀请 - Future acceptInvitationFromGroup( + /// + /// Accepts a group invitation. + /// + /// Param [groupId] The group ID. + /// + /// Param [inviter] The user who initiates the invitation. + /// + /// **return** The group instance which the user has accepted the invitation to join. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future acceptInvitation( String groupId, String inviter, ) async { @@ -704,53 +1171,57 @@ class EMGroupManager { } } - /// 拒绝群邀请,当群组是PrivateOnlyOwnerInvite / PrivateMemberCanInvite时, - /// 有人添加您入群时您会收到群邀请,用该方法拒绝群邀请 - Future declineInvitationFromGroup( + /// + /// Declines a group invitation. + /// + /// Param [groupId] The group ID. + /// + /// Param [inviter] The inviter. + /// + /// Param [reason] The reason of declining. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future declineInvitation( String groupId, String inviter, [ - String reason = '', + String? reason, ]) async { - Map req = {'groupId': groupId, 'inviter': inviter, 'reason': reason}; + Map req = {'groupId': groupId, 'inviter': inviter}; + req.setValueWithOutNull('reason', reason); Map result = await _channel.invokeMethod( ChatMethodKeys.declineInvitationFromGroup, req); try { EMError.hasErrorFromResult(result); - return EMGroup.fromJson(result[ChatMethodKeys.acceptInvitationFromGroup]); - } on EMError catch (e) { - throw e; - } - } - - /// 设置群组免打扰,设置后,当您不在线时您不会收到群推送 - Future ignoreGroupPush( - String groupId, [ - bool enable = true, - ]) async { - Map req = {'groupId': groupId, 'enable': enable}; - Map result = - await _channel.invokeMethod(ChatMethodKeys.ignoreGroupPush, req); - try { - EMError.hasErrorFromResult(result); - return EMGroup.fromJson(result[ChatMethodKeys.ignoreGroupPush]); } on EMError catch (e) { throw e; } } - /// @nodoc addGroupChangeListener - Adds [listener] to be aware of group change events. + /// + /// Registers a group event listener. + /// + /// The registered listener needs to be used together with {@link #removeGroupChangeListener(EMGroupEventListener)}. + /// + /// Param [listener] The group event listener to be registered. + /// void addGroupChangeListener(EMGroupEventListener listener) { _groupChangeListeners.add(listener); } - /// @nodoc removeGroupChangeListener - Remove [listener] from the listener list. + /// + /// Removes a group event listener. + /// + /// This method removes a group event listener registered with {@link #addGroupChangeListener(EMGroupEventListener)}. + /// + /// Param [listener] The group event listener to be removed. + /// void removeGroupChangeListener(EMGroupEventListener listener) { if (_groupChangeListeners.contains(listener)) { _groupChangeListeners.remove(listener); } } - /// @nodoc Future _onGroupChanged(Map? map) async { for (EMGroupEventListener listener in _groupChangeListeners) { var type = map!['type']; diff --git a/lib/src/em_push_manager.dart b/lib/src/em_push_manager.dart index 1e5e48fa..e49f5d4d 100644 --- a/lib/src/em_push_manager.dart +++ b/lib/src/em_push_manager.dart @@ -5,6 +5,9 @@ import 'internal/chat_method_keys.dart'; import 'models/em_error.dart'; import 'models/em_push_configs.dart'; +/// +/// The message push configuration options. +/// class EMPushManager { static const _channelPrefix = 'com.chat.im'; static const MethodChannel _channel = const MethodChannel( diff --git a/lib/src/em_userInfo_manager.dart b/lib/src/em_userInfo_manager.dart index adce64ea..0b6e5c71 100644 --- a/lib/src/em_userInfo_manager.dart +++ b/lib/src/em_userInfo_manager.dart @@ -6,6 +6,9 @@ import 'em_client.dart'; import 'models/em_error.dart'; import 'models/em_userInfo.dart'; +/// +/// The user information manager for updating and getting user properties. +/// class EMUserInfoManager { static const _channelPrefix = 'com.chat.im'; static const MethodChannel _channel = const MethodChannel( @@ -16,22 +19,25 @@ class EMUserInfoManager { //有效的联系人map Map _effectiveUserInfoMap = Map(); - EMUserInfoManager(); - - //更新自己的用户属性 - Future updateOwnUserInfo(EMUserInfo userInfo) async { + /// + /// Modifies the current user's information. + /// + /// Param [userInfo] userInfo The user information to be modified. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future updateOwnUserInfo(EMUserInfo userInfo) async { Map req = {'userInfo': userInfo.toJson()}; Map result = await _channel.invokeMethod(ChatMethodKeys.updateOwnUserInfo, req); try { EMError.hasErrorFromResult(result); - return EMUserInfo.fromJson(result[ChatMethodKeys.updateOwnUserInfo]); } on EMError catch (e) { throw e; } } - /// 更新自己用户属性 + @Deprecated("") Future updateOwnUserInfoWithType( EMUserInfoType type, String userInfoValue) async { Map req = { @@ -54,11 +60,21 @@ class EMUserInfoManager { } } - Future fetchOwnInfo({int expireTime = 3600}) async { + /// + /// Get the current user's information from server. + /// + /// Param [expireTime] expire time, Units are seconds. If the last fetch is less than the expiration time, it is directly fetched from the local cache; + /// otherwise, it is fetched from the server. + /// + /// **return** user properties. See {@link EMUserInfo} + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future fetchOwnInfo({int expireTime = 0}) async { String? currentUser = await EMClient.getInstance.getCurrentUsername(); if (currentUser != null) { try { - Map ret = await fetchUserInfoByIdWithExpireTime( + Map ret = await fetchUserInfoById( [currentUser], expireTime: expireTime, ); @@ -70,12 +86,22 @@ class EMUserInfoManager { return _ownUserInfo; } - /// 获取指定id的用户的用户属性, - /// `userIds` 需要获取的环信id; - /// `expireTime` 过期时间,单位秒。如果之前获取过, 如果距当前时间小于过期时间则不会重复获取 - Future> fetchUserInfoByIdWithExpireTime( - List userIds, - {int expireTime = 3600}) async { + /// + /// Gets user information with user ID. + /// + /// Param [userIds] The user ID array. + /// + /// Param [expireTime] expire time, Units are seconds. If the last fetch is less than the expiration time, it is directly fetched from the local cache; + /// otherwise, it is fetched from the server. + /// + /// **return** Map of User ids and user properties. key is user id and value is user properties. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future> fetchUserInfoById( + List userIds, { + int expireTime = 0, + }) async { List needReqIds = userIds .where((element) => !_effectiveUserInfoMap.containsKey(element) || @@ -112,10 +138,6 @@ class EMUserInfoManager { } } - /// 获取指定id的用户的指定类型的用户属性 - /// `userIds` 需要获取的环信id; - /// `types` 需要获取的属性 - /// `expireTime` 过期时间,单位秒。如果之前获取过, 如果距当前时间小于过期时间则不会重复获取 @Deprecated( 'Use userInfoManager.fetchUserInfoByIdWithExpireTime() method instead.') Future> fetchUserInfoByIdWithType( @@ -156,54 +178,6 @@ class EMUserInfoManager { } } - // 整型转化用户属性类型 【int => EMUserInfoType】 - static EMUserInfoType userInfoTypeFromInt(int type) { - EMUserInfoType ret = EMUserInfoType.NickName; - switch (type) { - case 0: - { - ret = EMUserInfoType.NickName; - } - break; - case 1: - { - ret = EMUserInfoType.AvatarURL; - } - break; - case 2: - { - ret = EMUserInfoType.Phone; - } - break; - case 3: - { - ret = EMUserInfoType.Mail; - } - break; - case 4: - { - ret = EMUserInfoType.Gender; - } - break; - case 5: - { - ret = EMUserInfoType.Sign; - } - break; - case 6: - { - ret = EMUserInfoType.Birth; - } - break; - case 7: - { - ret = EMUserInfoType.Ext; - } - } - return ret; - } - - // 用户属性类型转化整型 【EMUserInfoType => int】 static int _userInfoTypeToInt(EMUserInfoType type) { int ret = 0; switch (type) { diff --git a/lib/src/internal/chat_method_keys.dart b/lib/src/internal/chat_method_keys.dart index 0d10a49f..79eccf27 100644 --- a/lib/src/internal/chat_method_keys.dart +++ b/lib/src/internal/chat_method_keys.dart @@ -4,6 +4,7 @@ class ChatMethodKeys { static const String createAccount = 'createAccount'; static const String login = 'login'; static const String loginWithAgoraToken = 'loginWithAgoraToken'; + static const String renewToken = 'renewToken'; static const String logout = 'logout'; static const String changeAppKey = 'changeAppKey'; diff --git a/lib/src/models/em_group_options.dart b/lib/src/models/em_group_options.dart index f8fed8b0..04628959 100644 --- a/lib/src/models/em_group_options.dart +++ b/lib/src/models/em_group_options.dart @@ -4,11 +4,12 @@ import '../tools/em_extension.dart'; class EMGroupOptions { EMGroupOptions._private(); - EMGroupOptions( - {required EMGroupStyle style, - int count = 200, - bool inviteNeedConfirm = false, - String extension = ''}) { + EMGroupOptions({ + EMGroupStyle style = EMGroupStyle.PrivateOnlyOwnerInvite, + int count = 200, + bool inviteNeedConfirm = false, + String? extension, + }) { _style = style; _maxCount = count; _inviteNeedConfirm = inviteNeedConfirm; @@ -38,7 +39,7 @@ class EMGroupOptions { data['style'] = EMGroupOptions.styleTypeToInt(_style); data['maxCount'] = _maxCount; data['inviteNeedConfirm'] = _inviteNeedConfirm; - data['ext'] = _ext; + data.setValueWithOutNull("ext", _ext); return data; } diff --git a/lib/src/models/em_message.dart b/lib/src/models/em_message.dart index 70411105..5d3dfdf7 100644 --- a/lib/src/models/em_message.dart +++ b/lib/src/models/em_message.dart @@ -68,6 +68,9 @@ abstract class EMMessageStatusListener { void onStatusChanged() {} } +/// +/// +/// class EMMessage { EMMessage._private() { _tmpKey = localTime.toString(); @@ -277,7 +280,7 @@ class EMMessage { EMMessageStatusListener? listener; - void setMessageListener(EMMessageStatusListener? listener) { + void setMessageStatusListener(EMMessageStatusListener? listener) { this.listener = listener; } From 3f6252bd0873c20c457a6c332c1108e3376d1e4f Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Tue, 29 Mar 2022 17:19:52 +0800 Subject: [PATCH 12/56] update --- .../im_flutter_sdk/EMPushManagerWrapper.java | 10 +++++ lib/src/em_push_manager.dart | 39 +++++++++++++++++++ lib/src/models/em_chat_enums.dart | 1 + lib/src/models/em_push_configs.dart | 10 +++-- 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMPushManagerWrapper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMPushManagerWrapper.java index 7614fff6..a022adc2 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMPushManagerWrapper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMPushManagerWrapper.java @@ -112,6 +112,16 @@ private void imPushNoDisturb(JSONObject params, String channelName, Result resu }); } + private void enableOfflinePush(JSONObject params, String channelName, Result result) throws JSONException + { + + } + + private void disableOfflinePush(JSONObject params, String channelName, Result result) throws JSONException + { + + } + private void updateImPushStyle(JSONObject params, String channelName, Result result) throws JSONException { DisplayStyle style = params.getInt("pushStyle") == 0 ? DisplayStyle.SimpleBanner : DisplayStyle.MessageSummary; EMClient.getInstance().pushManager().asyncUpdatePushDisplayStyle(style, new EMWrapperCallBack(result, channelName, true)); diff --git a/lib/src/em_push_manager.dart b/lib/src/em_push_manager.dart index 1e5e48fa..28e7e0f4 100644 --- a/lib/src/em_push_manager.dart +++ b/lib/src/em_push_manager.dart @@ -5,6 +5,11 @@ import 'internal/chat_method_keys.dart'; import 'models/em_error.dart'; import 'models/em_push_configs.dart'; +enum DisplayStyle { + Simple, + Summary, +} + class EMPushManager { static const _channelPrefix = 'com.chat.im'; static const MethodChannel _channel = const MethodChannel( @@ -32,6 +37,29 @@ class EMPushManager { } } + Future enableOfflinePush() async {} + + Future disableOfflinePush({ + required int start, + required int to, + }) async {} + + Future updatePushServiceForGroup({ + required List groupId, + required bool noPush, + }) async { + Map req = {'noDisturb': noPush, 'group_id': groupId}; + Map result = + await _channel.invokeMethod(ChatMethodKeys.updateGroupPushService, req); + try { + EMError.hasErrorFromResult(result); + } on EMError catch (e) { + throw e; + } + } + + Future?> getNoPushGroups() async {} + /// 更新当前用户的[nickname],这样离线消息推送的时候可以显示用户昵称而不是id,需要登录环信服务器成功后调用才生效 Future updatePushNickname(String nickname) async { Map req = {'nickname': nickname}; @@ -44,6 +72,17 @@ class EMPushManager { } } + Future updatePushDisplayStyle(DisplayStyle displayStyle) async { + Map req = {'pushStyle': displayStyle == DisplayStyle.Simple ? 0 : 1}; + Map result = + await _channel.invokeMethod(ChatMethodKeys.updateImPushStyle, req); + try { + EMError.hasErrorFromResult(result); + } on EMError catch (e) { + throw e; + } + } + /// 上传华为推送token, 需要确保登录成功后再调用(可以是进入home页面后) Future updateHMSPushToken(String token) async { if (Platform.isAndroid) { diff --git a/lib/src/models/em_chat_enums.dart b/lib/src/models/em_chat_enums.dart index 0cc680ed..1354281b 100644 --- a/lib/src/models/em_chat_enums.dart +++ b/lib/src/models/em_chat_enums.dart @@ -17,6 +17,7 @@ enum EMConversationType { ChatRoom, // 聊天室消息 } +@Deprecated('Switch to using EMPushManager#DisplayStyle instead') enum EMPushStyle { Simple, Summary, diff --git a/lib/src/models/em_push_configs.dart b/lib/src/models/em_push_configs.dart index 7bc66a65..42ae0da5 100644 --- a/lib/src/models/em_push_configs.dart +++ b/lib/src/models/em_push_configs.dart @@ -15,6 +15,7 @@ class EMPushConfigs { List? _noDisturbGroups = []; EMPushStyle? get pushStyle => _pushStyle; + bool? get noDisturb => _noDisturb; int? get noDisturbStartHour => _noDisturbStartHour; int? get noDisturbEndHour => _noDisturbEndHour; @@ -44,7 +45,8 @@ extension EMPushConfigsExtension on EMPushConfigs { static const MethodChannel _channel = const MethodChannel('com.chat.im/chat_push_manager', JSONMethodCodec()); - /// 设置是否免打扰[isNoDisturb], [startTime], [endTime] + @Deprecated( + "Switch to using EMPushManager#enableOfflinePush and EMPushManager#disableOfflinePush instead") Future setNoDisturb( bool isNoDisturb, [ int startTime = 0, @@ -72,7 +74,7 @@ extension EMPushConfigsExtension on EMPushConfigs { } } - /// 设置消息推送显示样式[pushStyle] + @Deprecated("Switch to using EMPushManager#updatePushDisplayStyle instead") Future setPushStyle(EMPushStyle pushStyle) async { Map req = {'pushStyle': pushStyle == EMPushStyle.Simple ? 0 : 1}; Map result = @@ -84,7 +86,7 @@ extension EMPushConfigsExtension on EMPushConfigs { } } - /// 通过群id[groupId]设置群组是否免打扰[isNoDisturb] + @Deprecated("Switch to using EMPushManager#updatePushServiceForGroup instead") Future setGroupToDisturb( String groupId, bool isNoDisturb, @@ -99,7 +101,7 @@ extension EMPushConfigsExtension on EMPushConfigs { } } - /// 获取免打扰群组列表 + @Deprecated("Switch to using EMPushManager#getNoPushGroups instead") Future?> noDisturbGroupsFromServer() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getNoDisturbGroups); try { From 77ec46514d893d4403c54bc420b85e1ee3680f24 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Tue, 29 Mar 2022 19:16:31 +0800 Subject: [PATCH 13/56] update push manager. --- .../im_flutter_sdk/EMPushManagerWrapper.java | 39 +++++++++++- .../easemob/im_flutter_sdk/EMSDKMethod.java | 3 + ios/Classes/EMPushManagerWrapper.m | 61 ++++++++++++++++++- ios/Classes/EMSDKMethod.h | 7 ++- lib/src/em_push_manager.dart | 47 ++++++++++++-- lib/src/internal/chat_method_keys.dart | 3 + lib/src/models/em_push_configs.dart | 9 ++- 7 files changed, 157 insertions(+), 12 deletions(-) diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMPushManagerWrapper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMPushManagerWrapper.java index a022adc2..614474c5 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMPushManagerWrapper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMPushManagerWrapper.java @@ -58,6 +58,15 @@ else if(EMSDKMethod.updateHMSPushToken.equals(call.method)){ else if(EMSDKMethod.updateFCMPushToken.equals(call.method)){ updateFCMPushToken(param, call.method, result); } + else if (EMSDKMethod.enableOfflinePush.equals(call.method)) { + enableOfflinePush(param, call.method, result); + } + else if (EMSDKMethod.disableOfflinePush.equals(call.method)){ + disableOfflinePush(param, call.method, result); + } + else if (EMSDKMethod.getNoPushGroups.equals(call.method)) { + getNoPushGroups(param, call.method, result); + } else { super.onMethodCall(call, result); } @@ -114,11 +123,35 @@ private void imPushNoDisturb(JSONObject params, String channelName, Result resu private void enableOfflinePush(JSONObject params, String channelName, Result result) throws JSONException { - + asyncRunnable(()-> { + try { + EMClient.getInstance().pushManager().enableOfflinePush(); + onSuccess(result, channelName, null); + } catch(HyphenateException e) { + onError(result, e); + } + }); } private void disableOfflinePush(JSONObject params, String channelName, Result result) throws JSONException { + int startTime = params.getInt("start"); + int endTime = params.getInt("end"); + asyncRunnable(()-> { + try { + EMClient.getInstance().pushManager().disableOfflinePush(startTime, endTime); + onSuccess(result, channelName, null); + } catch(HyphenateException e) { + onError(result, e); + } + }); + } + + private void getNoPushGroups(JSONObject params, String channelName, Result result) { + asyncRunnable(()-> { + List groups = EMClient.getInstance().pushManager().getNoPushGroups(); + onSuccess(result, channelName, groups); + }); } @@ -129,12 +162,12 @@ private void updateImPushStyle(JSONObject params, String channelName, Result re private void updateGroupPushService(JSONObject params, String channelName, Result result) throws JSONException { String groupId = params.getString("group_id"); - boolean enablePush = params.getBoolean("noDisturb"); + boolean noPush = params.getBoolean("noPush"); List groupList = new ArrayList<>(); groupList.add(groupId); asyncRunnable(()-> { try { - EMClient.getInstance().pushManager().updatePushServiceForGroup(groupList, !enablePush); + EMClient.getInstance().pushManager().updatePushServiceForGroup(groupList, noPush); EMGroup group = EMClient.getInstance().groupManager().getGroup(groupId); onSuccess(result, channelName, EMGroupHelper.toJson(group)); } catch(HyphenateException e) { diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMSDKMethod.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMSDKMethod.java index be776508..590f20d9 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMSDKMethod.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMSDKMethod.java @@ -200,6 +200,9 @@ public class EMSDKMethod { static final String updatePushNickname = "updatePushNickname"; static final String updateHMSPushToken = "updateHMSPushToken"; static final String updateFCMPushToken = "updateFCMPushToken"; + static final String enableOfflinePush = "enableOfflinePush"; + static final String disableOfflinePush = "disableOfflinePush"; + static final String getNoPushGroups = "getNoPushGroups"; /// ImPushConfig static final String imPushNoDisturb = "imPushNoDisturb"; diff --git a/ios/Classes/EMPushManagerWrapper.m b/ios/Classes/EMPushManagerWrapper.m index 75f48373..929338a7 100644 --- a/ios/Classes/EMPushManagerWrapper.m +++ b/ios/Classes/EMPushManagerWrapper.m @@ -56,6 +56,16 @@ - (void)handleMethodCall:(FlutterMethodCall*)call [self bindDeviceToken:call.arguments channelName:call.method result:result]; + } else if ([EMMethodKeyEnablePush isEqualToString:call.method]) { + [self enablePush:call.arguments + channelName:call.method + result:result]; + } else if ([EMMethodKeyDisablePush isEqualToString:call.method]) { + [self disablePush:call.arguments + channelName:call.method + result:result]; + } else if ([EMMethodKeyGetNoPushGroups isEqualToString:call.method]) { + } else{ [super handleMethodCall:call result:result]; @@ -154,10 +164,10 @@ - (void)updateGroupPushService:(NSDictionary *)param result:(FlutterResult)result { __weak typeof(self) weakSelf = self; NSString *groupId = param[@"group_id"]; - bool enablePush = [param[@"enablePush"] boolValue]; + bool noPush = [param[@"noPush"] boolValue]; [EMClient.sharedClient.pushManager updatePushServiceForGroups:@[groupId] - disablePush:!enablePush + disablePush:noPush completion:^(EMError * _Nonnull aError) { EMGroup *aGroup = [EMGroup groupWithId:groupId]; @@ -202,4 +212,51 @@ - (void)bindDeviceToken:(NSDictionary *)param } +- (void)enablePush:(NSDictionary *)param + channelName:(NSString *)aChannelName + result:(FlutterResult)result { + __weak typeof(self) weakSelf = self; + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + EMError *error = [EMClient.sharedClient.pushManager enableOfflinePush]; + dispatch_async(dispatch_get_main_queue(), ^{ + [weakSelf wrapperCallBack:result + channelName:aChannelName + error:error + object:nil]; + }); + }); +} + +- (void)disablePush:(NSDictionary *)param + channelName:(NSString *)aChannelName + result:(FlutterResult)result { + int startTime = [param[@"start"] intValue]; + int endTime = [param[@"end"] intValue]; + __weak typeof(self) weakSelf = self; + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + EMError *error = [EMClient.sharedClient.pushManager disableOfflinePushStart:startTime end:endTime]; + dispatch_async(dispatch_get_main_queue(), ^{ + [weakSelf wrapperCallBack:result + channelName:aChannelName + error:error + object:nil]; + }); + }); +} + +- (void)getNoPushGroups:(NSDictionary *)param + channelName:(NSString *)aChannelName + result:(FlutterResult)result { + __weak typeof(self) weakSelf = self; + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + NSArray* groups = [EMClient.sharedClient.pushManager noPushGroups]; + dispatch_async(dispatch_get_main_queue(), ^{ + [weakSelf wrapperCallBack:result + channelName:aChannelName + error:nil + object:groups]; + }); + }); +} + @end diff --git a/ios/Classes/EMSDKMethod.h b/ios/Classes/EMSDKMethod.h index ed8e64e2..33c158e8 100644 --- a/ios/Classes/EMSDKMethod.h +++ b/ios/Classes/EMSDKMethod.h @@ -209,12 +209,17 @@ static NSString *const EMMethodKeyOnGroupChanged = @"onGroupChanged"; static NSString *const EMMethodKeyGetImPushConfig = @"getImPushConfig"; static NSString *const EMMethodKeyGetImPushConfigFromServer = @"getImPushConfigFromServer"; static NSString *const EMMethodKeyUpdatePushNickname = @"updatePushNickname"; +static NSString *const EMMethodKeyBindDeviceToken = @"updateAPNsPushToken"; +static NSString *const EMMethodKeyEnablePush = @"enableOfflinePush"; +static NSString *const EMMethodKeyDisablePush = @"disableOfflinePush"; +static NSString *const EMMethodKeyGetNoPushGroups = @"getNoPushGroups"; + static NSString *const EMMethodKeyImPushNoDisturb = @"imPushNoDisturb"; static NSString *const EMMethodKeyUpdateImPushStyle = @"updateImPushStyle"; static NSString *const EMMethodKeyUpdateGroupPushService = @"updateGroupPushService"; static NSString *const EMMethodKeyGetNoDisturbGroups = @"getNoDisturbGroups"; -static NSString *const EMMethodKeyBindDeviceToken = @"updateAPNsPushToken"; + #pragma mark - EMUserInfoManagerWrapper diff --git a/lib/src/em_push_manager.dart b/lib/src/em_push_manager.dart index 28e7e0f4..2fecfcd2 100644 --- a/lib/src/em_push_manager.dart +++ b/lib/src/em_push_manager.dart @@ -6,7 +6,10 @@ import 'models/em_error.dart'; import 'models/em_push_configs.dart'; enum DisplayStyle { + /// 显示 ”您有一条新消息“ Simple, + + /// 显示推送内容详情 Summary, } @@ -25,6 +28,7 @@ class EMPushManager { } } + /// 从服务器获取 `EMPushConfigs` Future getPushConfigsFromServer() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getImPushConfigFromServer); @@ -37,18 +41,42 @@ class EMPushManager { } } - Future enableOfflinePush() async {} + /// 开启离线推送 + Future enableOfflinePush() async { + Map result = await _channel.invokeMethod(ChatMethodKeys.enableOfflinePush); + try { + EMError.hasErrorFromResult(result); + } on EMError catch (e) { + throw e; + } + } + /// 关闭离线推送 + /// [start]: 开始时间 + /// [to]: 结束时间 + /// 如果需要设置24小时免打扰,可以设置start:0, to:24 Future disableOfflinePush({ required int start, required int to, - }) async {} + }) async { + Map req = {'start': start, 'end': to}; + Map result = + await _channel.invokeMethod(ChatMethodKeys.disableOfflinePush, req); + try { + EMError.hasErrorFromResult(result); + } on EMError catch (e) { + throw e; + } + } + /// 设置群组不接收推送 + /// [groupId] 群组id + /// [enablePush] 是否接收离线推送 Future updatePushServiceForGroup({ required List groupId, - required bool noPush, + required bool enablePush, }) async { - Map req = {'noDisturb': noPush, 'group_id': groupId}; + Map req = {'noPush': !enablePush, 'group_id': groupId}; Map result = await _channel.invokeMethod(ChatMethodKeys.updateGroupPushService, req); try { @@ -58,7 +86,15 @@ class EMPushManager { } } - Future?> getNoPushGroups() async {} + /// 从本地获取不接收推送的群组 + Future?> getNoPushGroups() async { + Map result = await _channel.invokeMethod(ChatMethodKeys.getNoPushGroups); + List list = []; + if (result.containsKey(ChatMethodKeys.getNoDisturbGroups)) { + list = result[ChatMethodKeys.getNoDisturbGroups]?.cast(); + } + return list; + } /// 更新当前用户的[nickname],这样离线消息推送的时候可以显示用户昵称而不是id,需要登录环信服务器成功后调用才生效 Future updatePushNickname(String nickname) async { @@ -72,6 +108,7 @@ class EMPushManager { } } + /// 设置推送样式 Future updatePushDisplayStyle(DisplayStyle displayStyle) async { Map req = {'pushStyle': displayStyle == DisplayStyle.Simple ? 0 : 1}; Map result = diff --git a/lib/src/internal/chat_method_keys.dart b/lib/src/internal/chat_method_keys.dart index 89d9668e..6dc0096d 100644 --- a/lib/src/internal/chat_method_keys.dart +++ b/lib/src/internal/chat_method_keys.dart @@ -215,6 +215,9 @@ class ChatMethodKeys { static const String updateHMSPushToken = 'updateHMSPushToken'; static const String updateFCMPushToken = 'updateFCMPushToken'; static const String updateAPNsPushToken = 'updateAPNsPushToken'; + static const String enableOfflinePush = 'enableOfflinePush'; + static const String disableOfflinePush = 'disableOfflinePush'; + static const String getNoPushGroups = 'getNoPushGroups'; /// ImPushConfig static const String imPushNoDisturb = 'imPushNoDisturb'; diff --git a/lib/src/models/em_push_configs.dart b/lib/src/models/em_push_configs.dart index 42ae0da5..b05268be 100644 --- a/lib/src/models/em_push_configs.dart +++ b/lib/src/models/em_push_configs.dart @@ -4,10 +4,13 @@ import '../internal/chat_method_keys.dart'; import '../tools/em_extension.dart'; import 'em_chat_enums.dart'; import 'em_error.dart'; +import '../em_push_manager.dart'; class EMPushConfigs { EMPushConfigs._private(); + DisplayStyle? _displayStyle; + @Deprecated("Switch to using DisplayStyle instead") EMPushStyle? _pushStyle; bool? _noDisturb; int? _noDisturbStartHour; @@ -16,6 +19,8 @@ class EMPushConfigs { EMPushStyle? get pushStyle => _pushStyle; + DisplayStyle? get displayStyle => _displayStyle; + bool? get noDisturb => _noDisturb; int? get noDisturbStartHour => _noDisturbStartHour; int? get noDisturbEndHour => _noDisturbEndHour; @@ -23,6 +28,8 @@ class EMPushConfigs { factory EMPushConfigs.fromJson(Map map) { return EMPushConfigs._private() + .._displayStyle = + map['pushStyle'] == 0 ? DisplayStyle.Simple : DisplayStyle.Summary .._pushStyle = map['pushStyle'] == 0 ? EMPushStyle.Simple : EMPushStyle.Summary .._noDisturb = map.boolValue('noDisturb') @@ -32,7 +39,7 @@ class EMPushConfigs { Map toJson() { Map data = Map(); - data['pushStyle'] = _pushStyle == EMPushStyle.Simple; + data['pushStyle'] = _displayStyle == DisplayStyle.Simple; data['noDisturb'] = _noDisturb; data['noDisturbStartHour'] = _noDisturbStartHour; data['noDisturbEndHour'] = _noDisturbEndHour; From ce33f0d4023f5406147d8842733920dc5455ed19 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Tue, 29 Mar 2022 19:28:54 +0800 Subject: [PATCH 14/56] update change log. --- CHANGELOG.md | 4 ++++ README.md | 18 +++++++++--------- lib/src/em_push_manager.dart | 3 ++- lib/src/models/em_push_configs.dart | 3 +-- pubspec.yaml | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a86947fb..10f40211 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## NEXT +## 3.8.3+9 + +- 将设置推送相关操作从EMPushConfigs中移到EMPushManager中; + ## 3.8.3+8 - 修复ios使用token登录失败; diff --git a/README.md b/README.md index 2f7367cd..cf3c43e6 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Demo中使用的音视频是针对声网音视频封装的[EaseCallKit](https:// ```dart dependencies: - im_flutter_sdk: ^3.8.3+7 + im_flutter_sdk: ^3.8.3+9 ``` 2. 执行`flutter pub get`; @@ -1558,7 +1558,7 @@ try{ ```dart try{ - EMImPushConfig pushManager = await EMClient.getInstance.pushManager.getImPushConfigFromServer(); + EMImPushConfigs pushConfigs = await EMClient.getInstance.pushManager.getPushConfigsFromServer(); } on EMError catch(e) { print('操作失败,原因是: $e'); } @@ -1568,7 +1568,7 @@ try{ ```dart try{ - EMImPushConfig pushConfig = await EMClient.getInstance.pushManager.getImPushConfig(); + EMImPushConfigs pushConfigs = await EMClient.getInstance.pushManager.getPushConfigsFromCache(); } on EMError catch(e) { print('操作失败,原因是: $e'); } @@ -1578,13 +1578,13 @@ try{ ```dart try{ - await pushConfig.setPushStyle(EMImPushStyle.Simple); + await EMClient.getInstance.pushManager.updatePushDisplayStyle(DisplayStyle.Simple); } on EMError catch(e) { print('操作失败,原因是: $e'); } ``` -> `EMImPushStyle`是收推送时样式,目前有两种样式: +> `DisplayStyle`是收推送时样式,目前有两种样式: > `Simple`显示“您有一条新消息”; > `Summary`显示推送详情; @@ -1592,7 +1592,7 @@ try{ ```dart try{ - await pushConfig.setNoDisturb(true, 10, 22); + await EMClient.getInstance.pushManager.disableOfflinePush(10, 22); } on EMError catch(e) { print('操作失败,原因是: $e'); } @@ -1604,7 +1604,7 @@ try{ ```dart try{ - await pushConfig.setNoDisturb(false); + await EMClient.getInstance.pushManager.enableOfflinePush(); } on EMError catch(e) { print('操作失败,原因是: $e'); } @@ -1614,7 +1614,7 @@ try{ ```dart try{ - await pushConfig.setGroupToDisturb(groupId, true); + await EMClient.getInstance.pushManager.updatePushServiceForGroup(groupId, false); } on EMError catch(e) { print('操作失败,原因是: $e'); } @@ -1624,7 +1624,7 @@ try{ ```dart try{ - List groupIdsList = await pushConfig.noDisturbGroupsFromServer(); + List groupIdsList = await EMClient.getInstance.pushManager.getNoPushGroupsFromCache(); } on EMError catch(e) { print('操作失败,原因是: $e'); } diff --git a/lib/src/em_push_manager.dart b/lib/src/em_push_manager.dart index 2fecfcd2..5ce6a603 100644 --- a/lib/src/em_push_manager.dart +++ b/lib/src/em_push_manager.dart @@ -87,7 +87,8 @@ class EMPushManager { } /// 从本地获取不接收推送的群组 - Future?> getNoPushGroups() async { + /// 如果需要从服务器获取,需要调用{@link #getPushConfigsFromServer}后再调用本方法 + Future?> getNoPushGroupsFromCache() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getNoPushGroups); List list = []; if (result.containsKey(ChatMethodKeys.getNoDisturbGroups)) { diff --git a/lib/src/models/em_push_configs.dart b/lib/src/models/em_push_configs.dart index b05268be..a4f55257 100644 --- a/lib/src/models/em_push_configs.dart +++ b/lib/src/models/em_push_configs.dart @@ -17,6 +17,7 @@ class EMPushConfigs { int? _noDisturbEndHour; List? _noDisturbGroups = []; + @Deprecated("Switch to using DisplayStyle instead") EMPushStyle? get pushStyle => _pushStyle; DisplayStyle? get displayStyle => _displayStyle; @@ -30,8 +31,6 @@ class EMPushConfigs { return EMPushConfigs._private() .._displayStyle = map['pushStyle'] == 0 ? DisplayStyle.Simple : DisplayStyle.Summary - .._pushStyle = - map['pushStyle'] == 0 ? EMPushStyle.Simple : EMPushStyle.Summary .._noDisturb = map.boolValue('noDisturb') .._noDisturbStartHour = map['noDisturbStartHour'] .._noDisturbEndHour = map['noDisturbEndHour']; diff --git a/pubspec.yaml b/pubspec.yaml index 469f87cd..3f95d509 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: im_flutter_sdk description: Easemob IM flutter SDK. -version: 3.8.3+8 +version: 3.8.3+9 homepage: http://www.easemob.com/product/im environment: From 8c3559c0ffbd0a673045faf8131715686996a92e Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Tue, 29 Mar 2022 19:34:51 +0800 Subject: [PATCH 15/56] update readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cf3c43e6..3243c7a4 100644 --- a/README.md +++ b/README.md @@ -1558,7 +1558,7 @@ try{ ```dart try{ - EMImPushConfigs pushConfigs = await EMClient.getInstance.pushManager.getPushConfigsFromServer(); + EMPushConfigs pushConfigs = await EMClient.getInstance.pushManager.getPushConfigsFromServer(); } on EMError catch(e) { print('操作失败,原因是: $e'); } @@ -1568,7 +1568,7 @@ try{ ```dart try{ - EMImPushConfigs pushConfigs = await EMClient.getInstance.pushManager.getPushConfigsFromCache(); + EMPushConfigs pushConfigs = await EMClient.getInstance.pushManager.getPushConfigsFromCache(); } on EMError catch(e) { print('操作失败,原因是: $e'); } From e832388a4924623297afd8bf833a56b0e4ac25e8 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Tue, 29 Mar 2022 20:08:58 +0800 Subject: [PATCH 16/56] update --- example/lib/pages/contacts/contact_select_page.dart | 4 ++-- example/lib/pages/contacts/contacts_page.dart | 4 ++-- example/lib/pages/group/joined_groups_page.dart | 6 ------ 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/example/lib/pages/contacts/contact_select_page.dart b/example/lib/pages/contacts/contact_select_page.dart index c12b4c59..624226d9 100644 --- a/example/lib/pages/contacts/contact_select_page.dart +++ b/example/lib/pages/contacts/contact_select_page.dart @@ -193,8 +193,8 @@ class ContactSelectPageState extends State { Future> _fetchUsersInfo(List list) async { List ret = []; - Map map = await EMClient.getInstance.userInfoManager - .fetchUserInfoByIdWithExpireTime(list); + Map map = + await EMClient.getInstance.userInfoManager.fetchUserInfoById(list); List emIds = map.keys.toList(); List noInfoIds = list.toList(); noInfoIds.removeWhere((element) { diff --git a/example/lib/pages/contacts/contacts_page.dart b/example/lib/pages/contacts/contacts_page.dart index fc6ccf7b..113b4675 100644 --- a/example/lib/pages/contacts/contacts_page.dart +++ b/example/lib/pages/contacts/contacts_page.dart @@ -290,8 +290,8 @@ class ContactsPageState extends State Future> _fetchUserInfo(List emIds) async { List ret = []; - Map map = await EMClient.getInstance.userInfoManager - .fetchUserInfoByIdWithExpireTime(emIds); + Map map = + await EMClient.getInstance.userInfoManager.fetchUserInfoById(emIds); List hasInfoIds = map.keys.toList(); for (var hasInfoId in hasInfoIds) { diff --git a/example/lib/pages/group/joined_groups_page.dart b/example/lib/pages/group/joined_groups_page.dart index cb4a1ca8..0eaca992 100644 --- a/example/lib/pages/group/joined_groups_page.dart +++ b/example/lib/pages/group/joined_groups_page.dart @@ -271,12 +271,6 @@ class JoinedGroupsPageState extends State { } _chat(EMGroup group) async { - EMCursorResult result = await EMClient.getInstance.groupManager - .getGroupMemberListFromServer("groupId", cursor: null); - - result = await EMClient.getInstance.groupManager - .getGroupMemberListFromServer("groupId", cursor: result.cursor); - EMConversation? con = await EMClient.getInstance.chatManager.getConversation( group.groupId, From 57a9678393b109a40e40714977f518def49675e5 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Tue, 29 Mar 2022 20:24:57 +0800 Subject: [PATCH 17/56] add ios get no push groups method. --- ios/Classes/EMPushManagerWrapper.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ios/Classes/EMPushManagerWrapper.m b/ios/Classes/EMPushManagerWrapper.m index 929338a7..958997ed 100644 --- a/ios/Classes/EMPushManagerWrapper.m +++ b/ios/Classes/EMPushManagerWrapper.m @@ -65,7 +65,9 @@ - (void)handleMethodCall:(FlutterMethodCall*)call channelName:call.method result:result]; } else if ([EMMethodKeyGetNoPushGroups isEqualToString:call.method]) { - + [self getNoPushGroups:call.arguments + channelName:call.method + result:result]; } else{ [super handleMethodCall:call result:result]; From 90e4b5f6bf81ac380cbe77655b8aec74b33b8652 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Tue, 29 Mar 2022 20:38:10 +0800 Subject: [PATCH 18/56] update --- .../im_flutter_sdk/EMPushManagerWrapper.java | 12 ++++-- ios/Classes/EMPushManagerWrapper.m | 7 ++-- lib/src/em_push_manager.dart | 40 ++++++++++++++----- 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMPushManagerWrapper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMPushManagerWrapper.java index c66479e5..2dc83add 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMPushManagerWrapper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMPushManagerWrapper.java @@ -168,15 +168,19 @@ private void updateImPushStyle(JSONObject params, String channelName, Result re } private void updateGroupPushService(JSONObject params, String channelName, Result result) throws JSONException { - String groupId = params.getString("group_id"); + JSONArray jsonArray = params.getJSONArray("group_ids"); boolean noPush = params.getBoolean("noPush"); + List groupList = new ArrayList<>(); - groupList.add(groupId); + for (int i = 0; i < jsonArray.length(); i++) { + String memberId = jsonArray.getString(i); + groupList.add(memberId); + } + asyncRunnable(()-> { try { EMClient.getInstance().pushManager().updatePushServiceForGroup(groupList, noPush); - EMGroup group = EMClient.getInstance().groupManager().getGroup(groupId); - onSuccess(result, channelName, EMGroupHelper.toJson(group)); + onSuccess(result, channelName, null); } catch(HyphenateException e) { onError(result, e); } diff --git a/ios/Classes/EMPushManagerWrapper.m b/ios/Classes/EMPushManagerWrapper.m index 2f13f6ea..92934d02 100644 --- a/ios/Classes/EMPushManagerWrapper.m +++ b/ios/Classes/EMPushManagerWrapper.m @@ -173,18 +173,17 @@ - (void)updateGroupPushService:(NSDictionary *)param channelName:(NSString *)aChannelName result:(FlutterResult)result { __weak typeof(self) weakSelf = self; - NSString *groupId = param[@"group_id"]; + NSArray *groupIds = param[@"group_ids"]; bool noPush = [param[@"noPush"] boolValue]; - [EMClient.sharedClient.pushManager updatePushServiceForGroups:@[groupId] + [EMClient.sharedClient.pushManager updatePushServiceForGroups:groupIds disablePush:noPush completion:^(EMError * _Nonnull aError) { - EMGroup *aGroup = [EMGroup groupWithId:groupId]; [weakSelf wrapperCallBack:result channelName:aChannelName error:aError - object:[aGroup toJson]]; + object:nil]; }]; } diff --git a/lib/src/em_push_manager.dart b/lib/src/em_push_manager.dart index 32dfbb63..1e91009e 100644 --- a/lib/src/em_push_manager.dart +++ b/lib/src/em_push_manager.dart @@ -5,6 +5,11 @@ import 'internal/chat_method_keys.dart'; import 'models/em_error.dart'; import 'models/em_push_configs.dart'; +/// +/// The push message presentation style: Simple represents the presentation of a simple message, +/// +/// and Summary represents the presentation of message content. +/// enum DisplayStyle { /// 显示 ”您有一条新消息“ Simple, @@ -44,7 +49,11 @@ class EMPushManager { } } - /// 开启离线推送 + /// + /// Turns on the push notification. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future enableOfflinePush() async { Map result = await _channel.invokeMethod(ChatMethodKeys.enableOfflinePush); try { @@ -54,15 +63,20 @@ class EMPushManager { } } - /// 关闭离线推送 - /// [start]: 开始时间 - /// [to]: 结束时间 - /// 如果需要设置24小时免打扰,可以设置start:0, to:24 + /// + /// Do not push the offline messages within the specified time period (24-hour clock). + /// + /// Param [start] The start hour. + /// + /// Param [end] The end hour. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future disableOfflinePush({ required int start, - required int to, + required int end, }) async { - Map req = {'start': start, 'end': to}; + Map req = {'start': start, 'end': end}; Map result = await _channel.invokeMethod(ChatMethodKeys.disableOfflinePush, req); try { @@ -72,14 +86,20 @@ class EMPushManager { } } - /// 设置群组不接收推送 + /// + /// Sets wether to turn on or turn off the push notification for the the specified groups. + /// /// [groupId] 群组id + /// /// [enablePush] 是否接收离线推送 + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future updatePushServiceForGroup({ - required List groupId, + required List groupIds, required bool enablePush, }) async { - Map req = {'noPush': !enablePush, 'group_id': groupId}; + Map req = {'noPush': !enablePush, 'group_ids': groupIds}; Map result = await _channel.invokeMethod(ChatMethodKeys.updateGroupPushService, req); try { From 98cf70c2618d8b2837582ec3d072f816f506de41 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Tue, 29 Mar 2022 20:49:30 +0800 Subject: [PATCH 19/56] update --- .../easemob/im_flutter_sdk/EMPushManagerWrapper.java | 11 +++++++---- ios/Classes/EMPushManagerWrapper.m | 7 +++---- lib/src/em_push_manager.dart | 6 +++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMPushManagerWrapper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMPushManagerWrapper.java index 614474c5..5049cf4c 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMPushManagerWrapper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMPushManagerWrapper.java @@ -8,6 +8,7 @@ import com.hyphenate.chat.EMPushManager.DisplayStyle; import com.hyphenate.exceptions.HyphenateException; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -161,15 +162,17 @@ private void updateImPushStyle(JSONObject params, String channelName, Result re } private void updateGroupPushService(JSONObject params, String channelName, Result result) throws JSONException { - String groupId = params.getString("group_id"); + JSONArray groupIds = params.getJSONArray("group_ids"); boolean noPush = params.getBoolean("noPush"); List groupList = new ArrayList<>(); - groupList.add(groupId); + for (int i = 0; i < groupIds.length(); i++) { + String groupId = groupIds.getString(i); + groupList.add(groupId); + } asyncRunnable(()-> { try { EMClient.getInstance().pushManager().updatePushServiceForGroup(groupList, noPush); - EMGroup group = EMClient.getInstance().groupManager().getGroup(groupId); - onSuccess(result, channelName, EMGroupHelper.toJson(group)); + onSuccess(result, channelName, null); } catch(HyphenateException e) { onError(result, e); } diff --git a/ios/Classes/EMPushManagerWrapper.m b/ios/Classes/EMPushManagerWrapper.m index 958997ed..eb5aeea6 100644 --- a/ios/Classes/EMPushManagerWrapper.m +++ b/ios/Classes/EMPushManagerWrapper.m @@ -165,18 +165,17 @@ - (void)updateGroupPushService:(NSDictionary *)param channelName:(NSString *)aChannelName result:(FlutterResult)result { __weak typeof(self) weakSelf = self; - NSString *groupId = param[@"group_id"]; + NSArray *groupIds = param[@"group_ids"]; bool noPush = [param[@"noPush"] boolValue]; - [EMClient.sharedClient.pushManager updatePushServiceForGroups:@[groupId] + [EMClient.sharedClient.pushManager updatePushServiceForGroups:groupIds disablePush:noPush completion:^(EMError * _Nonnull aError) { - EMGroup *aGroup = [EMGroup groupWithId:groupId]; [weakSelf wrapperCallBack:result channelName:aChannelName error:aError - object:[aGroup toJson]]; + object:nil]; }]; } diff --git a/lib/src/em_push_manager.dart b/lib/src/em_push_manager.dart index 5ce6a603..b696eccc 100644 --- a/lib/src/em_push_manager.dart +++ b/lib/src/em_push_manager.dart @@ -70,13 +70,13 @@ class EMPushManager { } /// 设置群组不接收推送 - /// [groupId] 群组id + /// [groupIds] 群组ids /// [enablePush] 是否接收离线推送 Future updatePushServiceForGroup({ - required List groupId, + required List groupIds, required bool enablePush, }) async { - Map req = {'noPush': !enablePush, 'group_id': groupId}; + Map req = {'noPush': !enablePush, 'group_ids': groupIds}; Map result = await _channel.invokeMethod(ChatMethodKeys.updateGroupPushService, req); try { From 27e20df400de550bf86d8666dd30a065a8fe4d22 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Tue, 29 Mar 2022 21:21:48 +0800 Subject: [PATCH 20/56] update --- .../lib/pages/chat/chat_items/chat_item.dart | 30 +-- example/lib/pages/chat/chat_page.dart | 28 +-- .../conversations/conversation_item.dart | 12 +- lib/src/em_chat_manager.dart | 9 +- lib/src/models/em_conversation.dart | 13 +- lib/src/models/em_message.dart | 221 +++++++++++------- 6 files changed, 185 insertions(+), 128 deletions(-) diff --git a/example/lib/pages/chat/chat_items/chat_item.dart b/example/lib/pages/chat/chat_items/chat_item.dart index e597779f..bebb3844 100644 --- a/example/lib/pages/chat/chat_items/chat_item.dart +++ b/example/lib/pages/chat/chat_items/chat_item.dart @@ -41,7 +41,7 @@ class ChatItem extends StatefulWidget { State createState() => ChatItemState(); } -class ChatItemState extends State implements EMMessageStatusListener { +class ChatItemState extends State implements StatusListener { void initState() { super.initState(); widget.msg.setMessageStatusListener(this); @@ -49,7 +49,7 @@ class ChatItemState extends State implements EMMessageStatusListener { @override Widget build(context) { - bool isRecv = widget.msg.direction == EMMessageDirection.RECEIVE; + bool isRecv = widget.msg.direction == MessageDirection.RECEIVE; return Builder( builder: (_) { _info() { @@ -74,7 +74,7 @@ class ChatItemState extends State implements EMMessageStatusListener { } Widget ret; - if (isRecv && widget.msg.chatType != EMMessageChatType.Chat) { + if (isRecv && widget.msg.chatType != ChatType.Chat) { ret = Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -190,7 +190,7 @@ class ChatItemState extends State implements EMMessageStatusListener { } else { return Builder( builder: (_) { - if (widget.msg.status == EMMessageStatus.PROGRESS) { + if (widget.msg.status == Status.PROGRESS) { return Padding( padding: EdgeInsets.all(sWidth(10)), child: SizedBox( @@ -201,8 +201,8 @@ class ChatItemState extends State implements EMMessageStatusListener { ), ), ); - } else if (widget.msg.status == EMMessageStatus.FAIL || - widget.msg.status == EMMessageStatus.CREATE) { + } else if (widget.msg.status == Status.FAIL || + widget.msg.status == Status.CREATE) { return IconButton( padding: EdgeInsets.zero, icon: Icon( @@ -260,20 +260,20 @@ class ChatItemState extends State implements EMMessageStatusListener { _messageBubble() { EMMessageBody body = widget.msg.body!; - bool isSend = widget.msg.direction != EMMessageDirection.RECEIVE; + bool isSend = widget.msg.direction != MessageDirection.RECEIVE; return Builder(builder: (_) { Widget bubble; switch (widget.msg.body!.type!) { - case EMMessageBodyType.TXT: + case MessageType.TXT: bubble = ChatTextBubble(body as EMTextMessageBody); break; - case EMMessageBodyType.LOCATION: + case MessageType.LOCATION: bubble = ChatLocationBubble(body as EMLocationMessageBody); break; - case EMMessageBodyType.IMAGE: + case MessageType.IMAGE: bubble = ChatImageBubble(body as EMImageMessageBody, isSend); break; - case EMMessageBodyType.VOICE: + case MessageType.VOICE: bubble = Builder(builder: (context) { return Selector( selector: (_, ChatVoicePlayer player) { @@ -287,14 +287,14 @@ class ChatItemState extends State implements EMMessageStatusListener { ); }); break; - case EMMessageBodyType.VIDEO: + case MessageType.VIDEO: bubble = ChatVideoBubble(body as EMVideoMessageBody); break; - case EMMessageBodyType.FILE: + case MessageType.FILE: bubble = ChatFileBubble(body as EMFileMessageBody); break; - case EMMessageBodyType.CMD: - case EMMessageBodyType.CUSTOM: + case MessageType.CMD: + case MessageType.CUSTOM: bubble = Container(); } return Container( diff --git a/example/lib/pages/chat/chat_page.dart b/example/lib/pages/chat/chat_page.dart index dc9279df..457391f8 100644 --- a/example/lib/pages/chat/chat_page.dart +++ b/example/lib/pages/chat/chat_page.dart @@ -238,8 +238,8 @@ class _ChatPageState extends State /// 发送消息已读回执 _makeMessageAsRead(EMMessage msg) async { - if (msg.chatType == EMMessageChatType.Chat && - msg.direction == EMMessageDirection.RECEIVE) { + if (msg.chatType == ChatType.Chat && + msg.direction == MessageDirection.RECEIVE) { if (msg.hasReadAck == false) { try { await EMClient.getInstance.chatManager.sendMessageReadAck(msg); @@ -311,9 +311,9 @@ class _ChatPageState extends State /// 点击bubble _messageBubbleOnTap(EMMessage msg) async { switch (msg.body!.type!) { - case EMMessageBodyType.TXT: + case MessageType.TXT: break; - case EMMessageBodyType.IMAGE: + case MessageType.IMAGE: { EMImageMessageBody body = msg.body as EMImageMessageBody; Image img; @@ -337,7 +337,7 @@ class _ChatPageState extends State ); } break; - case EMMessageBodyType.VOICE: + case MessageType.VOICE: { if (_voicePlayer.currentMsgId == msg.msgId) { _voicePlayer.stopPlay(); @@ -346,15 +346,15 @@ class _ChatPageState extends State } } break; - case EMMessageBodyType.VIDEO: + case MessageType.VIDEO: break; - case EMMessageBodyType.LOCATION: + case MessageType.LOCATION: break; - case EMMessageBodyType.FILE: + case MessageType.FILE: break; - case EMMessageBodyType.CMD: + case MessageType.CMD: break; - case EMMessageBodyType.CUSTOM: + case MessageType.CUSTOM: break; } } @@ -402,16 +402,16 @@ class _ChatPageState extends State /// 发消息方法 _sendMessage(EMMessage msg) async { _chatType() { - EMMessageChatType type = EMMessageChatType.Chat; + ChatType type = ChatType.Chat; switch (widget.conversation.type) { case EMConversationType.Chat: - type = EMMessageChatType.Chat; + type = ChatType.Chat; break; case EMConversationType.ChatRoom: - type = EMMessageChatType.ChatRoom; + type = ChatType.ChatRoom; break; case EMConversationType.GroupChat: - type = EMMessageChatType.GroupChat; + type = ChatType.GroupChat; break; default: } diff --git a/example/lib/pages/conversations/conversation_item.dart b/example/lib/pages/conversations/conversation_item.dart index 17d6523b..db9c6bb1 100644 --- a/example/lib/pages/conversations/conversation_item.dart +++ b/example/lib/pages/conversations/conversation_item.dart @@ -131,23 +131,23 @@ class _ConversationItemState extends State { } switch (_latestMessage.body!.type) { - case EMMessageBodyType.TXT: + case MessageType.TXT: var body = _latestMessage.body as EMTextMessageBody; showInfo = body.content!; break; - case EMMessageBodyType.IMAGE: + case MessageType.IMAGE: showInfo = '[图片]'; break; - case EMMessageBodyType.VIDEO: + case MessageType.VIDEO: showInfo = '[视频]'; break; - case EMMessageBodyType.FILE: + case MessageType.FILE: showInfo = '[文件]'; break; - case EMMessageBodyType.VOICE: + case MessageType.VOICE: showInfo = '[语音]'; break; - case EMMessageBodyType.LOCATION: + case MessageType.LOCATION: showInfo = '[位置]'; break; default: diff --git a/lib/src/em_chat_manager.dart b/lib/src/em_chat_manager.dart index aedeeeba..4c596cc4 100644 --- a/lib/src/em_chat_manager.dart +++ b/lib/src/em_chat_manager.dart @@ -57,14 +57,14 @@ class EMChatManager { /// If the message is voice, picture and other message with attachment, the SDK will automatically upload the attachment. /// You can set whether to upload the attachment to the chat sever by {@link EMOptions#serverTransfer(boolean)}. /// - /// To listen for the status of sending messages, call {@link EMMessage#setMessageStatusListener(EMMessageStatusListener)}. + /// To listen for the status of sending messages, call {@link EMMessage#setMessageStatusListener(StatusListener)}. /// /// Param [message] The message object to be sent /// /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// Future sendMessage(EMMessage message) async { - message.status = EMMessageStatus.PROGRESS; + message.status = Status.PROGRESS; Map result = await _channel.invokeMethod( ChatMethodKeys.sendMessage, message.toJson()); try { @@ -81,7 +81,7 @@ class EMChatManager { /// 重发消息 [message]. Future resendMessage(EMMessage message) async { - message.status = EMMessageStatus.PROGRESS; + message.status = Status.PROGRESS; Map result = await _channel.invokeMethod( ChatMethodKeys.resendMessage, message.toJson()); try { @@ -565,7 +565,8 @@ class EMChatManager { req['timeStamp'] = timeStamp; req['maxCount'] = maxCount; req['from'] = from; - req['direction'] = direction == EMMessageSearchDirection.Up ? "up" : "down"; + req['MessageDirection'] = + direction == EMMessageSearchDirection.Up ? "up" : "down"; Map result = await _channel.invokeMethod(ChatMethodKeys.searchChatMsgFromDB, req); diff --git a/lib/src/models/em_conversation.dart b/lib/src/models/em_conversation.dart index b5fddde5..9fff9044 100644 --- a/lib/src/models/em_conversation.dart +++ b/lib/src/models/em_conversation.dart @@ -216,18 +216,19 @@ extension EMConversationExtension on EMConversation { /// 根据类型获取当前会话汇总的消息 Future> loadMessagesWithMsgType({ - required EMMessageBodyType type, + required MessageType type, int timestamp = -1, int count = 20, String? sender, EMMessageSearchDirection direction = EMMessageSearchDirection.Up, }) async { Map req = this.toJson(); - req['type'] = EMMessageBody.bodyTypeToTypeStr(type); + req['type'] = EMMessageBody.messageTypeToTypeStr(type); req['timestamp'] = timestamp; req['count'] = count; req['sender'] = sender; - req['direction'] = direction == EMMessageSearchDirection.Up ? "up" : "down"; + req['MessageDirection'] = + direction == EMMessageSearchDirection.Up ? "up" : "down"; Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.loadMsgWithMsgType, req); @@ -249,7 +250,8 @@ extension EMConversationExtension on EMConversation { Map req = this.toJson(); req["startId"] = startMsgId; req['count'] = loadCount; - req['direction'] = direction == EMMessageSearchDirection.Up ? "up" : "down"; + req['MessageDirection'] = + direction == EMMessageSearchDirection.Up ? "up" : "down"; Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.loadMsgWithStartId, req); @@ -277,7 +279,8 @@ extension EMConversationExtension on EMConversation { req['sender'] = sender; } req['timestamp'] = timestamp; - req['direction'] = direction == EMMessageSearchDirection.Up ? "up" : "down"; + req['MessageDirection'] = + direction == EMMessageSearchDirection.Up ? "up" : "down"; Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.loadMsgWithKeywords, req); diff --git a/lib/src/models/em_message.dart b/lib/src/models/em_message.dart index 5d3dfdf7..70dcd52b 100644 --- a/lib/src/models/em_message.dart +++ b/lib/src/models/em_message.dart @@ -7,25 +7,52 @@ import '../tools/em_extension.dart'; import '../../im_flutter_sdk.dart'; import '../internal/em_message_state_handle.dart'; -// 消息类型 -enum EMMessageChatType { - Chat, // 单聊消息 - GroupChat, // 群聊消息 - ChatRoom, // 聊天室消息 +/// +/// The enumeration of the chat type. +/// +/// There are three chat types: one-to-one chat, group chat, and chat room. +/// +enum ChatType { + /// One-to-one chat. + Chat, + + /// Group chat. + GroupChat, + + /// Chat room. + ChatRoom, } -// 消息方向 -enum EMMessageDirection { - SEND, // 发送的消息 - RECEIVE, // 接收的消息 +/// +/// The enumeration of the message MessageDirection. +/// +/// Whether the message is sent or received. +/// +enum MessageDirection { + /// This message is sent from the local client. + SEND, + + /// The message is received by the local client. + RECEIVE, } -// 消息状态 -enum EMMessageStatus { - CREATE, // 创建 - PROGRESS, // 发送中 - SUCCESS, // 发送成功 - FAIL, // 发送失败 +/// +/// The enumeration of the message sending/reception status. +/// +/// The states include success, failure, being sent/being received, and created to be sent. +/// +enum Status { + /// The message is created to be sent. + CREATE, + + /// The message is being delivered/receiving. + PROGRESS, + + /// The message is successfully delivered/received. + SUCCESS, + + /// The message fails to be delivered/received. + FAIL, } // 附件状态 @@ -36,19 +63,36 @@ enum EMDownloadStatus { FAILED, // 下载失败 } -/// body类型 -enum EMMessageBodyType { - TXT, // 文字消息 - IMAGE, // 图片消息 - VIDEO, // 视频消息 - LOCATION, // 位置消息 - VOICE, // 音频消息 - FILE, // 文件消息 - CMD, // CMD消息 - CUSTOM, // CUSTOM消息 +/// +/// The enumeration of the message type. +/// +enum MessageType { + /// Text message. + TXT, + + /// Image message. + IMAGE, + + /// Video message. + VIDEO, + + /// Location message. + LOCATION, + + /// Voice message. + VOICE, + + /// File message. + FILE, + + /// Command message. + CMD, + + /// Customized message. + CUSTOM, } -abstract class EMMessageStatusListener { +abstract class StatusListener { /// 消息进度 void onProgress(int progress) {} @@ -69,7 +113,17 @@ abstract class EMMessageStatusListener { } /// +/// The message instance, which represents a sent/received message. +/// +/// For example: +/// Constructs a text message to send: /// +/// ```dart +/// EMMessage msg = EMMessage.createTxtSendMessage( +/// username: "user1", +/// content: "hello", +/// ); +/// ``` /// class EMMessage { EMMessage._private() { @@ -81,7 +135,7 @@ class EMMessage { /// 构造接收的消息 EMMessage.createReceiveMessage({ required this.body, - this.direction = EMMessageDirection.RECEIVE, + this.direction = MessageDirection.RECEIVE, }) { _tmpKey = localTime.toString(); _handle = EMMessageStateHandle( @@ -99,7 +153,7 @@ class EMMessage { /// 构造发送的消息 EMMessage.createSendMessage({ required this.body, - this.direction = EMMessageDirection.SEND, + this.direction = MessageDirection.SEND, this.to, this.hasRead = true, }) : this.from = EMClient.getInstance.currentUsername, @@ -278,9 +332,9 @@ class EMMessage { to: username, body: EMCustomMessageBody(event: event, params: params)); - EMMessageStatusListener? listener; + StatusListener? listener; - void setMessageStatusListener(EMMessageStatusListener? listener) { + void setMessageStatusListener(StatusListener? listener) { this.listener = listener; } @@ -324,13 +378,13 @@ class EMMessage { bool hasRead = false; /// 消息类型 - EMMessageChatType chatType = EMMessageChatType.Chat; + ChatType chatType = ChatType.Chat; /// 消息方向 - EMMessageDirection direction = EMMessageDirection.SEND; + MessageDirection direction = MessageDirection.SEND; - /// 消息状态 - EMMessageStatus status = EMMessageStatus.CREATE; + /// Gets the message sending/reception status. + Status status = Status.CREATE; /// 消息扩展 Map attributes = {}; @@ -344,8 +398,8 @@ class EMMessage { data['to'] = this.to; data['body'] = this.body!.toJson(); data['attributes'] = this.attributes; - data['direction'] = - this.direction == EMMessageDirection.SEND ? 'send' : 'rec'; + data['MessageDirection'] = + this.direction == MessageDirection.SEND ? 'send' : 'rec'; data['hasRead'] = this.hasRead; data['hasReadAck'] = this.hasReadAck; data['hasDeliverAck'] = this.hasDeliverAck; @@ -367,9 +421,9 @@ class EMMessage { ..from = map['from'] as String? ..body = _bodyFromMap(map['body']) ..attributes = map['attributes'] ?? {} - ..direction = map['direction'] == 'send' - ? EMMessageDirection.SEND - : EMMessageDirection.RECEIVE + ..direction = map['MessageDirection'] == 'send' + ? MessageDirection.SEND + : MessageDirection.RECEIVE ..hasRead = map.boolValue('hasRead') ..hasReadAck = map.boolValue('hasReadAck') ..needGroupAck = map.boolValue('needGroupAck') @@ -383,47 +437,47 @@ class EMMessage { ..status = _chatStatusFromInt(map['status'] as int?); } - static int chatTypeToInt(EMMessageChatType type) { - if (type == EMMessageChatType.ChatRoom) { + static int chatTypeToInt(ChatType type) { + if (type == ChatType.ChatRoom) { return 2; - } else if (type == EMMessageChatType.GroupChat) { + } else if (type == ChatType.GroupChat) { return 1; } else { return 0; } } - static EMMessageChatType chatTypeFromInt(int? type) { + static ChatType chatTypeFromInt(int? type) { if (type == 2) { - return EMMessageChatType.ChatRoom; + return ChatType.ChatRoom; } else if (type == 1) { - return EMMessageChatType.GroupChat; + return ChatType.GroupChat; } else { - return EMMessageChatType.Chat; + return ChatType.Chat; } } - static int _chatStatusToInt(EMMessageStatus status) { - if (status == EMMessageStatus.FAIL) { + static int _chatStatusToInt(Status status) { + if (status == Status.FAIL) { return 3; - } else if (status == EMMessageStatus.SUCCESS) { + } else if (status == Status.SUCCESS) { return 2; - } else if (status == EMMessageStatus.PROGRESS) { + } else if (status == Status.PROGRESS) { return 1; } else { return 0; } } - static EMMessageStatus _chatStatusFromInt(int? status) { + static Status _chatStatusFromInt(int? status) { if (status == 3) { - return EMMessageStatus.FAIL; + return Status.FAIL; } else if (status == 2) { - return EMMessageStatus.SUCCESS; + return Status.SUCCESS; } else if (status == 1) { - return EMMessageStatus.PROGRESS; + return Status.PROGRESS; } else { - return EMMessageStatus.CREATE; + return Status.CREATE; } } @@ -474,7 +528,7 @@ abstract class EMMessageBody { Map toJson() { final Map data = new Map(); - data['type'] = EMMessageBody.bodyTypeToTypeStr(this.type!); + data['type'] = EMMessageBody.messageTypeToTypeStr(this.type!); return data; } @@ -483,38 +537,37 @@ abstract class EMMessageBody { return toJson().toString(); } - static String bodyTypeToTypeStr(EMMessageBodyType type) { + static String messageTypeToTypeStr(MessageType type) { switch (type) { - case EMMessageBodyType.TXT: + case MessageType.TXT: return 'txt'; - case EMMessageBodyType.LOCATION: + case MessageType.LOCATION: return 'loc'; - case EMMessageBodyType.CMD: + case MessageType.CMD: return 'cmd'; - case EMMessageBodyType.CUSTOM: + case MessageType.CUSTOM: return 'custom'; - case EMMessageBodyType.FILE: + case MessageType.FILE: return 'file'; - case EMMessageBodyType.IMAGE: + case MessageType.IMAGE: return 'img'; - case EMMessageBodyType.VIDEO: + case MessageType.VIDEO: return 'video'; - case EMMessageBodyType.VOICE: + case MessageType.VOICE: return 'voice'; } } - // body 类型 - EMMessageBodyType? type; + /// Gets the chat message type. + MessageType? type; } /// text body class EMTextMessageBody extends EMMessageBody { - EMTextMessageBody({required this.content}) - : super(type: EMMessageBodyType.TXT); + EMTextMessageBody({required this.content}) : super(type: MessageType.TXT); EMTextMessageBody.fromJson({required Map map}) - : super.fromJson(map: map, type: EMMessageBodyType.TXT) { + : super.fromJson(map: map, type: MessageType.TXT) { this.content = map['content']; } @@ -532,10 +585,10 @@ class EMTextMessageBody extends EMMessageBody { class EMLocationMessageBody extends EMMessageBody { EMLocationMessageBody( {required this.latitude, required this.longitude, this.address}) - : super(type: EMMessageBodyType.LOCATION); + : super(type: MessageType.LOCATION); EMLocationMessageBody.fromJson({required Map map}) - : super.fromJson(map: map, type: EMMessageBodyType.LOCATION) { + : super.fromJson(map: map, type: MessageType.LOCATION) { this.latitude = map['latitude']; this.longitude = map['longitude']; this.address = map['address']; @@ -564,13 +617,13 @@ class EMFileMessageBody extends EMMessageBody { this.localPath, this.displayName, int? fileSize, - EMMessageBodyType type = EMMessageBodyType.FILE, + MessageType type = MessageType.FILE, }) : super(type: type) { this.fileSize = fileSize ?? 0; } EMFileMessageBody.fromJson( - {required Map map, EMMessageBodyType type = EMMessageBodyType.FILE}) + {required Map map, MessageType type = MessageType.FILE}) : super.fromJson(map: map, type: type) { this.secret = map['secret']; this.remotePath = map['remotePath']; @@ -653,11 +706,11 @@ class EMImageMessageBody extends EMFileMessageBody { localPath: localPath, displayName: displayName, fileSize: fileSize, - type: EMMessageBodyType.IMAGE, + type: MessageType.IMAGE, ); EMImageMessageBody.fromJson({required Map map}) - : super.fromJson(map: map, type: EMMessageBodyType.IMAGE) { + : super.fromJson(map: map, type: MessageType.IMAGE) { this.thumbnailLocalPath = map['thumbnailLocalPath']; this.thumbnailRemotePath = map['thumbnailRemotePath']; this.thumbnailSecret = map['thumbnailSecret']; @@ -719,11 +772,11 @@ class EMVideoMessageBody extends EMFileMessageBody { localPath: localPath, displayName: displayName, fileSize: fileSize, - type: EMMessageBodyType.VIDEO, + type: MessageType.VIDEO, ); EMVideoMessageBody.fromJson({required Map map}) - : super.fromJson(map: map, type: EMMessageBodyType.VIDEO) { + : super.fromJson(map: map, type: MessageType.VIDEO) { this.duration = map['duration'] as int?; this.thumbnailLocalPath = map['thumbnailLocalPath'] as String?; this.thumbnailRemotePath = map['thumbnailRemotePath'] as String?; @@ -782,11 +835,11 @@ class EMVoiceMessageBody extends EMFileMessageBody { localPath: localPath, displayName: displayName, fileSize: fileSize, - type: EMMessageBodyType.VOICE, + type: MessageType.VOICE, ); EMVoiceMessageBody.fromJson({required Map map}) - : super.fromJson(map: map, type: EMMessageBodyType.VOICE) { + : super.fromJson(map: map, type: MessageType.VOICE) { this.duration = map['duration']; } @@ -804,10 +857,10 @@ class EMVoiceMessageBody extends EMFileMessageBody { /// cmd body class EMCmdMessageBody extends EMMessageBody { EMCmdMessageBody({required this.action, this.deliverOnlineOnly = false}) - : super(type: EMMessageBodyType.CMD); + : super(type: MessageType.CMD); EMCmdMessageBody.fromJson({required Map map}) - : super.fromJson(map: map, type: EMMessageBodyType.CMD) { + : super.fromJson(map: map, type: MessageType.CMD) { this.action = map['action']; this.deliverOnlineOnly = map['deliverOnlineOnly'] == 0 ? false : true; } @@ -830,10 +883,10 @@ class EMCmdMessageBody extends EMMessageBody { /// custom body class EMCustomMessageBody extends EMMessageBody { EMCustomMessageBody({required this.event, this.params}) - : super(type: EMMessageBodyType.CUSTOM); + : super(type: MessageType.CUSTOM); EMCustomMessageBody.fromJson({required Map map}) - : super.fromJson(map: map, type: EMMessageBodyType.CUSTOM) { + : super.fromJson(map: map, type: MessageType.CUSTOM) { this.event = map['event']; this.params = map['params']?.cast(); } From a432a5a511273f7398bad8138ddb2dd1b637f5e7 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Wed, 30 Mar 2022 14:19:43 +0800 Subject: [PATCH 21/56] fix push manager methods key. --- lib/src/em_push_manager.dart | 4 ++-- lib/src/models/em_userInfo.dart | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/src/em_push_manager.dart b/lib/src/em_push_manager.dart index b696eccc..ec2d93dd 100644 --- a/lib/src/em_push_manager.dart +++ b/lib/src/em_push_manager.dart @@ -91,8 +91,8 @@ class EMPushManager { Future?> getNoPushGroupsFromCache() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getNoPushGroups); List list = []; - if (result.containsKey(ChatMethodKeys.getNoDisturbGroups)) { - list = result[ChatMethodKeys.getNoDisturbGroups]?.cast(); + if (result.containsKey(ChatMethodKeys.getNoPushGroups)) { + list = result[ChatMethodKeys.getNoPushGroups]?.cast(); } return list; } diff --git a/lib/src/models/em_userInfo.dart b/lib/src/models/em_userInfo.dart index bc956df6..a6eda39a 100644 --- a/lib/src/models/em_userInfo.dart +++ b/lib/src/models/em_userInfo.dart @@ -11,7 +11,7 @@ enum EMUserInfoType { } class EMUserInfo { - EMUserInfo(String aUserId); + EMUserInfo(this.userId); EMUserInfo._private({ required this.userId, @@ -98,7 +98,7 @@ class EMUserInfo { return data; } - String userId = ''; + final String userId; String? nickName; String? avatarUrl; String? mail; @@ -107,5 +107,5 @@ class EMUserInfo { String? sign; String? birth; String? ext; - int expireTime = DateTime.now().millisecondsSinceEpoch; + final int expireTime = DateTime.now().millisecondsSinceEpoch; } From 509d31f507413427fac82a5f16bc8be29a32379a Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Wed, 30 Mar 2022 15:02:28 +0800 Subject: [PATCH 22/56] rename --- .../lib/pages/chat/chat_items/chat_item.dart | 59 +++----- lib/im_flutter_sdk.dart | 3 + lib/src/em_chat_manager.dart | 7 +- lib/src/em_message_status_callback.dart | 26 ++++ lib/src/em_status_listener.dart | 22 +++ lib/src/internal/em_enum_transform_tools.dart | 79 ++++++++++ lib/src/models/em_conversation.dart | 12 +- lib/src/models/em_message.dart | 141 ++++-------------- 8 files changed, 184 insertions(+), 165 deletions(-) create mode 100644 lib/src/em_message_status_callback.dart create mode 100644 lib/src/em_status_listener.dart diff --git a/example/lib/pages/chat/chat_items/chat_item.dart b/example/lib/pages/chat/chat_items/chat_item.dart index bebb3844..291ab836 100644 --- a/example/lib/pages/chat/chat_items/chat_item.dart +++ b/example/lib/pages/chat/chat_items/chat_item.dart @@ -41,10 +41,26 @@ class ChatItem extends StatefulWidget { State createState() => ChatItemState(); } -class ChatItemState extends State implements StatusListener { +class ChatItemState extends State { void initState() { super.initState(); - widget.msg.setMessageStatusListener(this); + widget.msg.messageStatusCallBack = MessageStatusCallBack( + onSuccess: () { + if (mounted) { + setState(() {}); + } + }, + onError: (error) { + if (mounted) { + setState(() {}); + } + }, + onReadAck: () { + if (mounted) { + setState(() {}); + } + }, + ); } @override @@ -190,7 +206,7 @@ class ChatItemState extends State implements StatusListener { } else { return Builder( builder: (_) { - if (widget.msg.status == Status.PROGRESS) { + if (widget.msg.status == MessageStatus.PROGRESS) { return Padding( padding: EdgeInsets.all(sWidth(10)), child: SizedBox( @@ -201,8 +217,8 @@ class ChatItemState extends State implements StatusListener { ), ), ); - } else if (widget.msg.status == Status.FAIL || - widget.msg.status == Status.CREATE) { + } else if (widget.msg.status == MessageStatus.FAIL || + widget.msg.status == MessageStatus.CREATE) { return IconButton( padding: EdgeInsets.zero, icon: Icon( @@ -225,39 +241,6 @@ class ChatItemState extends State implements StatusListener { return Container(); } - @override - void onDeliveryAck() {} - - @override - void onError(EMError error) { - if (mounted) { - setState(() {}); - } - print('发送失败'); - } - - @override - void onProgress(int progress) { - print('progress --- $progress'); - } - - @override - void onReadAck() { - if (mounted) { - setState(() {}); - } - } - - @override - void onStatusChanged() {} - - @override - void onSuccess() { - if (mounted) { - setState(() {}); - } - } - _messageBubble() { EMMessageBody body = widget.msg.body!; bool isSend = widget.msg.direction != MessageDirection.RECEIVE; diff --git a/lib/im_flutter_sdk.dart b/lib/im_flutter_sdk.dart index ff90ba62..b68d81ca 100644 --- a/lib/im_flutter_sdk.dart +++ b/lib/im_flutter_sdk.dart @@ -21,6 +21,9 @@ export 'src/models/em_group_shared_file.dart'; export 'src/models/em_group_options.dart'; export 'src/models/em_chat_enums.dart'; +@Deprecated("Switch to using MessageStatusCallBack instead.") +export 'src/em_status_listener.dart'; +export 'src/em_message_status_callback.dart'; export 'src/em_chat_manager.dart'; export 'src/em_contact_manager.dart'; export 'src/em_group_manager.dart'; diff --git a/lib/src/em_chat_manager.dart b/lib/src/em_chat_manager.dart index 4c596cc4..24e90304 100644 --- a/lib/src/em_chat_manager.dart +++ b/lib/src/em_chat_manager.dart @@ -64,7 +64,7 @@ class EMChatManager { /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// Future sendMessage(EMMessage message) async { - message.status = Status.PROGRESS; + message.status = MessageStatus.PROGRESS; Map result = await _channel.invokeMethod( ChatMethodKeys.sendMessage, message.toJson()); try { @@ -81,7 +81,7 @@ class EMChatManager { /// 重发消息 [message]. Future resendMessage(EMMessage message) async { - message.status = Status.PROGRESS; + message.status = MessageStatus.PROGRESS; Map result = await _channel.invokeMethod( ChatMethodKeys.resendMessage, message.toJson()); try { @@ -565,8 +565,7 @@ class EMChatManager { req['timeStamp'] = timeStamp; req['maxCount'] = maxCount; req['from'] = from; - req['MessageDirection'] = - direction == EMMessageSearchDirection.Up ? "up" : "down"; + req['direction'] = direction == EMMessageSearchDirection.Up ? "up" : "down"; Map result = await _channel.invokeMethod(ChatMethodKeys.searchChatMsgFromDB, req); diff --git a/lib/src/em_message_status_callback.dart b/lib/src/em_message_status_callback.dart new file mode 100644 index 00000000..6054fd3f --- /dev/null +++ b/lib/src/em_message_status_callback.dart @@ -0,0 +1,26 @@ +import 'package:flutter/foundation.dart'; + +import 'models/em_error.dart'; + +class MessageStatusCallBack { + final void Function(int progress)? onProgress; + + final void Function(EMError error)? onError; + + final VoidCallback? onSuccess; + + final VoidCallback? onReadAck; + + final VoidCallback? onDeliveryAck; + + final VoidCallback? onStatusChanged; + + MessageStatusCallBack({ + this.onProgress, + this.onError, + this.onSuccess, + this.onReadAck, + this.onDeliveryAck, + this.onStatusChanged, + }); +} diff --git a/lib/src/em_status_listener.dart b/lib/src/em_status_listener.dart new file mode 100644 index 00000000..3df75a15 --- /dev/null +++ b/lib/src/em_status_listener.dart @@ -0,0 +1,22 @@ +import 'models/em_error.dart'; + +@Deprecated("Switch to using MessageStatusCallBack instead.") +abstract class StatusListener { + /// 消息进度 + void onProgress(int progress) {} + + /// 消息发送失败 + void onError(EMError error) {} + + /// 消息发送成功 + void onSuccess() {} + + /// 消息已读 + void onReadAck() {} + + /// 消息已送达 + void onDeliveryAck() {} + + /// 消息状态发生改变 + void onStatusChanged() {} +} diff --git a/lib/src/internal/em_enum_transform_tools.dart b/lib/src/internal/em_enum_transform_tools.dart index d7a29db4..eada04ce 100644 --- a/lib/src/internal/em_enum_transform_tools.dart +++ b/lib/src/internal/em_enum_transform_tools.dart @@ -1,3 +1,5 @@ +import '../models/em_message.dart'; + import '../em_listeners.dart'; EMContactGroupEvent? convertIntToEMContactGroupEvent(int? i) { @@ -56,3 +58,80 @@ EMContactGroupEvent? convertIntToEMContactGroupEvent(int? i) { return null; } } + +String messageTypeToTypeStr(MessageType type) { + switch (type) { + case MessageType.TXT: + return 'txt'; + case MessageType.LOCATION: + return 'loc'; + case MessageType.CMD: + return 'cmd'; + case MessageType.CUSTOM: + return 'custom'; + case MessageType.FILE: + return 'file'; + case MessageType.IMAGE: + return 'img'; + case MessageType.VIDEO: + return 'video'; + case MessageType.VOICE: + return 'voice'; + } +} + +int chatTypeToInt(ChatType type) { + if (type == ChatType.ChatRoom) { + return 2; + } else if (type == ChatType.GroupChat) { + return 1; + } else { + return 0; + } +} + +ChatType chatTypeFromInt(int? type) { + if (type == 2) { + return ChatType.ChatRoom; + } else if (type == 1) { + return ChatType.GroupChat; + } else { + return ChatType.Chat; + } +} + +int messageStatusToInt(MessageStatus status) { + if (status == MessageStatus.FAIL) { + return 3; + } else if (status == MessageStatus.SUCCESS) { + return 2; + } else if (status == MessageStatus.PROGRESS) { + return 1; + } else { + return 0; + } +} + +MessageStatus messageStatusFromInt(int? status) { + if (status == 3) { + return MessageStatus.FAIL; + } else if (status == 2) { + return MessageStatus.SUCCESS; + } else if (status == 1) { + return MessageStatus.PROGRESS; + } else { + return MessageStatus.CREATE; + } +} + +int downloadStatusToInt(EMDownloadStatus status) { + if (status == EMDownloadStatus.DOWNLOADING) { + return 0; + } else if (status == EMDownloadStatus.SUCCESS) { + return 1; + } else if (status == EMDownloadStatus.FAILED) { + return 2; + } else { + return 3; + } +} diff --git a/lib/src/models/em_conversation.dart b/lib/src/models/em_conversation.dart index 9fff9044..7e0cf2dd 100644 --- a/lib/src/models/em_conversation.dart +++ b/lib/src/models/em_conversation.dart @@ -4,6 +4,7 @@ import 'package:flutter/services.dart'; import '../tools/em_extension.dart'; import '../../im_flutter_sdk.dart'; import '../internal/chat_method_keys.dart'; +import '../internal/em_enum_transform_tools.dart'; enum EMMessageSearchDirection { Up, Down } @@ -223,12 +224,11 @@ extension EMConversationExtension on EMConversation { EMMessageSearchDirection direction = EMMessageSearchDirection.Up, }) async { Map req = this.toJson(); - req['type'] = EMMessageBody.messageTypeToTypeStr(type); + req['type'] = messageTypeToTypeStr(type); req['timestamp'] = timestamp; req['count'] = count; req['sender'] = sender; - req['MessageDirection'] = - direction == EMMessageSearchDirection.Up ? "up" : "down"; + req['direction'] = direction == EMMessageSearchDirection.Up ? "up" : "down"; Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.loadMsgWithMsgType, req); @@ -250,8 +250,7 @@ extension EMConversationExtension on EMConversation { Map req = this.toJson(); req["startId"] = startMsgId; req['count'] = loadCount; - req['MessageDirection'] = - direction == EMMessageSearchDirection.Up ? "up" : "down"; + req['direction'] = direction == EMMessageSearchDirection.Up ? "up" : "down"; Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.loadMsgWithStartId, req); @@ -279,8 +278,7 @@ extension EMConversationExtension on EMConversation { req['sender'] = sender; } req['timestamp'] = timestamp; - req['MessageDirection'] = - direction == EMMessageSearchDirection.Up ? "up" : "down"; + req['direction'] = direction == EMMessageSearchDirection.Up ? "up" : "down"; Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.loadMsgWithKeywords, req); diff --git a/lib/src/models/em_message.dart b/lib/src/models/em_message.dart index 70dcd52b..5ac47adf 100644 --- a/lib/src/models/em_message.dart +++ b/lib/src/models/em_message.dart @@ -1,5 +1,10 @@ import 'dart:math'; +import 'package:im_flutter_sdk/src/em_message_status_callback.dart'; + +import '../em_status_listener.dart'; +import '../internal/em_enum_transform_tools.dart'; + import '../tools/em_log.dart'; import '../tools/em_message_callback_manager.dart'; @@ -41,7 +46,7 @@ enum MessageDirection { /// /// The states include success, failure, being sent/being received, and created to be sent. /// -enum Status { +enum MessageStatus { /// The message is created to be sent. CREATE, @@ -92,26 +97,6 @@ enum MessageType { CUSTOM, } -abstract class StatusListener { - /// 消息进度 - void onProgress(int progress) {} - - /// 消息发送失败 - void onError(EMError error) {} - - /// 消息发送成功 - void onSuccess() {} - - /// 消息已读 - void onReadAck() {} - - /// 消息已送达 - void onDeliveryAck() {} - - /// 消息状态发生改变 - void onStatusChanged() {} -} - /// /// The message instance, which represents a sent/received message. /// @@ -173,7 +158,6 @@ class EMMessage { void dispose() { MessageCallBackManager.getInstance.removeMessage(_tmpKey); - // listener = null; } void _onMessageError(Map map) { @@ -182,7 +166,7 @@ class EMMessage { this._msgId = msg.msgId; this.status = msg.status; this.body = msg.body; - listener?.onError(EMError.fromJson(map['error'])); + messageStatusCallBack?.onError?.call(EMError.fromJson(map['error'])); return null; } @@ -191,7 +175,7 @@ class EMMessage { '发送 -- ' + ' msg_id: ' + this.msgId! + ' ' + map['progress'].toString(), ); int progress = map['progress']; - listener?.onProgress(progress); + messageStatusCallBack?.onProgress?.call(progress); return null; } @@ -200,7 +184,7 @@ class EMMessage { this._msgId = msg.msgId; this.status = msg.status; this.body = msg.body; - listener?.onSuccess(); + messageStatusCallBack?.onSuccess?.call(); EMLog.v('发送成功 -- ' + this.toString()); return null; } @@ -209,7 +193,7 @@ class EMMessage { EMLog.v('消息已读 -- ' + ' msg_id: ' + this.msgId!); EMMessage msg = EMMessage.fromJson(map); this.hasReadAck = msg.hasReadAck; - listener?.onReadAck(); + messageStatusCallBack?.onReadAck?.call(); return null; } @@ -217,14 +201,14 @@ class EMMessage { void _onMessageDeliveryAck(Map map) { EMMessage msg = EMMessage.fromJson(map); this.hasDeliverAck = msg.hasDeliverAck; - listener?.onDeliveryAck(); + messageStatusCallBack?.onDeliveryAck?.call(); return null; } void _onMessageStatusChanged(Map map) { EMMessage msg = EMMessage.fromJson(map); this.status = msg.status; - listener?.onStatusChanged(); + messageStatusCallBack?.onStatusChanged?.call(); return null; } @@ -332,12 +316,16 @@ class EMMessage { to: username, body: EMCustomMessageBody(event: event, params: params)); + @Deprecated("Switch to using messageStatusCallBack instead.") StatusListener? listener; + @Deprecated("Switch to using messageStatusCallBack instead.") void setMessageStatusListener(StatusListener? listener) { this.listener = listener; } + MessageStatusCallBack? messageStatusCallBack; + late String _tmpKey; /// 消息id @@ -384,7 +372,7 @@ class EMMessage { MessageDirection direction = MessageDirection.SEND; /// Gets the message sending/reception status. - Status status = Status.CREATE; + MessageStatus status = MessageStatus.CREATE; /// 消息扩展 Map attributes = {}; @@ -398,7 +386,7 @@ class EMMessage { data['to'] = this.to; data['body'] = this.body!.toJson(); data['attributes'] = this.attributes; - data['MessageDirection'] = + data['direction'] = this.direction == MessageDirection.SEND ? 'send' : 'rec'; data['hasRead'] = this.hasRead; data['hasReadAck'] = this.hasReadAck; @@ -410,7 +398,7 @@ class EMMessage { data['chatType'] = chatTypeToInt(this.chatType); data['localTime'] = this.localTime; data['serverTime'] = this.serverTime; - data['status'] = _chatStatusToInt(this.status); + data['status'] = messageStatusToInt(this.status); return data; } @@ -421,7 +409,7 @@ class EMMessage { ..from = map['from'] as String? ..body = _bodyFromMap(map['body']) ..attributes = map['attributes'] ?? {} - ..direction = map['MessageDirection'] == 'send' + ..direction = map['direction'] == 'send' ? MessageDirection.SEND : MessageDirection.RECEIVE ..hasRead = map.boolValue('hasRead') @@ -434,51 +422,7 @@ class EMMessage { ..chatType = chatTypeFromInt(map['chatType'] as int?) ..localTime = map['localTime'] as int ..serverTime = map['serverTime'] as int - ..status = _chatStatusFromInt(map['status'] as int?); - } - - static int chatTypeToInt(ChatType type) { - if (type == ChatType.ChatRoom) { - return 2; - } else if (type == ChatType.GroupChat) { - return 1; - } else { - return 0; - } - } - - static ChatType chatTypeFromInt(int? type) { - if (type == 2) { - return ChatType.ChatRoom; - } else if (type == 1) { - return ChatType.GroupChat; - } else { - return ChatType.Chat; - } - } - - static int _chatStatusToInt(Status status) { - if (status == Status.FAIL) { - return 3; - } else if (status == Status.SUCCESS) { - return 2; - } else if (status == Status.PROGRESS) { - return 1; - } else { - return 0; - } - } - - static Status _chatStatusFromInt(int? status) { - if (status == 3) { - return Status.FAIL; - } else if (status == 2) { - return Status.SUCCESS; - } else if (status == 1) { - return Status.PROGRESS; - } else { - return Status.CREATE; - } + ..status = messageStatusFromInt(map['status'] as int?); } static EMMessageBody? _bodyFromMap(Map map) { @@ -528,7 +472,7 @@ abstract class EMMessageBody { Map toJson() { final Map data = new Map(); - data['type'] = EMMessageBody.messageTypeToTypeStr(this.type!); + data['type'] = messageTypeToTypeStr(this.type!); return data; } @@ -537,27 +481,6 @@ abstract class EMMessageBody { return toJson().toString(); } - static String messageTypeToTypeStr(MessageType type) { - switch (type) { - case MessageType.TXT: - return 'txt'; - case MessageType.LOCATION: - return 'loc'; - case MessageType.CMD: - return 'cmd'; - case MessageType.CUSTOM: - return 'custom'; - case MessageType.FILE: - return 'file'; - case MessageType.IMAGE: - return 'img'; - case MessageType.VIDEO: - return 'video'; - case MessageType.VOICE: - return 'voice'; - } - } - /// Gets the chat message type. MessageType? type; } @@ -645,7 +568,7 @@ class EMFileMessageBody extends EMMessageBody { // } data['localPath'] = this.localPath; data['displayName'] = this.displayName ?? ''; - data['fileStatus'] = EMFileMessageBody.downloadStatusToInt(this.fileStatus); + data['fileStatus'] = downloadStatusToInt(this.fileStatus); return data; } @@ -678,18 +601,6 @@ class EMFileMessageBody extends EMMessageBody { return EMDownloadStatus.PENDING; } } - - static int downloadStatusToInt(EMDownloadStatus status) { - if (status == EMDownloadStatus.DOWNLOADING) { - return 0; - } else if (status == EMDownloadStatus.SUCCESS) { - return 1; - } else if (status == EMDownloadStatus.FAILED) { - return 2; - } else { - return 3; - } - } } /// image body @@ -731,8 +642,7 @@ class EMImageMessageBody extends EMFileMessageBody { data['sendOriginalImage'] = this.sendOriginalImage; data['height'] = this.height; data['width'] = this.width; - data['thumbnailStatus'] = - EMFileMessageBody.downloadStatusToInt(this.thumbnailStatus); + data['thumbnailStatus'] = downloadStatusToInt(this.thumbnailStatus); return data; } @@ -797,8 +707,7 @@ class EMVideoMessageBody extends EMFileMessageBody { data['thumbnailSecret'] = this.thumbnailSecret; data['height'] = this.height; data['width'] = this.width; - data['thumbnailStatus'] = - EMFileMessageBody.downloadStatusToInt(this.thumbnailStatus); + data['thumbnailStatus'] = downloadStatusToInt(this.thumbnailStatus); return data; } From 378a4101b7ca4820b0cf02a04f9bee2d09dfc832 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Thu, 31 Mar 2022 16:37:16 +0800 Subject: [PATCH 23/56] change files. --- .../com/easemob/im_flutter_sdk/EMHelper.java | 3 +- example/android/app/build.gradle | 4 +- example/android/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../chat/chat_items/chat_image_bubble.dart | 2 +- .../lib/pages/chat/chat_items/chat_item.dart | 4 +- .../chat/chat_items/chat_text_bubble.dart | 2 +- example/lib/pages/chat/chat_page.dart | 12 +- .../conversations/conversation_item.dart | 4 +- lib/im_flutter_sdk.dart | 13 +- lib/src/em_client.dart | 2 +- ...orm_tools.dart => em_transform_tools.dart} | 65 +- lib/src/models/em_chat_enums.dart | 101 +++ lib/src/models/em_cmd_message_body.dart | 42 + lib/src/models/em_conversation.dart | 2 +- lib/src/models/em_custom_message_body.dart | 36 + lib/src/models/em_file_message_body.dart | 84 ++ lib/src/models/em_group.dart | 112 ++- lib/src/models/em_image_message_body.dart | 99 +++ lib/src/models/em_location_message_body.dart | 63 ++ lib/src/models/em_message.dart | 761 ++++++------------ lib/src/models/em_message_body.dart | 27 + lib/src/models/em_text_message_body.dart | 33 + lib/src/models/em_video_message_body.dart | 90 +++ lib/src/models/em_voice_message_body.dart | 47 ++ lib/src/tools/em_extension.dart | 34 +- 26 files changed, 1029 insertions(+), 617 deletions(-) rename lib/src/internal/{em_enum_transform_tools.dart => em_transform_tools.dart} (72%) create mode 100644 lib/src/models/em_cmd_message_body.dart create mode 100644 lib/src/models/em_custom_message_body.dart create mode 100644 lib/src/models/em_file_message_body.dart create mode 100644 lib/src/models/em_image_message_body.dart create mode 100644 lib/src/models/em_location_message_body.dart create mode 100644 lib/src/models/em_message_body.dart create mode 100644 lib/src/models/em_text_message_body.dart create mode 100644 lib/src/models/em_video_message_body.dart create mode 100644 lib/src/models/em_voice_message_body.dart diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java index c8c89a8a..c146922e 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java @@ -436,7 +436,8 @@ static EMMessage fromJson(JSONObject json) throws JSONException { message.setStatus(statusFromInt(json.getInt("status"))); message.setChatType(chatTypeFromInt(json.getInt("chatType"))); message.setMsgId(json.getString("msgId")); - if (null != json.getJSONObject("attributes")) { + + if(json.has("attributes")){ JSONObject data = json.getJSONObject("attributes"); Iterator iterator = data.keys(); while (iterator.hasNext()) { diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 2fc41a4b..a45eca22 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 29 + compileSdkVersion 30 sourceSets { main.java.srcDirs += 'src/main/kotlin' @@ -40,7 +40,7 @@ android { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.easeim_flutter_demo" minSdkVersion 19 - targetSdkVersion 29 + targetSdkVersion 30 versionCode flutterVersionCode.toInteger() versionName flutterVersionName multiDexEnabled true diff --git a/example/android/build.gradle b/example/android/build.gradle index 4c0e9cc5..3ac23baa 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -6,7 +6,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.2.1' + classpath 'com.android.tools.build:gradle:7.1.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index fb9cd293..6dbde025 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip diff --git a/example/lib/pages/chat/chat_items/chat_image_bubble.dart b/example/lib/pages/chat/chat_items/chat_image_bubble.dart index e04312d3..35f444c6 100644 --- a/example/lib/pages/chat/chat_items/chat_image_bubble.dart +++ b/example/lib/pages/chat/chat_items/chat_image_bubble.dart @@ -32,7 +32,7 @@ class ChatImageBubble extends StatelessWidget { height = maxSize / width * height; width = maxSize; } - File localPath = File(body.localPath!); + File localPath = File(body.localPath); if (isSend && localPath.existsSync()) { image = Image.file( localPath, diff --git a/example/lib/pages/chat/chat_items/chat_item.dart b/example/lib/pages/chat/chat_items/chat_item.dart index 291ab836..f190304a 100644 --- a/example/lib/pages/chat/chat_items/chat_item.dart +++ b/example/lib/pages/chat/chat_items/chat_item.dart @@ -242,11 +242,11 @@ class ChatItemState extends State { } _messageBubble() { - EMMessageBody body = widget.msg.body!; + EMMessageBody body = widget.msg.body; bool isSend = widget.msg.direction != MessageDirection.RECEIVE; return Builder(builder: (_) { Widget bubble; - switch (widget.msg.body!.type!) { + switch (widget.msg.body.type) { case MessageType.TXT: bubble = ChatTextBubble(body as EMTextMessageBody); break; diff --git a/example/lib/pages/chat/chat_items/chat_text_bubble.dart b/example/lib/pages/chat/chat_items/chat_text_bubble.dart index 60d12c8e..fa472e28 100644 --- a/example/lib/pages/chat/chat_items/chat_text_bubble.dart +++ b/example/lib/pages/chat/chat_items/chat_text_bubble.dart @@ -42,7 +42,7 @@ class ChatTextBubble extends StatelessWidget { bottom: sHeight(9), ), child: ExpressionText( - body.content!, + body.content, TextStyle( color: Color.fromRGBO(51, 51, 51, 1), fontSize: sFontSize(17), diff --git a/example/lib/pages/chat/chat_page.dart b/example/lib/pages/chat/chat_page.dart index 457391f8..9a71d2dd 100644 --- a/example/lib/pages/chat/chat_page.dart +++ b/example/lib/pages/chat/chat_page.dart @@ -247,7 +247,7 @@ class _ChatPageState extends State } if (msg.hasRead == false) { try { - await widget.conversation.markMessageAsRead(msg.msgId!); + await widget.conversation.markMessageAsRead(msg.msgId); } on EMError {} } } @@ -284,7 +284,7 @@ class _ChatPageState extends State _loadMessages({int count = 20, bool moveBottom = true}) async { try { List msgs = await widget.conversation.loadMessages( - startMsgId: _msgList.length > 0 ? _msgList.first.msgId! : '', + startMsgId: _msgList.length > 0 ? _msgList.first.msgId : '', loadCount: count, ); _msgList.insertAll(0, msgs); @@ -310,21 +310,21 @@ class _ChatPageState extends State /// 点击bubble _messageBubbleOnTap(EMMessage msg) async { - switch (msg.body!.type!) { + switch (msg.body.type) { case MessageType.TXT: break; case MessageType.IMAGE: { EMImageMessageBody body = msg.body as EMImageMessageBody; Image img; - if (body.fileStatus != EMDownloadStatus.SUCCESS) { + if (body.fileStatus != DownloadStatus.SUCCESS) { img = Image.network( body.remotePath!, fit: BoxFit.cover, ); } else { img = Image.file( - File(body.localPath!), + File(body.localPath), fit: BoxFit.cover, ); } @@ -391,7 +391,7 @@ class _ChatPageState extends State filePath: imagePath, displayName: fileName, ); - EMImageMessageBody body = msg.body! as EMImageMessageBody; + EMImageMessageBody body = msg.body as EMImageMessageBody; body.height = info.image.height.toDouble(); body.width = info.image.width.toDouble(); msg.body = body; diff --git a/example/lib/pages/conversations/conversation_item.dart b/example/lib/pages/conversations/conversation_item.dart index db9c6bb1..c456358e 100644 --- a/example/lib/pages/conversations/conversation_item.dart +++ b/example/lib/pages/conversations/conversation_item.dart @@ -130,10 +130,10 @@ class _ConversationItemState extends State { return showInfo; } - switch (_latestMessage.body!.type) { + switch (_latestMessage.body.type) { case MessageType.TXT: var body = _latestMessage.body as EMTextMessageBody; - showInfo = body.content!; + showInfo = body.content; break; case MessageType.IMAGE: showInfo = '[图片]'; diff --git a/lib/im_flutter_sdk.dart b/lib/im_flutter_sdk.dart index b68d81ca..cf80019b 100644 --- a/lib/im_flutter_sdk.dart +++ b/lib/im_flutter_sdk.dart @@ -12,7 +12,7 @@ export 'src/models/em_cursor_result.dart'; export 'src/models/em_deviceInfo.dart'; export 'src/models/em_error.dart'; export 'src/models/em_group.dart'; -export 'src/models/em_message.dart'; + export 'src/models/em_options.dart'; export 'src/models/em_push_configs.dart'; export 'src/models/em_page_result.dart'; @@ -21,6 +21,17 @@ export 'src/models/em_group_shared_file.dart'; export 'src/models/em_group_options.dart'; export 'src/models/em_chat_enums.dart'; +export 'src/models/em_message.dart' show EMMessage; +export 'src/models/em_message_body.dart' show EMMessageBody; +export 'src/models/em_text_message_body.dart' show EMTextMessageBody; +export 'src/models/em_image_message_body.dart' show EMImageMessageBody; +export 'src/models/em_voice_message_body.dart' show EMVoiceMessageBody; +export 'src/models/em_video_message_body.dart' show EMVideoMessageBody; +export 'src/models/em_file_message_body.dart' show EMFileMessageBody; +export 'src/models/em_cmd_message_body.dart' show EMCmdMessageBody; +export 'src/models/em_custom_message_body.dart' show EMCustomMessageBody; +export 'src/models/em_location_message_body.dart' show EMLocationMessageBody; + @Deprecated("Switch to using MessageStatusCallBack instead.") export 'src/em_status_listener.dart'; export 'src/em_message_status_callback.dart'; diff --git a/lib/src/em_client.dart b/lib/src/em_client.dart index 66e22d7b..548bceb7 100644 --- a/lib/src/em_client.dart +++ b/lib/src/em_client.dart @@ -2,7 +2,7 @@ import 'dart:async'; import 'package:flutter/services.dart'; -import 'internal/em_enum_transform_tools.dart'; +import 'internal/em_transform_tools.dart'; import 'tools/em_extension.dart'; import '../im_flutter_sdk.dart'; import 'internal/chat_method_keys.dart'; diff --git a/lib/src/internal/em_enum_transform_tools.dart b/lib/src/internal/em_transform_tools.dart similarity index 72% rename from lib/src/internal/em_enum_transform_tools.dart rename to lib/src/internal/em_transform_tools.dart index eada04ce..1e0fabaa 100644 --- a/lib/src/internal/em_enum_transform_tools.dart +++ b/lib/src/internal/em_transform_tools.dart @@ -1,4 +1,4 @@ -import '../models/em_message.dart'; +import '../models/em_chat_enums.dart'; import '../em_listeners.dart'; @@ -124,14 +124,69 @@ MessageStatus messageStatusFromInt(int? status) { } } -int downloadStatusToInt(EMDownloadStatus status) { - if (status == EMDownloadStatus.DOWNLOADING) { +int downloadStatusToInt(DownloadStatus status) { + if (status == DownloadStatus.DOWNLOADING) { return 0; - } else if (status == EMDownloadStatus.SUCCESS) { + } else if (status == DownloadStatus.SUCCESS) { return 1; - } else if (status == EMDownloadStatus.FAILED) { + } else if (status == DownloadStatus.FAILED) { return 2; } else { return 3; } } + +EMGroupPermissionType permissionTypeFromInt(int? type) { + EMGroupPermissionType ret = EMGroupPermissionType.Member; + switch (type) { + case -1: + { + ret = EMGroupPermissionType.None; + } + break; + case 0: + { + ret = EMGroupPermissionType.Member; + } + break; + case 1: + { + ret = EMGroupPermissionType.Admin; + } + break; + case 2: + { + ret = EMGroupPermissionType.Owner; + } + break; + } + return ret; +} + +int permissionTypeToInt(EMGroupPermissionType? type) { + int ret = 0; + if (type == null) return ret; + switch (type) { + case EMGroupPermissionType.None: + { + ret = -1; + } + break; + case EMGroupPermissionType.Member: + { + ret = 0; + } + break; + case EMGroupPermissionType.Admin: + { + ret = 1; + } + break; + case EMGroupPermissionType.Owner: + { + ret = 2; + } + break; + } + return ret; +} diff --git a/lib/src/models/em_chat_enums.dart b/lib/src/models/em_chat_enums.dart index 1354281b..c048c8a7 100644 --- a/lib/src/models/em_chat_enums.dart +++ b/lib/src/models/em_chat_enums.dart @@ -22,3 +22,104 @@ enum EMPushStyle { Simple, Summary, } + +/// +/// The enumeration of the chat type. +/// +/// There are three chat types: one-to-one chat, group chat, and chat room. +/// +enum ChatType { + /// One-to-one chat. + Chat, + + /// Group chat. + GroupChat, + + /// Chat room. + ChatRoom, +} + +/// +/// The enumeration of the message MessageDirection. +/// +/// Whether the message is sent or received. +/// +enum MessageDirection { + /// This message is sent from the local client. + SEND, + + /// The message is received by the local client. + RECEIVE, +} + +/// +/// The enumeration of the message sending/reception status. +/// +/// The states include success, failure, being sent/being received, and created to be sent. +/// +enum MessageStatus { + /// The message is created to be sent. + CREATE, + + /// The message is being delivered/receiving. + PROGRESS, + + /// The message is successfully delivered/received. + SUCCESS, + + /// The message fails to be delivered/received. + FAIL, +} + +/// +/// The download status of the attachment file . +/// +enum DownloadStatus { + /// File message download is pending. + PENDING, + + /// The SDK is downloading the file message. + DOWNLOADING, + + /// The SDK successfully downloads the file message. + SUCCESS, + + /// The SDK fails to download the file message. + FAILED, +} + +/// +/// The enumeration of the message type. +/// +enum MessageType { + /// Text message. + TXT, + + /// Image message. + IMAGE, + + /// Video message. + VIDEO, + + /// Location message. + LOCATION, + + /// Voice message. + VOICE, + + /// File message. + FILE, + + /// Command message. + CMD, + + /// Customized message. + CUSTOM, +} + +enum EMGroupPermissionType { + None, + Member, + Admin, + Owner, +} diff --git a/lib/src/models/em_cmd_message_body.dart b/lib/src/models/em_cmd_message_body.dart new file mode 100644 index 00000000..4a1423e8 --- /dev/null +++ b/lib/src/models/em_cmd_message_body.dart @@ -0,0 +1,42 @@ +import '../tools/em_extension.dart'; + +import 'em_chat_enums.dart'; +import 'em_message_body.dart'; + +/// +/// The command message body. +/// +class EMCmdMessageBody extends EMMessageBody { + /// + /// Creates a command message. + /// + EMCmdMessageBody({required this.action, this.deliverOnlineOnly = false}) + : super(type: MessageType.CMD); + + EMCmdMessageBody.fromJson({required Map map}) + : super.fromJson(map: map, type: MessageType.CMD) { + this.action = map.getValue("action"); + this.deliverOnlineOnly = + map.getValueWithOutNull("deliverOnlineOnly", false); + } + + @override + Map toJson() { + final Map data = super.toJson(); + data.setValueWithOutNull("action", action); + data.setValueWithOutNull("deliverOnlineOnly", deliverOnlineOnly); + + return data; + } + + /// The command action content. + late final String action; + + /// + /// Checks whether this cmd message is only delivered to online users. + /// + /// `true`: Only delivers to online users. + /// `false`: Delivers to all users. + /// + bool deliverOnlineOnly = false; +} diff --git a/lib/src/models/em_conversation.dart b/lib/src/models/em_conversation.dart index 7e0cf2dd..e9003e82 100644 --- a/lib/src/models/em_conversation.dart +++ b/lib/src/models/em_conversation.dart @@ -4,7 +4,7 @@ import 'package:flutter/services.dart'; import '../tools/em_extension.dart'; import '../../im_flutter_sdk.dart'; import '../internal/chat_method_keys.dart'; -import '../internal/em_enum_transform_tools.dart'; +import '../internal/em_transform_tools.dart'; enum EMMessageSearchDirection { Up, Down } diff --git a/lib/src/models/em_custom_message_body.dart b/lib/src/models/em_custom_message_body.dart new file mode 100644 index 00000000..f7924b6d --- /dev/null +++ b/lib/src/models/em_custom_message_body.dart @@ -0,0 +1,36 @@ +import '../tools/em_extension.dart'; + +import 'em_chat_enums.dart'; +import 'em_message_body.dart'; + +/// +/// The custom message body. +/// +class EMCustomMessageBody extends EMMessageBody { + /// + /// Creates a custom message. + /// + EMCustomMessageBody({required this.event, this.params}) + : super(type: MessageType.CUSTOM); + + EMCustomMessageBody.fromJson({required Map map}) + : super.fromJson(map: map, type: MessageType.CUSTOM) { + this.event = map.getValue("event"); + this.params = map.getValue("params")?.cast(); + } + + @override + Map toJson() { + final Map data = super.toJson(); + data.setValueWithOutNull("event", event); + data.setValueWithOutNull("params", params); + + return data; + } + + /// The event. + late final String event; + + /// The params map. + Map? params; +} diff --git a/lib/src/models/em_file_message_body.dart b/lib/src/models/em_file_message_body.dart new file mode 100644 index 00000000..789d6a0f --- /dev/null +++ b/lib/src/models/em_file_message_body.dart @@ -0,0 +1,84 @@ +import 'package:im_flutter_sdk/src/internal/em_transform_tools.dart'; +import 'package:im_flutter_sdk/src/tools/em_extension.dart'; + +import 'em_chat_enums.dart'; +import 'em_message_body.dart'; + +/// +/// The file message. +/// +class EMFileMessageBody extends EMMessageBody { + /// Creates an file message body with an file. + /// + /// Param [localPath] The path of the image file. + /// + /// Param [displayName] The file name. like "file.doc" + /// + /// Param [fileSize] The size of the file in bytes. + /// + /// Param [type] The body type. + /// + EMFileMessageBody({ + required this.localPath, + this.displayName, + this.fileSize, + MessageType type = MessageType.FILE, + }) : super(type: type); + + EMFileMessageBody.fromJson( + {required Map map, MessageType type = MessageType.FILE}) + : super.fromJson(map: map, type: type) { + this.secret = map.getValue("secret"); + this.remotePath = map.getValue("remotePath"); + this.fileSize = map.getValue("fileSize"); + this.localPath = map.getValue("localPath"); + this.displayName = map.getValue("displayName"); + this.fileStatus = EMFileMessageBody.downloadStatusFromInt( + map.getValue("fileStatus"), + ); + } + + @override + Map toJson() { + final Map data = super.toJson(); + data.setValueWithOutNull("secret", this.secret); + data.setValueWithOutNull("remotePath", this.remotePath); + data.setValueWithOutNull("fileSize", this.fileSize); + data.setValueWithOutNull("localPath", this.localPath); + data.setValueWithOutNull("displayName", this.displayName); + data.setValueWithOutNull( + "fileStatus", downloadStatusToInt(this.fileStatus)); + + return data; + } + + /// The localPath of the attachment file. + late final String localPath; + + /// The file's token. + String? secret; + + /// The path of the attachment file in the server. + String? remotePath; + + /// The download status of the attachment file . + DownloadStatus fileStatus = DownloadStatus.PENDING; + + /// The size of the file in bytes. + int? fileSize; + + /// The file name. like "file.doc" + String? displayName; + + static DownloadStatus downloadStatusFromInt(int? status) { + if (status == 0) { + return DownloadStatus.DOWNLOADING; + } else if (status == 1) { + return DownloadStatus.SUCCESS; + } else if (status == 2) { + return DownloadStatus.FAILED; + } else { + return DownloadStatus.PENDING; + } + } +} diff --git a/lib/src/models/em_group.dart b/lib/src/models/em_group.dart index a464b04a..1e48e22e 100644 --- a/lib/src/models/em_group.dart +++ b/lib/src/models/em_group.dart @@ -1,13 +1,10 @@ +import '../internal/em_transform_tools.dart'; + import '../tools/em_extension.dart'; +import 'em_chat_enums.dart'; import 'em_group_options.dart'; -enum EMGroupPermissionType { - None, - Member, - Admin, - Owner, -} - +/// The group class. class EMGroup { EMGroup._private(); @@ -28,22 +25,64 @@ class EMGroup { EMGroupOptions? _options; EMGroupPermissionType? _permissionType; + /// The group ID. String get groupId => _groupId; + + /// The group name. String? get name => _name; + + /// The group description. String? get description => _description; + + /// The user ID of the group owner. String? get owner => _owner; + + /// The content of the group announcement. String? get announcement => _announcement; + + /// The member count of the group. int? get memberCount => _memberCount; List? get memberList => _memberList; + + /// + /// The admin list of the group. + /// + /// Be sure to fetch the detail specification of the group from the server first, see {@link EMGroupManager#getGroupSpecificationFromServer(String)}. + /// List? get adminList => _adminList; + + /// + /// The block list of the group. + /// + /// If no block list is found from the server, the return may be empty. + /// + /// Reference: + /// To fetch the block list, call {@link EMGroupManager#getBlockListFromServer(String, int?, int?)} + /// + /// Only the group owner or admin can call this method. + /// List? get blockList => _blockList; + + /// + /// The mute list of the group. + /// + /// Reference: + /// You can also fetch the mute list by calling {@link} + /// + /// And only the group owner or admin can call this method. + /// List? get muteList => _muteList; bool? get noticeEnable => _noticeEnable; + + /// + /// Gets whether the group message is blocked. + /// bool? get messageBlocked => _messageBlocked; bool? get isAllMemberMuted => _isAllMemberMuted; EMGroupOptions? get settings => _options; EMGroupPermissionType? get permissionType => _permissionType; + /// @nodoc factory EMGroup.fromJson(Map map) { return EMGroup._private() .._groupId = map['groupId'] @@ -60,7 +99,7 @@ class EMGroup { .._messageBlocked = map.boolValue('messageBlocked') .._isAllMemberMuted = map.boolValue('isAllMemberMuted') .._options = EMGroupOptions.fromJson(map['options']) - .._permissionType = EMGroup.permissionTypeFromInt(map['permissionType']); + .._permissionType = permissionTypeFromInt(map['permissionType']); } Map toJson() { @@ -81,65 +120,10 @@ class EMGroup { data.setValueWithOutNull("isAllMemberMuted", _isAllMemberMuted); data.setValueWithOutNull("options", _options?.toJson()); data.setValueWithOutNull( - "permissionType", EMGroup.permissionTypeToInt(_permissionType)); + "permissionType", permissionTypeToInt(_permissionType)); return data; } - static EMGroupPermissionType permissionTypeFromInt(int? type) { - EMGroupPermissionType ret = EMGroupPermissionType.Member; - switch (type) { - case -1: - { - ret = EMGroupPermissionType.None; - } - break; - case 0: - { - ret = EMGroupPermissionType.Member; - } - break; - case 1: - { - ret = EMGroupPermissionType.Admin; - } - break; - case 2: - { - ret = EMGroupPermissionType.Owner; - } - break; - } - return ret; - } - - static int permissionTypeToInt(EMGroupPermissionType? type) { - int ret = 0; - if (type == null) return ret; - switch (type) { - case EMGroupPermissionType.None: - { - ret = -1; - } - break; - case EMGroupPermissionType.Member: - { - ret = 0; - } - break; - case EMGroupPermissionType.Admin: - { - ret = 1; - } - break; - case EMGroupPermissionType.Owner: - { - ret = 2; - } - break; - } - return ret; - } - @override String toString() { return this.toJson().toString(); diff --git a/lib/src/models/em_image_message_body.dart b/lib/src/models/em_image_message_body.dart new file mode 100644 index 00000000..fef3c478 --- /dev/null +++ b/lib/src/models/em_image_message_body.dart @@ -0,0 +1,99 @@ +import '../internal/em_transform_tools.dart'; + +import '../tools/em_extension.dart'; + +import 'em_chat_enums.dart'; +import 'em_file_message_body.dart'; + +/// +/// The image message body class. +/// +class EMImageMessageBody extends EMFileMessageBody { + /// + /// Creates an image message body with an image file. + /// + /// Param [localPath] The path of the image file. + /// + /// Param [displayName] The image name. like "img.jpeg" + /// + /// Param [thumbnailLocalPath] The local path of the image thumbnail. + /// + /// Param [sendOriginalImage] The original image when sending an image. + /// + /// Param [fileSize] The size of the image file in bytes. + /// + /// Param [width] The image width. + /// + /// Param [height] The image height. + /// + EMImageMessageBody({ + required String localPath, + String? displayName, + this.thumbnailLocalPath, + this.sendOriginalImage = false, + int? fileSize, + this.width, + this.height, + }) : super( + localPath: localPath, + displayName: displayName, + fileSize: fileSize, + type: MessageType.IMAGE, + ); + + EMImageMessageBody.fromJson({required Map map}) + : super.fromJson(map: map, type: MessageType.IMAGE) { + this.thumbnailLocalPath = map.getValue("thumbnailLocalPath"); + this.thumbnailRemotePath = map.getValue("thumbnailRemotePath"); + this.thumbnailSecret = map.getValue("thumbnailSecret"); + this.sendOriginalImage = map.getValueWithOutNull( + "sendOriginalImage", + false, + ); + this.height = map.getValue("height"); + this.width = map.getValue("width"); + this.thumbnailStatus = EMFileMessageBody.downloadStatusFromInt( + map.getValue("thumbnailStatus"), + ); + } + + @override + Map toJson() { + final Map data = super.toJson(); + data.setValueWithOutNull("thumbnailLocalPath", thumbnailLocalPath); + data.setValueWithOutNull("thumbnailRemotePath", thumbnailRemotePath); + data.setValueWithOutNull("thumbnailSecret", thumbnailSecret); + data.setValueWithOutNull("sendOriginalImage", sendOriginalImage); + data.setValueWithOutNull("height", height); + data.setValueWithOutNull("width", width); + data.setValueWithOutNull( + "thumbnailStatus", downloadStatusToInt(this.thumbnailStatus)); + return data; + } + + /// + /// Sets whether to send the original image when sending an image. + /// + /// `false`: (default) Send the thumbnail(image with size larger than 100k will be compressed); + /// `true`: Send the original image. + /// + bool sendOriginalImage = false; + + /// The local path or the URI of the thumbnail as a string. + String? thumbnailLocalPath; + + /// The URL of the thumbnail on the server. + String? thumbnailRemotePath; + + /// The secret to access the thumbnail. A secret is required for verification for thumbnail download. + String? thumbnailSecret; + + /// The download status of the thumbnail. + DownloadStatus thumbnailStatus = DownloadStatus.PENDING; + + /// The image width. + double? width; + + /// The image height. + double? height; +} diff --git a/lib/src/models/em_location_message_body.dart b/lib/src/models/em_location_message_body.dart new file mode 100644 index 00000000..6ef3cf64 --- /dev/null +++ b/lib/src/models/em_location_message_body.dart @@ -0,0 +1,63 @@ +import '../tools/em_extension.dart'; + +import 'em_chat_enums.dart'; +import 'em_message_body.dart'; + +/// +/// The location message body. +/// +class EMLocationMessageBody extends EMMessageBody { + /// + /// Creates a location message body. + /// + /// Param [latitude] The latitude. + /// + /// Param [longitude] The longitude. + /// + /// Param [address] The address. + /// + /// Param [buildingName] The building name. + /// + EMLocationMessageBody({ + required this.latitude, + required this.longitude, + String? address, + String? buildingName, + }) : super(type: MessageType.LOCATION) { + _address = address; + _buildingName = buildingName; + } + + EMLocationMessageBody.fromJson({required Map map}) + : super.fromJson(map: map, type: MessageType.LOCATION) { + this.latitude = map.getValueWithOutNull("latitude", 0.0); + this.longitude = map.getValueWithOutNull("longitude", 0.0); + this._address = map.getValue("address"); + this._buildingName = map.getValue("buildingName"); + } + + @override + Map toJson() { + final Map data = super.toJson(); + data['latitude'] = this.latitude; + data['longitude'] = this.longitude; + data.setValueWithOutNull("address", this._address); + data.setValueWithOutNull("buildingName", this._buildingName); + return data; + } + + String? _address; + String? _buildingName; + + /// The address. + String? get address => _address; + + /// The building name. + String? get buildingName => _buildingName; + + /// The latitude. + late final double latitude; + + /// The longitude. + late final double longitude; +} diff --git a/lib/src/models/em_message.dart b/lib/src/models/em_message.dart index 5ac47adf..f4952388 100644 --- a/lib/src/models/em_message.dart +++ b/lib/src/models/em_message.dart @@ -1,102 +1,12 @@ import 'dart:math'; -import 'package:im_flutter_sdk/src/em_message_status_callback.dart'; - -import '../em_status_listener.dart'; -import '../internal/em_enum_transform_tools.dart'; - +import '../internal/em_transform_tools.dart'; import '../tools/em_log.dart'; - import '../tools/em_message_callback_manager.dart'; import '../tools/em_extension.dart'; import '../../im_flutter_sdk.dart'; import '../internal/em_message_state_handle.dart'; -/// -/// The enumeration of the chat type. -/// -/// There are three chat types: one-to-one chat, group chat, and chat room. -/// -enum ChatType { - /// One-to-one chat. - Chat, - - /// Group chat. - GroupChat, - - /// Chat room. - ChatRoom, -} - -/// -/// The enumeration of the message MessageDirection. -/// -/// Whether the message is sent or received. -/// -enum MessageDirection { - /// This message is sent from the local client. - SEND, - - /// The message is received by the local client. - RECEIVE, -} - -/// -/// The enumeration of the message sending/reception status. -/// -/// The states include success, failure, being sent/being received, and created to be sent. -/// -enum MessageStatus { - /// The message is created to be sent. - CREATE, - - /// The message is being delivered/receiving. - PROGRESS, - - /// The message is successfully delivered/received. - SUCCESS, - - /// The message fails to be delivered/received. - FAIL, -} - -// 附件状态 -enum EMDownloadStatus { - PENDING, // 下载未开始 - DOWNLOADING, // 下载中 - SUCCESS, // 下载成功 - FAILED, // 下载失败 -} - -/// -/// The enumeration of the message type. -/// -enum MessageType { - /// Text message. - TXT, - - /// Image message. - IMAGE, - - /// Video message. - VIDEO, - - /// Location message. - LOCATION, - - /// Voice message. - VOICE, - - /// File message. - FILE, - - /// Command message. - CMD, - - /// Customized message. - CUSTOM, -} - /// /// The message instance, which represents a sent/received message. /// @@ -117,10 +27,15 @@ class EMMessage { late EMMessageStateHandle _handle; - /// 构造接收的消息 + /// + /// Creates a new received message instance. + /// + /// Param [body] The message body. + /// + /// **return** The message instance. + /// EMMessage.createReceiveMessage({ required this.body, - this.direction = MessageDirection.RECEIVE, }) { _tmpKey = localTime.toString(); _handle = EMMessageStateHandle( @@ -132,15 +47,22 @@ class EMMessage { onMessageSuccess: _onMessageSuccess, onMessageStatusChanged: _onMessageStatusChanged, ); + this.direction = MessageDirection.RECEIVE; MessageCallBackManager.getInstance.addMessage(_tmpKey, _handle); } - /// 构造发送的消息 + /// + /// Creates a message instance for sending. + /// + /// Param [body] The message body. + /// + /// Param [to] Sets the user ID of the message recipient. + /// + /// **return** The message instance. + /// EMMessage.createSendMessage({ required this.body, - this.direction = MessageDirection.SEND, this.to, - this.hasRead = true, }) : this.from = EMClient.getInstance.currentUsername, this.conversationId = to { _tmpKey = localTime.toString(); @@ -153,6 +75,8 @@ class EMMessage { onMessageSuccess: _onMessageSuccess, onMessageStatusChanged: _onMessageStatusChanged, ); + this.hasRead = true; + this.direction = MessageDirection.SEND; MessageCallBackManager.getInstance.addMessage(_tmpKey, _handle); } @@ -172,7 +96,7 @@ class EMMessage { void _onMessageProgressChanged(Map map) { EMLog.v( - '发送 -- ' + ' msg_id: ' + this.msgId! + ' ' + map['progress'].toString(), + '发送 -- ' + ' msg_id: ' + this.msgId + ' ' + map['progress'].toString(), ); int progress = map['progress']; messageStatusCallBack?.onProgress?.call(progress); @@ -190,7 +114,7 @@ class EMMessage { } void _onMessageReadAck(Map map) { - EMLog.v('消息已读 -- ' + ' msg_id: ' + this.msgId!); + EMLog.v('消息已读 -- ' + ' msg_id: ' + this.msgId); EMMessage msg = EMMessage.fromJson(map); this.hasReadAck = msg.hasReadAck; messageStatusCallBack?.onReadAck?.call(); @@ -212,7 +136,15 @@ class EMMessage { return null; } - /// 构造发送的文字消息 + /// + /// Creates a text message for sending. + /// + /// Param [username] The ID of the message recipient(user or group). + /// + /// Param [content] The text content. + /// + /// **return** The message instance. + /// EMMessage.createTxtSendMessage({ required String username, required String content, @@ -221,11 +153,23 @@ class EMMessage { body: EMTextMessageBody(content: content), ); - /// 构造发送的文件消息 + /// + /// Creates a message to send a regular file. + /// + /// Param [username] The ID of the message recipient(user or group). + /// + /// Param [filePath] The file path. + /// + /// Param [displayName] The file name. like 'readme.doc' + /// + /// Param [fileSize] The file size. + /// + /// **return** The message instance. + /// EMMessage.createFileSendMessage({ required String username, required String filePath, - String displayName = '', + String? displayName, int? fileSize, }) : this.createSendMessage( to: username, @@ -235,16 +179,38 @@ class EMMessage { displayName: displayName, )); - /// 构造发送的图片消息 + /// + /// Creates an image message for sending. + /// + /// Param [username] The ID of the message recipient(user or group). + /// + /// Param [filePath] The image path. + /// + /// Param [displayName] The image name. like 'image.jpeg' + /// + /// Param [thumbnailLocalPath] The image thumbnail path. + /// + /// Param [sendOriginalImage] Whether to send the original image. + /// `true`: Send the original image. + /// `false`: (default) For an image greater than 100 KB, the SDK will compress it. + /// + /// Param [fileSize] The image file size. + /// + /// Param [width] The image width. + /// + /// Param [height] The image height. + /// + /// **return** The message instance. + /// EMMessage.createImageSendMessage({ required String username, required String filePath, - String displayName = '', - String thumbnailLocalPath = '', + String? displayName, + String? thumbnailLocalPath, bool sendOriginalImage = false, int? fileSize, - double width = 0, - double height = 0, + double? width, + double? height, }) : this.createSendMessage( to: username, body: EMImageMessageBody( @@ -256,16 +222,36 @@ class EMMessage { height: height, )); - /// 构造发送的视频消息 + /// + /// Creates a video message instance for sending. + /// + /// Param [username] The ID of the message recipient(user or group). + /// + /// Param [filePath] The path of the video file. + /// + /// Param [displayName] The video name. like 'video.mp4' + /// + /// Param [duration] The video duration in seconds. + /// + /// Param [fileSize] The video file size. + /// + /// Param [thumbnailLocalPath] The path of the thumbnail of the first frame of video. + /// + /// Param [width] The video thumbnail image width. + /// + /// Param [height] The video thumbnail image height. + /// + /// **return** The message instance. + /// EMMessage.createVideoSendMessage({ required String username, required String filePath, - String displayName = '', + String? displayName, int duration = 0, int? fileSize, - String thumbnailLocalPath = '', - double width = 0, - double height = 0, + String? thumbnailLocalPath, + double? width, + double? height, }) : this.createSendMessage( to: username, body: EMVideoMessageBody( @@ -278,13 +264,27 @@ class EMMessage { height: height, )); - /// 构造发送的音频消息 + /// + /// Creates a voice message for sending. + /// + /// Param [username] The ID of the message recipient(user or group). + /// + /// Param [filePath] The path of the voice file. + /// + /// Param [duration] The voice duration in seconds. + /// + /// Param [fileSize] The voice file size. + /// + /// Param [displayName] The voice name. like 'voice.mp3' + /// + /// **return** The message instance. + /// EMMessage.createVoiceSendMessage({ required String username, required String filePath, int duration = 0, int? fileSize, - String displayName = '', + String? displayName, }) : this.createSendMessage( to: username, body: EMVoiceMessageBody( @@ -293,16 +293,29 @@ class EMMessage { fileSize: fileSize, displayName: displayName)); - /// 构造发送的位置消息 + /// + /// Creates a location message for sending. + /// + /// Param [username] The ID of the message recipient(user or group). + /// + /// The latitude. + /// + /// The longitude. + /// + /// The location details. EMMessage.createLocationSendMessage({ required String username, required double latitude, required double longitude, - String address = '', + String? address, + String? buildingName, }) : this.createSendMessage( to: username, body: EMLocationMessageBody( - latitude: latitude, longitude: longitude, address: address)); + latitude: latitude, + longitude: longitude, + address: address, + )); /// 构造发送的cmd消息 EMMessage.createCmdSendMessage({required String username, required action}) @@ -324,105 +337,159 @@ class EMMessage { this.listener = listener; } + /// + /// Sets the message status change callback. + /// Your app should set messageStatusCallBack to get the message status and then refresh the UI accordingly. + /// MessageStatusCallBack? messageStatusCallBack; late String _tmpKey; - /// 消息id - String? _msgId, - msgLocalId = DateTime.now().millisecondsSinceEpoch.toString() + - Random().nextInt(99999).toString(); + int _groupAckCount = 0; - String? get msgId => _msgId ?? msgLocalId; - - /// 消息所属会话id + /// 消息id + String? _msgId; + String msgLocalId = DateTime.now().millisecondsSinceEpoch.toString() + + Random().nextInt(99999).toString(); + + /// + /// Gets the message ID. + /// + /// **return** The message ID. + String get msgId => _msgId ?? msgLocalId; + + /// + /// The conversation ID. + /// String? conversationId; - /// 消息发送方 + /// + /// The user ID of the message sender. + /// String? from = ''; - /// 消息接收方 + /// + /// The user ID of the message recipient. + /// String? to = ''; - /// 消息本地时间 + /// + /// The local timestamp of the message. + /// int localTime = DateTime.now().millisecondsSinceEpoch; - /// 消息的服务器时间 + /// + /// The local timestamp of the message. + /// int serverTime = DateTime.now().millisecondsSinceEpoch; - /// 消息是否收到已送达回执 + /// + /// The delivery receipt, which is to check whether the other party has received the message. + /// + /// Whether the other party has received the message. + /// `true`:the message has been delivered to the other party. + /// bool hasDeliverAck = false; - /// 消息是否发送/收到已读回执 + /// + /// Whether the other party has read the message. + /// `true`: The message has been read by the other party. + /// bool hasReadAck = false; - /// 是否需要群消息已读回执,默认为false + /// + /// Sets whether read receipts are required for group messages. + /// + /// `true`: Read receipts are required; + /// `false`: Read receipts are NOT required. + /// bool needGroupAck = false; - /// 群消息已读数量,只有在群消息时有效 - int groupAckCount = 0; - - /// 是否已读 + /// + /// Gets the number of members that have read the group message. + /// + int get groupAckCount => _groupAckCount; + + /// + /// Checks whether the message is read. + /// + /// `true`: The message is read. + /// `false`: The message is unread. + /// bool hasRead = false; - /// 消息类型 + /// + /// The enumeration of the chat type. + /// + /// There are three chat types: one-to-one chat, group chat, and chat room. + /// ChatType chatType = ChatType.Chat; - /// 消息方向 + /// + /// The message direction. see {@link MessageDirection} + /// MessageDirection direction = MessageDirection.SEND; - /// Gets the message sending/reception status. + /// + /// Gets the message sending/reception status. see {@link MessageStatus} + /// MessageStatus status = MessageStatus.CREATE; - /// 消息扩展 - Map attributes = {}; + /// + /// Message's extension attribute. + /// + Map? attributes; - /// msg body - EMMessageBody? body; + /// + /// Message body. We recommend you use {@link EMMessageBody)}. + /// + late EMMessageBody body; + /// @nodoc Map toJson() { final Map data = new Map(); - data['from'] = this.from; - data['to'] = this.to; - data['body'] = this.body!.toJson(); - data['attributes'] = this.attributes; - data['direction'] = - this.direction == MessageDirection.SEND ? 'send' : 'rec'; - data['hasRead'] = this.hasRead; - data['hasReadAck'] = this.hasReadAck; - data['hasDeliverAck'] = this.hasDeliverAck; - data['needGroupAck'] = this.needGroupAck; - data['groupAckCount'] = this.groupAckCount; - data['msgId'] = this.msgId; - data['conversationId'] = this.conversationId ?? this.to; - data['chatType'] = chatTypeToInt(this.chatType); - data['localTime'] = this.localTime; - data['serverTime'] = this.serverTime; - data['status'] = messageStatusToInt(this.status); + data.setValueWithOutNull("from", from); + data.setValueWithOutNull("to", to); + data.setValueWithOutNull("body", body.toJson()); + data.setValueWithOutNull("attributes", attributes); + data.setValueWithOutNull( + "direction", this.direction == MessageDirection.SEND ? 'send' : 'rec'); + data.setValueWithOutNull("hasRead", hasRead); + data.setValueWithOutNull("hasReadAck", hasReadAck); + data.setValueWithOutNull("hasDeliverAck", hasDeliverAck); + data.setValueWithOutNull("needGroupAck", needGroupAck); + data.setValueWithOutNull("groupAckCount", groupAckCount); + data.setValueWithOutNull("msgId", msgId); + data.setValueWithOutNull("conversationId", this.conversationId ?? this.to); + data.setValueWithOutNull("chatType", chatTypeToInt(chatType)); + data.setValueWithOutNull("localTime", localTime); + data.setValueWithOutNull("serverTime", serverTime); + data.setValueWithOutNull("status", messageStatusToInt(this.status)); return data; } + /// @nodoc factory EMMessage.fromJson(Map map) { return EMMessage._private() - ..to = map['to'] as String? - ..from = map['from'] as String? - ..body = _bodyFromMap(map['body']) - ..attributes = map['attributes'] ?? {} - ..direction = map['direction'] == 'send' + ..to = map.getValue("to") + ..from = map.getValue("from") + ..body = _bodyFromMap(map.getValue("body"))! + ..attributes = map.getValue("attributes") + ..direction = map.getValue("direction") == 'send' ? MessageDirection.SEND : MessageDirection.RECEIVE ..hasRead = map.boolValue('hasRead') ..hasReadAck = map.boolValue('hasReadAck') ..needGroupAck = map.boolValue('needGroupAck') - ..groupAckCount = map["groupAckCount"] as int? ?? 0 + .._groupAckCount = map.getValue("groupAckCount") ..hasDeliverAck = map.boolValue('hasDeliverAck') - .._msgId = map['msgId'] as String? - ..conversationId = map['conversationId'] as String? - ..chatType = chatTypeFromInt(map['chatType'] as int?) - ..localTime = map['localTime'] as int - ..serverTime = map['serverTime'] as int - ..status = messageStatusFromInt(map['status'] as int?); + .._msgId = map.getValue("msgId") + ..conversationId = map.getValue("conversationId") + ..chatType = chatTypeFromInt(map.getValue("chatType")) + ..localTime = map.getValue("localTime") + ..serverTime = map.getValue("serverTime") + ..status = messageStatusFromInt(map.getValue("status")); } static EMMessageBody? _bodyFromMap(Map map) { @@ -463,357 +530,3 @@ class EMMessage { return toJson().toString(); } } - -// message body -abstract class EMMessageBody { - EMMessageBody({required this.type}); - - EMMessageBody.fromJson({required Map map, this.type}); - - Map toJson() { - final Map data = new Map(); - data['type'] = messageTypeToTypeStr(this.type!); - return data; - } - - @override - String toString() { - return toJson().toString(); - } - - /// Gets the chat message type. - MessageType? type; -} - -/// text body -class EMTextMessageBody extends EMMessageBody { - EMTextMessageBody({required this.content}) : super(type: MessageType.TXT); - - EMTextMessageBody.fromJson({required Map map}) - : super.fromJson(map: map, type: MessageType.TXT) { - this.content = map['content']; - } - - @override - Map toJson() { - final Map data = super.toJson(); - data['content'] = this.content; - return data; - } - - String? content = ''; -} - -/// location body -class EMLocationMessageBody extends EMMessageBody { - EMLocationMessageBody( - {required this.latitude, required this.longitude, this.address}) - : super(type: MessageType.LOCATION); - - EMLocationMessageBody.fromJson({required Map map}) - : super.fromJson(map: map, type: MessageType.LOCATION) { - this.latitude = map['latitude']; - this.longitude = map['longitude']; - this.address = map['address']; - } - - @override - Map toJson() { - final Map data = super.toJson(); - data['address'] = this.address; - data['latitude'] = this.latitude; - data['longitude'] = this.longitude; - return data; - } - - /// 地址 - String? address = ''; - - /// 经纬度 - double? latitude = 0; - double? longitude = 0; -} - -/// file body -class EMFileMessageBody extends EMMessageBody { - EMFileMessageBody({ - this.localPath, - this.displayName, - int? fileSize, - MessageType type = MessageType.FILE, - }) : super(type: type) { - this.fileSize = fileSize ?? 0; - } - - EMFileMessageBody.fromJson( - {required Map map, MessageType type = MessageType.FILE}) - : super.fromJson(map: map, type: type) { - this.secret = map['secret']; - this.remotePath = map['remotePath']; - this.fileSize = map['fileSize']; - this.localPath = map['localPath']; - this.displayName = map['displayName']; - this.fileStatus = EMFileMessageBody.downloadStatusFromInt( - map['fileStatus'], - ); - } - - @override - Map toJson() { - final Map data = super.toJson(); - data['secret'] = this.secret; - data['remotePath'] = this.remotePath; - // if (this.fileSize != 0) { - data['fileSize'] = this.fileSize; - // } - data['localPath'] = this.localPath; - data['displayName'] = this.displayName ?? ''; - data['fileStatus'] = downloadStatusToInt(this.fileStatus); - return data; - } - - /// 本地路径 - String? localPath = ''; - - /// secret - String? secret = ''; - - /// 服务器路径 - String? remotePath = ''; - - /// 附件状态 - EMDownloadStatus fileStatus = EMDownloadStatus.PENDING; - - /// 文件大小 - int fileSize = 0; - - /// 文件名称 - String? displayName = ''; - - static EMDownloadStatus downloadStatusFromInt(int? status) { - if (status == 0) { - return EMDownloadStatus.DOWNLOADING; - } else if (status == 1) { - return EMDownloadStatus.SUCCESS; - } else if (status == 2) { - return EMDownloadStatus.FAILED; - } else { - return EMDownloadStatus.PENDING; - } - } -} - -/// image body -class EMImageMessageBody extends EMFileMessageBody { - EMImageMessageBody({ - String? localPath, - String? displayName, - this.thumbnailLocalPath, - this.sendOriginalImage, - int? fileSize, - this.width, - this.height, - }) : super( - localPath: localPath, - displayName: displayName, - fileSize: fileSize, - type: MessageType.IMAGE, - ); - - EMImageMessageBody.fromJson({required Map map}) - : super.fromJson(map: map, type: MessageType.IMAGE) { - this.thumbnailLocalPath = map['thumbnailLocalPath']; - this.thumbnailRemotePath = map['thumbnailRemotePath']; - this.thumbnailSecret = map['thumbnailSecret']; - this.sendOriginalImage = map.boolValue('sendOriginalImage'); - this.height = map['height']?.toDouble(); - this.width = map['width']?.toDouble(); - this.thumbnailStatus = EMFileMessageBody.downloadStatusFromInt( - map['thumbnailStatus'], - ); - } - - @override - Map toJson() { - final Map data = super.toJson(); - data['thumbnailLocalPath'] = this.thumbnailLocalPath; - data['thumbnailRemotePath'] = this.thumbnailRemotePath; - data['thumbnailSecret'] = this.thumbnailSecret; - data['sendOriginalImage'] = this.sendOriginalImage; - data['height'] = this.height; - data['width'] = this.width; - data['thumbnailStatus'] = downloadStatusToInt(this.thumbnailStatus); - return data; - } - - /// 是否是原图 - bool? sendOriginalImage = false; - - /// 缩略图本地地址 - String? thumbnailLocalPath = ''; - - /// 缩略图服务器地址 - String? thumbnailRemotePath = ''; - - /// 缩略图 secret - String? thumbnailSecret = ''; - - /// 缩略图状态 - EMDownloadStatus thumbnailStatus = EMDownloadStatus.PENDING; - - /// 宽 - double? width = 0; - - /// 高 - double? height = 0; -} - -/// video body -class EMVideoMessageBody extends EMFileMessageBody { - EMVideoMessageBody({ - String? localPath, - String? displayName, - this.duration, - int? fileSize, - this.thumbnailLocalPath, - this.height, - this.width, - }) : super( - localPath: localPath, - displayName: displayName, - fileSize: fileSize, - type: MessageType.VIDEO, - ); - - EMVideoMessageBody.fromJson({required Map map}) - : super.fromJson(map: map, type: MessageType.VIDEO) { - this.duration = map['duration'] as int?; - this.thumbnailLocalPath = map['thumbnailLocalPath'] as String?; - this.thumbnailRemotePath = map['thumbnailRemotePath'] as String?; - this.thumbnailSecret = map['thumbnailSecret'] as String?; - this.height = map['height']?.toDouble(); - this.width = map['width']?.toDouble(); - this.thumbnailStatus = EMFileMessageBody.downloadStatusFromInt( - map['thumbnailStatus'], - ); - } - - @override - Map toJson() { - final Map data = super.toJson(); - data['duration'] = this.duration; - data['thumbnailLocalPath'] = this.thumbnailLocalPath; - data['thumbnailRemotePath'] = this.thumbnailRemotePath; - data['thumbnailSecret'] = this.thumbnailSecret; - data['height'] = this.height; - data['width'] = this.width; - data['thumbnailStatus'] = downloadStatusToInt(this.thumbnailStatus); - return data; - } - - /// 时长。秒 - int? duration = 0; - - /// 缩略图本地地址 - String? thumbnailLocalPath = ''; - - /// 缩略图服务器地址 - String? thumbnailRemotePath = ''; - - /// 缩略图 secret - String? thumbnailSecret = ''; - - /// 缩略图状态 - EMDownloadStatus thumbnailStatus = EMDownloadStatus.PENDING; - - /// 宽 - double? width = 0; - - /// 高 - double? height = 0; -} - -/// voice body -class EMVoiceMessageBody extends EMFileMessageBody { - EMVoiceMessageBody({ - localPath, - String? displayName, - int? fileSize, - this.duration, - }) : super( - localPath: localPath, - displayName: displayName, - fileSize: fileSize, - type: MessageType.VOICE, - ); - - EMVoiceMessageBody.fromJson({required Map map}) - : super.fromJson(map: map, type: MessageType.VOICE) { - this.duration = map['duration']; - } - - @override - Map toJson() { - final Map data = super.toJson(); - data['duration'] = this.duration; - return data; - } - - /// 时长, 秒 - int? duration = 0; -} - -/// cmd body -class EMCmdMessageBody extends EMMessageBody { - EMCmdMessageBody({required this.action, this.deliverOnlineOnly = false}) - : super(type: MessageType.CMD); - - EMCmdMessageBody.fromJson({required Map map}) - : super.fromJson(map: map, type: MessageType.CMD) { - this.action = map['action']; - this.deliverOnlineOnly = map['deliverOnlineOnly'] == 0 ? false : true; - } - - @override - Map toJson() { - final Map data = super.toJson(); - data['action'] = this.action; - data['deliverOnlineOnly'] = this.deliverOnlineOnly; - return data; - } - - /// cmd 标识 - String? action = ''; - - /// 只投在线 - bool? deliverOnlineOnly = false; -} - -/// custom body -class EMCustomMessageBody extends EMMessageBody { - EMCustomMessageBody({required this.event, this.params}) - : super(type: MessageType.CUSTOM); - - EMCustomMessageBody.fromJson({required Map map}) - : super.fromJson(map: map, type: MessageType.CUSTOM) { - this.event = map['event']; - this.params = map['params']?.cast(); - } - - @override - Map toJson() { - final Map data = super.toJson(); - data['event'] = event; - if (params != null) { - data['params'] = params; - } - - return data; - } - - /// 自定义事件key - String? event = ''; - - /// 附加参数 - Map? params = {}; -} diff --git a/lib/src/models/em_message_body.dart b/lib/src/models/em_message_body.dart new file mode 100644 index 00000000..e36f1415 --- /dev/null +++ b/lib/src/models/em_message_body.dart @@ -0,0 +1,27 @@ +import '../internal/em_transform_tools.dart'; +import 'em_chat_enums.dart'; + +/// @nodoc +abstract class EMMessageBody { + EMMessageBody({required this.type}); + + EMMessageBody.fromJson({ + required Map map, + required this.type, + }); + + /// @nodoc + Map toJson() { + final Map data = new Map(); + data['type'] = messageTypeToTypeStr(this.type); + return data; + } + + @override + String toString() { + return toJson().toString(); + } + + /// Gets the chat message type. + MessageType type; +} diff --git a/lib/src/models/em_text_message_body.dart b/lib/src/models/em_text_message_body.dart new file mode 100644 index 00000000..eac50f3d --- /dev/null +++ b/lib/src/models/em_text_message_body.dart @@ -0,0 +1,33 @@ +import '../tools/em_extension.dart'; + +import 'em_chat_enums.dart'; +import 'em_message_body.dart'; + +/// +/// Text message body. +/// +class EMTextMessageBody extends EMMessageBody { + /// + /// Creates a text message body. + /// + /// Param [content] The text content. + /// + EMTextMessageBody({required this.content}) : super(type: MessageType.TXT); + + EMTextMessageBody.fromJson({required Map map}) + : super.fromJson(map: map, type: MessageType.TXT) { + this.content = map.getValueWithOutNull("content", ""); + } + + @override + + ///@nodoc + Map toJson() { + final Map data = super.toJson(); + data['content'] = this.content; + return data; + } + + /// The text content. + late final String content; +} diff --git a/lib/src/models/em_video_message_body.dart b/lib/src/models/em_video_message_body.dart new file mode 100644 index 00000000..76d01b23 --- /dev/null +++ b/lib/src/models/em_video_message_body.dart @@ -0,0 +1,90 @@ +import '../internal/em_transform_tools.dart'; +import '../tools/em_extension.dart'; + +import 'em_chat_enums.dart'; +import 'em_file_message_body.dart'; + +/// +/// The video message body. +/// +class EMVideoMessageBody extends EMFileMessageBody { + /// + /// Creates a video message body. + /// + /// Param [localPath] The path of the video file. + /// + /// Param [displayName] The video name. like "video.mp4" + /// + /// Param [duration] The video duration in seconds. + /// + /// Param [fileSize] The size of the video file in bytes. + /// + /// Param [thumbnailLocalPath] The local path of the video thumbnail. + /// + /// Param [height] The video height. + /// + /// Param [width] The video width. + /// + EMVideoMessageBody({ + required String localPath, + String? displayName, + this.duration, + int? fileSize, + this.thumbnailLocalPath, + this.height, + this.width, + }) : super( + localPath: localPath, + displayName: displayName, + fileSize: fileSize, + type: MessageType.VIDEO, + ); + + EMVideoMessageBody.fromJson({required Map map}) + : super.fromJson(map: map, type: MessageType.VIDEO) { + this.duration = map.getValue("duration"); + this.thumbnailLocalPath = map.getValue("thumbnailLocalPath"); + this.thumbnailRemotePath = map.getValue("thumbnailRemotePath"); + this.thumbnailSecret = map.getValue("thumbnailSecret"); + this.height = map.getValue("height"); + this.width = map.getValue("width"); + this.thumbnailStatus = EMFileMessageBody.downloadStatusFromInt( + map.getValue("thumbnailStatus")); + } + + @override + Map toJson() { + final Map data = super.toJson(); + data.setValueWithOutNull("duration", duration); + data.setValueWithOutNull("thumbnailLocalPath", thumbnailLocalPath); + data.setValueWithOutNull("thumbnailRemotePath", thumbnailRemotePath); + data.setValueWithOutNull("thumbnailSecret", thumbnailSecret); + data.setValueWithOutNull("height", height); + data.setValueWithOutNull("width", width); + data.setValueWithOutNull( + "thumbnailStatus", downloadStatusToInt(this.thumbnailStatus)); + + return data; + } + + /// The video duration in seconds. + int? duration; + + /// The local path of the video thumbnail. + String? thumbnailLocalPath; + + /// The URL of the thumbnail on the server. + String? thumbnailRemotePath; + + /// The secret key of the video thumbnail. + String? thumbnailSecret; + + /// The download status of the video thumbnail. + DownloadStatus thumbnailStatus = DownloadStatus.PENDING; + + /// The video width. + double? width; + + /// The video height. + double? height; +} diff --git a/lib/src/models/em_voice_message_body.dart b/lib/src/models/em_voice_message_body.dart new file mode 100644 index 00000000..92546fe2 --- /dev/null +++ b/lib/src/models/em_voice_message_body.dart @@ -0,0 +1,47 @@ +import '../tools/em_extension.dart'; + +import 'em_file_message_body.dart'; +import 'em_chat_enums.dart'; + +/// +/// The voice message body. +/// +class EMVoiceMessageBody extends EMFileMessageBody { + /// + /// Creates a voice message body. + /// + /// Param [localPath] The path of the voice file. + /// + /// Param [displayName] The voice name. like "voice.mp3" + /// + /// Param [fileSize] The size of the voice file in bytes. + /// + /// Param [duration] The voice duration in seconds. + /// + EMVoiceMessageBody({ + localPath, + String? displayName, + int? fileSize, + this.duration, + }) : super( + localPath: localPath, + displayName: displayName, + fileSize: fileSize, + type: MessageType.VOICE, + ); + + EMVoiceMessageBody.fromJson({required Map map}) + : super.fromJson(map: map, type: MessageType.VOICE) { + this.duration = map.getValue("duration"); + } + + @override + Map toJson() { + final Map data = super.toJson(); + data.setValueWithOutNull("duration", duration); + return data; + } + + /// The voice duration in seconds. + int? duration; +} diff --git a/lib/src/tools/em_extension.dart b/lib/src/tools/em_extension.dart index 25d631d8..a82700f1 100644 --- a/lib/src/tools/em_extension.dart +++ b/lib/src/tools/em_extension.dart @@ -53,11 +53,9 @@ extension MapExtension on Map { return null; } } -} -extension MapWithoutNull on Map { - setValueWithOutNull(String key, T? value, - [Object Function(T object)? callback]) { + void setValueWithOutNull(String key, T? value, + {Object Function(T object)? callback, T? defaultValue}) { if (value != null) { if (callback != null) { Object v = callback(value); @@ -65,6 +63,34 @@ extension MapWithoutNull on Map { } else { this[key] = value; } + } else { + if (defaultValue != null) { + this[key] = defaultValue; + } + } + } + + T getValueWithOutNull(String key, T defaultValue) { + T ret = defaultValue; + if (this.containsKey(key)) { + dynamic value = this[key]; + if (value is T) { + ret = value; + } + } + return ret; + } + + T? getValue(String key) { + T? ret; + if (this.containsKey(key)) { + dynamic value = this[key]; + if (value is T) { + ret = value; + } else { + ret = null; + } } + return ret; } } From f505c451e9b2a1f9c9a750a4406b7952250d32a9 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Thu, 31 Mar 2022 16:40:32 +0800 Subject: [PATCH 24/56] fix: listValue error. --- lib/src/tools/em_extension.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/src/tools/em_extension.dart b/lib/src/tools/em_extension.dart index 25d631d8..a59b275b 100644 --- a/lib/src/tools/em_extension.dart +++ b/lib/src/tools/em_extension.dart @@ -1,6 +1,8 @@ // 思考: 是否要把所有格式转换的部分都放到这个extension中? import '../models/em_group_shared_file.dart'; +Type typeOf() => T; + extension MapExtension on Map { bool boolValue(String key) { if (!containsKey(key)) { @@ -35,13 +37,13 @@ extension MapExtension on Map { List? listValue(String key) { if (this.containsKey(key)) { List obj = this[key]; - if (T is String) { + if (typeOf().toString() == "String") { List strList = []; for (var item in obj) { strList.add(item); } return strList as List; - } else if (T is EMGroupSharedFile) { + } else if (typeOf().toString() == "EMGroupSharedFile") { List fileList = []; for (var item in obj) { var file = EMGroupSharedFile.fromJson(item); From f056ec410ab69c968147df6e9ba88db2f0c442fd Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Thu, 31 Mar 2022 19:17:42 +0800 Subject: [PATCH 25/56] update api referance. --- example/lib/main.dart | 12 +- example/lib/pages/group/group_info_page.dart | 2 +- lib/src/em_group_manager.dart | 7 +- lib/src/em_userInfo_manager.dart | 109 ------- lib/src/models/em_group.dart | 69 +++++ lib/src/models/em_options.dart | 310 ++++++++++++++----- lib/src/models/em_page_result.dart | 9 + lib/src/models/em_push_config.dart | 1 + lib/src/models/em_push_configs.dart | 1 + lib/src/models/em_userInfo.dart | 119 ++++--- lib/src/tools/em_extension.dart | 1 - 11 files changed, 396 insertions(+), 244 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 18edb6dc..7983e4e5 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -27,12 +27,14 @@ void main() { } void initSDK() async { - var options = EMOptions(appKey: 'easemob-demo#easeim'); - options.deleteMessagesAsExitGroup = false; - options.deleteMessagesAsExitChatRoom = false; - options.debugModel = true; - options.enableAPNs("EaseIM_APNS_Product"); + var options = EMOptions( + appKey: 'easemob-demo#easeim', + deleteMessagesAsExitGroup: false, + deleteMessagesAsExitChatRoom: false, + debugModel: true, + ); + options.enableAPNs("EaseIM_APNS_Product"); await EMClient.getInstance.init(options); debugPrint("has init"); } diff --git a/example/lib/pages/group/group_info_page.dart b/example/lib/pages/group/group_info_page.dart index 5bf613bd..e8940981 100644 --- a/example/lib/pages/group/group_info_page.dart +++ b/example/lib/pages/group/group_info_page.dart @@ -26,7 +26,7 @@ class GroupInfoPageState extends State { Widget build(BuildContext context) { bool needApproval = false; if (_group != null) { - if (_group!.settings?.style == EMGroupStyle.PublicJoinNeedApproval) { + if (_group!.isMemberOnly == false) { needApproval = true; } else { needApproval = false; diff --git a/lib/src/em_group_manager.dart b/lib/src/em_group_manager.dart index 1ab804dd..a298b966 100644 --- a/lib/src/em_group_manager.dart +++ b/lib/src/em_group_manager.dart @@ -145,8 +145,8 @@ class EMGroupManager { /// /// After the group is created, the data in the cache and database will be updated and multiple devices will receive the notification event and /// update the group to the cache and database. - /// You can set {@link com.hyphenate.EMMultiDeviceListener} to listen on the event. The event callback function - /// is {@link EMMultiDeviceListener#onGroupEvent(int, String, List)}, where the first parameter is the event, + /// You can set {@link EMMultiDeviceListener} to listen on the event. The event callback function + /// is {@link EMMultiDeviceListener#onGroupEvent(EMContactGroupEvent, String, List)}, where the first parameter is the event, /// for example, {@link EMContactGroupEvent#GROUP_CREATE} for the group creation event. /// /// Param [groupName] The group name. @@ -453,8 +453,7 @@ class EMGroupManager { /// /// Adds users to the group. /// - /// Only the group owner or admin can call this method. - /// 邀请用户加入私有群,用于私有群: PrivateOnlyOwnerInvite / PrivateMemberCanInvite ???? + /// 群类型是 PrivateOnlyOwnerInvite / PrivateMemberCanInvite / PublicJoinNeedApproval 的群组可以邀请用户加入 /// /// Param [groupId] The group ID. /// diff --git a/lib/src/em_userInfo_manager.dart b/lib/src/em_userInfo_manager.dart index 1b327c43..24dde92e 100644 --- a/lib/src/em_userInfo_manager.dart +++ b/lib/src/em_userInfo_manager.dart @@ -37,29 +37,6 @@ class EMUserInfoManager { } } - @Deprecated("") - Future updateOwnUserInfoWithType( - EMUserInfoType type, String userInfoValue) async { - Map req = { - 'userInfoType': _userInfoTypeToInt(type), - 'userInfoValue': userInfoValue - }; - Map result = await _channel.invokeMethod( - ChatMethodKeys.updateOwnUserInfoWithType, req); - try { - EMError.hasErrorFromResult(result); - if (result[ChatMethodKeys.updateOwnUserInfoWithType] != null) { - _ownUserInfo = EMUserInfo.fromJson( - result[ChatMethodKeys.updateOwnUserInfoWithType]); - _effectiveUserInfoMap[_ownUserInfo!.userId] = _ownUserInfo!; - } - - return _ownUserInfo; - } on EMError catch (e) { - throw e; - } - } - /// /// Get the current user's information from server. /// @@ -138,92 +115,6 @@ class EMUserInfoManager { } } - @Deprecated( - 'Use userInfoManager.fetchUserInfoByIdWithExpireTime() method instead.') - Future> fetchUserInfoByIdWithType( - List userIds, List types, - {int expireTime = 3600}) async { - List userInfoTypes = []; - types.forEach((element) { - int type = _userInfoTypeToInt(element); - userInfoTypes.add(type); - }); - - List reqIds = userIds - .where((element) => - !_effectiveUserInfoMap.containsKey(element) || - (_effectiveUserInfoMap.containsKey(element) && - DateTime.now().millisecondsSinceEpoch - - _effectiveUserInfoMap[element]!.expireTime > - expireTime * 1000)) - .toList(); - Map resultMap = Map(); - - Map req = {'userIds': reqIds, 'userInfoTypes': userInfoTypes}; - Map result = await _channel.invokeMethod( - ChatMethodKeys.fetchUserInfoByIdWithType, req); - - try { - EMError.hasErrorFromResult(result); - result[ChatMethodKeys.fetchUserInfoByIdWithType].forEach((key, value) { - EMUserInfo eUserInfo = EMUserInfo.fromJson(value); - resultMap[key] = eUserInfo; - - _effectiveUserInfoMap[key] = eUserInfo; - }); - - return resultMap as FutureOr>; - } on EMError catch (e) { - throw e; - } - } - - static int _userInfoTypeToInt(EMUserInfoType type) { - int ret = 0; - switch (type) { - case EMUserInfoType.NickName: - { - ret = 0; - } - break; - case EMUserInfoType.AvatarURL: - { - ret = 1; - } - break; - case EMUserInfoType.Phone: - { - ret = 2; - } - break; - case EMUserInfoType.Mail: - { - ret = 3; - } - break; - case EMUserInfoType.Gender: - { - ret = 4; - } - break; - case EMUserInfoType.Sign: - { - ret = 5; - } - break; - case EMUserInfoType.Birth: - { - ret = 6; - } - break; - case EMUserInfoType.Ext: - { - ret = 7; - } - } - return ret; - } - void clearUserInfoCache() { _ownUserInfo = null; _effectiveUserInfoMap.clear(); diff --git a/lib/src/models/em_group.dart b/lib/src/models/em_group.dart index 1e48e22e..3356df1a 100644 --- a/lib/src/models/em_group.dart +++ b/lib/src/models/em_group.dart @@ -72,16 +72,85 @@ class EMGroup { /// And only the group owner or admin can call this method. /// List? get muteList => _muteList; + + @Deprecated("") bool? get noticeEnable => _noticeEnable; /// /// Gets whether the group message is blocked. /// bool? get messageBlocked => _messageBlocked; + + /// + /// Whether all members are muted. + /// + /// This method has limitations and is recommended to be used with caution. + /// + /// The state is updated when a all-muted/all-unmuted callback is received, but only for the in-memory object. + /// After the in-memory object is collected and pulled again from the database or server, the state becomes unreliable. + /// bool? get isAllMemberMuted => _isAllMemberMuted; + + @Deprecated( + "Switch to using isMemberOnly | isMemberAllowToInvite | maxUserCount to instead.") EMGroupOptions? get settings => _options; + + /// The current user's role in group. EMGroupPermissionType? get permissionType => _permissionType; + /// + /// The max number of group members allowed in a group. The param is set when the group is created. + /// + /// Be sure to fetch the detail specification of the group from the server first, see {@link EMGroupManager#getGroupSpecificationFromServer(String)}. If not, the SDK returns nil. + /// + /// **return** The allowed max number of group members. + /// + int? get maxUserCount => _options?.maxCount; + + /// + /// Fetches the group property: whether users can auto join the group VS need requesting or invitation from a group member to join the group. + /// + /// There are four types of group properties used to define the style of a group, + /// and `isMemberOnly` contains three types including: + /// PrivateOnlyOwnerInvite, + /// PrivateMemberCanInvite, + /// PublicJoinNeedApproval. + /// And do not include {@link EMGroupManager.EMGroupStyle#PublicOpenJoin}. + /// + /// **return** + /// `true`: Users can not join the group freely. Needs the invitation from the group owner or members, or the application been approved by the group owner or admins. + /// `false`: Users can join freely without the group owner or member‘s invitation or the new joiner’s application been approved. + bool get isMemberOnly { + if (_options == null) { + return true; + } + + if (_options?.style == EMGroupStyle.PrivateMemberCanInvite || + _options?.style == EMGroupStyle.PrivateOnlyOwnerInvite || + _options?.style == EMGroupStyle.PublicJoinNeedApproval) { + return true; + } + return false; + } + + /// + /// Gets whether the group member is allowed to invite other users to join the group. + /// + /// **return** + /// `true`: The group member can invite other users to join the group; + /// `false`: Do not allow the group member invite other users to join the group. + /// + bool get isMemberAllowToInvite { + if (_options == null) { + return true; + } + if (_options?.style == EMGroupStyle.PrivateMemberCanInvite) { + return true; + } + + return false; + } + /// @nodoc factory EMGroup.fromJson(Map map) { return EMGroup._private() diff --git a/lib/src/models/em_options.dart b/lib/src/models/em_options.dart index 584d4e5d..5179cc42 100644 --- a/lib/src/models/em_options.dart +++ b/lib/src/models/em_options.dart @@ -1,137 +1,275 @@ import '../tools/em_extension.dart'; import 'em_push_config.dart'; +/// +/// The settings of the chat SDK. +/// You can set parameters and options of the SDK. +/// For example, whether to encrypt the messages before sending, whether to automatically accept the friend invitations. +/// class EMOptions { - /// 环信 appKey, 必须设置。 - String? appKey = ''; + /// The app key you got from the console when create an app. + late final String appKey; - /// 是否自动登录,当为`true`时,首次登录成功后,您再次启动App时,sdk会在 - /// 初始化后自定为您登录上一次登录的账号。 - bool? autoLogin = true; + /// + /// Enables/Disables automatic login. + /// + /// `true`: (default) Enables automatic login; + /// `false`: Disables automatic login. + /// + final bool autoLogin; - bool? debugModel = false; + final bool debugModel; - /// 自动同意好友申请,当设置为`true`时, - /// 您在线时收到好友申请将自动同意, - /// 如您不在线,等您上线后会自动同意。 - bool? acceptInvitationAlways = false; + /// + /// Whether to accept friend invitations from other users automatically. + /// + /// `true`: (default) Accepts friend invitations automatically; + /// `false`: Do not accept friend invitations automatically. + final bool acceptInvitationAlways; - /// 是否自动同意群邀请,当设置为`true`时, - /// 您在线时收到加群邀请会自动同意, - /// 如您不在线,等您上线后会自动同意。 - bool? autoAcceptGroupInvitation = false; + /// + /// Whether to accept group invitations automatically. + /// + /// `true`: (default) Accepts group invitations automatically; + /// `false`: Do not accept group invitations automatically. + /// + final bool autoAcceptGroupInvitation; - /// 是否允许发送已读回执,默认值为`ture`, - /// 当为false时,当您通过EMChatManager调用sendMessageReadAck无效; - bool? requireAck = true; + /// + /// Whether the read receipt is required. + /// + /// `true`: (default) The read receipt is required; + /// `false`: The read receipt is not required. + /// + final bool requireAck; - /// 是否发送已送达回执,默认为`false`, 当为`ture`时, - /// 您收到消息后会自动相对方发送已送达回执。 - /// 对方可以通过`onMessagesDelivered()`方法监听; - bool? requireDeliveryAck = false; + /// + /// Whether the delivery receipt is required. + /// + /// `true`: (default) The read receipt is required; + /// `false`: The read receipt is not required. + /// + final bool requireDeliveryAck; - /// 退出群组时是否删除相应会话, 当为`true`时, - /// 您离开群组后对应的群消息会被删除。 - bool? deleteMessagesAsExitGroup = true; + /// + /// Whether to delete the group message when leaving a group. + /// + /// `true`: (default) Delete the messages when leaving the group. + /// `false`: Do not delete the messages when leaving a group. + /// + final bool deleteMessagesAsExitGroup; - /// 退出聊天室时是否删除相应会话, 当为`true`时, - /// 您离开聊天室后对应的聊天室消息会被删除。 - bool? deleteMessagesAsExitChatRoom = true; + /// + /// Whether to delete the chat room message when leaving the chat room. + /// + /// `true`: (default) Delete the chat room related message record when leaving the chat room. + /// `false`: Do not delete the chat room related message record when leaving the chat room. + /// + final bool deleteMessagesAsExitChatRoom; - /// 是否允许聊天室创建者退出聊天室,当为`true`时, - /// 聊天室创建者可以退出聊天室。 - bool? isChatRoomOwnerLeaveAllowed = true; + /// + /// Whether to allow the chat room owner to leave the chat room. + /// + /// `true`: (default) Allow the chat room owner to leave the chat room. + /// `false`: Do not allow the chat room owner to leave the chat room. + /// + final bool isChatRoomOwnerLeaveAllowed; - /// 消息按照服务器时间排序, 当为`true`时,您从数据库中 - /// 获取的消息是按照服务器时间排序的,否则是按照消息的本地时间排序。 - bool? sortMessageByServerTime = true; + /// + /// Whether to sort messages by the server received time. + /// + /// `true`: (default) Sort messages by the server received time; + /// `false`: Do not sort messages by the server received time. + /// + final bool sortMessageByServerTime; - bool? usingHttpsOnly = false; - bool? serverTransfer = true; - bool? isAutoDownload = true; + /// + /// Sets whether only HTTPS is used for REST operations. + /// + /// `true`: (default) Only HTTPS is used. + /// `false`: Allow to use both HTTP and HTTPS. + /// + final bool usingHttpsOnly; - EMPushConfig _pushConfig = EMPushConfig(); + /// + /// Whether to upload the message attachments automatically to the chat server. + /// + /// `true`: (default) Use the default way to upload and download the message attachments by chat server; + /// `false`: Do not use the default way to upload and download the message attachments by chat server, using a customized path instead. + /// + final bool serverTransfer; + + /// + /// Whether to auto download the thumbnail. + /// + /// `true`: (default) Download the thumbnail automatically; + /// `false`: Do not download the thumbnail automatically. + /// + final bool isAutoDownloadThumbnail; + + /// + /// Sets whether to disable DNS. + /// + /// + /// `true`: (default) Disable DNS; + /// `false`: Do not disable DNS. + final bool enableDNSConfig; + + /// The DNS url. + final String? dnsUrl; + + /// The custom REST server. + final String? restServer; + + /// The custom im message server url. + final String? imServer; - bool? enableDNSConfig = true; - String? dnsUrl = ''; - String? restServer = ''; - String? imServer = ''; - int? imPort = 0; + /// The custom im server port. + final int? imPort; - /// 开启Oppo推送,`appkey`是Oppo的appkey,`secret`是Oppo的secret。申请流程访问 - /// `http://docs-im.easemob.com/im/android/push/thirdpartypush` - void enableOppPush(String appKey, String secret) { + EMPushConfig _pushConfig = EMPushConfig(); + + /// + void enableOppoPush(String appKey, String secret) { _pushConfig.enableOppoPush = true; _pushConfig.oppoAppKey = appKey; _pushConfig.oppoAppSecret = secret; } - /// 开启小米推送, `appId`是推送用AppId, `appKey`是推送用AppKey。申请流程请访问 - /// `http://docs-im.easemob.com/im/android/push/thirdpartypush` + /// + /// Passes the app ID and app key of Mi push to enable Mi push on Mi devices. + /// + /// Param [appId] The Xiaomi Push App ID. + /// + /// Param [appKey] The Xiaomi push app key. + /// void enableMiPush(String appId, String appKey) { _pushConfig.enableMiPush = true; _pushConfig.miAppId = appId; _pushConfig.miAppKey = appKey; } + /// + /// Sets the FCM sender ID. + /// void enableFCM(String appId) { _pushConfig.enableFCM = true; _pushConfig.fcmId = appId; } + /// + /// Be sure to set the app ID and app key in AndroidManifest in order to make Vivo push available on Vivo devices. + /// void enableVivoPush() { _pushConfig.enableVivoPush = true; } - /// 华为推送,具体流程请访问 - /// `http://docs-im.easemob.com/im/android/push/thirdpartypush` + /// + /// Enables Huawei push on Huawei devices. + /// + /// Be sure to set app ID in AndroidManifest or to set agconnect-services.json. + /// void enableHWPush() { _pushConfig.enableHWPush = true; } - /// 开启苹果推送,具体申请证书和上传流程请参考文档 - /// `http://docs-im.easemob.com/im/ios/apns/deploy` + /// + /// Enables ios push on ios devices. + /// + /// Param [certName] The ios device push cert name. void enableAPNs(String certName) { _pushConfig.enableAPNS = true; _pushConfig.apnsCertName = certName; } - EMOptions({required this.appKey}); - - /// 设置自定义server地址 - void customServerInfo({ - required String customRestServer, - required String customImServer, - required int customImPort, - }) { - restServer = customRestServer; - imServer = customImServer; - imPort = customImPort; - enableDNSConfig = false; - } + /// + /// Sets the app options. + /// + /// Param [appKey] The app key you got from the console when create an app. + /// + /// Param [autoLogin] Enables/Disables automatic login. default is `true`. + /// + /// Param [debugModel] + /// + /// Param [acceptInvitationAlways] Whether to accept friend invitations from other users automatically. default is `false`. + /// + /// Param [autoAcceptGroupInvitation] Whether to accept group invitations automatically. default is `false`. + /// + /// Param [requireAck] Whether the read receipt is required. default is `true`. + /// + /// Param [requireDeliveryAck] Whether the delivery receipt is required. default is `true`. + /// + /// Param [deleteMessagesAsExitGroup] Whether to delete the group message when leaving a group. default is `true`. + /// + /// Param [deleteMessagesAsExitChatRoom] Whether to delete the chat room message when leaving the chat room. default is `true`. + /// + /// Param [isChatRoomOwnerLeaveAllowed] Whether to allow the chat room owner to leave the chat room. default is `true`. + /// + /// Param [sortMessageByServerTime] Whether to sort messages by the server received time. default is `true`. + /// + /// Param [usingHttpsOnly] Sets whether only HTTPS is used for REST operations. default is `true`. + /// + /// Param [serverTransfer] Whether to upload the message attachments automatically to the chat server. default is `true`. + /// + /// Param [isAutoDownloadThumbnail] Whether to auto download the thumbnail. default is `true`. + /// + /// Param [enableDNSConfig] Sets whether to disable DNS. + /// + /// Param [dnsUrl] The DNS url. + /// + /// Param [restServer] The custom REST server. + /// + /// Param [imPort] The custom im server port. + /// + /// Param [imServer] The custom im message server url. + /// + /// + EMOptions( + {required this.appKey, + this.autoLogin = true, + this.debugModel = false, + this.acceptInvitationAlways = false, + this.autoAcceptGroupInvitation = false, + this.requireAck = false, + this.requireDeliveryAck = false, + this.deleteMessagesAsExitGroup = true, + this.deleteMessagesAsExitChatRoom = true, + this.isChatRoomOwnerLeaveAllowed = true, + this.sortMessageByServerTime = true, + this.usingHttpsOnly = true, + this.serverTransfer = true, + this.isAutoDownloadThumbnail = true, + this.enableDNSConfig = true, + this.dnsUrl, + this.restServer, + this.imPort, + this.imServer}); factory EMOptions.fromJson(Map json) { - var ret = EMOptions(appKey: json['appKey']) - ..autoLogin = json.boolValue('autoLogin') - ..debugModel = json.boolValue('debugModel') - ..requireAck = json.boolValue('requireAck') - ..requireDeliveryAck = json.boolValue('requireDeliveryAck') - ..sortMessageByServerTime = json.boolValue('sortMessageByServerTime') - ..acceptInvitationAlways = json.boolValue('acceptInvitationAlways') - ..autoAcceptGroupInvitation = json.boolValue('autoAcceptGroupInvitation') - ..deleteMessagesAsExitGroup = json.boolValue('deleteMessagesAsExitGroup') - ..deleteMessagesAsExitChatRoom = - json.boolValue('deleteMessagesAsExitChatRoom') - ..isAutoDownload = json.boolValue('isAutoDownload') - ..isChatRoomOwnerLeaveAllowed = - json.boolValue('isChatRoomOwnerLeaveAllowed') - ..serverTransfer = json.boolValue('serverTransfer') - ..usingHttpsOnly = json.boolValue('usingHttpsOnly') - ..enableDNSConfig = json.boolValue('enableDNSConfig') - ..imPort = json.intValue("imPort") - ..imServer = json.stringValue("imServer") - ..restServer = json.stringValue("restServer") - ..dnsUrl = json.stringValue("dnsUrl"); + var ret = EMOptions( + appKey: json['appKey'], + autoLogin: json.boolValue('autoLogin'), + debugModel: json.boolValue('debugModel'), + requireAck: json.boolValue('requireAck'), + requireDeliveryAck: json.boolValue('requireDeliveryAck'), + sortMessageByServerTime: json.boolValue('sortMessageByServerTime'), + acceptInvitationAlways: json.boolValue('acceptInvitationAlways'), + autoAcceptGroupInvitation: json.boolValue('autoAcceptGroupInvitation'), + deleteMessagesAsExitGroup: json.boolValue('deleteMessagesAsExitGroup'), + deleteMessagesAsExitChatRoom: + json.boolValue('deleteMessagesAsExitChatRoom'), + isAutoDownloadThumbnail: json.boolValue('isAutoDownload'), + isChatRoomOwnerLeaveAllowed: + json.boolValue('isChatRoomOwnerLeaveAllowed'), + serverTransfer: json.boolValue('serverTransfer'), + usingHttpsOnly: json.boolValue('usingHttpsOnly'), + enableDNSConfig: json.boolValue('enableDNSConfig'), + imPort: json.intValue("imPort"), + imServer: json.stringValue("imServer"), + restServer: json.stringValue("restServer"), + dnsUrl: json.stringValue("dnsUrl"), + ); + ret._pushConfig = EMPushConfig(); if (json['pushConfig'] != null) { ret._pushConfig.updateFromJson(json); @@ -158,7 +296,7 @@ class EMOptions { data.setValueWithOutNull("enableDNSConfig", enableDNSConfig); data.setValueWithOutNull("imPort", imPort); data.setValueWithOutNull("imServer", imServer); - data.setValueWithOutNull("isAutoDownload", isAutoDownload); + data.setValueWithOutNull("isAutoDownload", isAutoDownloadThumbnail); data.setValueWithOutNull( "isChatRoomOwnerLeaveAllowed", isChatRoomOwnerLeaveAllowed); data.setValueWithOutNull("requireAck", requireAck); diff --git a/lib/src/models/em_page_result.dart b/lib/src/models/em_page_result.dart index 1b680a38..40867192 100644 --- a/lib/src/models/em_page_result.dart +++ b/lib/src/models/em_page_result.dart @@ -1,5 +1,11 @@ typedef PageResultCallback = Object Function(dynamic obj); +/// +///This object instance is returned when calling the method of fetching by pages. +/// Returns the next page count and the data count of next page. If the pageCount is less than the count you set, there is no more data on server. +/// +/// Param [T] Generics. +/// class EMPageResult { EMPageResult._private(); @@ -18,6 +24,9 @@ class EMPageResult { int? _pageCount; List? _data; + /// The page count. get pageCount => _pageCount; + + /// The result data. List? get data => _data; } diff --git a/lib/src/models/em_push_config.dart b/lib/src/models/em_push_config.dart index d3cdcb74..9b9f0fb0 100644 --- a/lib/src/models/em_push_config.dart +++ b/lib/src/models/em_push_config.dart @@ -1,5 +1,6 @@ import '../tools/em_extension.dart'; +/// @nodoc class EMPushConfig { String? mzAppId = ''; String? mzAppKey = ''; diff --git a/lib/src/models/em_push_configs.dart b/lib/src/models/em_push_configs.dart index a4f55257..883f8a4f 100644 --- a/lib/src/models/em_push_configs.dart +++ b/lib/src/models/em_push_configs.dart @@ -6,6 +6,7 @@ import 'em_chat_enums.dart'; import 'em_error.dart'; import '../em_push_manager.dart'; +/// The push configs info class. class EMPushConfigs { EMPushConfigs._private(); diff --git a/lib/src/models/em_userInfo.dart b/lib/src/models/em_userInfo.dart index a6eda39a..f55dd17f 100644 --- a/lib/src/models/em_userInfo.dart +++ b/lib/src/models/em_userInfo.dart @@ -1,17 +1,25 @@ -//用户属性类型 -enum EMUserInfoType { - NickName, - AvatarURL, - Phone, - Mail, - Gender, - Sign, - Birth, - Ext, -} +import '../tools/em_extension.dart'; +/// +/// The user attribute class that contains user attributes. +/// class EMUserInfo { - EMUserInfo(this.userId); + /// + /// Creates a userInfo. + /// + /// Param [userId] The user Id. + /// + EMUserInfo( + this.userId, { + this.nickName, + this.avatarUrl, + this.mail, + this.phone, + this.gender = 0, + this.sign, + this.birth, + this.ext, + }); EMUserInfo._private({ required this.userId, @@ -19,31 +27,49 @@ class EMUserInfo { this.avatarUrl, this.mail, this.phone, - this.gender, + this.gender = 0, this.sign, this.birth, this.ext, }); + /// @nodac factory EMUserInfo.fromJson(Map map) { - EMUserInfo info = EMUserInfo._private( - userId: map['userId'], + EMUserInfo info = EMUserInfo( + map.getValue("userId"), + nickName: map.getValue("nickName"), + avatarUrl: map.getValue("avatarUrl"), + mail: map.getValue("mail"), + phone: map.getValue("phone"), + gender: map.getValueWithOutNull("gender", 0), + sign: map.getValue("sign"), + birth: map.getValue("birth"), + ext: map.getValue("ext"), ); - info.nickName = map['nickName']; - info.avatarUrl = map['avatarUrl']; - info.mail = map['mail']; - info.phone = map['phone']; - if (map.containsKey("gender")) { - if (map['gender'] as int != 0) { - info.gender = map['gender'] as int; - } - } - info.sign = map['sign']; - info.birth = map['birth']; - info.ext = map['ext']; return info; } + /// + /// Set user attribute. + /// + /// Param [nickName] The user's nickname. + /// + /// Param [avatarUrl] The avatar URL of the user. + /// + /// Param [mail] The email address of the user. + /// + /// Param [phone] The phone number of the user. + /// + /// Param [gender] The user's gender. The value can only be 0, 1, or 2. 0: default; 1: male; 2: female. Other values are invalid. + /// + /// Param [sign] The user's signature. + /// + /// Param [birth] The user's birthday. + /// + /// Param [ext] The user's extension information. You can set it to an empty string or type custom information and encapsulate them as a JSON string. + /// + /// **return** The userInfo instance. + /// EMUserInfo copyWith({ String? nickName, String? avatarUrl, @@ -67,6 +93,7 @@ class EMUserInfo { ); } + /// @nodac Map toJson() { Map data = Map(); data['userId'] = userId; @@ -82,9 +109,7 @@ class EMUserInfo { if (phone != null) { data['phone'] = phone; } - if (gender != null) { - data['gender'] = gender; - } + data['gender'] = gender; if (sign != null) { data['sign'] = sign; } @@ -98,14 +123,32 @@ class EMUserInfo { return data; } + /// The user ID. final String userId; - String? nickName; - String? avatarUrl; - String? mail; - String? phone; - int? gender; - String? sign; - String? birth; - String? ext; + + /// The user's nickname. + final String? nickName; + + /// The avatar URL of the user. + final String? avatarUrl; + + /// The email address of the user. + final String? mail; + + /// The phone number of the user. + final String? phone; + + /// The user's gender. The value can only be 0, 1, or 2. 0: default; 1: male; 2: female. Other values are invalid. + final int gender; + + /// The user's signature. + final String? sign; + + /// The user's birthday. + final String? birth; + + /// The user's extension information. You can set it to an empty string or type custom information and encapsulate them as a JSON string. + final String? ext; + final int expireTime = DateTime.now().millisecondsSinceEpoch; } diff --git a/lib/src/tools/em_extension.dart b/lib/src/tools/em_extension.dart index 8d7b4cee..782e4496 100644 --- a/lib/src/tools/em_extension.dart +++ b/lib/src/tools/em_extension.dart @@ -1,4 +1,3 @@ -// 思考: 是否要把所有格式转换的部分都放到这个extension中? import '../models/em_group_shared_file.dart'; Type typeOf() => T; From 0912aaf504e2592934ebb0cc1780b7946072b5ce Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Fri, 1 Apr 2022 19:06:02 +0800 Subject: [PATCH 26/56] update api referance. --- .../EMChatRoomManagerWrapper.java | 17 +- .../com/easemob/im_flutter_sdk/EMHelper.java | 1 + .../pages/chatroom/chat_room_list_page.dart | 4 +- lib/im_flutter_sdk.dart | 1 + lib/src/em_chat_room_manager.dart | 21 ++- lib/src/internal/em_transform_tools.dart | 55 ++++++ lib/src/models/em_chat_enums.dart | 19 +- lib/src/models/em_chat_room.dart | 178 +++++++++++------- lib/src/models/em_group.dart | 8 +- lib/src/models/em_group_message_ack.dart | 86 +++++++-- lib/src/models/em_group_options.dart | 106 +++++------ lib/src/models/em_group_shared_file.dart | 41 ++++ 12 files changed, 376 insertions(+), 161 deletions(-) diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMChatRoomManagerWrapper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMChatRoomManagerWrapper.java index e45d0cfe..b48d0fc7 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMChatRoomManagerWrapper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMChatRoomManagerWrapper.java @@ -145,10 +145,15 @@ public void onError(int code, String desc) { private void fetchChatRoomInfoFromServer(JSONObject param, String channelName, MethodChannel.Result result) throws JSONException { String roomId = param.getString("roomId"); - + boolean fetchMembers = param.getBoolean("fetchMembers"); asyncRunnable(() -> { + EMChatRoom room = null; try { - EMChatRoom room = EMClient.getInstance().chatroomManager().fetchChatRoomFromServer(roomId); + if (fetchMembers) { + room = EMClient.getInstance().chatroomManager().fetchChatRoomFromServer(roomId, true); + }else { + room = EMClient.getInstance().chatroomManager().fetchChatRoomFromServer(roomId); + } onSuccess(result, channelName, EMChatRoomHelper.toJson(room)); } catch (HyphenateException e) { onError(result, e); @@ -247,13 +252,17 @@ private void changeChatRoomDescription(JSONObject param, String channelName, Met private void fetchChatRoomMembers(JSONObject param, String channelName, MethodChannel.Result result) throws JSONException { String roomId = param.getString("roomId"); - String cursor = param.getString("cursor"); + String cursor = null; + if(param.has("cursor")) { + cursor = param.getString("cursor"); + } int pageSize = param.getInt("pageSize"); + String finalCursor = cursor; asyncRunnable(() -> { try { EMCursorResult cursorResult = EMClient.getInstance().chatroomManager() - .fetchChatRoomMembers(roomId, cursor, pageSize); + .fetchChatRoomMembers(roomId, finalCursor, pageSize); onSuccess(result, channelName, EMCursorResultHelper.toJson(cursorResult)); } catch (HyphenateException e) { onError(result, e); diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java index c146922e..5194850b 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java @@ -588,6 +588,7 @@ class EMGroupAckHelper { static MaptoJson(EMGroupReadAck ack) { Map data = new HashMap<>(); data.put("msg_id", ack.getMsgId()); + data.put("ack_id", ack.getAckId()); data.put("from", ack.getFrom()); data.put("count", ack.getCount()); data.put("timestamp", ack.getTimestamp()); diff --git a/example/lib/pages/chatroom/chat_room_list_page.dart b/example/lib/pages/chatroom/chat_room_list_page.dart index fcc51f02..87ae3c05 100644 --- a/example/lib/pages/chatroom/chat_room_list_page.dart +++ b/example/lib/pages/chatroom/chat_room_list_page.dart @@ -122,7 +122,7 @@ class ChatRoomsListPagesState extends State { child: ListTile( onTap: () => _chatToRoom(room), title: Text( - room.name, + room.name ?? room.roomId, maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle( @@ -190,7 +190,7 @@ class ChatRoomsListPagesState extends State { SmartDialog.showToast('会话创建失败'); return; } - con.name = room.name; + con.name = room.name ?? room.roomId; Navigator.of(context).pushNamed( '/chat', arguments: [con.name, con], diff --git a/lib/im_flutter_sdk.dart b/lib/im_flutter_sdk.dart index cf80019b..9561f1ab 100644 --- a/lib/im_flutter_sdk.dart +++ b/lib/im_flutter_sdk.dart @@ -35,6 +35,7 @@ export 'src/models/em_location_message_body.dart' show EMLocationMessageBody; @Deprecated("Switch to using MessageStatusCallBack instead.") export 'src/em_status_listener.dart'; export 'src/em_message_status_callback.dart'; + export 'src/em_chat_manager.dart'; export 'src/em_contact_manager.dart'; export 'src/em_group_manager.dart'; diff --git a/lib/src/em_chat_room_manager.dart b/lib/src/em_chat_room_manager.dart index a2586aa0..318aa6ab 100644 --- a/lib/src/em_chat_room_manager.dart +++ b/lib/src/em_chat_room_manager.dart @@ -203,16 +203,26 @@ class EMChatRoomManager { /// /// Gets details of a chat room from the server, excluding the member list by default. + /// The member list, if required, can contain at most 200 members if need. For more members, + /// call {@link EMChatRoomManager#fetchChatRoomMembers(String, String?, int?)}. /// /// Param [roomId] The chat room ID. /// + /// Param [fetchMembers] Whether to get chat room members, default is false. + /// /// **return** The chat room instance. /// /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// - Future fetchChatRoomInfoFromServer(String roomId) async { - Map result = await _channel.invokeMethod( - ChatMethodKeys.fetchChatRoomInfoFromServer, {"roomId": roomId}); + Future fetchChatRoomInfoFromServer( + String roomId, { + bool fetchMembers = false, + }) async { + Map result = await _channel + .invokeMethod(ChatMethodKeys.fetchChatRoomInfoFromServer, { + "roomId": roomId, + "fetchMembers": fetchMembers, + }); try { EMError.hasErrorFromResult(result); return EMChatRoom.fromJson( @@ -394,10 +404,11 @@ class EMChatRoomManager { /// Future> fetchChatRoomMembers( String roomId, { - String cursor = '', + String? cursor, int pageSize = 200, }) async { - Map req = {"roomId": roomId, "cursor": cursor, "pageSize": pageSize}; + Map req = {"roomId": roomId, "pageSize": pageSize}; + req.setValueWithOutNull("cursor", cursor); Map result = await _channel.invokeMethod(ChatMethodKeys.fetchChatRoomMembers, req); try { diff --git a/lib/src/internal/em_transform_tools.dart b/lib/src/internal/em_transform_tools.dart index 1e0fabaa..756b70b5 100644 --- a/lib/src/internal/em_transform_tools.dart +++ b/lib/src/internal/em_transform_tools.dart @@ -190,3 +190,58 @@ int permissionTypeToInt(EMGroupPermissionType? type) { } return ret; } + +EMGroupStyle groupStyleTypeFromInt(int? type) { + EMGroupStyle ret = EMGroupStyle.PrivateOnlyOwnerInvite; + switch (type) { + case 0: + { + ret = EMGroupStyle.PrivateOnlyOwnerInvite; + } + break; + case 1: + { + ret = EMGroupStyle.PrivateMemberCanInvite; + } + break; + case 2: + { + ret = EMGroupStyle.PublicJoinNeedApproval; + } + break; + case 3: + { + ret = EMGroupStyle.PublicOpenJoin; + } + break; + } + return ret; +} + +int groupStyleTypeToInt(EMGroupStyle? type) { + int ret = 0; + if (type == null) return ret; + switch (type) { + case EMGroupStyle.PrivateOnlyOwnerInvite: + { + ret = 0; + } + break; + case EMGroupStyle.PrivateMemberCanInvite: + { + ret = 1; + } + break; + case EMGroupStyle.PublicJoinNeedApproval: + { + ret = 2; + } + break; + case EMGroupStyle.PublicOpenJoin: + { + ret = 3; + } + break; + } + return ret; +} diff --git a/lib/src/models/em_chat_enums.dart b/lib/src/models/em_chat_enums.dart index c048c8a7..cd94de11 100644 --- a/lib/src/models/em_chat_enums.dart +++ b/lib/src/models/em_chat_enums.dart @@ -1,8 +1,19 @@ +/// +/// The group styles. +/// enum EMGroupStyle { - PrivateOnlyOwnerInvite, // 私有群,只有群主能邀请他人进群,被邀请人会收到邀请信息,同意后可入群; - PrivateMemberCanInvite, // 私有群,所有人都可以邀请他人进群,被邀请人会收到邀请信息,同意后可入群; - PublicJoinNeedApproval, // 公开群,可以通过获取公开群列表api取的,申请加入时需要管理员以上权限用户同意; - PublicOpenJoin, // 公开群,可以通过获取公开群列表api取的,可以直接进入; + /// Private groups. Only the group owner can invite users to join. + PrivateOnlyOwnerInvite, + + /// Private groups. Both the group owner and group members can invite users to join. + PrivateMemberCanInvite, + + /// Public groups. Only the owner can invite users to join. + /// A user can join a group only after the owner approves the user's group request; + PublicJoinNeedApproval, + + /// Public groups. A user can join a group without the group owner approving user's group request. + PublicOpenJoin, } enum EMChatRoomPermissionType { diff --git a/lib/src/models/em_chat_room.dart b/lib/src/models/em_chat_room.dart index 2259c86d..0f8b2993 100644 --- a/lib/src/models/em_chat_room.dart +++ b/lib/src/models/em_chat_room.dart @@ -1,88 +1,132 @@ import '../../src/tools/em_extension.dart'; import 'em_chat_enums.dart'; +/// +/// Chat room types. +/// class EMChatRoom { - EMChatRoom._private(); + EMChatRoom._private({ + required this.roomId, + this.name, + this.description, + this.owner, + this.announcement, + this.memberCount, + this.maxUsers, + this.adminList, + this.memberList, + this.blockList, + this.muteList, + this.isAllMemberMuted, + this.permissionType = EMChatRoomPermissionType.None, + }); String toString() => toJson().toString(); + /// @nodoc factory EMChatRoom.fromJson(Map map) { - return EMChatRoom._private() - .._roomId = map['roomId'] as String - .._name = map.stringValue("name") - .._description = map.stringValue("desc") - .._owner = map.stringValue("owner") - .._memberCount = map.intValue("memberCount") - .._maxUsers = map.intValue("maxUsers") - .._adminList = map.listValue("adminList") - .._memberList = map.listValue("memberList") - .._blockList = map.listValue("blockList") - .._muteList = map.listValue("muteList") - .._announcement = map.stringValue("announcement") - .._permissionType = - EMChatRoom.permissionTypeFromInt(map['permissionType']) - .._isAllMemberMuted = map.boolValue('isAllMemberMuted'); + return EMChatRoom._private( + roomId: map.getValue('roomId'), + name: map.getValue("name"), + description: map.getValue("desc"), + owner: map.getValue("owner"), + memberCount: map.getValue("memberCount"), + maxUsers: map.getValue("maxUsers"), + adminList: map.listValue("adminList"), + memberList: map.listValue("memberList"), + blockList: map.listValue("blockList"), + muteList: map.listValue("muteList"), + announcement: map.getValue("announcement"), + permissionType: EMChatRoom.permissionTypeFromInt(map.getValue("key")), + isAllMemberMuted: map.boolValue('isAllMemberMuted')); } + /// @nodoc Map toJson() { final Map data = new Map(); - data['roomId'] = _roomId; - data.setValueWithOutNull("name", _name); - data.setValueWithOutNull("desc", _description); + data['roomId'] = roomId; + data.setValueWithOutNull("name", name); + data.setValueWithOutNull("desc", description); data.setValueWithOutNull("owner", owner); - data.setValueWithOutNull("memberCount", _memberCount); - data.setValueWithOutNull("maxUsers", _maxUsers); - data.setValueWithOutNull("adminList", _adminList); - data.setValueWithOutNull("memberList", _memberList); - data.setValueWithOutNull("blockList", _blockList); - data.setValueWithOutNull("muteList", _muteList); - data.setValueWithOutNull("announcement", _announcement); - data.setValueWithOutNull("isAllMemberMuted", _isAllMemberMuted); - data['permissionType'] = EMChatRoom.permissionTypeToInt(_permissionType); + data.setValueWithOutNull("memberCount", memberCount); + data.setValueWithOutNull("maxUsers", maxUsers); + data.setValueWithOutNull("adminList", adminList); + data.setValueWithOutNull("memberList", memberList); + data.setValueWithOutNull("blockList", blockList); + data.setValueWithOutNull("muteList", muteList); + data.setValueWithOutNull("announcement", announcement); + data.setValueWithOutNull("isAllMemberMuted", isAllMemberMuted); + data['permissionType'] = EMChatRoom.permissionTypeToInt(permissionType); return data; } - // 房间id - late String _roomId; - // 房间名称 - String? _name = ''; - // 房间描述 - String? _description = ''; - // 房主 - String? _owner = ''; - //公告 - String? _announcement = ''; - // 当前人数 - int? _memberCount = 0; - // 最大人数 - int? _maxUsers = 0; - // 管理员列表 - List? _adminList; - // 成员列表 - List? _memberList; - // 黑名单列表 - List? _blockList; - // 禁言列表 - List? _muteList; - // 是否全员禁言 - bool? _isAllMemberMuted; + /// The chat room ID. + final String roomId; + + /// The chat room name. + final String? name; + + /// The chat room description. + final String? description; + + /// The chat room owner ID. If this method returns an empty string, the SDK fails to get chat room details. + final String? owner; + + /// The chat room announcement. + /// + /// To get the chat room announcement, you can call {@link EMChatRoomManager#fetchChatRoomAnnouncement(String)} + /// + /// **return** The chat room announcement. If this method returns an empty string, the SDK fails to get the chat room announcement. + /// + final String? announcement; + + /// + /// The number of online members. + /// + final int? memberCount; + + /// + /// The maximum number of members in the chat room which is determined during chat room creation. + /// + /// This method can return a correct value only after you call EMChatRoomManager#fetchChatRoomInfoFromServer(String) to get chat room details. + /// + final int? maxUsers; + + /// + /// The chat room admin list. + /// + final List? adminList; + + /// + /// The member list. + /// + /// You can get the member list in the following ways: + /// When there are less than 200 members, use {@link EMChatRoomManager#fetchChatRoomInfoFromServer(String, bool?)} to get them. + /// If true is passed to the second parameter, you can get up to 200 members. + /// + final List? memberList; + + /// + /// The chat room block list. + /// + /// To get the block list, you can call {@link EMChatRoomManager#fetchChatRoomBlockList(String, int?, int?)}. + /// + final List? blockList; + + /// + /// The mute list of the chat room. + /// + /// To get the mute list, you can call {@link EMChatRoomManager#fetchChatRoomMuteList(String, int?, int?)}. + /// + final List? muteList; + + /// + /// Checks whether all members are muted. + /// + final bool? isAllMemberMuted; // 在聊天室中的角色 - EMChatRoomPermissionType _permissionType = EMChatRoomPermissionType.None; - - String get roomId => _roomId; - get name => _name; - get description => _description; - get owner => _owner; - get announcement => _announcement; - get memberCount => _memberCount; - get maxUsers => _maxUsers; - get adminList => _adminList; - get memberList => _memberList; - get blockList => _blockList; - get muteList => _muteList; - get isAllMemberMuted => _isAllMemberMuted; - get permissionType => _permissionType; + final EMChatRoomPermissionType permissionType; static EMChatRoomPermissionType permissionTypeFromInt(int? type) { EMChatRoomPermissionType ret = EMChatRoomPermissionType.Member; diff --git a/lib/src/models/em_group.dart b/lib/src/models/em_group.dart index 3356df1a..e22cc25d 100644 --- a/lib/src/models/em_group.dart +++ b/lib/src/models/em_group.dart @@ -4,15 +4,17 @@ import '../tools/em_extension.dart'; import 'em_chat_enums.dart'; import 'em_group_options.dart'; +/// /// The group class. +/// class EMGroup { EMGroup._private(); late String _groupId; String? _name; - String? _description = ''; - String? _owner = ''; - String? _announcement = ''; + String? _description; + String? _owner; + String? _announcement; int? _memberCount; List? _memberList; List? _adminList; diff --git a/lib/src/models/em_group_message_ack.dart b/lib/src/models/em_group_message_ack.dart index 1c02809e..6f0ddb84 100644 --- a/lib/src/models/em_group_message_ack.dart +++ b/lib/src/models/em_group_message_ack.dart @@ -1,30 +1,78 @@ +import '../tools/em_extension.dart'; + +/// +/// Returns read recipients for group messages. +/// +/// Calls {@link EMChatManager#fetchGroupAcks(String, String?, int)} to return the requested result, for example: +/// +/// ```dart +/// EMCursorResult result = await EMClient.getInstance.chatManager.fetchGroupAcks("msgId"); +/// ``` +/// class EMGroupMessageAck { - /// 对应的消息id - late String messageId; + /// + /// Gets the group message ID. + /// + /// **return** The group message ID. + /// + final String messageId; + + /// + /// Gets the read receipt ID of group messages. + /// + /// **return** The read receipt ID. + /// + final String ackId; - /// 已读发送方id - late String from; + /// + /// Gets the ID of user who sends the read receipt. + /// + /// **return** The read receipt sender ID. + /// + final String from; - /// 已读回复内容 - String? content; + /// + /// Gets the read receipt extension. + /// + /// Sends the read receipt passed as the third parameter in {@link EMChatManager#sendGroupMessageReadAck(String, String, String?)}. + /// + /// **return** The read receipt extension. + /// + final String? content; - /// 群消息已读人数 - int readCount = 0; + /// + /// Gets the count in which read receipts of group messages are sent. + /// + /// **return** The count in which read receipts of group messages are sent. + /// + final int readCount; - /// 本条已读发送时间 - int timestamp = 0; + /// + /// Gets the timestamp of sending read receipts of group messages. + /// + /// **return** The timestamp of sending read receipts of group messages. + final int timestamp; + /// @nodoc factory EMGroupMessageAck.fromJson(Map map) { - EMGroupMessageAck ack = EMGroupMessageAck._private(); - ack.messageId = map["msg_id"] as String; - ack.from = map["from"] as String; - if (map.containsKey("content")) { - ack.content = map["content"] as String; - } - ack.readCount = map["count"] as int; - ack.timestamp = map["timestamp"] as int; + EMGroupMessageAck ack = EMGroupMessageAck._private( + ackId: map["ack_id"] as String, + messageId: map["msg_id"] as String, + from: map["from"] as String, + content: map.getValue("content"), + readCount: map.getValueWithOutNull("count", 0), + timestamp: map.getValueWithOutNull("timestamp", 0), + ); + return ack; } - EMGroupMessageAck._private(); + EMGroupMessageAck._private({ + required this.ackId, + required this.messageId, + required this.from, + required this.content, + required this.readCount, + required this.timestamp, + }); } diff --git a/lib/src/models/em_group_options.dart b/lib/src/models/em_group_options.dart index 04628959..78c5b1da 100644 --- a/lib/src/models/em_group_options.dart +++ b/lib/src/models/em_group_options.dart @@ -1,9 +1,25 @@ +import '../internal/em_transform_tools.dart'; + import 'em_chat_enums.dart'; import '../tools/em_extension.dart'; +/// +/// Group property options to be configured during group creation. +/// class EMGroupOptions { EMGroupOptions._private(); + /// + /// Create a group property options + /// + /// Param [style] The group style. see {EMGroupStyle} + /// + /// Param [count] The maximum number of members in a group. default is 200. + /// + /// Param [inviteNeedConfirm] + /// + /// Param [extension] + /// EMGroupOptions({ EMGroupStyle style = EMGroupStyle.PrivateOnlyOwnerInvite, int count = 200, @@ -21,83 +37,59 @@ class EMGroupOptions { bool? _inviteNeedConfirm; String? _ext; + /// + /// Gets the group style. see {EMGroupStyle} + /// + /// **return** The group style. see {EMGroupStyle} + /// EMGroupStyle? get style => _style; + + /// + /// Get maximum number of members in a group. + /// + /// **return** The maximum number of members in a group. + /// int? get maxCount => _maxCount; + + /// + /// This option defines whether to ask for content when inviting a user to join a group. + /// + /// Whether automatically accepting the invitation to join a group depends on two settings: inviteNeedConfirm, an option during group creation, + /// and {@link EMOptions#autoAcceptGroupInvitation(boolean)} which determines whether to automatically accept an invitation to join the group. + /// There are two cases: + /// (1) If inviteNeedConfirm is set to 'false', adds the invitee directly to the group on the server side + /// regardless of the setting of {@link EMOptions#autoAcceptGroupInvitation(boolean)}. + /// + /// (2) If inviteNeedConfirm is set to 'true', the user automatically joins a group or decides whether to join, depending on the setting of {@link EMOptions#autoAcceptGroupInvitation(boolean)}. + /// {@link EMOptions#autoAcceptGroupInvitation(boolean)} is an SDK-level operation. If it is set to true, + /// SDK calls the API for agreeing to join the group to automatically accept the joining invitation. + /// If inviteNeedConfirm is set to false, SDK does not automatically accept its invitation, + /// but the user decides to accept or reject the invitation. + /// + /// **return** The whether to ask for content when inviting a user to join a group. + /// bool? get inviteNeedConfirm => _inviteNeedConfirm; String? get ext => _ext; + /// @nodoc factory EMGroupOptions.fromJson(Map? map) { return EMGroupOptions._private() - .._style = EMGroupOptions.styleTypeFromInt(map?['style']) + .._style = groupStyleTypeFromInt(map?['style']) .._maxCount = map?['maxCount'] .._ext = map?['ext'] .._inviteNeedConfirm = map?.boolValue('inviteNeedConfirm'); } + /// @nodoc Map toJson() { Map data = Map(); - data['style'] = EMGroupOptions.styleTypeToInt(_style); + data['style'] = groupStyleTypeToInt(_style); data['maxCount'] = _maxCount; data['inviteNeedConfirm'] = _inviteNeedConfirm; data.setValueWithOutNull("ext", _ext); return data; } - static EMGroupStyle styleTypeFromInt(int? type) { - EMGroupStyle ret = EMGroupStyle.PrivateOnlyOwnerInvite; - switch (type) { - case 0: - { - ret = EMGroupStyle.PrivateOnlyOwnerInvite; - } - break; - case 1: - { - ret = EMGroupStyle.PrivateMemberCanInvite; - } - break; - case 2: - { - ret = EMGroupStyle.PublicJoinNeedApproval; - } - break; - case 3: - { - ret = EMGroupStyle.PublicOpenJoin; - } - break; - } - return ret; - } - - static int styleTypeToInt(EMGroupStyle? type) { - int ret = 0; - if (type == null) return ret; - switch (type) { - case EMGroupStyle.PrivateOnlyOwnerInvite: - { - ret = 0; - } - break; - case EMGroupStyle.PrivateMemberCanInvite: - { - ret = 1; - } - break; - case EMGroupStyle.PublicJoinNeedApproval: - { - ret = 2; - } - break; - case EMGroupStyle.PublicOpenJoin: - { - ret = 3; - } - break; - } - return ret; - } - @override String toString() { return this.toJson().toString(); diff --git a/lib/src/models/em_group_shared_file.dart b/lib/src/models/em_group_shared_file.dart index 9f3e45b7..e6d149f9 100644 --- a/lib/src/models/em_group_shared_file.dart +++ b/lib/src/models/em_group_shared_file.dart @@ -1,5 +1,15 @@ import '../tools/em_extension.dart'; +/// +/// The shared file info class. +/// +/// For example: +/// You can use the following method to get information about the group shared file +/// through {@link EMGroupManager#getGroupFileListFromServer(String, int?, int?)} +/// +/// ```dart +/// List? list = await EMClient.getInstance.groupManager.getGroupFileListFromServer(groupId); +/// ``` class EMGroupSharedFile { EMGroupSharedFile._private(); @@ -9,12 +19,42 @@ class EMGroupSharedFile { int? _createTime; int? _fileSize; + /// + /// Gets the shared file ID. + /// + /// **return** The shared file ID. + /// String? get fileId => _fileId; + + /// + /// Gets the shared file name. + /// + /// **return** The shared file name. + /// String? get fileName => _fileName; + + /// + /// Gets the username who uploads the shared file. + /// + /// **return** The username who uploads the shared file. + /// String? get fileOwner => _fileOwner; + + /// + /// Gets the update Unix timestamp of the shared file, in ms. + /// + /// **return** The update Unix timestamp of the shared file, in ms. + /// int? get createTime => _createTime; + + /// + /// Gets the data length of the shared file, in bytes. + /// + /// **return** The data length of the shared file, in bytes. + /// int? get fileSize => _fileSize; + /// @nodoc factory EMGroupSharedFile.fromJson(Map? map) { return EMGroupSharedFile._private() .._fileId = map?["fileId"] @@ -24,6 +64,7 @@ class EMGroupSharedFile { .._fileSize = map?["fileSize"]; } + /// @nodoc Map toJson() { Map data = Map(); data.setValueWithOutNull("fileId", _fileId); From 7a8ff99472c72f0b478aa6fdaa34d2fa77e11319 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Fri, 1 Apr 2022 20:00:11 +0800 Subject: [PATCH 27/56] add api referance. --- lib/src/internal/em_transform_tools.dart | 34 ++++++++++++++++ lib/src/models/em_chat_enums.dart | 5 +++ lib/src/models/em_chat_room.dart | 52 +++++++----------------- 3 files changed, 54 insertions(+), 37 deletions(-) diff --git a/lib/src/internal/em_transform_tools.dart b/lib/src/internal/em_transform_tools.dart index 756b70b5..9ac282f7 100644 --- a/lib/src/internal/em_transform_tools.dart +++ b/lib/src/internal/em_transform_tools.dart @@ -245,3 +245,37 @@ int groupStyleTypeToInt(EMGroupStyle? type) { } return ret; } + +EMChatRoomPermissionType chatRoomPermissionTypeFromInt(int? type) { + EMChatRoomPermissionType ret = EMChatRoomPermissionType.Member; + switch (type) { + case -1: + return EMChatRoomPermissionType.None; + case 0: + return EMChatRoomPermissionType.Member; + case 1: + return EMChatRoomPermissionType.Admin; + case 2: + return EMChatRoomPermissionType.Owner; + } + return ret; +} + +int chatRoomPermissionTypeToInt(EMChatRoomPermissionType type) { + int ret = 0; + switch (type) { + case EMChatRoomPermissionType.None: + ret = -1; + break; + case EMChatRoomPermissionType.Member: + ret = 0; + break; + case EMChatRoomPermissionType.Admin: + ret = 1; + break; + case EMChatRoomPermissionType.Owner: + ret = 2; + break; + } + return ret; +} diff --git a/lib/src/models/em_chat_enums.dart b/lib/src/models/em_chat_enums.dart index cd94de11..ced70468 100644 --- a/lib/src/models/em_chat_enums.dart +++ b/lib/src/models/em_chat_enums.dart @@ -134,3 +134,8 @@ enum EMGroupPermissionType { Admin, Owner, } + +enum EMMessageSearchDirection { + Up, + Down, +} diff --git a/lib/src/models/em_chat_room.dart b/lib/src/models/em_chat_room.dart index 0f8b2993..6670a197 100644 --- a/lib/src/models/em_chat_room.dart +++ b/lib/src/models/em_chat_room.dart @@ -1,3 +1,5 @@ +import '../internal/em_transform_tools.dart'; + import '../../src/tools/em_extension.dart'; import 'em_chat_enums.dart'; @@ -37,7 +39,7 @@ class EMChatRoom { blockList: map.listValue("blockList"), muteList: map.listValue("muteList"), announcement: map.getValue("announcement"), - permissionType: EMChatRoom.permissionTypeFromInt(map.getValue("key")), + permissionType: chatRoomPermissionTypeFromInt(map.getValue("key")), isAllMemberMuted: map.boolValue('isAllMemberMuted')); } @@ -56,7 +58,7 @@ class EMChatRoom { data.setValueWithOutNull("muteList", muteList); data.setValueWithOutNull("announcement", announcement); data.setValueWithOutNull("isAllMemberMuted", isAllMemberMuted); - data['permissionType'] = EMChatRoom.permissionTypeToInt(permissionType); + data['permissionType'] = chatRoomPermissionTypeToInt(permissionType); return data; } @@ -124,41 +126,17 @@ class EMChatRoom { /// /// Checks whether all members are muted. /// + /// This method has use limitations and should be used with caution. + /// Pay attention to the following when using this method: + /// Upon your receipt of the callback of one-click mute or unmute after you join the chat room, the status will be updated and the staus obtained using this method is correct. + /// + /// After you exit from the chat room before reentering it, the status obtained using this method is not trustworthy. + /// **return** Whether all members are muted. + /// `true`: All members are muted. + /// `false`: Not all members are muted. + /// final bool? isAllMemberMuted; - // 在聊天室中的角色 - final EMChatRoomPermissionType permissionType; - static EMChatRoomPermissionType permissionTypeFromInt(int? type) { - EMChatRoomPermissionType ret = EMChatRoomPermissionType.Member; - switch (type) { - case -1: - return EMChatRoomPermissionType.None; - case 0: - return EMChatRoomPermissionType.Member; - case 1: - return EMChatRoomPermissionType.Admin; - case 2: - return EMChatRoomPermissionType.Owner; - } - return ret; - } - - static int permissionTypeToInt(EMChatRoomPermissionType type) { - int ret = 0; - switch (type) { - case EMChatRoomPermissionType.None: - ret = -1; - break; - case EMChatRoomPermissionType.Member: - ret = 0; - break; - case EMChatRoomPermissionType.Admin: - ret = 1; - break; - case EMChatRoomPermissionType.Owner: - ret = 2; - break; - } - return ret; - } + /// The current user's role in the chat room, see {@link EMChatRoomPermissionType}. + final EMChatRoomPermissionType permissionType; } From 38d2b77f58a1ff8761d7008f6317a417370e8e51 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Fri, 1 Apr 2022 20:09:39 +0800 Subject: [PATCH 28/56] update --- lib/src/models/em_chat_enums.dart | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/src/models/em_chat_enums.dart b/lib/src/models/em_chat_enums.dart index ced70468..1b61a9bc 100644 --- a/lib/src/models/em_chat_enums.dart +++ b/lib/src/models/em_chat_enums.dart @@ -16,12 +16,6 @@ enum EMGroupStyle { PublicOpenJoin, } -enum EMChatRoomPermissionType { - None, - Member, - Admin, - Owner, -} enum EMConversationType { Chat, // 单聊消息 GroupChat, // 群聊消息 @@ -135,6 +129,13 @@ enum EMGroupPermissionType { Owner, } +enum EMChatRoomPermissionType { + None, + Member, + Admin, + Owner, +} + enum EMMessageSearchDirection { Up, Down, From 406668816013db39aa7fdbb237c3114b3f25f023 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Sat, 2 Apr 2022 17:15:04 +0800 Subject: [PATCH 29/56] change conversation. --- .../im_flutter_sdk/EMConversationWrapper.java | 4 +- example/lib/pages/chat/chat_page.dart | 6 +- .../pages/chatroom/chat_room_list_page.dart | 4 +- .../conversations/conversation_item.dart | 68 ++-- .../conversations/conversations_page.dart | 8 +- .../lib/pages/group/joined_groups_page.dart | 4 +- lib/im_flutter_sdk.dart | 1 - lib/src/em_chat_manager.dart | 9 +- lib/src/internal/em_transform_tools.dart | 33 ++ lib/src/models/em_chat_enums.dart | 14 +- lib/src/models/em_conversation.dart | 346 ++++++++++-------- lib/src/models/em_options.dart | 4 +- lib/src/models/em_userInfo.dart | 2 +- 13 files changed, 294 insertions(+), 209 deletions(-) diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMConversationWrapper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMConversationWrapper.java index 87f03645..d4bb7322 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMConversationWrapper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMConversationWrapper.java @@ -84,6 +84,9 @@ else if (EMSDKMethod.loadMsgWithMsgType.equals(call.method)) { else if (EMSDKMethod.loadMsgWithTime.equals(call.method)) { loadMsgWithTime(param, call.method, result); } + else if (EMSDKMethod.getLatestMessage.equals(call.method)){ + + } else { @@ -311,7 +314,6 @@ private void loadMsgWithTime(JSONObject params, String channelName, Result resul }); } - private EMConversation conversationWithParam(JSONObject params ) throws JSONException { String con_id = params.getString("con_id"); EMConversation.EMConversationType type = EMConversationHelper.typeFromInt(params.getInt("type")); diff --git a/example/lib/pages/chat/chat_page.dart b/example/lib/pages/chat/chat_page.dart index 9a71d2dd..500d90ca 100644 --- a/example/lib/pages/chat/chat_page.dart +++ b/example/lib/pages/chat/chat_page.dart @@ -283,11 +283,13 @@ class _ChatPageState extends State /// 下拉加载更多消息 _loadMessages({int count = 20, bool moveBottom = true}) async { try { - List msgs = await widget.conversation.loadMessages( + List? msgs = await widget.conversation.loadMessages( startMsgId: _msgList.length > 0 ? _msgList.first.msgId : '', loadCount: count, ); - _msgList.insertAll(0, msgs); + if (msgs != null) { + _msgList.insertAll(0, msgs); + } } on EMError { } finally { if (moveBottom) { diff --git a/example/lib/pages/chatroom/chat_room_list_page.dart b/example/lib/pages/chatroom/chat_room_list_page.dart index 87ae3c05..28f1949d 100644 --- a/example/lib/pages/chatroom/chat_room_list_page.dart +++ b/example/lib/pages/chatroom/chat_room_list_page.dart @@ -190,10 +190,10 @@ class ChatRoomsListPagesState extends State { SmartDialog.showToast('会话创建失败'); return; } - con.name = room.name ?? room.roomId; + Navigator.of(context).pushNamed( '/chat', - arguments: [con.name, con], + arguments: [con.id, con], ).then((value) => EMClient.getInstance.chatRoomManager.leaveChatRoom(room.roomId)); } diff --git a/example/lib/pages/conversations/conversation_item.dart b/example/lib/pages/conversations/conversation_item.dart index c456358e..901e0cf9 100644 --- a/example/lib/pages/conversations/conversation_item.dart +++ b/example/lib/pages/conversations/conversation_item.dart @@ -54,8 +54,11 @@ class _ConversationItemState extends State { Positioned( top: sHeight(10), right: sWidth(5), - child: unreadCountWidget( - _unreadCount(), + child: FutureBuilder( + future: _unreadCount(), + builder: (context, snapshot) { + return unreadCountWidget(snapshot.data ?? 0); + }, ), ), ], @@ -86,13 +89,18 @@ class _ConversationItemState extends State { Container( margin: EdgeInsets.only( left: sWidth(5), right: sWidth(12)), - child: Text( - _latestMessageTime(), - maxLines: 1, - style: TextStyle( - color: Color.fromRGBO(153, 153, 153, 1), - fontSize: sFontSize(12), - ), + child: FutureBuilder( + future: _latestMessageTime(), + builder: (context, snapshot) { + return Text( + snapshot.data ?? "", + maxLines: 1, + style: TextStyle( + color: Color.fromRGBO(153, 153, 153, 1), + fontSize: sFontSize(12), + ), + ); + }, ), ), ], @@ -102,16 +110,20 @@ class _ConversationItemState extends State { Expanded( flex: 1, child: Container( - padding: EdgeInsets.only(right: sWidth(10)), - child: ExpressionText( - _showInfo(), - TextStyle( - color: Color.fromRGBO(153, 153, 153, 1), - fontSize: sFontSize(14), - ), - maxLine: 1, - ), - ), + padding: EdgeInsets.only(right: sWidth(10)), + child: FutureBuilder( + future: _showInfo(), + builder: (context, snapshot) { + return ExpressionText( + snapshot.data ?? "", + TextStyle( + color: Color.fromRGBO(153, 153, 153, 1), + fontSize: sFontSize(14), + ), + maxLine: 1, + ); + }, + )), ), ], ), @@ -123,9 +135,9 @@ class _ConversationItemState extends State { } /// 消息详情 - String _showInfo() { + Future _showInfo() async { String showInfo = ''; - EMMessage? _latestMessage = this.widget.conversation.latestMessage; + EMMessage? _latestMessage = await this.widget.conversation.latestMessage(); if (_latestMessage == null) { return showInfo; } @@ -158,19 +170,17 @@ class _ConversationItemState extends State { /// 显示的名称 String _showName() { - return this.widget.conversation.name; + return this.widget.conversation.id; } /// 未读数 - int _unreadCount() { - return this.widget.conversation.unreadCount; + Future _unreadCount() async { + return this.widget.conversation.unreadCount(); } /// 消息时间 - String _latestMessageTime() { - if (this.widget.conversation.latestMessage == null) { - return ''; - } - return timeStrByMs(this.widget.conversation.latestMessage?.serverTime ?? 0); + Future _latestMessageTime() async { + EMMessage? msg = await this.widget.conversation.latestMessage(); + return timeStrByMs(msg?.serverTime ?? 0); } } diff --git a/example/lib/pages/conversations/conversations_page.dart b/example/lib/pages/conversations/conversations_page.dart index 37ed4b87..07df450a 100644 --- a/example/lib/pages/conversations/conversations_page.dart +++ b/example/lib/pages/conversations/conversations_page.dart @@ -155,15 +155,13 @@ class ConversationPageState extends State /// 更新会话列表 void _reLoadAllConversations() async { try { + int count = + await EMClient.getInstance.chatManager.getUnreadMessageCount(); List list = await EMClient.getInstance.chatManager.loadAllConversations(); _conversationsList.clear(); _conversationsList.addAll(list); _refreshController.refreshCompleted(); - int count = 0; - for (var conversation in _conversationsList) { - count += conversation.unreadCount; - } widget.updateCount(count); } on Error { _refreshController.refreshFailed(); @@ -206,7 +204,7 @@ class ConversationPageState extends State EMConversation con = _conversationsList[index]; Navigator.of(context).pushNamed( '/chat', - arguments: [con.name, con], + arguments: [con.id, con], ).then((value) { // 返回时刷新页面 _reLoadAllConversations(); diff --git a/example/lib/pages/group/joined_groups_page.dart b/example/lib/pages/group/joined_groups_page.dart index 0eaca992..b064e794 100644 --- a/example/lib/pages/group/joined_groups_page.dart +++ b/example/lib/pages/group/joined_groups_page.dart @@ -280,10 +280,10 @@ class JoinedGroupsPageState extends State { SmartDialog.showToast('会话创建失败'); return; } - con.name = group.name!; + // con.name = group.name!; Navigator.of(context).pushNamed( '/chat', - arguments: [con.name, con], + arguments: [con.id, con], ).then((value) { eventBus.fire(EventBusManager.updateConversations()); }); diff --git a/lib/im_flutter_sdk.dart b/lib/im_flutter_sdk.dart index 9561f1ab..873957d6 100644 --- a/lib/im_flutter_sdk.dart +++ b/lib/im_flutter_sdk.dart @@ -2,7 +2,6 @@ library im_flutter_sdk; export 'src/em_client.dart'; -export 'src/models/em_message.dart'; export 'src/models/em_group_message_ack.dart'; // export 'src/tools/em_log.dart'; export 'src/em_listeners.dart'; diff --git a/lib/src/em_chat_manager.dart b/lib/src/em_chat_manager.dart index 24e90304..3952fa27 100644 --- a/lib/src/em_chat_manager.dart +++ b/lib/src/em_chat_manager.dart @@ -1,6 +1,7 @@ import "dart:async"; import 'package:flutter/services.dart'; +import 'internal/em_transform_tools.dart'; import 'tools/em_extension.dart'; import '../im_flutter_sdk.dart'; import 'internal/chat_method_keys.dart'; @@ -256,7 +257,7 @@ class EMChatManager { ]) async { Map req = { "con_id": conversationId, - "type": EMConversation.typeToInt(type), + "type": conversationTypeToInt(type), "createIfNeed": createIfNeed }; Map result = @@ -519,7 +520,7 @@ class EMChatManager { }) async { Map req = Map(); req['con_id'] = conversationId; - req['type'] = EMConversation.typeToInt(type); + req['type'] = conversationTypeToInt(type); req['pageSize'] = pageSize; req['startMsgId'] = startMsgId; Map result = @@ -558,14 +559,14 @@ class EMChatManager { int timeStamp = -1, int maxCount = 20, String from = '', - EMMessageSearchDirection direction = EMMessageSearchDirection.Up, + EMSearchDirection direction = EMSearchDirection.Up, }) async { Map req = Map(); req['keywords'] = keywords; req['timeStamp'] = timeStamp; req['maxCount'] = maxCount; req['from'] = from; - req['direction'] = direction == EMMessageSearchDirection.Up ? "up" : "down"; + req['direction'] = direction == EMSearchDirection.Up ? "up" : "down"; Map result = await _channel.invokeMethod(ChatMethodKeys.searchChatMsgFromDB, req); diff --git a/lib/src/internal/em_transform_tools.dart b/lib/src/internal/em_transform_tools.dart index 9ac282f7..42cb5a3a 100644 --- a/lib/src/internal/em_transform_tools.dart +++ b/lib/src/internal/em_transform_tools.dart @@ -279,3 +279,36 @@ int chatRoomPermissionTypeToInt(EMChatRoomPermissionType type) { } return ret; } + +int conversationTypeToInt(EMConversationType? type) { + int ret = 0; + if (type == null) return ret; + switch (type) { + case EMConversationType.Chat: + ret = 0; + break; + case EMConversationType.GroupChat: + ret = 1; + break; + case EMConversationType.ChatRoom: + ret = 2; + break; + } + return ret; +} + +EMConversationType conversationTypeFromInt(int? type) { + EMConversationType ret = EMConversationType.Chat; + switch (type) { + case 0: + ret = EMConversationType.Chat; + break; + case 1: + ret = EMConversationType.GroupChat; + break; + case 2: + ret = EMConversationType.ChatRoom; + break; + } + return ret; +} diff --git a/lib/src/models/em_chat_enums.dart b/lib/src/models/em_chat_enums.dart index 1b61a9bc..4a449681 100644 --- a/lib/src/models/em_chat_enums.dart +++ b/lib/src/models/em_chat_enums.dart @@ -16,10 +16,16 @@ enum EMGroupStyle { PublicOpenJoin, } +/// The conversation types. enum EMConversationType { - Chat, // 单聊消息 - GroupChat, // 群聊消息 - ChatRoom, // 聊天室消息 + /// One-to-one chat. + Chat, + + /// Group chat. + GroupChat, + + /// Chat room. + ChatRoom, } @Deprecated('Switch to using EMPushManager#DisplayStyle instead') @@ -136,7 +142,7 @@ enum EMChatRoomPermissionType { Owner, } -enum EMMessageSearchDirection { +enum EMSearchDirection { Up, Down, } diff --git a/lib/src/models/em_conversation.dart b/lib/src/models/em_conversation.dart index e9003e82..dea0c2de 100644 --- a/lib/src/models/em_conversation.dart +++ b/lib/src/models/em_conversation.dart @@ -6,199 +6,217 @@ import '../../im_flutter_sdk.dart'; import '../internal/chat_method_keys.dart'; import '../internal/em_transform_tools.dart'; -enum EMMessageSearchDirection { Up, Down } - +/// +/// The conversation class, which represents a conversation with a user/group/chat room and contains the messages that are sent and received. +/// +/// The following code shows how to get the number of the unread messages from the conversation. +/// ```dart +/// // ConversationId can be the other party id, the group id, or the chat room id. +/// EMConversation? con = await EMClient.getInstance.chatManager.getConversation(conversationId); +/// int? unreadCount = con?.unreadCount; +/// ``` +/// class EMConversation { - EMConversation._private(); + EMConversation._private( + this.id, + this.type, + this._ext, + ); + /// @nodoc factory EMConversation.fromJson(Map map) { Map? ext = map['ext']?.cast(); - String? name; - if (ext != null) { - if (ext.containsKey("con_name")) { - name = ext['con_name']!; - ext.remove('con_name'); - } - } + EMConversation ret = EMConversation._private( + map.getValueWithOutNull("con_id", ""), + conversationTypeFromInt(map['type']), + ext, + ); - EMConversation ret = EMConversation._private(); - ret.type = typeFromInt(map['type']); - ret.id = map['con_id']; - ret._unreadCount = map['unreadCount']; - ret._ext = ext; - ret._name = name ?? ''; - if (map['latestMessage'] != null) { - ret._latestMessage = EMMessage.fromJson(map['latestMessage']); - } - if (map['lastReceivedMessage'] != null) { - ret._lastReceivedMessage = EMMessage.fromJson(map['lastReceivedMessage']); - } return ret; } + /// @nodoc Map toJson() { final Map data = new Map(); - data['type'] = typeToInt(this.type); + data['type'] = conversationTypeToInt(this.type); data['con_id'] = this.id; return data; } - late String id; - late EMConversationType type; + /// + /// The conversation ID. + /// + /// For one-to-one chat,the conversation ID is the same with the other side's name. + /// For group chat, the conversation ID is the group ID, different with group name. + /// For chat room, the conversation ID is the chatroom ID, different with chat room name. + /// For help desk, it is the same with one-to-one chat, the conversation ID is also the other chat user's name. + /// + /// The conversation ID. + /// + final String id; + + /// + /// The conversation type. + /// + final EMConversationType type; - int _unreadCount = 0; Map? _ext; - String? _name; - EMMessage? _latestMessage; - EMMessage? _lastReceivedMessage; - - static int typeToInt(EMConversationType? type) { - int ret = 0; - if (type == null) return ret; - switch (type) { - case EMConversationType.Chat: - ret = 0; - break; - case EMConversationType.GroupChat: - ret = 1; - break; - case EMConversationType.ChatRoom: - ret = 2; - break; - } - return ret; - } - - static EMConversationType typeFromInt(int? type) { - EMConversationType ret = EMConversationType.Chat; - switch (type) { - case 0: - ret = EMConversationType.Chat; - break; - case 1: - ret = EMConversationType.GroupChat; - break; - case 2: - ret = EMConversationType.ChatRoom; - break; - } - return ret; - } } extension EMConversationExtension on EMConversation { static const MethodChannel _emConversationChannel = const MethodChannel('com.chat.im/chat_conversation', JSONMethodCodec()); - int get unreadCount { - return _unreadCount; - } - - EMMessage? get latestMessage { - return _latestMessage; - } + Map? get ext => _ext; - EMMessage? get lastReceivedMessage { - return _lastReceivedMessage; - } - - String get name { - if (this._name != null && this._name!.length > 0) - return this._name!; - else - return this.id; - } - - set name(String name) { - this._name = name; - _syncNameToNative(); - } - - Map? get ext { - return this._ext; + Future setExt(Map? ext) async { + Map req = this.toJson(); + req.setValueWithOutNull("ext", ext); + Map result = await _emConversationChannel.invokeMethod( + ChatMethodKeys.syncConversationExt, req); + try { + EMError.hasErrorFromResult(result); + _ext = ext; + } on EMError catch (e) { + throw e; + } } - set ext(Map? map) { - this._ext = map; - _syncExtToNative(); + Future latestMessage() async { + Map req = this.toJson(); + Map result = await _emConversationChannel.invokeMethod( + ChatMethodKeys.getLatestMessage, req); + try { + EMError.hasErrorFromResult(result); + if (result.containsKey(ChatMethodKeys.getLatestMessage)) { + return EMMessage.fromJson(result[ChatMethodKeys.getLatestMessage]); + } else { + return null; + } + } on EMError catch (e) { + throw e; + } } - Future _syncNameToNative() async { + Future lastReceivedMessageMessage() async { Map req = this.toJson(); - req['con_name'] = this._name ?? ''; - await _emConversationChannel.invokeMethod( - ChatMethodKeys.syncConversationName, req); + Map result = await _emConversationChannel.invokeMethod( + ChatMethodKeys.getLatestMessageFromOthers, req); + try { + EMError.hasErrorFromResult(result); + if (result.containsKey(ChatMethodKeys.getLatestMessageFromOthers)) { + return EMMessage.fromJson( + result[ChatMethodKeys.getLatestMessageFromOthers]); + } else { + return null; + } + } on EMError catch (e) { + throw e; + } } - Future _syncExtToNative() async { + Future unreadCount() async { Map req = this.toJson(); - req['ext'] = this._ext ?? ''; - await _emConversationChannel.invokeMethod( - ChatMethodKeys.syncConversationExt, req); + Map result = await _emConversationChannel.invokeMethod( + ChatMethodKeys.getUnreadMsgCount, req); + try { + EMError.hasErrorFromResult(result); + if (result.containsKey(ChatMethodKeys.getUnreadMsgCount)) { + return result[ChatMethodKeys.getUnreadMsgCount]; + } else { + return 0; + } + } on EMError catch (e) { + throw e; + } } /// 根据消息id设置消息已读,如果消息不属于当前会话则设置无效 - Future markMessageAsRead(String messageId) async { + Future markMessageAsRead(String messageId) async { Map req = this.toJson(); req['msg_id'] = messageId; Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.markMessageAsRead, req); - EMError.hasErrorFromResult(result); - return result.boolValue(ChatMethodKeys.markMessageAsRead); + try { + EMError.hasErrorFromResult(result); + } on EMError catch (e) { + throw e; + } } /// 设置当前会话中所有消息为已读 Future markAllMessagesAsRead() async { Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.markAllMessagesAsRead, this.toJson()); - EMError.hasErrorFromResult(result); + try { + EMError.hasErrorFromResult(result); + } on EMError catch (e) { + throw e; + } } /// 插入消息,插入的消息会根据消息时间插入到对应的位置 - Future insertMessage(EMMessage message) async { + Future insertMessage(EMMessage message) async { Map req = this.toJson(); req['msg'] = message.toJson(); Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.insertMessage, req); - EMError.hasErrorFromResult(result); - return result.boolValue(ChatMethodKeys.insertMessage); + try { + EMError.hasErrorFromResult(result); + } on EMError catch (e) { + throw e; + } } /// 添加消息,添加的消息会添加到最后一条消息的位置 - Future appendMessage(EMMessage message) async { + Future appendMessage(EMMessage message) async { Map req = this.toJson(); req['msg'] = message.toJson(); Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.appendMessage, req); - return result.boolValue(ChatMethodKeys.appendMessage); + try { + EMError.hasErrorFromResult(result); + } on EMError catch (e) { + throw e; + } } /// 更新消息 - Future updateMessage(EMMessage message) async { + Future updateMessage(EMMessage message) async { Map req = this.toJson(); req['msg'] = message.toJson(); Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.updateConversationMessage, req); EMError.hasErrorFromResult(result); - return result.boolValue(ChatMethodKeys.updateConversationMessage); + try { + EMError.hasErrorFromResult(result); + } on EMError catch (e) { + throw e; + } } /// 根据消息id [messageId] 删除消息 - Future deleteMessage(String messageId) async { + Future deleteMessage(String messageId) async { Map req = this.toJson(); req['msg_id'] = messageId; Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.removeMessage, req); - EMError.hasErrorFromResult(result); - return result.boolValue(ChatMethodKeys.removeMessage); + try { + EMError.hasErrorFromResult(result); + } on EMError catch (e) { + throw e; + } } // 删除当前会话中所有消息 - Future deleteAllMessages() async { + Future deleteAllMessages() async { Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.clearAllMessages, this.toJson()); - EMError.hasErrorFromResult(result); - return result.boolValue(ChatMethodKeys.clearAllMessages); + try { + EMError.hasErrorFromResult(result); + } on EMError catch (e) { + throw e; + } } /// 根据消息id获取消息,如果消息id不属于当前会话,则无法获取到 @@ -207,61 +225,71 @@ extension EMConversationExtension on EMConversation { req['msg_id'] = messageId; Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.loadMsgWithId, req); - EMError.hasErrorFromResult(result); - if (result[ChatMethodKeys.loadMsgWithId] != null) { - return EMMessage.fromJson(result[ChatMethodKeys.loadMsgWithId]); - } else { - return null; + try { + EMError.hasErrorFromResult(result); + if (result[ChatMethodKeys.loadMsgWithId] != null) { + return EMMessage.fromJson(result[ChatMethodKeys.loadMsgWithId]); + } else { + return null; + } + } on EMError catch (e) { + throw e; } } /// 根据类型获取当前会话汇总的消息 - Future> loadMessagesWithMsgType({ + Future?> loadMessagesWithMsgType({ required MessageType type, int timestamp = -1, int count = 20, String? sender, - EMMessageSearchDirection direction = EMMessageSearchDirection.Up, + EMSearchDirection direction = EMSearchDirection.Up, }) async { Map req = this.toJson(); req['type'] = messageTypeToTypeStr(type); req['timestamp'] = timestamp; req['count'] = count; req['sender'] = sender; - req['direction'] = direction == EMMessageSearchDirection.Up ? "up" : "down"; + req['direction'] = direction == EMSearchDirection.Up ? "up" : "down"; Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.loadMsgWithMsgType, req); - EMError.hasErrorFromResult(result); - - List list = []; - result[ChatMethodKeys.loadMsgWithMsgType]?.forEach((element) { - list.add(EMMessage.fromJson(element)); - }); - return list; + try { + EMError.hasErrorFromResult(result); + List list = []; + result[ChatMethodKeys.loadMsgWithMsgType]?.forEach((element) { + list.add(EMMessage.fromJson(element)); + }); + return list; + } on EMError catch (e) { + throw e; + } } /// 根据起始消息id获取消息 - Future> loadMessages({ + Future?> loadMessages({ String startMsgId = '', int loadCount = 20, - EMMessageSearchDirection direction = EMMessageSearchDirection.Up, + EMSearchDirection direction = EMSearchDirection.Up, }) async { Map req = this.toJson(); req["startId"] = startMsgId; req['count'] = loadCount; - req['direction'] = direction == EMMessageSearchDirection.Up ? "up" : "down"; + req['direction'] = direction == EMSearchDirection.Up ? "up" : "down"; Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.loadMsgWithStartId, req); - EMError.hasErrorFromResult(result); - - List msgList = []; - result[ChatMethodKeys.loadMsgWithStartId]?.forEach((element) { - msgList.add(EMMessage.fromJson(element)); - }); - return msgList; + try { + EMError.hasErrorFromResult(result); + List msgList = []; + result[ChatMethodKeys.loadMsgWithStartId]?.forEach((element) { + msgList.add(EMMessage.fromJson(element)); + }); + return msgList; + } on EMError catch (e) { + throw e; + } } Future> loadMessagesWithKeyword( @@ -269,7 +297,7 @@ extension EMConversationExtension on EMConversation { String? sender, int timestamp = -1, int count = 20, - EMMessageSearchDirection direction = EMMessageSearchDirection.Up, + EMSearchDirection direction = EMSearchDirection.Up, }) async { Map req = this.toJson(); req["keywords"] = keywords; @@ -278,18 +306,21 @@ extension EMConversationExtension on EMConversation { req['sender'] = sender; } req['timestamp'] = timestamp; - req['direction'] = direction == EMMessageSearchDirection.Up ? "up" : "down"; + req['direction'] = direction == EMSearchDirection.Up ? "up" : "down"; Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.loadMsgWithKeywords, req); - EMError.hasErrorFromResult(result); - - List msgList = []; - result[ChatMethodKeys.loadMsgWithKeywords]?.forEach((element) { - msgList.add(EMMessage.fromJson(element)); - }); - return msgList; + try { + EMError.hasErrorFromResult(result); + List msgList = []; + result[ChatMethodKeys.loadMsgWithKeywords]?.forEach((element) { + msgList.add(EMMessage.fromJson(element)); + }); + return msgList; + } on EMError catch (e) { + throw e; + } } Future> loadMessagesFromTime({ @@ -305,12 +336,15 @@ extension EMConversationExtension on EMConversation { Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.loadMsgWithTime, req); - EMError.hasErrorFromResult(result); - - List msgList = []; - result[ChatMethodKeys.loadMsgWithTime]?.forEach((element) { - msgList.add(EMMessage.fromJson(element)); - }); - return msgList; + try { + EMError.hasErrorFromResult(result); + List msgList = []; + result[ChatMethodKeys.loadMsgWithTime]?.forEach((element) { + msgList.add(EMMessage.fromJson(element)); + }); + return msgList; + } on EMError catch (e) { + throw e; + } } } diff --git a/lib/src/models/em_options.dart b/lib/src/models/em_options.dart index 5179cc42..7a7c01b8 100644 --- a/lib/src/models/em_options.dart +++ b/lib/src/models/em_options.dart @@ -110,9 +110,9 @@ class EMOptions { /// /// Sets whether to disable DNS. /// + /// `true`: (default) Enable DNS; + /// `false`: Do not enable DNS. /// - /// `true`: (default) Disable DNS; - /// `false`: Do not disable DNS. final bool enableDNSConfig; /// The DNS url. diff --git a/lib/src/models/em_userInfo.dart b/lib/src/models/em_userInfo.dart index f55dd17f..0ef92566 100644 --- a/lib/src/models/em_userInfo.dart +++ b/lib/src/models/em_userInfo.dart @@ -68,7 +68,7 @@ class EMUserInfo { /// /// Param [ext] The user's extension information. You can set it to an empty string or type custom information and encapsulate them as a JSON string. /// - /// **return** The userInfo instance. + /// **return** The new userInfo instance. /// EMUserInfo copyWith({ String? nickName, From 7e5de403b1fe88df88591652e98e7aef30ca8f12 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Sat, 2 Apr 2022 19:00:23 +0800 Subject: [PATCH 30/56] update api referance. --- lib/im_flutter_sdk.dart | 4 +- lib/src/models/em_chat_enums.dart | 26 ++++ lib/src/models/em_conversation.dart | 208 +++++++++++++++++++++++---- lib/src/models/em_cursor_result.dart | 33 +++-- lib/src/models/em_deviceInfo.dart | 45 +++--- lib/src/models/em_error.dart | 26 ++-- lib/src/models/em_message.dart | 4 +- 7 files changed, 274 insertions(+), 72 deletions(-) diff --git a/lib/im_flutter_sdk.dart b/lib/im_flutter_sdk.dart index 873957d6..fc61269a 100644 --- a/lib/im_flutter_sdk.dart +++ b/lib/im_flutter_sdk.dart @@ -2,9 +2,9 @@ library im_flutter_sdk; export 'src/em_client.dart'; -export 'src/models/em_group_message_ack.dart'; -// export 'src/tools/em_log.dart'; export 'src/em_listeners.dart'; + +export 'src/models/em_group_message_ack.dart'; export 'src/models/em_chat_room.dart'; export 'src/models/em_conversation.dart'; export 'src/models/em_cursor_result.dart'; diff --git a/lib/src/models/em_chat_enums.dart b/lib/src/models/em_chat_enums.dart index 4a449681..edc1fe4a 100644 --- a/lib/src/models/em_chat_enums.dart +++ b/lib/src/models/em_chat_enums.dart @@ -128,21 +128,47 @@ enum MessageType { CUSTOM, } +/// +/// The enum of the group permission types. +/// enum EMGroupPermissionType { + /// The unknown type. None, + + /// The group member. Member, + + /// The group admin. Admin, + + /// The group owner. Owner, } +/// +/// Chat room role types. +/// enum EMChatRoomPermissionType { + /// Unknown type. None, + + /// Regular member. Member, + + /// Chat room admin. Admin, + + /// Chat room owner. Owner, } +/// +/// The message search direction type. +/// enum EMSearchDirection { + /// The search older messages type Up, + + /// The search newer messages type. Down, } diff --git a/lib/src/models/em_conversation.dart b/lib/src/models/em_conversation.dart index dea0c2de..17951f49 100644 --- a/lib/src/models/em_conversation.dart +++ b/lib/src/models/em_conversation.dart @@ -36,7 +36,7 @@ class EMConversation { } /// @nodoc - Map toJson() { + Map _toJson() { final Map data = new Map(); data['type'] = conversationTypeToInt(this.type); data['con_id'] = this.id; @@ -70,7 +70,7 @@ extension EMConversationExtension on EMConversation { Map? get ext => _ext; Future setExt(Map? ext) async { - Map req = this.toJson(); + Map req = this._toJson(); req.setValueWithOutNull("ext", ext); Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.syncConversationExt, req); @@ -82,8 +82,17 @@ extension EMConversationExtension on EMConversation { } } + /// + /// Gets the last message from the conversation. + /// + /// The operation does not change the unread message count. + /// + /// Gets from the cache first, if no message is found, loads from the local database and then put it in the cache. + /// + /// **return** The message instance. + /// Future latestMessage() async { - Map req = this.toJson(); + Map req = this._toJson(); Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.getLatestMessage, req); try { @@ -98,8 +107,13 @@ extension EMConversationExtension on EMConversation { } } - Future lastReceivedMessageMessage() async { - Map req = this.toJson(); + /// + /// Gets the latest message from the conversation. + /// + /// **return** The message instance. + /// + Future lastReceivedMessage() async { + Map req = this._toJson(); Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.getLatestMessageFromOthers, req); try { @@ -115,8 +129,15 @@ extension EMConversationExtension on EMConversation { } } + /// + /// Gets the number of unread messages of the conversation. + /// + /// **return** The unread message count of the conversation. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future unreadCount() async { - Map req = this.toJson(); + Map req = this._toJson(); Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.getUnreadMsgCount, req); try { @@ -131,9 +152,15 @@ extension EMConversationExtension on EMConversation { } } - /// 根据消息id设置消息已读,如果消息不属于当前会话则设置无效 + /// + /// Marks a message as read. + /// + /// Param [messageId] The message ID. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future markMessageAsRead(String messageId) async { - Map req = this.toJson(); + Map req = this._toJson(); req['msg_id'] = messageId; Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.markMessageAsRead, req); @@ -144,10 +171,12 @@ extension EMConversationExtension on EMConversation { } } - /// 设置当前会话中所有消息为已读 + /// + /// Marks all messages as read. + /// Future markAllMessagesAsRead() async { Map result = await _emConversationChannel.invokeMethod( - ChatMethodKeys.markAllMessagesAsRead, this.toJson()); + ChatMethodKeys.markAllMessagesAsRead, this._toJson()); try { EMError.hasErrorFromResult(result); } on EMError catch (e) { @@ -155,9 +184,17 @@ extension EMConversationExtension on EMConversation { } } - /// 插入消息,插入的消息会根据消息时间插入到对应的位置 + /// + /// Inserts a message to a conversation in local database and SDK will update the last message automatically. + /// + /// The conversation ID of the message should be the same as conversation ID of the conversation in order to insert the message into the conversation correctly. The inserting message will be inserted based on timestamp. + /// + /// Param [message] The message instance. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future insertMessage(EMMessage message) async { - Map req = this.toJson(); + Map req = this._toJson(); req['msg'] = message.toJson(); Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.insertMessage, req); @@ -168,9 +205,17 @@ extension EMConversationExtension on EMConversation { } } - /// 添加消息,添加的消息会添加到最后一条消息的位置 + /// + /// Inserts a message to the end of a conversation in the local database. + /// + /// The `conversationId` of the message should be the same as the `conversationId` of the conversation in order to insert the message into the conversation correctly. And the `latestMessage` and other properties of the session should be updated. + /// + /// Param [message] The message instance. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future appendMessage(EMMessage message) async { - Map req = this.toJson(); + Map req = this._toJson(); req['msg'] = message.toJson(); Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.appendMessage, req); @@ -181,9 +226,17 @@ extension EMConversationExtension on EMConversation { } } - /// 更新消息 + /// + /// Uses this method to update a message in local database. Changing properties will affect data in database. + /// + /// The latestMessage of the conversation and other properties will be updated accordingly. The messageID of the message cannot be updated. + /// + /// Param [message] The message to be updated. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future updateMessage(EMMessage message) async { - Map req = this.toJson(); + Map req = this._toJson(); req['msg'] = message.toJson(); Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.updateConversationMessage, req); @@ -195,9 +248,17 @@ extension EMConversationExtension on EMConversation { } } - /// 根据消息id [messageId] 删除消息 + /// + /// Deletes a message in the local database. + /// + /// Note: Operates only on the local database. + /// + /// Param [messageId] The message id to be deleted. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future deleteMessage(String messageId) async { - Map req = this.toJson(); + Map req = this._toJson(); req['msg_id'] = messageId; Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.removeMessage, req); @@ -208,10 +269,14 @@ extension EMConversationExtension on EMConversation { } } - // 删除当前会话中所有消息 + /// + /// Deletes all the messages of the conversation from the memory cache and local database. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future deleteAllMessages() async { Map result = await _emConversationChannel.invokeMethod( - ChatMethodKeys.clearAllMessages, this.toJson()); + ChatMethodKeys.clearAllMessages, this._toJson()); try { EMError.hasErrorFromResult(result); } on EMError catch (e) { @@ -219,9 +284,20 @@ extension EMConversationExtension on EMConversation { } } - /// 根据消息id获取消息,如果消息id不属于当前会话,则无法获取到 + /// + /// Gets the message with message ID. + /// + /// If the message already loaded into the memory cache, the message will be directly returned, + /// otherwise the message will be loaded from the local database, and be set into the cache. + /// + /// Param [messageId] The message ID. + /// + /// **return** The message instance. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future loadMessage(String messageId) async { - Map req = this.toJson(); + Map req = this._toJson(); req['msg_id'] = messageId; Map result = await _emConversationChannel.invokeMethod( ChatMethodKeys.loadMsgWithId, req); @@ -237,7 +313,28 @@ extension EMConversationExtension on EMConversation { } } - /// 根据类型获取当前会话汇总的消息 + /// + /// Searches messages from the local database according the following parameters: the message type, the Unix timestamp, max count, sender. + /// + /// Note: + /// Be cautious about the memory usage when the maxCount is large. + /// + /// Param [type] The message type, including TXT、VOICE、IMAGE and so on. + /// + /// Param [timestamp] The Unix timestamp for search. + /// + /// Param [count] The max number of message to search. + /// + /// Param [sender] The sender of the message. The param can also be used to search in group chat. + /// + /// Param [direction] The direction in which the message is loaded: EMSearchDirection. + /// `EMSearchDirection.Up`: get aCount of messages before the timestamp of the specified message ID; + /// `EMSearchDirection.Down`: get aCount of messages after the timestamp of the specified message ID. + /// + /// **return** The message list. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future?> loadMessagesWithMsgType({ required MessageType type, int timestamp = -1, @@ -245,7 +342,7 @@ extension EMConversationExtension on EMConversation { String? sender, EMSearchDirection direction = EMSearchDirection.Up, }) async { - Map req = this.toJson(); + Map req = this._toJson(); req['type'] = messageTypeToTypeStr(type); req['timestamp'] = timestamp; req['count'] = count; @@ -266,13 +363,32 @@ extension EMConversationExtension on EMConversation { } } - /// 根据起始消息id获取消息 + /// + /// Loads more messages from the local database. + /// + /// Loads messages from the local database before the specified message. + /// + /// The messages will also be stored in to current conversation's memory cache. + /// So when next time calling {@link #getAllMessages()}, the result will contain those messages. + /// + /// Param [startMsgId] The specified message ID. If the `startMsgId` is set as "" or null, the SDK will load latest messages in database. + /// + /// Param [loadCount] The number of records in a page. + /// + /// Param [direction] The direction in which the message is loaded: EMSearchDirection. + /// `EMSearchDirection.Up`: get aCount of messages before the timestamp of the specified message ID; + /// `EMSearchDirection.Down`: get aCount of messages after the timestamp of the specified message ID. + /// + /// **return** The message list. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future?> loadMessages({ String startMsgId = '', int loadCount = 20, EMSearchDirection direction = EMSearchDirection.Up, }) async { - Map req = this.toJson(); + Map req = this._toJson(); req["startId"] = startMsgId; req['count'] = loadCount; req['direction'] = direction == EMSearchDirection.Up ? "up" : "down"; @@ -292,6 +408,27 @@ extension EMConversationExtension on EMConversation { } } + /// + /// Searches messages from the local database by the following parameters: keywords, timestamp, max count, sender, search direction. + /// + /// Note: Be cautious about memory usage when the maxCount is large. + /// + /// Param [keywords] The keywords in message. + /// + /// Param [sender] The message sender. The param can also be used to search in group chat. + /// + /// Param [timestamp] The timestamp for search. + /// + /// Param [count] The max number of message to search. + /// + /// Param [direction] The direction in which the message is loaded: EMSearchDirection. + /// `EMSearchDirection.Up`: get aCount of messages before the timestamp of the specified message ID; + /// `EMSearchDirection.Down`: get aCount of messages after the timestamp of the specified message ID. + /// + /// **returns** The list of searched messages. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future> loadMessagesWithKeyword( String keywords, { String? sender, @@ -299,7 +436,7 @@ extension EMConversationExtension on EMConversation { int count = 20, EMSearchDirection direction = EMSearchDirection.Up, }) async { - Map req = this.toJson(); + Map req = this._toJson(); req["keywords"] = keywords; req['count'] = count; if (sender != null) { @@ -323,12 +460,27 @@ extension EMConversationExtension on EMConversation { } } + /// + /// Searches messages from the local database according the following parameters. + /// + /// Note: Be cautious about the memory usage when the maxCount is large. + /// + /// Param [startTime] The start Unix timestamp to search. + /// + /// Param [endTime] The end Unix timestamp to search. + /// + /// Param [count] The max number of message to search. + /// + /// **returns** The list of searched messages. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Future> loadMessagesFromTime({ required int startTime, required int endTime, int count = 20, }) async { - Map req = this.toJson(); + Map req = this._toJson(); req["startTime"] = startTime; req['endTime'] = endTime; req['count'] = count; diff --git a/lib/src/models/em_cursor_result.dart b/lib/src/models/em_cursor_result.dart index b51ee49d..1802acdf 100644 --- a/lib/src/models/em_cursor_result.dart +++ b/lib/src/models/em_cursor_result.dart @@ -1,23 +1,36 @@ typedef CursorResultCallback = Object Function(dynamic obj); +/// +/// This is a generic class with cursors and paging to get results. +/// Returns an instance with the list and the cursor. +/// +/// For example: +/// ```dart +/// String? cursor; +/// EMCursorResult result = await EMClient.getInstance.groupManager.getPublicGroupsFromServer(pageSize: 10, cursor: cursor); +/// List? group = result.data; +/// cursor = result.cursor; +/// ``` +/// class EMCursorResult { - EMCursorResult._private(); + EMCursorResult._private( + this.cursor, + this.data, + ); factory EMCursorResult.fromJson(Map map, {dataItemCallback: CursorResultCallback}) { - EMCursorResult result = EMCursorResult._private() - .._cursor = map['cursor'] - .._data = []; - + List list = []; (map['list'] as List) - .forEach((element) => result._data!.add(dataItemCallback(element))); + .forEach((element) => list.add(dataItemCallback(element))); + EMCursorResult result = EMCursorResult._private(map['cursor'], list); return result; } - String? _cursor; - List? _data; + /// The cursor. + final String? cursor; - String? get cursor => _cursor; - List? get data => _data; + /// The data; + final List data; } diff --git a/lib/src/models/em_deviceInfo.dart b/lib/src/models/em_deviceInfo.dart index 04245b9f..01c96f72 100644 --- a/lib/src/models/em_deviceInfo.dart +++ b/lib/src/models/em_deviceInfo.dart @@ -1,31 +1,40 @@ +import '../tools/em_extension.dart'; + +/// +/// The Multi-device information. +/// class EMDeviceInfo { - EMDeviceInfo._private(); + EMDeviceInfo._private( + this.resource, + this.deviceUUID, + this.deviceName, + ); + /// @nodoc Map toJson() { Map data = Map(); - data['resource'] = _resource; - data['deviceUUID'] = _deviceUUID; - data['deviceName'] = _deviceName; + data.setValueWithOutNull("resource", resource); + data.setValueWithOutNull("deviceUUID", deviceUUID); + data.setValueWithOutNull("deviceName", deviceName); + return data; } + /// @nodoc factory EMDeviceInfo.fromJson(Map map) { - return EMDeviceInfo._private() - .._resource = map['resource'] - .._deviceUUID = map['deviceUUID'] - .._deviceName = map['deviceName']; + return EMDeviceInfo._private( + map.getValue("resource"), + map.getValue("deviceUUID"), + map.getValue("deviceName"), + ); } - /// 设备资源描述 - String? get resource => _resource; - - /// 设备的UUID - String? get deviceUUID => _deviceUUID; + /// The other devices‘ information. + final String? resource; - /// 设备名称 - String? get deviceName => _deviceName; + /// The UUID of the device. + final String? deviceUUID; - String? _resource; - String? _deviceUUID; - String? _deviceName; + /// The device type. For example: "Pixel 6 Pro". + final String? deviceName; } diff --git a/lib/src/models/em_error.dart b/lib/src/models/em_error.dart index 76c711dd..7c1aa620 100644 --- a/lib/src/models/em_error.dart +++ b/lib/src/models/em_error.dart @@ -1,23 +1,25 @@ +/// +/// The error defined by the SDK. +/// class EMError { - EMError._private([int? code, String? desc]) - : _code = code ?? 0, - _description = desc ?? ""; + EMError._private(this.code, this.description); - late int _code; - late String _description; + /// + /// The error code. + /// + final int code; - int get code { - return _code; - } - - String get description { - return _description; - } + /// + /// The error description. + /// + final String description; + /// @nodoc factory EMError.fromJson(Map map) { return EMError._private(map['code'], map['description']); } + /// @nodoc static hasErrorFromResult(Map map) { if (map['error'] == null) { return; diff --git a/lib/src/models/em_message.dart b/lib/src/models/em_message.dart index f4952388..335825bb 100644 --- a/lib/src/models/em_message.dart +++ b/lib/src/models/em_message.dart @@ -349,14 +349,14 @@ class EMMessage { /// 消息id String? _msgId; - String msgLocalId = DateTime.now().millisecondsSinceEpoch.toString() + + String _msgLocalId = DateTime.now().millisecondsSinceEpoch.toString() + Random().nextInt(99999).toString(); /// /// Gets the message ID. /// /// **return** The message ID. - String get msgId => _msgId ?? msgLocalId; + String get msgId => _msgId ?? _msgLocalId; /// /// The conversation ID. From 6a550a09d793a08507f849e724f34d1989252890 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Sun, 3 Apr 2022 13:42:22 +0800 Subject: [PATCH 31/56] update --- .../lib/pages/group/public_groups_page.dart | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/example/lib/pages/group/public_groups_page.dart b/example/lib/pages/group/public_groups_page.dart index f889bc2e..4b0f88f3 100644 --- a/example/lib/pages/group/public_groups_page.dart +++ b/example/lib/pages/group/public_groups_page.dart @@ -151,14 +151,12 @@ class PublicGroupsPageState extends State { ); _refreshController.loadComplete(); _cursor = cursor.cursor; - if (cursor.data != null) { - _groupsList.addAll(cursor.data!); - // 返回数据小于pageSize,说明是最后一页 - if (_pageSize > cursor.data!.length) { - _isEnd = true; - if (mounted) { - setState(() {}); - } + _groupsList.addAll(cursor.data); + // 返回数据小于pageSize,说明是最后一页 + if (_pageSize > cursor.data.length) { + _isEnd = true; + if (mounted) { + setState(() {}); } } } on EMError catch (e) { @@ -176,12 +174,12 @@ class PublicGroupsPageState extends State { pageSize: _pageSize, ); _refreshController.refreshCompleted(); - if (_pageSize > cursor.data!.length) { + if (_pageSize > cursor.data.length) { _isEnd = true; } _cursor = cursor.cursor; _groupsList.clear(); - _groupsList.addAll(cursor.data!); + _groupsList.addAll(cursor.data); SmartDialog.showToast('获取成功'); if (mounted) { setState(() {}); From 71eb9643f60695834d523a55446457d3a041b958 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Sun, 3 Apr 2022 19:38:41 +0800 Subject: [PATCH 32/56] update api referance. --- example/lib/pages/contacts/contacts_page.dart | 2 +- lib/src/em_chat_room_manager.dart | 1 + lib/src/em_client.dart | 12 +- lib/src/em_contact_manager.dart | 16 +- lib/src/em_group_manager.dart | 1 + lib/src/em_listeners.dart | 666 ++++++++++++++---- lib/src/internal/em_event_keys.dart | 44 ++ lib/src/internal/em_transform_tools.dart | 56 +- lib/src/models/em_chat_enums.dart | 82 +++ 9 files changed, 690 insertions(+), 190 deletions(-) diff --git a/example/lib/pages/contacts/contacts_page.dart b/example/lib/pages/contacts/contacts_page.dart index 113b4675..67e0c7eb 100644 --- a/example/lib/pages/contacts/contacts_page.dart +++ b/example/lib/pages/contacts/contacts_page.dart @@ -17,7 +17,7 @@ class ContactsPage extends StatefulWidget { } class ContactsPageState extends State - implements EMContactEventListener { + implements EMContactManagerListener { List _contactList = []; List _topList = [ ContactModel.custom('新的好友'), diff --git a/lib/src/em_chat_room_manager.dart b/lib/src/em_chat_room_manager.dart index 318aa6ab..d3a41a0d 100644 --- a/lib/src/em_chat_room_manager.dart +++ b/lib/src/em_chat_room_manager.dart @@ -1,6 +1,7 @@ import "dart:async"; import 'package:flutter/services.dart'; +import 'internal/em_event_keys.dart'; import 'tools/em_extension.dart'; import 'internal/chat_method_keys.dart'; import '../im_flutter_sdk.dart'; diff --git a/lib/src/em_client.dart b/lib/src/em_client.dart index 548bceb7..96a9cfec 100644 --- a/lib/src/em_client.dart +++ b/lib/src/em_client.dart @@ -452,11 +452,17 @@ class EMClient { var event = map['event']; for (var listener in _multiDeviceListeners) { if (event >= 10) { - listener.onGroupEvent(convertIntToEMContactGroupEvent(event), - map['target'], map['userNames']); + listener.onGroupEvent( + convertIntToEMContactGroupEvent(event)!, + map['target'], + map['userNames'], + ); } else { listener.onContactEvent( - convertIntToEMContactGroupEvent(event), map['target'], map['ext']); + convertIntToEMContactGroupEvent(event)!, + map['target'], + map['ext'], + ); } } } diff --git a/lib/src/em_contact_manager.dart b/lib/src/em_contact_manager.dart index d23df700..e4b0fbf1 100644 --- a/lib/src/em_contact_manager.dart +++ b/lib/src/em_contact_manager.dart @@ -26,13 +26,13 @@ class EMContactManager { }); } - final List _contactChangeEventListeners = []; + final List _contactManagerListeners = []; Future _onContactChanged(Map event) async { var type = event['type']; - String? username = event['username']; + String username = event['username']; String? reason = event['reason']; - for (var listener in _contactChangeEventListeners) { + for (var listener in _contactManagerListeners) { switch (type) { case EMContactChangeEvent.CONTACT_ADD: listener.onContactAdded(username); @@ -290,8 +290,8 @@ class EMContactManager { /// /// Param [contactListener] The contact listener to be registered. /// - void addContactListener(EMContactEventListener contactListener) { - _contactChangeEventListeners.add(contactListener); + void addContactListener(EMContactManagerListener contactListener) { + _contactManagerListeners.add(contactListener); } /// @@ -299,9 +299,9 @@ class EMContactManager { /// /// Param [contactListener] The contact listener to be removed. /// - void removeContactListener(EMContactEventListener contactListener) { - if (_contactChangeEventListeners.contains(contactListener)) { - _contactChangeEventListeners.remove(contactListener); + void removeContactListener(EMContactManagerListener contactListener) { + if (_contactManagerListeners.contains(contactListener)) { + _contactManagerListeners.remove(contactListener); } } } diff --git a/lib/src/em_group_manager.dart b/lib/src/em_group_manager.dart index a298b966..efa93556 100644 --- a/lib/src/em_group_manager.dart +++ b/lib/src/em_group_manager.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:flutter/services.dart'; import 'em_listeners.dart'; +import 'internal/em_event_keys.dart'; import 'models/em_cursor_result.dart'; import 'models/em_error.dart'; import 'models/em_group.dart'; diff --git a/lib/src/em_listeners.dart b/lib/src/em_listeners.dart index 0ba467f0..281200a1 100644 --- a/lib/src/em_listeners.dart +++ b/lib/src/em_listeners.dart @@ -1,32 +1,91 @@ import '../im_flutter_sdk.dart'; +/// +/// The chat connection listener. +/// +/// For the occasion of onDisconnected during unstable network condition, you don't need to reconnect manually, +/// the chat SDK will handle it automatically. +/// +/// There are only two states: onConnected, onDisconnected. +/// +/// Note: We recommend not to update UI based on those methods, because this method is called on worker thread. If you update UI in those methods, other UI errors might be invoked. +/// Also do not insert heavy computation work here, which might invoke other listeners to handle this connection event. +/// +/// Register: +/// ```dart +/// EMClient.getInstance.addConnectionListener(mConnectionListener); +/// ``` +/// +/// Unregister: +/// ```dart +/// EMClient.getInstance.removeConnectionListener(mConnectionListener); +/// ``` +/// abstract class EMConnectionListener { - /// 网络已连接 + /// + /// Occurs when the SDK connects to the chat server successfully. + /// void onConnected(); - /// 连接失败,原因是[errorCode] + /// + /// Occurs when the SDK disconnect from the chat server. + /// + /// Note that the logout may not be performed at the bottom level when the SDK is disconnected. + /// void onDisconnected(int? errorCode); - /// token 即将过期 + /// + /// Occurs when the token is about to expire. + /// void onTokenWillExpire(); - /// token 已经过期 + /// + /// Occurs when the token has expired. + /// void onTokenDidExpire(); } -/// @nodoc +/// +/// The multi-device event listener. +/// Listens for callback for the current user's actions on other devices, including contact changes and group changes. +/// +/// Registers a multi-device event listener: +/// ```dart +/// EMClient.getInstance.addMultiDeviceListener(mMultiDeviceListener); +/// ``` +/// +/// Removes a multi-device event listener: +/// ```dart +/// EMClient.getInstance.removeMultiDeviceListener(mMultiDeviceListener); +/// ``` abstract class EMMultiDeviceListener { - /// @nodoc + /// + /// The multi-device event callback of contact. + /// + /// Param [event] The event type. + /// + /// Param [username] The username. + /// + /// Param [ext] The extended Information. + /// void onContactEvent( - EMContactGroupEvent? event, - String? target, + EMMultiDevicesEvent event, + String username, String? ext, ); - /// @nodoc + /// + /// The multi-device event callback of group. + /// + /// Param [event] The event type. + /// + /// Param [groupId] The group ID. + /// + /// Param [usernames] The userIds. + /// void onGroupEvent( - EMContactGroupEvent? event, - String? target, + EMMultiDevicesEvent event, + String groupId, List? usernames, ); } @@ -35,148 +94,216 @@ abstract class EMCustomListener { void onDataReceived(Map map); } -/// @nodoc -enum EMContactGroupEvent { - CONTACT_REMOVE, - CONTACT_ACCEPT, - CONTACT_DECLINE, - CONTACT_BAN, - CONTACT_ALLOW, - GROUP_CREATE, - GROUP_DESTROY, - GROUP_JOIN, - GROUP_LEAVE, - GROUP_APPLY, - GROUP_APPLY_ACCEPT, - GROUP_APPLY_DECLINE, - GROUP_INVITE, - GROUP_INVITE_ACCEPT, - GROUP_INVITE_DECLINE, - GROUP_KICK, - GROUP_BAN, - GROUP_ALLOW, - GROUP_BLOCK, - GROUP_UNBLOCK, - GROUP_ASSIGN_OWNER, - GROUP_ADD_ADMIN, - GROUP_REMOVE_ADMIN, - GROUP_ADD_MUTE, - GROUP_REMOVE_MUTE, -} - -abstract class EMContactEventListener { - /// 被[userName]添加为好友 - void onContactAdded(String? userName); +/// +/// The contact updates listener. +/// +/// Listen for the contact changes, including requests to add friends, notifications to delete friends, +/// requests to accept friends, and requests to reject friends. +/// +/// Register listener: +/// ```dart +/// EMClient.getInstance.contactManager.addContactListener(contactListener); +/// ``` +/// +/// Unregister listener: +/// ```dart +/// EMClient.getInstance.contactManager.removeContactListener(contactListener); +/// ``` +/// +abstract class EMContactManagerListener { + /// + /// Occurs when user is added as a contact by another user. + /// + /// Param [userName] The new contact to be added. + /// + void onContactAdded(String userName); - /// 被[userName]从好友中删除 + /// + /// Occurs when a user is removed from the contact list by another user. + /// + /// Param [userName] The user who is removed from the contact list by another user. + /// void onContactDeleted(String? userName); - /// 收到[userName]的好友申请,原因是[reason] - void onContactInvited(String? userName, String? reason); - - /// 发出的好友申请被[userName]同意 - void onFriendRequestAccepted(String? userName); - - /// 发出的好友申请被[userName]拒绝 /// - void onFriendRequestDeclined(String? userName); -} + /// Occurs when a user receives a friend request. + /// + /// Param [userName] The user who initiated the friend request. + /// + /// Param [reason] The invitation message. + /// + void onContactInvited(String userName, String? reason); -abstract class EMConversationListener { - void onConversationUpdate(); -} + /// + /// Occurs when a friend request is approved. + /// + /// Param [userName] The user who initiated the friend request. + /// + void onFriendRequestAccepted(String userName); -/// @nodoc -class EMChatRoomEvent { - static const String ON_CHAT_ROOM_DESTROYED = "onChatRoomDestroyed"; - static const String ON_MEMBER_JOINED = "onMemberJoined"; - static const String ON_MEMBER_EXITED = "onMemberExited"; - static const String ON_REMOVED_FROM_CHAT_ROOM = "onRemovedFromChatRoom"; - static const String ON_MUTE_LIST_ADDED = "onMuteListAdded"; - static const String ON_MUTE_LIST_REMOVED = "onMuteListRemoved"; - static const String ON_ADMIN_ADDED = "onAdminAdded"; - static const String ON_ADMIN_REMOVED = "onAdminRemoved"; - static const String ON_OWNER_CHANGED = "onOwnerChanged"; - static const String ON_ANNOUNCEMENT_CHANGED = "onAnnouncementChanged"; - static const String ON_WHITE_LIST_REMOVED = "onWhiteListRemoved"; - static const String ON_WHITE_LIST_ADDED = "onWhiteListAdded"; - static const String ON_ALL_MEMBER_MUTE_STATE_CHANGED = - "onAllMemberMuteStateChanged"; + /// + /// Occurs when a friend request is declined. + /// + /// Param [userName] The user who initiated the friend request. + /// + void onFriendRequestDeclined(String userName); } +// abstract class EMConversationListener { +// void onConversationUpdate(); +// } + +/// +/// The chat room change listener. +/// +/// Register chat room change listener: +/// ```dart +/// EMClient.getInstance.chatRoomManager.addChatRoomChangeListener(listener); +/// ``` +/// +///Unregister chat room change listener: +/// ```dart +/// EMClient.getInstance.chatRoomManager.removeChatRoomListener(listener); +/// ``` +/// abstract class EMChatRoomEventListener { - /// id是[roomId],名称是[roomName]的聊天室被销毁 + /// + /// Occurs when the chat room is destroyed. + /// + /// Param [roomId] The chatroom ID. + /// + /// Param [roomName] The chatroom subject. + /// void onChatRoomDestroyed(String roomId, String? roomName); - /// 有用户[participant]加入id是[roomId]的聊天室 + /// + /// Occurs when a member join the chatroom. + /// + /// Param [roomId] The chatroom ID. + /// + /// Param [participant] The new member's username. + /// void onMemberJoinedFromChatRoom(String roomId, String participant); - /// 有用户[participant]离开id是[roomId],名字是[roomName]的聊天室 + /// + /// Occurs when a member leaves the chatroom. + /// + /// Param [roomId] The chatroom ID. + /// + /// Param [participant] The new member's username. + /// void onMemberExitedFromChatRoom( String roomId, String? roomName, String participant); - /// 用户[participant]被id是[roomId],名称[roomName]的聊天室删除 + /// + /// Occurs when a member is dismissed from a chat room. + /// + /// Param [roomId] The chatroom ID. + /// + /// Param [roomName] The chatroom subject. + /// + /// Param [participant] The member is dismissed from a chat room. + /// void onRemovedFromChatRoom( - String roomId, String? roomName, String? participant); + String roomId, + String? roomName, + String? participant, + ); - /// @nodoc id是[roomId]的聊天室禁言列表[mutes]有增加 + /// + /// Occurs when there are chat room member(s) muted (added to mute list), + /// + /// Param [roomId] The chatroom ID. + /// + /// Param [mutes] The members to be muted. + /// + /// Param [expireTime] The mute duration. + /// void onMuteListAddedFromChatRoom( - String roomId, List mutes, String? expireTime); + String roomId, + List mutes, + String? expireTime, + ); - /// @nodoc id是[roomId]的聊天室禁言列表[mutes]有减少 - void onMuteListRemovedFromChatRoom(String roomId, List mutes); + /// + /// Occurs when there are chat room member(s) unmuted (removed from mute list). + /// + /// Param [roomId] The chatroom ID. + /// + /// Param [mutes] The member(s) muted is removed from the mute list. + /// + void onMuteListRemovedFromChatRoom( + String roomId, + List mutes, + ); - /// @nodoc id是[roomId]的聊天室增加id是[admin]管理员 + /// + /// Occurs when a member has been changed to an admin. + /// + /// Param [roomId] The chatroom ID. + /// + /// Param [admin] The member who has been changed to an admin. + /// void onAdminAddedFromChatRoom(String roomId, String admin); - /// @nodoc id是[roomId]的聊天室移除id是[admin]管理员 + /// + /// Occurs when an admin is been removed. + /// + /// Param [roomId] The chatroom ID. + /// + /// Param [admin] The member whose admin permission is removed. + /// void onAdminRemovedFromChatRoom(String roomId, String admin); - /// @nodoc id是[roomId]的聊天室所有者由[oldOwner]变更为[newOwner] + /// + /// Occurs when the chat room ownership has been transferred. + /// + /// Param [roomId] The chatroom ID. + /// + /// Param [newOwner] The new owner. + /// + /// Param [oldOwner] The previous owner. + /// void onOwnerChangedFromChatRoom( String roomId, String newOwner, String oldOwner); - /// @nodoc id是[roomId]的聊天室公告变为[announcement] + /// + /// Occurs when the announcement changed. + /// + /// Param [roomId] The chatroom ID. + /// + /// Param [announcement] The changed announcement. + /// void onAnnouncementChangedFromChatRoom(String roomId, String announcement); - /// 有用户被添加到聊天室白名单 + /// + /// Occurs when the chat room member(s) is added to the allowlist. + /// + /// Param [roomId] The chatroom ID. + /// + /// Param [members] The member(s) to be added to the allowlist. + /// void onWhiteListAddedFromChatRoom(String roomId, List members); - /// 有用户从聊天室白名单被移除 + /// + /// Occurs when the chat room member(s) is removed from the allowlist. + /// + /// Param [roomId] The chatroom ID. + /// + /// Param [members] The member(s) is removed from the allowlist. + /// void onWhiteListRemovedFromChatRoom(String roomId, List members); - /// 聊天室禁言状态发生变化 + /// + /// Occurs when all members in the chat room are muted or unmuted. + /// + /// Param [roomId] The chatroom ID. + /// + /// Param [isAllMuted] Whether all chat room members is muted or unmuted. + /// void onAllChatRoomMemberMuteStateChanged(String roomId, bool isAllMuted); } -/// @nodoc -class EMGroupChangeEvent { - static const String ON_INVITATION_RECEIVED = "onInvitationReceived"; - static const String ON_INVITATION_ACCEPTED = "onInvitationAccepted"; - static const String ON_INVITATION_DECLINED = "onInvitationDeclined"; - static const String ON_AUTO_ACCEPT_INVITATION = - "onAutoAcceptInvitationFromGroup"; - static const String ON_USER_REMOVED = "onUserRemoved"; - static const String ON_REQUEST_TO_JOIN_RECEIVED = "onRequestToJoinReceived"; - static const String ON_REQUEST_TO_JOIN_DECLINED = "onRequestToJoinDeclined"; - static const String ON_REQUEST_TO_JOIN_ACCEPTED = "onRequestToJoinAccepted"; - static const String ON_GROUP_DESTROYED = "onGroupDestroyed"; - static const String ON_MUTE_LIST_ADDED = "onMuteListAdded"; - static const String ON_MUTE_LIST_REMOVED = "onMuteListRemoved"; - static const String ON_ADMIN_ADDED = "onAdminAdded"; - static const String ON_ADMIN_REMOVED = "onAdminRemoved"; - static const String ON_OWNER_CHANGED = "onOwnerChanged"; - static const String ON_MEMBER_JOINED = "onMemberJoined"; - static const String ON_MEMBER_EXITED = "onMemberExited"; - static const String ON_ANNOUNCEMENT_CHANGED = "onAnnouncementChanged"; - static const String ON_SHARED_FILE_ADDED = "onSharedFileAdded"; - static const String ON_SHARED_FILE__DELETED = "onSharedFileDeleted"; - static const String ON_WHITE_LIST_REMOVED = "onWhiteListRemoved"; - static const String ON_WHITE_LIST_ADDED = "onWhiteListAdded"; - static const String ON_ALL_MEMBER_MUTE_STATE_CHANGED = - "onAllMemberMuteStateChanged"; -} - @Deprecated('Use EMGroupEventListener.') abstract class EMGroupChangeListener { /// id是[groupId], 名称是[groupName]的群邀请被[inviter]拒绝,理由是[reason] @@ -255,105 +382,348 @@ abstract class EMGroupChangeListener { void onAllGroupMemberMuteStateChanged(String groupId, bool isAllMuted); } +/// +/// The group change listener. +/// +/// Listens for group events such as requesting to join a group, approving or declining a group request, and kicking a user out of a group. +/// +/// Registers a group change listener: +/// ```dart +/// EMClient.getInstance.groupManager.addGroupChangeListener(listener); +/// ``` +/// +/// Unregisters a group change listener: +/// ```dart +/// EMClient.getInstance.groupManager.removeGroupChangeListener(listener); +/// ``` abstract class EMGroupEventListener { - /// id是[groupId], 名称是[groupName]的群邀请被[inviter]拒绝,理由是[reason] + /// + /// Occurs when the user receives a group invitation. + /// + /// Param [groupId] The group ID. + /// + /// Param [groupName] The group name. + /// + /// Param [inviter] The invitee ID. + /// + /// Param [reason] The reason for invitation. + /// void onInvitationReceivedFromGroup( String groupId, String? groupName, String inviter, String? reason); - /// 收到用户[applicant]申请加入id是[groupId], 名称是[groupName]的群,原因是[reason] + /// + /// Occurs when the group owner or administrator receives a group request from a user. + /// + /// Param [groupId] The group ID. + /// + /// Param [groupName] The group name. + /// + /// Param [applicant] The ID of the user requesting to join the group. + /// + /// Param [reason] The reason for requesting to join the group. + /// void onRequestToJoinReceivedFromGroup( String groupId, String? groupName, String applicant, String? reason); - /// 入群申请被同意 + /// + /// Occurs when a group request is accepted. + /// + /// Param [groupId] The group ID. + /// + /// Param [groupName] The group name. + /// + /// Param [accepter] The ID of the user that accepts the group request. + /// void onRequestToJoinAcceptedFromGroup( String groupId, String? groupName, String accepter); - /// 入群申请被拒绝 + /// + /// Occurs when a group request is declined. + /// + /// Param [groupId] The group ID. + /// + /// Param [groupName] The group name. + /// + /// Param [decliner] The ID of the user that declines the group request. + /// + /// Param [reason] The reason for declining. + /// void onRequestToJoinDeclinedFromGroup( - String groupId, String? groupName, String decliner, String? reason); + String groupId, + String? groupName, + String decliner, + String? reason, + ); - /// 入群邀请被同意 + /// + /// Occurs when a group invitation is accepted. + /// + /// Param [groupId] The group ID. + /// + /// Param [invitee] The invitee ID. + /// + /// Param [reason] The reason for acceptance. + /// void onInvitationAcceptedFromGroup( - String groupId, String invitee, String? reason); + String groupId, + String invitee, + String? reason, + ); - /// 入群邀请被拒绝 + /// + /// Occurs when a group invitation is declined. + /// + /// Param [groupId] The group ID. + /// + /// Param [invitee] The invitee ID. + /// + /// Param [reason] The reason for declining. + /// void onInvitationDeclinedFromGroup( String groupId, String invitee, String? reason); - /// 被移出群组 + /// + /// Occurs when the current user is removed from the group by the group admin. + /// + /// Param [groupId] The group ID. + /// + /// Param [groupName] The group name. + /// void onUserRemovedFromGroup(String groupId, String? groupName); - /// 群组解散 + /// + /// Occurs when a group is destroyed. + /// + /// Param [groupId] The group ID. + /// + /// Param [groupName] The group name. + /// void onGroupDestroyed(String groupId, String? groupName); - /// @nodoc 自动同意加群 + /// + /// Occurs when the group invitation is accepted automatically. + /// For settings, see {@link EMOptions#autoAcceptGroupInvitation(boolean value)}. + /// The SDK will join the group before notifying the app of the acceptance of the group invitation. + /// + /// Param [groupId] The group ID. + /// + /// Param [inviter] The inviter ID. + /// + /// Param [inviteMessage] The invitation message. + /// void onAutoAcceptInvitationFromGroup( String groupId, String inviter, String? inviteMessage); - /// 群禁言列表增加 + /// + /// Occurs when one or more group members are muted. + /// + /// Note: The mute function is different from a block list. + /// A user, when muted, can still see group messages, but cannot send messages in the group. + /// However, a user on the block list can neither see nor send group messages. + /// + /// Param [groupId] The group ID. + /// + /// Param [mutes] The member(s) added to the mute list. + /// + /// Param [muteExpire] The mute duration in milliseconds. + /// void onMuteListAddedFromGroup( String groupId, List mutes, int? muteExpire); - /// 群禁言列表减少 + /// + /// Occurs when one or more group members are unmuted. + /// + /// Param [groupId] The group ID. + /// + /// Param [mutes] The member(s) added to the mute list. + /// void onMuteListRemovedFromGroup(String groupId, List mutes); - /// 群管理增加 + /// + /// Occurs when a member is set as an admin. + /// + /// Param [groupId] The group ID. + /// + /// Param [admin] The member that is set as an admin. + /// void onAdminAddedFromGroup(String groupId, String admin); - /// 群管理被移除 + /// + /// Occurs when a member's admin privileges are removed. + /// + /// Param [groupId] The group ID. + /// + /// Param [admin] The member whose admin privileges are removed. + /// void onAdminRemovedFromGroup(String groupId, String admin); - /// 群所有者变更 + /// + /// Occurs when the group ownership is transferred. + /// + /// Param [groupId] The group ID. + /// + /// Param [newOwner] The new owner. + /// + /// Param [oldOwner] The previous owner. + /// void onOwnerChangedFromGroup( String groupId, String newOwner, String oldOwner); - /// 有用户加入群 + /// + /// Occurs when a member joins a group. + /// + /// Param [groupId] The group ID. + /// + /// Param [member] The ID of the new member. + /// void onMemberJoinedFromGroup(String groupId, String member); - /// 有用户离开群 + /// + /// Occurs when a member proactively leaves the group. + /// + /// Param [groupId] The group ID. + /// + /// Param [member] The member leaving the group. + /// void onMemberExitedFromGroup(String groupId, String member); - /// 群公告变更 + /// + /// Occurs when the announcement is updated. + /// + /// Param [groupId] The group ID. + /// + /// Param [announcement] The updated announcement content. + /// void onAnnouncementChangedFromGroup(String groupId, String announcement); - /// 群共享文件增加 + /// + /// Occurs when a shared file is added to a group. + /// + /// Param [groupId] The group ID. + /// + /// Param [sharedFile] The new shared file. + /// void onSharedFileAddedFromGroup(String groupId, EMGroupSharedFile sharedFile); - /// 群共享文件被删除 + /// + /// Occurs when a shared file is removed from a group. + /// + /// Param [groupId] The group ID. + /// + /// Param [fileId] The ID of the removed shared file. + /// void onSharedFileDeletedFromGroup(String groupId, String fileId); - /// 有用户被添加到群组白名单 + /// + /// Occurs when one or more group members are added to the allowlist. + /// + /// Param [groupId] The group ID. + /// + /// Param [members] The member(s) removed from the allowlist. + /// void onWhiteListAddedFromGroup(String groupId, List members); - /// 有用户从群组白名单被移除 + /// + /// Occurs when one or more members are removed from the allowlist. + /// + /// Param [groupId] The group ID. + /// + /// Param [members] The member(s) added to the allowlist. + /// void onWhiteListRemovedFromGroup(String groupId, List members); - /// 群组禁言状态发生变化 + /// + /// Occurs when all group members are muted or unmuted. + /// + /// Param [groupId] The group ID. + /// + /// Param [isAllMuted] Whether all group members are muted or unmuted. true: all group members are muted; false: all group members are unmuted. + /// void onAllGroupMemberMuteStateChanged(String groupId, bool isAllMuted); } +/// +/// The message event listener. +/// +/// This listener is used to check whether messages are received. If messages are sent successfully, a delivery receipt will be returned (delivery receipt needs to be enabled: {@link EMOptions#requireDeliveryAck(boolean)}. +/// If the peer reads the received message, a read receipt will be returned (read receipt needs to be enabled: {@link EMOptions#requireAck(boolean)}) +/// During message delivery, the message ID will be changed from a local uuid to a global unique ID that is generated by the server to uniquely identify a message on all devices using the SDK. +/// This API should be implemented in the app to listen for message status changes. +/// +/// Adds the message listener: +/// ```dart +/// EMClient.getInstance.chatManager.addChatManagerListener(listener); +/// ``` +/// +/// Removes the message listener: +/// ```dart +/// EMClient.getInstance.chatManager.removeChatManagerListener(listener); +/// ``` +/// abstract class EMChatManagerListener { - /// 收到消息[messages] + /// + /// Occurs when a message is received. + /// + /// This callback is triggered to notify the user when a message such as texts or an image, video, voice, location, or file is received. + /// + /// Param [messages] The received messages. + /// void onMessagesReceived(List messages) {} - /// 收到cmd消息[messages] + /// + /// Occurs when a command message is received. + /// + /// This callback only contains a command message body that is usually invisible to users. + /// + /// Param [messages]The received cmd messages. + /// void onCmdMessagesReceived(List messages) {} - /// 收到[messages]消息已读 + /// + /// Occurs when a read receipt is received for a message. + /// + /// Param [messages] The has read messages. + /// void onMessagesRead(List messages) {} - /// 收到[groupMessageAcks]群消息已读回调 + /// + /// Occurs when a read receipt is received for a group message. + /// + /// Param [groupMessageAcks] The group message acks. + /// void onGroupMessageRead(List groupMessageAcks) {} - /// 收到[messages]消息已送达 + /// + /// Occurs when a delivery receipt is received. + /// + /// Param [messages] The has delivered messages. + /// void onMessagesDelivered(List messages) {} - /// 收到[messages]消息被撤回 + /// + /// Occurs when a received message is recalled. + /// + /// Param [messages] The recalled messages. + /// void onMessagesRecalled(List messages) {} - /// 会话列表变化 + /// + /// Occurs when the conversation updated. + /// void onConversationsUpdate() {} - /// 会话已读`from`是已读的发送方, `to`是已读的接收方 + /// + /// Occurs when received conversation read receipt. + /// + /// Occurs in the following scenarios: + /// (1) The message is read by the receiver (The conversation receipt is sent). + /// Upon receiving this event, the SDK sets the `isAcked` property of the message in the conversation to `true` in the local database. + /// (2) In the multi-device login scenario, when one device sends a Conversation receipt, + /// the server will set the number of unread messages to 0, and the callback occurs on the other devices. + /// and sets the `isRead` property of the message in the conversation to `true` in the local database. + /// + /// Param [from] The user who sends the read receipt. + /// Param [to] The user who receives the read receipt. + /// void onConversationRead(String from, String to) {} } diff --git a/lib/src/internal/em_event_keys.dart b/lib/src/internal/em_event_keys.dart index 711a61dd..f4e64938 100644 --- a/lib/src/internal/em_event_keys.dart +++ b/lib/src/internal/em_event_keys.dart @@ -5,3 +5,47 @@ class EMContactChangeEvent { static const String INVITATION_ACCEPTED = 'onFriendRequestAccepted'; static const String INVITATION_DECLINED = 'onFriendRequestDeclined'; } + +class EMChatRoomEvent { + static const String ON_CHAT_ROOM_DESTROYED = "onChatRoomDestroyed"; + static const String ON_MEMBER_JOINED = "onMemberJoined"; + static const String ON_MEMBER_EXITED = "onMemberExited"; + static const String ON_REMOVED_FROM_CHAT_ROOM = "onRemovedFromChatRoom"; + static const String ON_MUTE_LIST_ADDED = "onMuteListAdded"; + static const String ON_MUTE_LIST_REMOVED = "onMuteListRemoved"; + static const String ON_ADMIN_ADDED = "onAdminAdded"; + static const String ON_ADMIN_REMOVED = "onAdminRemoved"; + static const String ON_OWNER_CHANGED = "onOwnerChanged"; + static const String ON_ANNOUNCEMENT_CHANGED = "onAnnouncementChanged"; + static const String ON_WHITE_LIST_REMOVED = "onWhiteListRemoved"; + static const String ON_WHITE_LIST_ADDED = "onWhiteListAdded"; + static const String ON_ALL_MEMBER_MUTE_STATE_CHANGED = + "onAllMemberMuteStateChanged"; +} + +class EMGroupChangeEvent { + static const String ON_INVITATION_RECEIVED = "onInvitationReceived"; + static const String ON_INVITATION_ACCEPTED = "onInvitationAccepted"; + static const String ON_INVITATION_DECLINED = "onInvitationDeclined"; + static const String ON_AUTO_ACCEPT_INVITATION = + "onAutoAcceptInvitationFromGroup"; + static const String ON_USER_REMOVED = "onUserRemoved"; + static const String ON_REQUEST_TO_JOIN_RECEIVED = "onRequestToJoinReceived"; + static const String ON_REQUEST_TO_JOIN_DECLINED = "onRequestToJoinDeclined"; + static const String ON_REQUEST_TO_JOIN_ACCEPTED = "onRequestToJoinAccepted"; + static const String ON_GROUP_DESTROYED = "onGroupDestroyed"; + static const String ON_MUTE_LIST_ADDED = "onMuteListAdded"; + static const String ON_MUTE_LIST_REMOVED = "onMuteListRemoved"; + static const String ON_ADMIN_ADDED = "onAdminAdded"; + static const String ON_ADMIN_REMOVED = "onAdminRemoved"; + static const String ON_OWNER_CHANGED = "onOwnerChanged"; + static const String ON_MEMBER_JOINED = "onMemberJoined"; + static const String ON_MEMBER_EXITED = "onMemberExited"; + static const String ON_ANNOUNCEMENT_CHANGED = "onAnnouncementChanged"; + static const String ON_SHARED_FILE_ADDED = "onSharedFileAdded"; + static const String ON_SHARED_FILE__DELETED = "onSharedFileDeleted"; + static const String ON_WHITE_LIST_REMOVED = "onWhiteListRemoved"; + static const String ON_WHITE_LIST_ADDED = "onWhiteListAdded"; + static const String ON_ALL_MEMBER_MUTE_STATE_CHANGED = + "onAllMemberMuteStateChanged"; +} diff --git a/lib/src/internal/em_transform_tools.dart b/lib/src/internal/em_transform_tools.dart index 42cb5a3a..425d9bd4 100644 --- a/lib/src/internal/em_transform_tools.dart +++ b/lib/src/internal/em_transform_tools.dart @@ -1,61 +1,57 @@ import '../models/em_chat_enums.dart'; -import '../em_listeners.dart'; - -EMContactGroupEvent? convertIntToEMContactGroupEvent(int? i) { +EMMultiDevicesEvent? convertIntToEMContactGroupEvent(int? i) { switch (i) { case 2: - return EMContactGroupEvent.CONTACT_REMOVE; + return EMMultiDevicesEvent.CONTACT_REMOVE; case 3: - return EMContactGroupEvent.CONTACT_ACCEPT; + return EMMultiDevicesEvent.CONTACT_ACCEPT; case 4: - return EMContactGroupEvent.CONTACT_DECLINE; + return EMMultiDevicesEvent.CONTACT_DECLINE; case 5: - return EMContactGroupEvent.CONTACT_BAN; + return EMMultiDevicesEvent.CONTACT_BAN; case 6: - return EMContactGroupEvent.CONTACT_ALLOW; + return EMMultiDevicesEvent.CONTACT_ALLOW; case 10: - return EMContactGroupEvent.GROUP_CREATE; + return EMMultiDevicesEvent.GROUP_CREATE; case 11: - return EMContactGroupEvent.GROUP_DESTROY; + return EMMultiDevicesEvent.GROUP_DESTROY; case 12: - return EMContactGroupEvent.GROUP_JOIN; + return EMMultiDevicesEvent.GROUP_JOIN; case 13: - return EMContactGroupEvent.GROUP_LEAVE; + return EMMultiDevicesEvent.GROUP_LEAVE; case 14: - return EMContactGroupEvent.GROUP_APPLY; + return EMMultiDevicesEvent.GROUP_APPLY; case 15: - return EMContactGroupEvent.GROUP_APPLY_ACCEPT; + return EMMultiDevicesEvent.GROUP_APPLY_ACCEPT; case 16: - return EMContactGroupEvent.GROUP_APPLY_DECLINE; + return EMMultiDevicesEvent.GROUP_APPLY_DECLINE; case 17: - return EMContactGroupEvent.GROUP_INVITE; + return EMMultiDevicesEvent.GROUP_INVITE; case 18: - return EMContactGroupEvent.GROUP_INVITE_ACCEPT; + return EMMultiDevicesEvent.GROUP_INVITE_ACCEPT; case 19: - return EMContactGroupEvent.GROUP_INVITE_DECLINE; + return EMMultiDevicesEvent.GROUP_INVITE_DECLINE; case 20: - return EMContactGroupEvent.GROUP_KICK; + return EMMultiDevicesEvent.GROUP_KICK; case 21: - return EMContactGroupEvent.GROUP_BAN; + return EMMultiDevicesEvent.GROUP_BAN; case 22: - return EMContactGroupEvent.GROUP_ALLOW; + return EMMultiDevicesEvent.GROUP_ALLOW; case 23: - return EMContactGroupEvent.GROUP_BLOCK; + return EMMultiDevicesEvent.GROUP_BLOCK; case 24: - return EMContactGroupEvent.GROUP_UNBLOCK; + return EMMultiDevicesEvent.GROUP_UNBLOCK; case 25: - return EMContactGroupEvent.GROUP_ASSIGN_OWNER; + return EMMultiDevicesEvent.GROUP_ASSIGN_OWNER; case 26: - return EMContactGroupEvent.GROUP_ADD_ADMIN; + return EMMultiDevicesEvent.GROUP_ADD_ADMIN; case 27: - return EMContactGroupEvent.GROUP_REMOVE_ADMIN; + return EMMultiDevicesEvent.GROUP_REMOVE_ADMIN; case 28: - return EMContactGroupEvent.GROUP_ADD_MUTE; + return EMMultiDevicesEvent.GROUP_ADD_MUTE; case 29: - return EMContactGroupEvent.GROUP_REMOVE_MUTE; - default: - return null; + return EMMultiDevicesEvent.GROUP_REMOVE_MUTE; } } diff --git a/lib/src/models/em_chat_enums.dart b/lib/src/models/em_chat_enums.dart index edc1fe4a..01c98c0a 100644 --- a/lib/src/models/em_chat_enums.dart +++ b/lib/src/models/em_chat_enums.dart @@ -172,3 +172,85 @@ enum EMSearchDirection { /// The search newer messages type. Down, } + +/// +/// Multi-device event types. +/// +/// This enumeration takes user A logged into both DeviceA1 and DeviceA2 as an example to illustrate the various multi-device event types and when these events are triggered. +/// +enum EMMultiDevicesEvent { + /// The current user removed a contact on another device. + CONTACT_REMOVE, + + /// The current user accepted a friend request on another device. + CONTACT_ACCEPT, + + /// The current user declined a friend request on another device. + CONTACT_DECLINE, + + /// The current user added a contact to the block list on another device. + CONTACT_BAN, + + /// The current user removed a contact from the block list on another device. + CONTACT_ALLOW, + + /// The current user created a group on another device. + GROUP_CREATE, + + /// The current user destroyed a group on another device. + GROUP_DESTROY, + + /// The current user joined a group on another device. + GROUP_JOIN, + + /// The current user left a group on another device. + GROUP_LEAVE, + + /// The current user requested to join a group on another device. + GROUP_APPLY, + + /// The current user accepted a group request on another device. + GROUP_APPLY_ACCEPT, + + /// The current user declined a group request on another device. + GROUP_APPLY_DECLINE, + + /// The current user invited a user to join the group on another device. + GROUP_INVITE, + + /// The current user accepted a group invitation on another device. + GROUP_INVITE_ACCEPT, + + /// The current user declined a group invitation on another device. + GROUP_INVITE_DECLINE, + + /// The current user kicked a member out of a group on another device. + GROUP_KICK, + + /// The current user added a member to a group block list on another device. + GROUP_BAN, + + /// The current user removed a member from a group block list on another device. + GROUP_ALLOW, + + /// The current user blocked a group on another device. + GROUP_BLOCK, + + /// The current user unblocked a group on another device. + GROUP_UNBLOCK, + + /// The current user transferred the group ownership on another device. + GROUP_ASSIGN_OWNER, + + /// The current user added an admin on another device. + GROUP_ADD_ADMIN, + + /// The current user removed an admin on another device. + GROUP_REMOVE_ADMIN, + + /// The current user muted a member on another device. + GROUP_ADD_MUTE, + + /// The current user unmuted a member on another device. + GROUP_REMOVE_MUTE, +} From 3d81710ed055f0a4316198df0fc9cde70d8a11e9 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Wed, 6 Apr 2022 10:28:37 +0800 Subject: [PATCH 33/56] update android --- .../com/easemob/im_flutter_sdk/EMHelper.java | 152 ++++++++++++------ 1 file changed, 102 insertions(+), 50 deletions(-) diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java index 5194850b..b299f490 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java @@ -57,12 +57,9 @@ static EMOptions fromJson(JSONObject json, Context context) throws JSONException options.setDeleteMessagesAsExitGroup(json.getBoolean("deleteMessagesAsExitGroup")); options.setDeleteMessagesAsExitChatRoom(json.getBoolean("deleteMessagesAsExitChatRoom")); options.setAutoDownloadThumbnail(json.getBoolean("isAutoDownload")); - // options.setAutoLogin(json.getBoolean("")); isChatRoomOwnerLeaveAllowed - // options.setAutoLogin(json.getBoolean("")); debugModel - // options.setAutoLogin(json.getBoolean("")); serverTransfer + options.allowChatroomOwnerLeave(json.getBoolean("isChatRoomOwnerLeaveAllowed")); + options.setAutoTransferMessageAttachments(json.getBoolean("serverTransfer")); options.setUsingHttpsOnly(json.getBoolean("usingHttpsOnly")); - // options.setAutoLogin(json.getBoolean("")); EMPushConfig - // options.setAutoLogin(json.getBoolean("")); enableDNSConfig options.enableDNSConfig(json.getBoolean("enableDNSConfig")); if (!json.getBoolean("enableDNSConfig")) { options.setImPort(json.getInt("imPort")); @@ -99,6 +96,7 @@ static EMOptions fromJson(JSONObject json, Context context) throws JSONException } + /* static Map toJson(EMOptions options) { Map data = new HashMap<>(); data.put("appKey", options.getAppKey()); @@ -125,6 +123,7 @@ static Map toJson(EMOptions options) { return data; } + */ } class EMGroupHelper { @@ -140,11 +139,6 @@ static Map toJson(EMGroup group) { data.put("adminList", group.getAdminList()); data.put("blockList", group.getBlackList()); data.put("muteList", group.getMuteList()); - - if (group.getGroupId() != null && EMClient.getInstance().pushManager().getNoPushGroups() != null) { - data.put("noticeEnable", - !EMClient.getInstance().pushManager().getNoPushGroups().contains(group.getGroupId())); - } data.put("messageBlocked", group.isMsgBlocked()); data.put("isAllMemberMuted", group.isAllMemberMuted()); data.put("permissionType", intTypeFromGroupPermissionType(group.getGroupPermissionType())); @@ -222,7 +216,9 @@ static EMGroupOptions fromJson(JSONObject json) throws JSONException { EMGroupOptions options = new EMGroupOptions(); options.maxUsers = json.getInt("maxCount"); options.inviteNeedConfirm = json.getBoolean("inviteNeedConfirm"); - options.extField = json.getString("ext"); + if (json.has("ext")){ + options.extField = json.getString("ext"); + } options.style = styleFromInt(json.getInt("style")); return options; } @@ -413,11 +409,11 @@ static EMMessage fromJson(JSONObject json) throws JSONException { } } - if (!json.isNull("to")) { + if (json.has("to")) { message.setTo(json.getString("to")); } - if (!json.isNull("from")) { + if (json.has("from")) { message.setFrom(json.getString("from")); } @@ -435,7 +431,9 @@ static EMMessage fromJson(JSONObject json) throws JSONException { message.setMsgTime(json.getLong("serverTime")); message.setStatus(statusFromInt(json.getInt("status"))); message.setChatType(chatTypeFromInt(json.getInt("chatType"))); - message.setMsgId(json.getString("msgId")); + if (json.has("msgId")){ + message.setMsgId(json.getString("msgId")); + } if(json.has("attributes")){ JSONObject data = json.getJSONObject("attributes"); @@ -618,9 +616,18 @@ static Map textBodyToJson(EMTextMessageBody body) { static EMLocationMessageBody localBodyFromJson(JSONObject json) throws JSONException { double latitude = json.getDouble("latitude"); double longitude = json.getDouble("longitude"); - String address = json.getString("address"); + String address = null; + String buildingName = null; + if (json.has("address")){ + address = json.getString("address"); + } + + if (json.has("buildingName")){ + buildingName = json.getString("buildingName"); + } + + EMLocationMessageBody body = new EMLocationMessageBody(address, latitude, longitude, buildingName); - EMLocationMessageBody body = new EMLocationMessageBody(address, latitude, longitude); return body; } @@ -628,6 +635,7 @@ static Map localBodyToJson(EMLocationMessageBody body) { Map data = new HashMap<>(); data.put("latitude", body.getLatitude()); data.put("longitude", body.getLongitude()); + data.put("buildingName", body.getBuildingName()); data.put("address", body.getAddress()); data.put("type", "loc"); return data; @@ -681,9 +689,16 @@ static EMFileMessageBody fileBodyFromJson(JSONObject json) throws JSONException File file = new File(localPath); EMNormalFileMessageBody body = new EMNormalFileMessageBody(file); - body.setFileName(json.getString("displayName")); - body.setRemoteUrl(json.getString("remotePath")); - body.setSecret(json.getString("secret")); + if (json.has("displayName")){ + body.setFileName(json.getString("displayName")); + } + if (json.has("remotePath")){ + body.setRemoteUrl(json.getString("remotePath")); + } + if (json.has("secret")){ + body.setSecret(json.getString("secret")); + } + body.setDownloadStatus(downloadStatusFromInt(json.getInt("fileStatus"))); body.setFileLength(json.getInt("fileSize")); return body; @@ -696,7 +711,6 @@ static Map fileBodyToJson(EMNormalFileMessageBody body) { data.put("displayName", body.getFileName()); data.put("remotePath", body.getRemoteUrl()); data.put("secret", body.getSecret()); - data.put("fileSize", body.getFileSize()); data.put("fileStatus", downloadStatusToInt(body.downloadStatus())); data.put("type", "file"); return data; @@ -707,21 +721,30 @@ static EMImageMessageBody imageBodyFromJson(JSONObject json) throws JSONExceptio File file = new File(localPath); EMImageMessageBody body = new EMImageMessageBody(file); - body.setFileName(json.getString("displayName")); - body.setRemoteUrl(json.getString("remotePath")); - body.setSecret(json.getString("secret")); - body.setDownloadStatus(downloadStatusFromInt(json.getInt("fileStatus"))); - if (json.getString("thumbnailLocalPath") != null) { + if (json.has("displayName")){ + body.setFileName(json.getString("displayName")); + } + if (json.has("remotePath")){ + body.setRemoteUrl(json.getString("remotePath")); + } + if (json.has("secret")){ + body.setSecret(json.getString("secret")); + } + if (json.has("thumbnailLocalPath")) { body.setThumbnailLocalPath(json.getString("thumbnailLocalPath")); } - body.setThumbnailUrl(json.getString("thumbnailRemotePath")); - body.setThumbnailSecret(json.getString("thumbnailSecret")); + if (json.has("thumbnailRemotePath")){ + body.setThumbnailUrl(json.getString("thumbnailRemotePath")); + } + if (json.has("thumbnailSecret")){ + body.setThumbnailSecret(json.getString("thumbnailSecret")); + } body.setFileLength(json.getInt("fileSize")); int width = json.getInt("height"); int height = json.getInt("width"); body.setThumbnailSize(width, height); body.setSendOriginalImage(json.getBoolean("sendOriginalImage")); - + body.setDownloadStatus(downloadStatusFromInt(json.getInt("fileStatus"))); return body; } @@ -745,23 +768,32 @@ static Map imageBodyToJson(EMImageMessageBody body) { static EMVideoMessageBody videoBodyFromJson(JSONObject json) throws JSONException { String localPath = json.getString("localPath"); - String thumbnailLocalPath = json.getString("thumbnailLocalPath"); int duration = json.getInt("duration"); int fileSize = json.getInt("fileSize"); - EMVideoMessageBody body = new EMVideoMessageBody(localPath, thumbnailLocalPath, duration, fileSize); - body.setThumbnailUrl(json.getString("thumbnailRemotePath")); + EMVideoMessageBody body = new EMVideoMessageBody(localPath, null, duration, fileSize); + if (json.has("thumbnailRemotePath")){ + body.setThumbnailUrl(json.getString("thumbnailRemotePath")); + } if (json.getString("thumbnailLocalPath") != null) { body.setLocalThumb(json.getString("thumbnailLocalPath")); } - body.setThumbnailSecret(json.getString("thumbnailSecret")); - body.setFileName(json.getString("displayName")); + if (json.has("thumbnailSecret")){ + body.setThumbnailSecret(json.getString("thumbnailSecret")); + } + if (json.has("displayName")){ + body.setFileName(json.getString("displayName")); + } + if (json.has("remotePath")){ + body.setRemoteUrl(json.getString("remotePath")); + } + if (json.has("secret")){ + body.setSecret(json.getString("secret")); + } + + body.setDownloadStatus(downloadStatusFromInt(json.getInt("fileStatus"))); int width = json.getInt("height"); int height = json.getInt("width"); body.setThumbnailSize(width, height); - body.setRemoteUrl(json.getString("remotePath")); - body.setDownloadStatus(downloadStatusFromInt(json.getInt("fileStatus"))); - body.setSecret(json.getString("secret")); - body.setFileLength(json.getInt("fileSize")); return body; } @@ -770,7 +802,6 @@ static Map videoBodyToJson(EMVideoMessageBody body) { data.put("localPath", body.getLocalUrl()); data.put("thumbnailLocalPath", body.getLocalThumbUri()); data.put("duration", body.getDuration()); - data.put("fileSize", body.getVideoFileLength()); data.put("thumbnailRemotePath", body.getThumbnailUrl()); data.put("thumbnailSecret", body.getThumbnailSecret()); data.put("displayName", body.getFileName()); @@ -791,10 +822,16 @@ static EMVoiceMessageBody voiceBodyFromJson(JSONObject json) throws JSONExceptio int duration = json.getInt("duration"); EMVoiceMessageBody body = new EMVoiceMessageBody(file, duration); body.setDownloadStatus(downloadStatusFromInt(json.getInt("fileStatus"))); - body.setFileName(json.getString("displayName")); + if (json.has("displayName")){ + body.setFileName(json.getString("displayName")); + } + if (json.has("secret")){ + body.setSecret(json.getString("secret")); + } + if (json.has("remotePath")){ + body.setRemoteUrl(json.getString("remotePath")); + } body.setFileLength(json.getLong("fileSize")); - body.setSecret(json.getString("secret")); - body.setFileLength(json.getInt("fileSize")); return body; } @@ -1041,19 +1078,34 @@ static Map toJson(HyphenateException e) { class EMUserInfoHelper { static EMUserInfo fromJson(JSONObject obj) throws JSONException { EMUserInfo userInfo = new EMUserInfo(); + if (obj.has("userId")){ + userInfo.setUserId(obj.getString("userId")); + } + if (obj.has("nickName")){ + userInfo.setNickname(obj.getString("nickName")); + } - userInfo.setUserId(obj.getString("userId")); - userInfo.setNickName(obj.optString("nickName")); if (obj.has("gender")){ userInfo.setGender(obj.getInt("gender")); } - - userInfo.setEmail(obj.optString("mail")); - userInfo.setPhoneNumber(obj.optString("phone")); - userInfo.setSignature(obj.optString("sign")); - userInfo.setAvatarUrl(obj.optString("avatarUrl")); - userInfo.setExt(obj.optString("ext")); - userInfo.setBirth(obj.optString("birth")); + if (obj.has("mail")){ + userInfo.setEmail(obj.optString("mail")); + } + if (obj.has("phone")){ + userInfo.setPhoneNumber(obj.optString("phone")); + } + if (obj.has("sign")){ + userInfo.setSignature(obj.optString("sign")); + } + if (obj.has("avatarUrl")){ + userInfo.setAvatarUrl(obj.optString("avatarUrl")); + } + if (obj.has("ext")){ + userInfo.setExt(obj.getString("ext")); + } + if (obj.has("birth")){ + userInfo.setBirth(obj.getString("birth")); + } return userInfo; } From ac42cb08be5768bd751fbe97e52d1108f77f7246 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Wed, 6 Apr 2022 11:20:41 +0800 Subject: [PATCH 34/56] fix ios call wrong method. --- ios/Classes/EMChatManagerWrapper.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ios/Classes/EMChatManagerWrapper.m b/ios/Classes/EMChatManagerWrapper.m index 819d7c8c..91b6a994 100644 --- a/ios/Classes/EMChatManagerWrapper.m +++ b/ios/Classes/EMChatManagerWrapper.m @@ -54,9 +54,9 @@ - (void)handleMethodCall:(FlutterMethodCall*)call channelName:call.method result:result]; } else if ([EMMethodKeyAckGroupMessageRead isEqualToString:call.method]) { - [self ackMessageRead:call.arguments - channelName:call.method - result:result]; + [self ackGroupMessageRead:call.arguments + channelName:call.method + result:result]; } else if ([EMMethodKeyAckConversationRead isEqualToString:call.method]) { [self ackConversationRead:call.arguments channelName:call.method From 0611034cd928a97b73dd5772111f2a2fc90b6fe8 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Wed, 6 Apr 2022 11:29:00 +0800 Subject: [PATCH 35/56] change android manifest files.(thx Chan.) --- example/android/app/src/main/AndroidManifest.xml | 2 +- lib/src/tools/em_extension.dart | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 66731b18..52b6d4b2 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -6,7 +6,7 @@ additional functionality it is fine to subclass or reimplement FlutterApplication and put your custom class here. --> diff --git a/lib/src/tools/em_extension.dart b/lib/src/tools/em_extension.dart index a59b275b..54684545 100644 --- a/lib/src/tools/em_extension.dart +++ b/lib/src/tools/em_extension.dart @@ -51,9 +51,8 @@ extension MapExtension on Map { } return fileList as List; } - } else { - return null; } + return null; } } From 14fb2f359ccbbbb38db7d4470304bcad6fb39af3 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Wed, 6 Apr 2022 12:28:41 +0800 Subject: [PATCH 36/56] change options default. --- example/android/app/build.gradle | 2 +- example/android/build.gradle | 2 +- example/lib/main.dart | 1 + example/lib/pages/contacts/contacts_page.dart | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 2fc41a4b..c2cc2f63 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 29 + compileSdkVersion 31 sourceSets { main.java.srcDirs += 'src/main/kotlin' diff --git a/example/android/build.gradle b/example/android/build.gradle index 4c0e9cc5..3ae9bf12 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.3.50' + ext.kotlin_version = '1.5.31' repositories { google() mavenCentral() diff --git a/example/lib/main.dart b/example/lib/main.dart index 18edb6dc..68b700d0 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -30,6 +30,7 @@ void initSDK() async { var options = EMOptions(appKey: 'easemob-demo#easeim'); options.deleteMessagesAsExitGroup = false; options.deleteMessagesAsExitChatRoom = false; + options.autoAcceptGroupInvitation = true; options.debugModel = true; options.enableAPNs("EaseIM_APNS_Product"); diff --git a/example/lib/pages/contacts/contacts_page.dart b/example/lib/pages/contacts/contacts_page.dart index fc6ccf7b..a3a74411 100644 --- a/example/lib/pages/contacts/contacts_page.dart +++ b/example/lib/pages/contacts/contacts_page.dart @@ -249,6 +249,7 @@ class ContactsPageState extends State _contactList.addAll(list); } } on EMError { + _contactList.clear(); SmartDialog.showToast('获取失败'); _loadLocalContacts(count); } finally { From daf96b34ea95f56282e04d158d7a7fa34fad2398 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Thu, 7 Apr 2022 11:35:38 +0800 Subject: [PATCH 37/56] add building name. --- android/src/main/AndroidManifest.xml | 1 - .../easemob/im_flutter_sdk/EMSDKMethod.java | 2 +- example/android/app/proguard-rules.pro | 21 +++++++++++++++++++ example/lib/main.dart | 4 +--- ios/Classes/EMChatMessage+Flutter.m | 5 ++++- ios/Classes/EMClientWrapper.m | 5 +---- ios/Classes/EMSDKMethod.h | 2 +- lib/src/em_client.dart | 2 +- lib/src/internal/chat_method_keys.dart | 2 +- lib/src/models/em_options.dart | 2 +- 10 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 example/android/app/proguard-rules.pro diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 4ed69573..55dc9640 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -7,7 +7,6 @@ - diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMSDKMethod.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMSDKMethod.java index 98c95c3e..e7fe6284 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMSDKMethod.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMSDKMethod.java @@ -141,7 +141,7 @@ public class EMSDKMethod { static final String isMemberInChatRoomWhiteListFromServer = "isMemberInChatRoomWhiteListFromServer"; static final String muteAllChatRoomMembers = "muteAllChatRoomMembers"; - static final String unMuteAllChatRoomMembers = "umMuteAllChatRoomMembers"; + static final String unMuteAllChatRoomMembers = "unMuteAllChatRoomMembers"; // EMChatRoomManagerListener diff --git a/example/android/app/proguard-rules.pro b/example/android/app/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/example/android/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/example/lib/main.dart b/example/lib/main.dart index 337e7382..1982c479 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -41,8 +41,6 @@ void initSDK() async { } class EaseIMDemo extends StatelessWidget { - final FocusNode focusNode = FocusNode(); - @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([ @@ -50,7 +48,7 @@ class EaseIMDemo extends StatelessWidget { ]); return GestureDetector( onTap: () { - focusNode.unfocus(); + FocusScope.of(context).requestFocus(FocusNode()); }, child: ScreenUtilInit( designSize: Size(375, 667), diff --git a/ios/Classes/EMChatMessage+Flutter.m b/ios/Classes/EMChatMessage+Flutter.m index 7ba347b0..4c90c01c 100644 --- a/ios/Classes/EMChatMessage+Flutter.m +++ b/ios/Classes/EMChatMessage+Flutter.m @@ -292,9 +292,11 @@ + (EMMessageBody *)fromJson:(NSDictionary *)aJson { double latitude = [aJson[@"latitude"] doubleValue]; double longitude = [aJson[@"longitude"] doubleValue]; NSString *address = aJson[@"address"]; + NSString *buildingName = aJson[@"buildingName"]; + EMLocationMessageBody *ret = [[EMLocationMessageBody alloc] initWithLatitude:latitude longitude:longitude - address:address]; + address:address buildingName:buildingName]; return ret; } @@ -303,6 +305,7 @@ - (NSDictionary *)toJson { ret[@"address"] = self.address; ret[@"latitude"] = @(self.latitude); ret[@"longitude"] = @(self.longitude); + ret[@"buildingName"] = self.buildingName; return ret; } diff --git a/ios/Classes/EMClientWrapper.m b/ios/Classes/EMClientWrapper.m index a71f91bc..0d7f2c59 100644 --- a/ios/Classes/EMClientWrapper.m +++ b/ios/Classes/EMClientWrapper.m @@ -354,10 +354,7 @@ - (void)loginWithAgoraToken:(NSDictionary *)param result:(FlutterResult)result { [weakSelf wrapperCallBack:result channelName:EMMethodKeyLoginWithAgoraToken error:aError - object:@{ - @"username": aUsername, - @"token": EMClient.sharedClient.accessUserToken - }]; + object:EMClient.sharedClient.currentUsername]; }]; } diff --git a/ios/Classes/EMSDKMethod.h b/ios/Classes/EMSDKMethod.h index a9de5566..2114a16d 100644 --- a/ios/Classes/EMSDKMethod.h +++ b/ios/Classes/EMSDKMethod.h @@ -153,7 +153,7 @@ static NSString *const EMMethodKeyFetchChatRoomWhiteListFromServer = @"fetchChat static NSString *const EMMethodKeyIsMemberInChatRoomWhiteListFromServer = @"isMemberInChatRoomWhiteListFromServer"; static NSString *const EMMethodKeyMuteAllChatRoomMembers = @"muteAllChatRoomMembers"; -static NSString *const EMMethodKeyUnMuteAllChatRoomMembers = @"umMuteAllChatRoomMembers"; +static NSString *const EMMethodKeyUnMuteAllChatRoomMembers = @"unMuteAllChatRoomMembers"; static NSString *const EMMethodKeyChatroomChanged = @"onChatRoomChanged"; diff --git a/lib/src/em_client.dart b/lib/src/em_client.dart index 96a9cfec..9b709e9c 100644 --- a/lib/src/em_client.dart +++ b/lib/src/em_client.dart @@ -197,7 +197,7 @@ class EMClient { await _channel.invokeMethod(ChatMethodKeys.loginWithAgoraToken, req); try { EMError.hasErrorFromResult(result); - _currentUsername = result[ChatMethodKeys.loginWithAgoraToken]; + _currentUsername = username; } on EMError catch (e) { throw e; } diff --git a/lib/src/internal/chat_method_keys.dart b/lib/src/internal/chat_method_keys.dart index 02e03c3c..27f33a3c 100644 --- a/lib/src/internal/chat_method_keys.dart +++ b/lib/src/internal/chat_method_keys.dart @@ -150,7 +150,7 @@ class ChatMethodKeys { "isMemberInChatRoomWhiteListFromServer"; static const String muteAllChatRoomMembers = "muteAllChatRoomMembers"; - static const String unMuteAllChatRoomMembers = "umMuteAllChatRoomMembers"; + static const String unMuteAllChatRoomMembers = "unMuteAllChatRoomMembers"; /// EMChatRoomManagerListener static const String chatRoomChange = 'onChatRoomChanged'; diff --git a/lib/src/models/em_options.dart b/lib/src/models/em_options.dart index 7a7c01b8..32d5673f 100644 --- a/lib/src/models/em_options.dart +++ b/lib/src/models/em_options.dart @@ -230,7 +230,7 @@ class EMOptions { this.debugModel = false, this.acceptInvitationAlways = false, this.autoAcceptGroupInvitation = false, - this.requireAck = false, + this.requireAck = true, this.requireDeliveryAck = false, this.deleteMessagesAsExitGroup = true, this.deleteMessagesAsExitChatRoom = true, From 9c3e25fb7d3c49635121d18d68fee9d7822982eb Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Thu, 7 Apr 2022 16:17:13 +0800 Subject: [PATCH 38/56] fix files message progress. --- lib/src/em_chat_manager.dart | 1 - lib/src/models/em_message.dart | 139 +++++++++++++++++++-------------- 2 files changed, 82 insertions(+), 58 deletions(-) diff --git a/lib/src/em_chat_manager.dart b/lib/src/em_chat_manager.dart index 206e3956..3ef12916 100644 --- a/lib/src/em_chat_manager.dart +++ b/lib/src/em_chat_manager.dart @@ -4,7 +4,6 @@ import 'package:flutter/services.dart'; import 'tools/em_extension.dart'; import '../im_flutter_sdk.dart'; import 'internal/chat_method_keys.dart'; -import 'tools/em_message_callback_manager.dart'; class EMChatManager { static const _channelPrefix = 'com.chat.im'; diff --git a/lib/src/models/em_message.dart b/lib/src/models/em_message.dart index 70411105..db9d223d 100644 --- a/lib/src/models/em_message.dart +++ b/lib/src/models/em_message.dart @@ -1,11 +1,9 @@ import 'dart:math'; -import '../tools/em_log.dart'; - -import '../tools/em_message_callback_manager.dart'; +import 'package:flutter/services.dart'; +import '../internal/chat_method_keys.dart'; import '../tools/em_extension.dart'; import '../../im_flutter_sdk.dart'; -import '../internal/em_message_state_handle.dart'; // 消息类型 enum EMMessageChatType { @@ -68,30 +66,58 @@ abstract class EMMessageStatusListener { void onStatusChanged() {} } -class EMMessage { - EMMessage._private() { - _tmpKey = localTime.toString(); +class MessageCallBackManager { + static const _channelPrefix = 'com.chat.im'; + static const MethodChannel _emMessageChannel = + const MethodChannel('$_channelPrefix/chat_message', JSONMethodCodec()); + Map cacheMessageMap = {}; + static MessageCallBackManager? _instance; + static MessageCallBackManager get getInstance => + _instance = _instance ?? MessageCallBackManager._internal(); + MessageCallBackManager._internal() { + _emMessageChannel.setMethodCallHandler((MethodCall call) async { + Map argMap = call.arguments; + int? localTime = argMap['localTime']; + EMMessage? msg = cacheMessageMap[localTime.toString()]; + if (msg == null) { + return null; + } + if (call.method == ChatMethodKeys.onMessageProgressUpdate) { + return msg._onMessageProgressChanged(argMap); + } else if (call.method == ChatMethodKeys.onMessageError) { + return msg._onMessageError(argMap); + } else if (call.method == ChatMethodKeys.onMessageSuccess) { + return msg._onMessageSuccess(argMap); + } else if (call.method == ChatMethodKeys.onMessageReadAck) { + return msg._onMessageReadAck(argMap); + } else if (call.method == ChatMethodKeys.onMessageDeliveryAck) { + return msg._onMessageDeliveryAck(argMap); + } else if (call.method == ChatMethodKeys.onMessageStatusChanged) { + return msg._onMessageStatusChanged(argMap); + } + return null; + }); + } + + addMessage(EMMessage message) { + cacheMessageMap[message.localTime.toString()] = message; + } + + removeMessage(EMMessage message) { + if (cacheMessageMap.containsKey(message.localTime.toString())) { + cacheMessageMap.remove(message.localTime.toString()); + } } +} - late EMMessageStateHandle _handle; +class EMMessage { + EMMessage._private(); /// 构造接收的消息 EMMessage.createReceiveMessage({ required this.body, this.direction = EMMessageDirection.RECEIVE, - }) { - _tmpKey = localTime.toString(); - _handle = EMMessageStateHandle( - _tmpKey, - onMessageDeliveryAck: _onMessageDeliveryAck, - onMessageError: _onMessageError, - onMessageProgressChanged: _onMessageProgressChanged, - onMessageReadAck: _onMessageReadAck, - onMessageSuccess: _onMessageSuccess, - onMessageStatusChanged: _onMessageStatusChanged, - ); - MessageCallBackManager.getInstance.addMessage(_tmpKey, _handle); - } + }); /// 构造发送的消息 EMMessage.createSendMessage({ @@ -100,74 +126,70 @@ class EMMessage { this.to, this.hasRead = true, }) : this.from = EMClient.getInstance.currentUsername, - this.conversationId = to { - _tmpKey = localTime.toString(); - _handle = EMMessageStateHandle( - _tmpKey, - onMessageDeliveryAck: _onMessageDeliveryAck, - onMessageError: _onMessageError, - onMessageProgressChanged: _onMessageProgressChanged, - onMessageReadAck: _onMessageReadAck, - onMessageSuccess: _onMessageSuccess, - onMessageStatusChanged: _onMessageStatusChanged, - ); - MessageCallBackManager.getInstance.addMessage(_tmpKey, _handle); - } + this.conversationId = to; void dispose() { - MessageCallBackManager.getInstance.removeMessage(_tmpKey); - // listener = null; + MessageCallBackManager.getInstance.removeMessage(this); } - void _onMessageError(Map map) { - EMLog.v('发送失败 -- ' + map.toString()); + Future? _onMessageError(Map map) { EMMessage msg = EMMessage.fromJson(map['message']); this._msgId = msg.msgId; this.status = msg.status; this.body = msg.body; - listener?.onError(EMError.fromJson(map['error'])); + if (listener != null) { + listener!.onError(EMError.fromJson(map['error'])); + } return null; } - void _onMessageProgressChanged(Map map) { - EMLog.v( - '发送 -- ' + ' msg_id: ' + this.msgId! + ' ' + map['progress'].toString(), - ); - int progress = map['progress']; - listener?.onProgress(progress); + Future? _onMessageProgressChanged(Map map) { + if (this.listener != null) { + int progress = map['progress']; + listener!.onProgress(progress); + } return null; } - void _onMessageSuccess(Map map) { + Future? _onMessageSuccess(Map map) { EMMessage msg = EMMessage.fromJson(map['message']); this._msgId = msg.msgId; this.status = msg.status; this.body = msg.body; - listener?.onSuccess(); - EMLog.v('发送成功 -- ' + this.toString()); + if (listener != null) { + listener!.onSuccess(); + } + return null; } - void _onMessageReadAck(Map map) { - EMLog.v('消息已读 -- ' + ' msg_id: ' + this.msgId!); + Future? _onMessageReadAck(Map map) { EMMessage msg = EMMessage.fromJson(map); this.hasReadAck = msg.hasReadAck; - listener?.onReadAck(); + if (listener != null) { + listener!.onReadAck(); + } return null; } - void _onMessageDeliveryAck(Map map) { + Future? _onMessageDeliveryAck(Map map) { EMMessage msg = EMMessage.fromJson(map); this.hasDeliverAck = msg.hasDeliverAck; - listener?.onDeliveryAck(); + + if (listener != null) { + listener!.onDeliveryAck(); + } return null; } - void _onMessageStatusChanged(Map map) { + Future? _onMessageStatusChanged(Map map) { EMMessage msg = EMMessage.fromJson(map); this.status = msg.status; - listener?.onStatusChanged(); + + if (listener != null) { + listener!.onStatusChanged(); + } return null; } @@ -279,10 +301,13 @@ class EMMessage { void setMessageListener(EMMessageStatusListener? listener) { this.listener = listener; + if (listener != null) { + MessageCallBackManager.getInstance.addMessage(this); + } else { + MessageCallBackManager.getInstance.removeMessage(this); + } } - late String _tmpKey; - /// 消息id String? _msgId, msgLocalId = DateTime.now().millisecondsSinceEpoch.toString() + From 9cc2b6fc0565b3ba882ea92e313671170d91c62b Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Thu, 7 Apr 2022 17:40:54 +0800 Subject: [PATCH 39/56] fix file size wrong key. --- .../main/java/com/easemob/im_flutter_sdk/EMHelper.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java index 9d7511a7..402e4317 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java @@ -732,8 +732,8 @@ static EMImageMessageBody imageBodyFromJson(JSONObject json) throws JSONExceptio body.setThumbnailUrl(json.getString("thumbnailRemotePath")); body.setThumbnailSecret(json.getString("thumbnailSecret")); body.setFileLength(json.getInt("fileSize")); - int width = json.getInt("height"); - int height = json.getInt("width"); + int width = json.getInt("width"); + int height = json.getInt("height"); body.setThumbnailSize(width, height); body.setSendOriginalImage(json.getBoolean("sendOriginalImage")); @@ -770,8 +770,8 @@ static EMVideoMessageBody videoBodyFromJson(JSONObject json) throws JSONExceptio } body.setThumbnailSecret(json.getString("thumbnailSecret")); body.setFileName(json.getString("displayName")); - int width = json.getInt("height"); - int height = json.getInt("width"); + int width = json.getInt("width"); + int height = json.getInt("height"); body.setThumbnailSize(width, height); body.setRemoteUrl(json.getString("remotePath")); body.setDownloadStatus(downloadStatusFromInt(json.getInt("fileStatus"))); From 635bddaaec60ecfa51fd1a2de1d1b2426528faa1 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Thu, 7 Apr 2022 21:30:07 +0800 Subject: [PATCH 40/56] update --- lib/src/em_chat_manager.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/src/em_chat_manager.dart b/lib/src/em_chat_manager.dart index a25535fa..7dc053ac 100644 --- a/lib/src/em_chat_manager.dart +++ b/lib/src/em_chat_manager.dart @@ -27,7 +27,6 @@ class EMChatManager { /// @nodoc EMChatManager() { - MessageCallBackManager.getInstance; _channel.setMethodCallHandler((MethodCall call) async { if (call.method == ChatMethodKeys.onMessagesReceived) { return _onMessagesReceived(call.arguments); From 0042b6a69c5a9fd78b5b5b3f251943b0c18c9f4c Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Thu, 7 Apr 2022 22:46:17 +0800 Subject: [PATCH 41/56] fix null values. --- .../com/easemob/im_flutter_sdk/EMHelper.java | 22 +- .../chat/chat_items/chat_image_bubble.dart | 4 +- .../lib/pages/chat/chat_items/chat_item.dart | 32 +- example/lib/pages/chat/chat_page.dart | 2 +- lib/src/internal/em_transform_tools.dart | 1 + lib/src/models/em_chat_room.dart | 16 +- lib/src/models/em_cmd_message_body.dart | 4 +- lib/src/models/em_conversation.dart | 2 +- lib/src/models/em_custom_message_body.dart | 4 +- lib/src/models/em_deviceInfo.dart | 6 +- lib/src/models/em_file_message_body.dart | 12 +- lib/src/models/em_group_message_ack.dart | 6 +- lib/src/models/em_image_message_body.dart | 18 +- lib/src/models/em_location_message_body.dart | 8 +- lib/src/models/em_message.dart | 342 +++++++++--------- lib/src/models/em_text_message_body.dart | 2 +- lib/src/models/em_userInfo.dart | 18 +- lib/src/models/em_video_message_body.dart | 14 +- lib/src/models/em_voice_message_body.dart | 2 +- lib/src/tools/em_extension.dart | 49 ++- 20 files changed, 313 insertions(+), 251 deletions(-) diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java index c847b4ce..a3175e3e 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java @@ -739,12 +739,22 @@ static EMImageMessageBody imageBodyFromJson(JSONObject json) throws JSONExceptio if (json.has("thumbnailSecret")){ body.setThumbnailSecret(json.getString("thumbnailSecret")); } - body.setFileLength(json.getInt("fileSize")); - int width = json.getInt("width"); - int height = json.getInt("height"); - body.setThumbnailSize(width, height); - body.setSendOriginalImage(json.getBoolean("sendOriginalImage")); - body.setDownloadStatus(downloadStatusFromInt(json.getInt("fileStatus"))); + if (json.has("fileSize")){ + body.setFileLength(json.getInt("fileSize")); + } + if (json.has("width") && json.has("height")){ + int width = json.getInt("width"); + int height = json.getInt("height"); + body.setThumbnailSize(width, height); + } + if (json.has("sendOriginalImage")){ + body.setSendOriginalImage(json.getBoolean("sendOriginalImage")); + } + + if (json.has("fileStatus")){ + body.setDownloadStatus(downloadStatusFromInt(json.getInt("fileStatus"))); + } + return body; } diff --git a/example/lib/pages/chat/chat_items/chat_image_bubble.dart b/example/lib/pages/chat/chat_items/chat_image_bubble.dart index 35f444c6..60b90f93 100644 --- a/example/lib/pages/chat/chat_items/chat_image_bubble.dart +++ b/example/lib/pages/chat/chat_items/chat_image_bubble.dart @@ -22,8 +22,8 @@ class ChatImageBubble extends StatelessWidget { Widget image; // 作为接收方,是有图片size的,需要先根据size缩放 - double width = body.width!; - double height = body.height!; + double width = body.width ?? 100; + double height = body.height ?? 100; if (height > width) { width = maxSize / height * width; diff --git a/example/lib/pages/chat/chat_items/chat_item.dart b/example/lib/pages/chat/chat_items/chat_item.dart index f190304a..7261f424 100644 --- a/example/lib/pages/chat/chat_items/chat_item.dart +++ b/example/lib/pages/chat/chat_items/chat_item.dart @@ -44,23 +44,21 @@ class ChatItem extends StatefulWidget { class ChatItemState extends State { void initState() { super.initState(); - widget.msg.messageStatusCallBack = MessageStatusCallBack( - onSuccess: () { - if (mounted) { - setState(() {}); - } - }, - onError: (error) { - if (mounted) { - setState(() {}); - } - }, - onReadAck: () { - if (mounted) { - setState(() {}); - } - }, - ); + widget.msg.messageStatusCallBack = MessageStatusCallBack(onSuccess: () { + if (mounted) { + setState(() {}); + } + }, onError: (error) { + if (mounted) { + setState(() {}); + } + }, onReadAck: () { + if (mounted) { + setState(() {}); + } + }, onProgress: (progress) { + debugPrint("progress --- $progress"); + }); } @override diff --git a/example/lib/pages/chat/chat_page.dart b/example/lib/pages/chat/chat_page.dart index 500d90ca..09a61c00 100644 --- a/example/lib/pages/chat/chat_page.dart +++ b/example/lib/pages/chat/chat_page.dart @@ -380,7 +380,7 @@ class _ChatPageState extends State } /// 发送图片消息 - _sendImageMessage(String imagePath, [String fileName = '']) { + _sendImageMessage(String imagePath, {String? fileName}) { Image.file( File(imagePath), fit: BoxFit.contain, diff --git a/lib/src/internal/em_transform_tools.dart b/lib/src/internal/em_transform_tools.dart index 425d9bd4..3f8eae74 100644 --- a/lib/src/internal/em_transform_tools.dart +++ b/lib/src/internal/em_transform_tools.dart @@ -53,6 +53,7 @@ EMMultiDevicesEvent? convertIntToEMContactGroupEvent(int? i) { case 29: return EMMultiDevicesEvent.GROUP_REMOVE_MUTE; } + return null; } String messageTypeToTypeStr(MessageType type) { diff --git a/lib/src/models/em_chat_room.dart b/lib/src/models/em_chat_room.dart index 3f697de0..03aa7167 100644 --- a/lib/src/models/em_chat_room.dart +++ b/lib/src/models/em_chat_room.dart @@ -28,18 +28,18 @@ class EMChatRoom { /// @nodoc factory EMChatRoom.fromJson(Map map) { return EMChatRoom._private( - roomId: map.getValue('roomId'), - name: map.getValue("name"), - description: map.getValue("desc"), - owner: map.getValue("owner"), - memberCount: map.getValue("memberCount"), - maxUsers: map.getValue("maxUsers"), + roomId: map["roomId"], + name: map.getStringValue("name"), + description: map.getStringValue("desc"), + owner: map.getStringValue("owner"), + memberCount: map.getIntValue("memberCount"), + maxUsers: map.getIntValue("maxUsers"), adminList: map.listValue("adminList"), memberList: map.listValue("memberList"), blockList: map.listValue("blockList"), muteList: map.listValue("muteList"), - announcement: map.getValue("announcement"), - permissionType: chatRoomPermissionTypeFromInt(map.getValue("key")), + announcement: map.getStringValue("announcement"), + permissionType: chatRoomPermissionTypeFromInt(map.getIntValue("key")), isAllMemberMuted: map.boolValue('isAllMemberMuted')); } diff --git a/lib/src/models/em_cmd_message_body.dart b/lib/src/models/em_cmd_message_body.dart index 4a1423e8..ea854666 100644 --- a/lib/src/models/em_cmd_message_body.dart +++ b/lib/src/models/em_cmd_message_body.dart @@ -15,9 +15,9 @@ class EMCmdMessageBody extends EMMessageBody { EMCmdMessageBody.fromJson({required Map map}) : super.fromJson(map: map, type: MessageType.CMD) { - this.action = map.getValue("action"); + this.action = map["action"]; this.deliverOnlineOnly = - map.getValueWithOutNull("deliverOnlineOnly", false); + map.getBoolValue("deliverOnlineOnly", defaultValue: false)!; } @override diff --git a/lib/src/models/em_conversation.dart b/lib/src/models/em_conversation.dart index 17951f49..02472a0c 100644 --- a/lib/src/models/em_conversation.dart +++ b/lib/src/models/em_conversation.dart @@ -27,7 +27,7 @@ class EMConversation { factory EMConversation.fromJson(Map map) { Map? ext = map['ext']?.cast(); EMConversation ret = EMConversation._private( - map.getValueWithOutNull("con_id", ""), + map["con_id"], conversationTypeFromInt(map['type']), ext, ); diff --git a/lib/src/models/em_custom_message_body.dart b/lib/src/models/em_custom_message_body.dart index f7924b6d..392b9c60 100644 --- a/lib/src/models/em_custom_message_body.dart +++ b/lib/src/models/em_custom_message_body.dart @@ -15,8 +15,8 @@ class EMCustomMessageBody extends EMMessageBody { EMCustomMessageBody.fromJson({required Map map}) : super.fromJson(map: map, type: MessageType.CUSTOM) { - this.event = map.getValue("event"); - this.params = map.getValue("params")?.cast(); + this.event = map["event"]; + this.params = map["params"]?.cast(); } @override diff --git a/lib/src/models/em_deviceInfo.dart b/lib/src/models/em_deviceInfo.dart index 01c96f72..cffb2849 100644 --- a/lib/src/models/em_deviceInfo.dart +++ b/lib/src/models/em_deviceInfo.dart @@ -23,9 +23,9 @@ class EMDeviceInfo { /// @nodoc factory EMDeviceInfo.fromJson(Map map) { return EMDeviceInfo._private( - map.getValue("resource"), - map.getValue("deviceUUID"), - map.getValue("deviceName"), + map.getStringValue("resource"), + map.getStringValue("deviceUUID"), + map.getStringValue("deviceName"), ); } diff --git a/lib/src/models/em_file_message_body.dart b/lib/src/models/em_file_message_body.dart index 789d6a0f..98a76cd2 100644 --- a/lib/src/models/em_file_message_body.dart +++ b/lib/src/models/em_file_message_body.dart @@ -28,13 +28,13 @@ class EMFileMessageBody extends EMMessageBody { EMFileMessageBody.fromJson( {required Map map, MessageType type = MessageType.FILE}) : super.fromJson(map: map, type: type) { - this.secret = map.getValue("secret"); - this.remotePath = map.getValue("remotePath"); - this.fileSize = map.getValue("fileSize"); - this.localPath = map.getValue("localPath"); - this.displayName = map.getValue("displayName"); + this.secret = map.getStringValue("secret"); + this.remotePath = map.getStringValue("remotePath"); + this.fileSize = map.getIntValue("fileSize"); + this.localPath = map.getStringValue("localPath", defaultValue: "")!; + this.displayName = map.getStringValue("displayName"); this.fileStatus = EMFileMessageBody.downloadStatusFromInt( - map.getValue("fileStatus"), + map.getIntValue("fileStatus"), ); } diff --git a/lib/src/models/em_group_message_ack.dart b/lib/src/models/em_group_message_ack.dart index 6f0ddb84..c34eff72 100644 --- a/lib/src/models/em_group_message_ack.dart +++ b/lib/src/models/em_group_message_ack.dart @@ -59,9 +59,9 @@ class EMGroupMessageAck { ackId: map["ack_id"] as String, messageId: map["msg_id"] as String, from: map["from"] as String, - content: map.getValue("content"), - readCount: map.getValueWithOutNull("count", 0), - timestamp: map.getValueWithOutNull("timestamp", 0), + content: map["content"], + readCount: map.getIntValue("count", defaultValue: 0)!, + timestamp: map.getIntValue("timestamp", defaultValue: 0)!, ); return ack; diff --git a/lib/src/models/em_image_message_body.dart b/lib/src/models/em_image_message_body.dart index fef3c478..9cee4f9b 100644 --- a/lib/src/models/em_image_message_body.dart +++ b/lib/src/models/em_image_message_body.dart @@ -43,17 +43,17 @@ class EMImageMessageBody extends EMFileMessageBody { EMImageMessageBody.fromJson({required Map map}) : super.fromJson(map: map, type: MessageType.IMAGE) { - this.thumbnailLocalPath = map.getValue("thumbnailLocalPath"); - this.thumbnailRemotePath = map.getValue("thumbnailRemotePath"); - this.thumbnailSecret = map.getValue("thumbnailSecret"); - this.sendOriginalImage = map.getValueWithOutNull( + this.thumbnailLocalPath = map.getStringValue("thumbnailLocalPath"); + this.thumbnailRemotePath = map.getStringValue("thumbnailRemotePath"); + this.thumbnailSecret = map.getStringValue("thumbnailSecret"); + this.sendOriginalImage = map.getBoolValue( "sendOriginalImage", - false, - ); - this.height = map.getValue("height"); - this.width = map.getValue("width"); + defaultValue: false, + )!; + this.height = map.getDoubleValue("height"); + this.width = map.getDoubleValue("width"); this.thumbnailStatus = EMFileMessageBody.downloadStatusFromInt( - map.getValue("thumbnailStatus"), + map.getIntValue("thumbnailStatus"), ); } diff --git a/lib/src/models/em_location_message_body.dart b/lib/src/models/em_location_message_body.dart index 6ef3cf64..aa9f0c22 100644 --- a/lib/src/models/em_location_message_body.dart +++ b/lib/src/models/em_location_message_body.dart @@ -30,10 +30,10 @@ class EMLocationMessageBody extends EMMessageBody { EMLocationMessageBody.fromJson({required Map map}) : super.fromJson(map: map, type: MessageType.LOCATION) { - this.latitude = map.getValueWithOutNull("latitude", 0.0); - this.longitude = map.getValueWithOutNull("longitude", 0.0); - this._address = map.getValue("address"); - this._buildingName = map.getValue("buildingName"); + this.latitude = map.getDoubleValue("latitude", defaultValue: 0.0)!; + this.longitude = map.getDoubleValue("longitude", defaultValue: 0.0)!; + this._address = map.getStringValue("address"); + this._buildingName = map.getStringValue("buildingName"); } @override diff --git a/lib/src/models/em_message.dart b/lib/src/models/em_message.dart index 335825bb..b4ef7643 100644 --- a/lib/src/models/em_message.dart +++ b/lib/src/models/em_message.dart @@ -1,11 +1,12 @@ import 'dart:math'; +import 'package:flutter/services.dart'; + +import '../internal/chat_method_keys.dart'; import '../internal/em_transform_tools.dart'; -import '../tools/em_log.dart'; -import '../tools/em_message_callback_manager.dart'; + import '../tools/em_extension.dart'; import '../../im_flutter_sdk.dart'; -import '../internal/em_message_state_handle.dart'; /// /// The message instance, which represents a sent/received message. @@ -21,11 +22,122 @@ import '../internal/em_message_state_handle.dart'; /// ``` /// class EMMessage { - EMMessage._private() { - _tmpKey = localTime.toString(); + int _groupAckCount = 0; + + /// 消息id + String? _msgId; + String _msgLocalId = DateTime.now().millisecondsSinceEpoch.toString() + + Random().nextInt(99999).toString(); + + /// + /// Gets the message ID. + /// + /// **return** The message ID. + String get msgId => _msgId ?? _msgLocalId; + + /// + /// The conversation ID. + /// + String? conversationId; + + /// + /// The user ID of the message sender. + /// + String? from = ''; + + /// + /// The user ID of the message recipient. + /// + String? to = ''; + + /// + /// The local timestamp of the message. + /// + int localTime = DateTime.now().millisecondsSinceEpoch; + + /// + /// The local timestamp of the message. + /// + int serverTime = DateTime.now().millisecondsSinceEpoch; + + /// + /// The delivery receipt, which is to check whether the other party has received the message. + /// + /// Whether the other party has received the message. + /// `true`:the message has been delivered to the other party. + /// + bool hasDeliverAck = false; + + /// + /// Whether the other party has read the message. + /// `true`: The message has been read by the other party. + /// + bool hasReadAck = false; + + /// + /// Sets whether read receipts are required for group messages. + /// + /// `true`: Read receipts are required; + /// `false`: Read receipts are NOT required. + /// + bool needGroupAck = false; + + /// + /// Gets the number of members that have read the group message. + /// + int get groupAckCount => _groupAckCount; + + /// + /// Checks whether the message is read. + /// + /// `true`: The message is read. + /// `false`: The message is unread. + /// + bool hasRead = false; + + /// + /// The enumeration of the chat type. + /// + /// There are three chat types: one-to-one chat, group chat, and chat room. + /// + ChatType chatType = ChatType.Chat; + + /// + /// The message direction. see {@link MessageDirection} + /// + MessageDirection direction = MessageDirection.SEND; + + /// + /// Gets the message sending/reception status. see {@link MessageStatus} + /// + MessageStatus status = MessageStatus.CREATE; + + /// + /// Message's extension attribute. + /// + Map? attributes; + + /// + /// Message body. We recommend you use {@link EMMessageBody)}. + /// + late EMMessageBody body; + + /// + /// Sets the message status change callback. + /// Your app should set messageStatusCallBack to get the message status and then refresh the UI accordingly. + /// + MessageStatusCallBack? _messageStatusCallBack; + + set messageStatusCallBack(MessageStatusCallBack? callback) { + _messageStatusCallBack = callback; + if (callback != null) { + MessageCallBackManager.getInstance.addMessage(this); + } else { + MessageCallBackManager.getInstance.removeMessage(localTime.toString()); + } } - late EMMessageStateHandle _handle; + EMMessage._private(); /// /// Creates a new received message instance. @@ -37,18 +149,7 @@ class EMMessage { EMMessage.createReceiveMessage({ required this.body, }) { - _tmpKey = localTime.toString(); - _handle = EMMessageStateHandle( - _tmpKey, - onMessageDeliveryAck: _onMessageDeliveryAck, - onMessageError: _onMessageError, - onMessageProgressChanged: _onMessageProgressChanged, - onMessageReadAck: _onMessageReadAck, - onMessageSuccess: _onMessageSuccess, - onMessageStatusChanged: _onMessageStatusChanged, - ); this.direction = MessageDirection.RECEIVE; - MessageCallBackManager.getInstance.addMessage(_tmpKey, _handle); } /// @@ -65,41 +166,26 @@ class EMMessage { this.to, }) : this.from = EMClient.getInstance.currentUsername, this.conversationId = to { - _tmpKey = localTime.toString(); - _handle = EMMessageStateHandle( - _tmpKey, - onMessageDeliveryAck: _onMessageDeliveryAck, - onMessageError: _onMessageError, - onMessageProgressChanged: _onMessageProgressChanged, - onMessageReadAck: _onMessageReadAck, - onMessageSuccess: _onMessageSuccess, - onMessageStatusChanged: _onMessageStatusChanged, - ); this.hasRead = true; this.direction = MessageDirection.SEND; - MessageCallBackManager.getInstance.addMessage(_tmpKey, _handle); } void dispose() { - MessageCallBackManager.getInstance.removeMessage(_tmpKey); + MessageCallBackManager.getInstance.removeMessage(localTime.toString()); } void _onMessageError(Map map) { - EMLog.v('发送失败 -- ' + map.toString()); EMMessage msg = EMMessage.fromJson(map['message']); this._msgId = msg.msgId; this.status = msg.status; this.body = msg.body; - messageStatusCallBack?.onError?.call(EMError.fromJson(map['error'])); + _messageStatusCallBack?.onError?.call(EMError.fromJson(map['error'])); return null; } void _onMessageProgressChanged(Map map) { - EMLog.v( - '发送 -- ' + ' msg_id: ' + this.msgId + ' ' + map['progress'].toString(), - ); int progress = map['progress']; - messageStatusCallBack?.onProgress?.call(progress); + _messageStatusCallBack?.onProgress?.call(progress); return null; } @@ -108,16 +194,15 @@ class EMMessage { this._msgId = msg.msgId; this.status = msg.status; this.body = msg.body; - messageStatusCallBack?.onSuccess?.call(); - EMLog.v('发送成功 -- ' + this.toString()); + _messageStatusCallBack?.onSuccess?.call(); + return null; } void _onMessageReadAck(Map map) { - EMLog.v('消息已读 -- ' + ' msg_id: ' + this.msgId); EMMessage msg = EMMessage.fromJson(map); this.hasReadAck = msg.hasReadAck; - messageStatusCallBack?.onReadAck?.call(); + _messageStatusCallBack?.onReadAck?.call(); return null; } @@ -125,14 +210,14 @@ class EMMessage { void _onMessageDeliveryAck(Map map) { EMMessage msg = EMMessage.fromJson(map); this.hasDeliverAck = msg.hasDeliverAck; - messageStatusCallBack?.onDeliveryAck?.call(); + _messageStatusCallBack?.onDeliveryAck?.call(); return null; } void _onMessageStatusChanged(Map map) { EMMessage msg = EMMessage.fromJson(map); this.status = msg.status; - messageStatusCallBack?.onStatusChanged?.call(); + _messageStatusCallBack?.onStatusChanged?.call(); return null; } @@ -337,114 +422,6 @@ class EMMessage { this.listener = listener; } - /// - /// Sets the message status change callback. - /// Your app should set messageStatusCallBack to get the message status and then refresh the UI accordingly. - /// - MessageStatusCallBack? messageStatusCallBack; - - late String _tmpKey; - - int _groupAckCount = 0; - - /// 消息id - String? _msgId; - String _msgLocalId = DateTime.now().millisecondsSinceEpoch.toString() + - Random().nextInt(99999).toString(); - - /// - /// Gets the message ID. - /// - /// **return** The message ID. - String get msgId => _msgId ?? _msgLocalId; - - /// - /// The conversation ID. - /// - String? conversationId; - - /// - /// The user ID of the message sender. - /// - String? from = ''; - - /// - /// The user ID of the message recipient. - /// - String? to = ''; - - /// - /// The local timestamp of the message. - /// - int localTime = DateTime.now().millisecondsSinceEpoch; - - /// - /// The local timestamp of the message. - /// - int serverTime = DateTime.now().millisecondsSinceEpoch; - - /// - /// The delivery receipt, which is to check whether the other party has received the message. - /// - /// Whether the other party has received the message. - /// `true`:the message has been delivered to the other party. - /// - bool hasDeliverAck = false; - - /// - /// Whether the other party has read the message. - /// `true`: The message has been read by the other party. - /// - bool hasReadAck = false; - - /// - /// Sets whether read receipts are required for group messages. - /// - /// `true`: Read receipts are required; - /// `false`: Read receipts are NOT required. - /// - bool needGroupAck = false; - - /// - /// Gets the number of members that have read the group message. - /// - int get groupAckCount => _groupAckCount; - - /// - /// Checks whether the message is read. - /// - /// `true`: The message is read. - /// `false`: The message is unread. - /// - bool hasRead = false; - - /// - /// The enumeration of the chat type. - /// - /// There are three chat types: one-to-one chat, group chat, and chat room. - /// - ChatType chatType = ChatType.Chat; - - /// - /// The message direction. see {@link MessageDirection} - /// - MessageDirection direction = MessageDirection.SEND; - - /// - /// Gets the message sending/reception status. see {@link MessageStatus} - /// - MessageStatus status = MessageStatus.CREATE; - - /// - /// Message's extension attribute. - /// - Map? attributes; - - /// - /// Message body. We recommend you use {@link EMMessageBody)}. - /// - late EMMessageBody body; - /// @nodoc Map toJson() { final Map data = new Map(); @@ -472,24 +449,24 @@ class EMMessage { /// @nodoc factory EMMessage.fromJson(Map map) { return EMMessage._private() - ..to = map.getValue("to") - ..from = map.getValue("from") - ..body = _bodyFromMap(map.getValue("body"))! - ..attributes = map.getValue("attributes") - ..direction = map.getValue("direction") == 'send' + ..to = map.getStringValue("to") + ..from = map.getStringValue("from") + ..body = _bodyFromMap(map["body"])! + ..attributes = map.getMapValue("attributes") + ..direction = map.getStringValue("direction") == 'send' ? MessageDirection.SEND : MessageDirection.RECEIVE ..hasRead = map.boolValue('hasRead') ..hasReadAck = map.boolValue('hasReadAck') ..needGroupAck = map.boolValue('needGroupAck') - .._groupAckCount = map.getValue("groupAckCount") + .._groupAckCount = map.getIntValue("groupAckCount", defaultValue: 0)! ..hasDeliverAck = map.boolValue('hasDeliverAck') - .._msgId = map.getValue("msgId") - ..conversationId = map.getValue("conversationId") - ..chatType = chatTypeFromInt(map.getValue("chatType")) - ..localTime = map.getValue("localTime") - ..serverTime = map.getValue("serverTime") - ..status = messageStatusFromInt(map.getValue("status")); + .._msgId = map.getStringValue("msgId") + ..conversationId = map.getStringValue("conversationId") + ..chatType = chatTypeFromInt(map.getIntValue("chatType")) + ..localTime = map.getIntValue("localTime", defaultValue: 0)! + ..serverTime = map.getIntValue("serverTime", defaultValue: 0)! + ..status = messageStatusFromInt(map.intValue("status")); } static EMMessageBody? _bodyFromMap(Map map) { @@ -530,3 +507,46 @@ class EMMessage { return toJson().toString(); } } + +class MessageCallBackManager { + static const _channelPrefix = 'com.chat.im'; + static const MethodChannel _emMessageChannel = + const MethodChannel('$_channelPrefix/chat_message', JSONMethodCodec()); + Map cacheHandleMap = {}; + static MessageCallBackManager? _instance; + static MessageCallBackManager get getInstance => + _instance = _instance ?? MessageCallBackManager._internal(); + + MessageCallBackManager._internal() { + _emMessageChannel.setMethodCallHandler((MethodCall call) async { + Map argMap = call.arguments; + int? localTime = argMap['localTime']; + EMMessage? handle = cacheHandleMap[localTime.toString()]; + + if (call.method == ChatMethodKeys.onMessageProgressUpdate) { + return handle?._onMessageProgressChanged(argMap); + } else if (call.method == ChatMethodKeys.onMessageError) { + return handle?._onMessageError(argMap); + } else if (call.method == ChatMethodKeys.onMessageSuccess) { + return handle?._onMessageSuccess(argMap); + } else if (call.method == ChatMethodKeys.onMessageReadAck) { + return handle?._onMessageReadAck(argMap); + } else if (call.method == ChatMethodKeys.onMessageDeliveryAck) { + return handle?._onMessageDeliveryAck(argMap); + } else if (call.method == ChatMethodKeys.onMessageStatusChanged) { + return handle?._onMessageStatusChanged(argMap); + } + return null; + }); + } + + void addMessage(EMMessage message) { + cacheHandleMap[message.localTime.toString()] = message; + } + + void removeMessage(String key) { + if (cacheHandleMap.containsKey(key)) { + cacheHandleMap.remove(key); + } + } +} diff --git a/lib/src/models/em_text_message_body.dart b/lib/src/models/em_text_message_body.dart index eac50f3d..dc207dee 100644 --- a/lib/src/models/em_text_message_body.dart +++ b/lib/src/models/em_text_message_body.dart @@ -16,7 +16,7 @@ class EMTextMessageBody extends EMMessageBody { EMTextMessageBody.fromJson({required Map map}) : super.fromJson(map: map, type: MessageType.TXT) { - this.content = map.getValueWithOutNull("content", ""); + this.content = map.getStringValue("content", defaultValue: "")!; } @override diff --git a/lib/src/models/em_userInfo.dart b/lib/src/models/em_userInfo.dart index 0ef92566..b28b9822 100644 --- a/lib/src/models/em_userInfo.dart +++ b/lib/src/models/em_userInfo.dart @@ -36,15 +36,15 @@ class EMUserInfo { /// @nodac factory EMUserInfo.fromJson(Map map) { EMUserInfo info = EMUserInfo( - map.getValue("userId"), - nickName: map.getValue("nickName"), - avatarUrl: map.getValue("avatarUrl"), - mail: map.getValue("mail"), - phone: map.getValue("phone"), - gender: map.getValueWithOutNull("gender", 0), - sign: map.getValue("sign"), - birth: map.getValue("birth"), - ext: map.getValue("ext"), + map["userId"], + nickName: map.getStringValue("nickName"), + avatarUrl: map.getStringValue("avatarUrl"), + mail: map.getStringValue("mail"), + phone: map.getStringValue("phone"), + gender: map.getIntValue("gender", defaultValue: 0)!, + sign: map.getStringValue("sign"), + birth: map.getStringValue("birth"), + ext: map.getStringValue("ext"), ); return info; } diff --git a/lib/src/models/em_video_message_body.dart b/lib/src/models/em_video_message_body.dart index 76d01b23..73b41d89 100644 --- a/lib/src/models/em_video_message_body.dart +++ b/lib/src/models/em_video_message_body.dart @@ -42,14 +42,14 @@ class EMVideoMessageBody extends EMFileMessageBody { EMVideoMessageBody.fromJson({required Map map}) : super.fromJson(map: map, type: MessageType.VIDEO) { - this.duration = map.getValue("duration"); - this.thumbnailLocalPath = map.getValue("thumbnailLocalPath"); - this.thumbnailRemotePath = map.getValue("thumbnailRemotePath"); - this.thumbnailSecret = map.getValue("thumbnailSecret"); - this.height = map.getValue("height"); - this.width = map.getValue("width"); + this.duration = map.getIntValue("duration"); + this.thumbnailLocalPath = map.getStringValue("thumbnailLocalPath"); + this.thumbnailRemotePath = map.getStringValue("thumbnailRemotePath"); + this.thumbnailSecret = map.getStringValue("thumbnailSecret"); + this.height = map.getDoubleValue("height")?.toDouble(); + this.width = map.getDoubleValue("width")?.toDouble(); this.thumbnailStatus = EMFileMessageBody.downloadStatusFromInt( - map.getValue("thumbnailStatus")); + map.getIntValue("thumbnailStatus")); } @override diff --git a/lib/src/models/em_voice_message_body.dart b/lib/src/models/em_voice_message_body.dart index 92546fe2..0a352b56 100644 --- a/lib/src/models/em_voice_message_body.dart +++ b/lib/src/models/em_voice_message_body.dart @@ -32,7 +32,7 @@ class EMVoiceMessageBody extends EMFileMessageBody { EMVoiceMessageBody.fromJson({required Map map}) : super.fromJson(map: map, type: MessageType.VOICE) { - this.duration = map.getValue("duration"); + this.duration = map.getIntValue("duration"); } @override diff --git a/lib/src/tools/em_extension.dart b/lib/src/tools/em_extension.dart index 333b353c..2f38346a 100644 --- a/lib/src/tools/em_extension.dart +++ b/lib/src/tools/em_extension.dart @@ -70,25 +70,58 @@ extension MapExtension on Map { } } - T getValueWithOutNull(String key, T defaultValue) { - T ret = defaultValue; + int? getIntValue(String key, {int? defaultValue}) { + int? ret = defaultValue; if (this.containsKey(key)) { dynamic value = this[key]; - if (value is T) { + if (value is int) { ret = value; } } return ret; } - T? getValue(String key) { - T? ret; + bool? getBoolValue(String key, {bool? defaultValue}) { + bool? ret = defaultValue; if (this.containsKey(key)) { dynamic value = this[key]; - if (value is T) { + if (value is bool) { + ret = value; + } + } + return ret; + } + + String? getStringValue(String key, {String? defaultValue}) { + String? ret = defaultValue; + if (this.containsKey(key)) { + dynamic value = this[key]; + if (value is String) { + ret = value; + } + } + return ret; + } + + double? getDoubleValue(String key, {double? defaultValue}) { + double? ret = defaultValue; + if (this.containsKey(key)) { + dynamic value = this[key]; + if (value is double) { + ret = value; + } else if (value is int) { + ret = value.toDouble(); + } + } + return ret; + } + + Map? getMapValue(String key, {Map? defaultValue}) { + Map? ret = defaultValue; + if (this.containsKey(key)) { + Map? value = this[key]; + if (value is double) { ret = value; - } else { - ret = null; } } return ret; From 0f721f787ad4a77bbfde78c1301231741bb57aa3 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Fri, 8 Apr 2022 11:19:29 +0800 Subject: [PATCH 42/56] fix: android json object wrong. --- .../com/easemob/im_flutter_sdk/EMHelper.java | 38 ++++++++++++++----- .../chat/chat_items/chat_voice_bubble.dart | 2 +- lib/src/models/em_custom_message_body.dart | 6 ++- lib/src/models/em_video_message_body.dart | 6 +-- lib/src/models/em_voice_message_body.dart | 6 +-- lib/src/tools/em_extension.dart | 2 + 6 files changed, 41 insertions(+), 19 deletions(-) diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java index a3175e3e..2a7e78a8 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java @@ -428,7 +428,10 @@ static EMMessage fromJson(JSONObject json) throws JSONException { } message.setLocalTime(json.getLong("localTime")); - message.setMsgTime(json.getLong("serverTime")); + if (json.has("serverTime")){ + message.setMsgTime(json.getLong("serverTime")); + } + message.setStatus(statusFromInt(json.getInt("status"))); message.setChatType(chatTypeFromInt(json.getInt("chatType"))); if (json.has("msgId")){ @@ -698,9 +701,11 @@ static EMFileMessageBody fileBodyFromJson(JSONObject json) throws JSONException if (json.has("secret")){ body.setSecret(json.getString("secret")); } - body.setDownloadStatus(downloadStatusFromInt(json.getInt("fileStatus"))); - body.setFileLength(json.getInt("fileSize")); + if (json.has("fileSize")){ + body.setFileLength(json.getInt("fileSize")); + } + return body; } @@ -779,8 +784,8 @@ static Map imageBodyToJson(EMImageMessageBody body) { static EMVideoMessageBody videoBodyFromJson(JSONObject json) throws JSONException { String localPath = json.getString("localPath"); int duration = json.getInt("duration"); - int fileSize = json.getInt("fileSize"); - EMVideoMessageBody body = new EMVideoMessageBody(localPath, null, duration, fileSize); + EMVideoMessageBody body = new EMVideoMessageBody(localPath, null, duration, 0); + if (json.has("thumbnailRemotePath")){ body.setThumbnailUrl(json.getString("thumbnailRemotePath")); } @@ -799,11 +804,21 @@ static EMVideoMessageBody videoBodyFromJson(JSONObject json) throws JSONExceptio if (json.has("secret")){ body.setSecret(json.getString("secret")); } + if (json.has("fileSize")){ + body.setVideoFileLength(json.getInt("fileSize")); + } + + if(json.has("fileStatus")){ + body.setDownloadStatus(downloadStatusFromInt(json.getInt("fileStatus"))); + } + + if (json.has("width") && json.has("height")){ + int width = json.getInt("width"); + int height = json.getInt("height"); + body.setThumbnailSize(width, height); + } + - body.setDownloadStatus(downloadStatusFromInt(json.getInt("fileStatus"))); - int width = json.getInt("width"); - int height = json.getInt("height"); - body.setThumbnailSize(width, height); return body; } @@ -841,7 +856,10 @@ static EMVoiceMessageBody voiceBodyFromJson(JSONObject json) throws JSONExceptio if (json.has("remotePath")){ body.setRemoteUrl(json.getString("remotePath")); } - body.setFileLength(json.getLong("fileSize")); + if (json.has("fileSize")){ + body.setFileLength(json.getLong("fileSize")); + } + return body; } diff --git a/example/lib/pages/chat/chat_items/chat_voice_bubble.dart b/example/lib/pages/chat/chat_items/chat_voice_bubble.dart index 832461f7..89c74108 100644 --- a/example/lib/pages/chat/chat_items/chat_voice_bubble.dart +++ b/example/lib/pages/chat/chat_items/chat_voice_bubble.dart @@ -48,7 +48,7 @@ class ChatVoiceBubbleState extends State controller.stop(); controller.reverse(from: 0); } - double width = minSize * widget.body.duration! / 15; + double width = minSize * widget.body.duration / 15; if (width < minSize) width = minSize; if (width > maxSize) width = maxSize; return Container( diff --git a/lib/src/models/em_custom_message_body.dart b/lib/src/models/em_custom_message_body.dart index 392b9c60..2d098bf6 100644 --- a/lib/src/models/em_custom_message_body.dart +++ b/lib/src/models/em_custom_message_body.dart @@ -10,8 +10,10 @@ class EMCustomMessageBody extends EMMessageBody { /// /// Creates a custom message. /// - EMCustomMessageBody({required this.event, this.params}) - : super(type: MessageType.CUSTOM); + EMCustomMessageBody({ + required this.event, + this.params, + }) : super(type: MessageType.CUSTOM); EMCustomMessageBody.fromJson({required Map map}) : super.fromJson(map: map, type: MessageType.CUSTOM) { diff --git a/lib/src/models/em_video_message_body.dart b/lib/src/models/em_video_message_body.dart index 73b41d89..1703c031 100644 --- a/lib/src/models/em_video_message_body.dart +++ b/lib/src/models/em_video_message_body.dart @@ -28,7 +28,7 @@ class EMVideoMessageBody extends EMFileMessageBody { EMVideoMessageBody({ required String localPath, String? displayName, - this.duration, + this.duration = 0, int? fileSize, this.thumbnailLocalPath, this.height, @@ -42,7 +42,7 @@ class EMVideoMessageBody extends EMFileMessageBody { EMVideoMessageBody.fromJson({required Map map}) : super.fromJson(map: map, type: MessageType.VIDEO) { - this.duration = map.getIntValue("duration"); + this.duration = map.getIntValue("duration", defaultValue: 0)!; this.thumbnailLocalPath = map.getStringValue("thumbnailLocalPath"); this.thumbnailRemotePath = map.getStringValue("thumbnailRemotePath"); this.thumbnailSecret = map.getStringValue("thumbnailSecret"); @@ -68,7 +68,7 @@ class EMVideoMessageBody extends EMFileMessageBody { } /// The video duration in seconds. - int? duration; + late final int duration; /// The local path of the video thumbnail. String? thumbnailLocalPath; diff --git a/lib/src/models/em_voice_message_body.dart b/lib/src/models/em_voice_message_body.dart index 0a352b56..f8aa1b2d 100644 --- a/lib/src/models/em_voice_message_body.dart +++ b/lib/src/models/em_voice_message_body.dart @@ -20,9 +20,9 @@ class EMVoiceMessageBody extends EMFileMessageBody { /// EMVoiceMessageBody({ localPath, + this.duration = 0, String? displayName, int? fileSize, - this.duration, }) : super( localPath: localPath, displayName: displayName, @@ -32,7 +32,7 @@ class EMVoiceMessageBody extends EMFileMessageBody { EMVoiceMessageBody.fromJson({required Map map}) : super.fromJson(map: map, type: MessageType.VOICE) { - this.duration = map.getIntValue("duration"); + this.duration = map.getIntValue("duration", defaultValue: 0)!; } @override @@ -43,5 +43,5 @@ class EMVoiceMessageBody extends EMFileMessageBody { } /// The voice duration in seconds. - int? duration; + late final int duration; } diff --git a/lib/src/tools/em_extension.dart b/lib/src/tools/em_extension.dart index 2f38346a..ce462c7e 100644 --- a/lib/src/tools/em_extension.dart +++ b/lib/src/tools/em_extension.dart @@ -54,6 +54,8 @@ extension MapExtension on Map { return null; } + /// + /// 如果给的value是null则不设置到map中。 void setValueWithOutNull(String key, T? value, {Object Function(T object)? callback, T? defaultValue}) { if (value != null) { From 89882434669c1584e079fb4a42eebf262c389632 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Fri, 8 Apr 2022 11:51:48 +0800 Subject: [PATCH 43/56] rename message callback --- lib/src/models/em_message.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/models/em_message.dart b/lib/src/models/em_message.dart index b4ef7643..19d1904a 100644 --- a/lib/src/models/em_message.dart +++ b/lib/src/models/em_message.dart @@ -128,7 +128,7 @@ class EMMessage { /// MessageStatusCallBack? _messageStatusCallBack; - set messageStatusCallBack(MessageStatusCallBack? callback) { + void setMessageStatusCallBack(MessageStatusCallBack? callback) { _messageStatusCallBack = callback; if (callback != null) { MessageCallBackManager.getInstance.addMessage(this); From f4c9b7d89b527f82e7439bc9c60cbaa8774ea727 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Fri, 8 Apr 2022 15:12:49 +0800 Subject: [PATCH 44/56] fix android join public group crash. --- .../im_flutter_sdk/EMGroupManagerWrapper.java | 23 +++++++++++-------- ios/Classes/EMGroupManagerWrapper.m | 1 + 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMGroupManagerWrapper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMGroupManagerWrapper.java index 9ba82fc3..814d472a 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMGroupManagerWrapper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMGroupManagerWrapper.java @@ -684,18 +684,21 @@ private void updateGroupExt(JSONObject param, String channelName, Result result) } private void joinPublicGroup(JSONObject param, String channelName, Result result) throws JSONException { - String groupId = param.getString("groupId"); - EMWrapperCallBack callBack = new EMWrapperCallBack(result, channelName, null) { - @Override - public void onSuccess() { - EMGroup group = EMClient.getInstance().groupManager().getGroup(groupId); - super.object = EMGroupHelper.toJson(group); - super.onSuccess(); + String groupId = param.getString("groupId"); + asyncRunnable(()->{ + try{ + EMGroup group = EMClient.getInstance().groupManager().getGroupFromServer(groupId); + if (group.isMemberOnly()){ + throw new HyphenateException(603,"User has no permission for this operation"); + } + EMClient.getInstance().groupManager().joinGroup(groupId); + EMGroup joinedGroup = EMClient.getInstance().groupManager().getGroup(groupId); + onSuccess(result, channelName, EMGroupHelper.toJson(joinedGroup)); + }catch (HyphenateException e){ + onError(result, e); } - }; - - EMClient.getInstance().groupManager().asyncJoinGroup(groupId, callBack); + }); } private void requestToJoinPublicGroup(JSONObject param, String channelName, Result result) throws JSONException { diff --git a/ios/Classes/EMGroupManagerWrapper.m b/ios/Classes/EMGroupManagerWrapper.m index b649f46b..34e713bd 100644 --- a/ios/Classes/EMGroupManagerWrapper.m +++ b/ios/Classes/EMGroupManagerWrapper.m @@ -842,6 +842,7 @@ - (void)updateGroupExt:(NSDictionary *)param channelName:(NSString *)aChannelNam - (void)joinPublicGroup:(NSDictionary *)param channelName:(NSString *)aChannelName result:(FlutterResult)result { __weak typeof(self) weakSelf = self; + [EMClient.sharedClient.groupManager joinPublicGroup:param[@"groupId"] completion:^(EMGroup *aGroup, EMError *aError) { From 2d65af8b470a9e1d49014d848b38fef2223bbf46 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Fri, 8 Apr 2022 19:58:14 +0800 Subject: [PATCH 45/56] change methods name. --- .../im_flutter_sdk/EMChatManagerWrapper.java | 7 - .../im_flutter_sdk/EMClientWrapper.java | 44 +- .../im_flutter_sdk/EMConversationWrapper.java | 19 - .../im_flutter_sdk/EMGroupManagerWrapper.java | 211 +++++++--- .../easemob/im_flutter_sdk/EMSDKMethod.java | 7 +- .../EMUserInfoManagerWrapper.java | 1 - .../lib/pages/chat/chat_items/chat_item.dart | 4 +- ios/Classes/EMChatManagerWrapper.m | 131 +++--- ios/Classes/EMChatroomManagerWrapper.m | 82 ++-- ios/Classes/EMClientWrapper.m | 94 +++-- ios/Classes/EMContactManagerWrapper.m | 32 +- ios/Classes/EMConversationWrapper.m | 58 +-- ios/Classes/EMGroupManagerWrapper.m | 134 +++--- ios/Classes/EMPushManagerWrapper.m | 32 +- ios/Classes/EMSDKMethod.h | 386 +++++++++--------- ios/Classes/EMUserInfoManagerWrapper.m | 10 +- lib/src/internal/chat_method_keys.dart | 354 ++++++++-------- lib/src/internal/em_message_state_handle.dart | 2 - lib/src/models/em_message.dart | 9 - .../tools/em_message_callback_manager.dart | 2 - 20 files changed, 803 insertions(+), 816 deletions(-) diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMChatManagerWrapper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMChatManagerWrapper.java index 3a52ab81..809f1d45 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMChatManagerWrapper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMChatManagerWrapper.java @@ -560,13 +560,6 @@ public void onMessageRecalled(List messages) { post(() -> channel.invokeMethod(EMSDKMethod.onMessagesRecalled, msgList)); } - @Override - public void onMessageChanged(EMMessage message, Object change) { - Map data = new HashMap<>(); - data.put("message", EMMessageHelper.toJson(message)); - post(() -> channel.invokeMethod(EMSDKMethod.onMessageStatusChanged, data)); - } - @Override public void onGroupMessageRead(List var1) { ArrayList> msgList = new ArrayList<>(); diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMClientWrapper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMClientWrapper.java index e70abf73..d0ed296a 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMClientWrapper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMClientWrapper.java @@ -71,10 +71,6 @@ else if (EMSDKMethod.changeAppKey.equals(call.method)) { changeAppKey(param, call.method, result); } - else if (EMSDKMethod.updateCurrentUserNick.equals(call.method)) - { - updateCurrentUserNick(param, call.method, result); - } else if (EMSDKMethod.uploadLog.equals(call.method)) { uploadLog(param, call.method, result); @@ -114,6 +110,9 @@ else if (EMSDKMethod.getToken.equals(call.method)) else if (EMSDKMethod.isConnected.equals(call.method)) { isConnected(param, call.method, result); } + else if (EMSDKMethod.renewToken.equals(call.method)){ + renewToken(param, call.method, result); + } else { super.onMethodCall(call, result); } @@ -215,19 +214,6 @@ private void isConnected(JSONObject param, String channelName, Result result) th onSuccess(result, channelName, EMClient.getInstance().isConnected()); } - private void updateCurrentUserNick(JSONObject param, String channelName, Result result) throws JSONException { - String nickName = param.getString("nickname"); - asyncRunnable(()->{ - try { - boolean status = EMClient.getInstance().pushManager().updatePushNickname(nickName); - onSuccess(result, channelName, status); - } catch (HyphenateException e) { - onError(result, e); - } - }); - } - - private void uploadLog(JSONObject param, String channelName, Result result) throws JSONException { EMClient.getInstance().uploadLog(new EMWrapperCallBack(result, channelName, true)); } @@ -278,6 +264,21 @@ private void onMultiDeviceEvent(JSONObject param, String channelName, Result res } + private void init(JSONObject param, String channelName, Result result) throws JSONException { + EMOptions options = EMOptionsHelper.fromJson(param, this.context); + EMClient.getInstance().init(this.context, options); + EMClient.getInstance().setDebugMode(param.getBoolean("debugModel")); + bindingManagers(); + addEMListener(); + onSuccess(result, channelName, null); + } + + private void renewToken(JSONObject param, String channelName, Result result) throws JSONException { + String agoraToken = param.getString("agora_token"); + EMClient.getInstance().renewToken(agoraToken); + onSuccess(result, channelName, null); + } + private void getLoggedInDevicesFromServer(JSONObject param, String channelName, Result result) throws JSONException { String username = param.getString("username"); String password = param.getString("password"); @@ -304,14 +305,7 @@ private void bindingManagers() { new EMPushManagerWrapper(binging, "chat_push_manager"); new EMUserInfoManagerWrapper(binging, "chat_userInfo_manager"); } - private void init(JSONObject param, String channelName, Result result) throws JSONException { - EMOptions options = EMOptionsHelper.fromJson(param, this.context); - EMClient.getInstance().init(this.context, options); - EMClient.getInstance().setDebugMode(param.getBoolean("debugModel")); - bindingManagers(); - addEMListener(); - onSuccess(result, channelName, null); - } + private void addEMListener() { EMClient.getInstance().addMultiDeviceListener(new EMMultiDeviceListener() { diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMConversationWrapper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMConversationWrapper.java index b18bcaaf..2bf1a8fc 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMConversationWrapper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMConversationWrapper.java @@ -44,9 +44,6 @@ else if (EMSDKMethod.markMessageAsRead.equals(call.method)) { else if (EMSDKMethod.syncConversationExt.equals(call.method)){ syncConversationExt(param, call.method, result); } - else if (EMSDKMethod.syncConversationName.equals(call.method)){ - syncConversationName(param, call.method, result); - } else if (EMSDKMethod.removeMessage.equals(call.method)) { removeMessage(param, call.method, result); @@ -120,22 +117,6 @@ private void markMessageAsRead(JSONObject params, String channelName, Result res }); } - private void syncConversationName(JSONObject params, String channelName, Result result) throws JSONException { - EMConversation conversation = conversationWithParam(params); - String conName = params.getString("con_name"); - String extField = conversation.getExtField(); - JSONObject jsonObject = new JSONObject(); - if(!extField.isEmpty()){ - jsonObject = new JSONObject(extField); - } - jsonObject.put("con_name", conName); - String jsonStr = jsonObject.toString(); - conversation.setExtField(jsonStr); - asyncRunnable(()->{ - onSuccess(result, channelName, true); - }); - } - private void syncConversationExt(JSONObject params, String channelName, Result result) throws JSONException { EMConversation conversation = conversationWithParam(params); JSONObject ext = params.getJSONObject("ext"); diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMGroupManagerWrapper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMGroupManagerWrapper.java index 814d472a..c5c4ac04 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMGroupManagerWrapper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMGroupManagerWrapper.java @@ -171,8 +171,14 @@ private void getGroupsWithoutPushNotification(JSONObject param, String channelNa private void getJoinedGroupsFromServer(JSONObject param, String channelName, Result result) throws JSONException { - int pageSize = param.getInt("pageSize"); - int pageNum = param.getInt("pageNum"); + int pageSize = 0; + if (param.has("pageSize")){ + pageSize = param.getInt("pageSize"); + } + int pageNum = 0; + if (param.has("pageNum")){ + pageNum = param.getInt("pageNum"); + } EMValueWrapperCallBack> callBack = new EMValueWrapperCallBack>(result, channelName) { @@ -190,7 +196,10 @@ public void onSuccess(List object) { } private void getPublicGroupsFromServer(JSONObject param, String channelName, Result result) throws JSONException { - int pageSize = param.getInt("pageSize"); + int pageSize = 0; + if (param.has("pageSize")){ + pageSize = param.getInt("pageSize"); + } String cursor = null; if (param.has("cursor")){ cursor = param.getString("cursor"); @@ -285,8 +294,14 @@ public void onSuccess(EMCursorResult object) { private void getGroupBlockListFromServer(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - int pageNum = param.getInt("pageNum"); - int pageSize = param.getInt("pageSize"); + int pageSize = 0; + if (param.has("pageSize")){ + pageSize = param.getInt("pageSize"); + } + int pageNum = 0; + if (param.has("pageNum")){ + pageNum = param.getInt("pageNum"); + } EMClient.getInstance().groupManager().asyncGetBlockedUsers(groupId, pageNum, pageSize, new EMValueWrapperCallBack>(result, channelName)); @@ -294,8 +309,15 @@ private void getGroupBlockListFromServer(JSONObject param, String channelName, R private void getGroupMuteListFromServer(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - int pageNum = param.getInt("pageNum"); - int pageSize = param.getInt("pageSize"); + int pageSize = 0; + if (param.has("pageSize")){ + pageSize = param.getInt("pageSize"); + } + int pageNum = 0; + if (param.has("pageNum")){ + pageNum = param.getInt("pageNum"); + } + EMValueWrapperCallBack> callBack = new EMValueWrapperCallBack>(result, channelName) { @@ -323,8 +345,14 @@ private void isMemberInWhiteListFromServer(JSONObject param, String channelName, private void getGroupFileListFromServer(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - int pageNum = param.getInt("pageNum"); - int pageSize = param.getInt("pageSize"); + int pageNum = 0; + if (param.has("pageNum")){ + pageNum = param.getInt("pageNum"); + } + int pageSize = 0; + if (param.has("pageSize")) { + pageSize = param.getInt("pageSize"); + } EMValueWrapperCallBack> callBack = new EMValueWrapperCallBack>( result, channelName) { @@ -354,23 +382,34 @@ private void inviterUser(JSONObject param, String channelName, Result result) th if (param.has("reason")) { reason = param.getString("reason"); } - JSONArray array = param.getJSONArray("members"); - String[] members = new String[array.length()]; - for (int i = 0; i < array.length(); i++) { - members[i] = array.getString(i); + String[] members = null; + if (param.has("members")){ + JSONArray array = param.getJSONArray("members"); + members = new String[array.length()]; + for (int i = 0; i < array.length(); i++) { + members[i] = array.getString(i); + } + } + if (members == null) { + members = new String[0]; } - EMClient.getInstance().groupManager().asyncInviteUser(groupId, members, reason, new EMWrapperCallBack(result, channelName, true)); } private void addMembers(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - JSONArray array = param.getJSONArray("members"); - String[] members = new String[array.length()]; - for (int i = 0; i < array.length(); i++) { - members[i] = array.getString(i); + String[] members = null; + if (param.has("members")){ + JSONArray array = param.getJSONArray("members"); + members = new String[array.length()]; + for (int i = 0; i < array.length(); i++) { + members[i] = array.getString(i); + } + } + if (members == null) { + members = new String[0]; } String welcome = null; @@ -378,9 +417,10 @@ private void addMembers(JSONObject param, String channelName, Result result) thr welcome = param.getString("welcome"); } String finalWelcome = welcome; + String[] finalMembers = members; asyncRunnable(() -> { try { - EMClient.getInstance().groupManager().addUsersToGroup(groupId, members, finalWelcome); + EMClient.getInstance().groupManager().addUsersToGroup(groupId, finalMembers, finalWelcome); onSuccess(result, channelName, true); } catch (HyphenateException e) { onError(result, e); @@ -390,11 +430,12 @@ private void addMembers(JSONObject param, String channelName, Result result) thr private void removeMembers(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - JSONArray array = param.getJSONArray("members"); - List members = new ArrayList<>(); - for (int i = 0; i < array.length(); i++) { - members.add(array.getString(i)); + if (param.has("members")){ + JSONArray array = param.getJSONArray("members"); + for (int i = 0; i < array.length(); i++) { + members.add(array.getString(i)); + } } EMClient.getInstance().groupManager().asyncRemoveUsersFromGroup(groupId, members, @@ -403,10 +444,12 @@ private void removeMembers(JSONObject param, String channelName, Result result) private void blockMembers(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - JSONArray array = param.getJSONArray("members"); List members = new ArrayList<>(); - for (int i = 0; i < array.length(); i++) { - members.add(array.getString(i)); + if (param.has("members")){ + JSONArray array = param.getJSONArray("members"); + for (int i = 0; i < array.length(); i++) { + members.add(array.getString(i)); + } } EMClient.getInstance().groupManager().asyncBlockUsers(groupId, members, @@ -415,10 +458,12 @@ private void blockMembers(JSONObject param, String channelName, Result result) t private void unblockMembers(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - JSONArray array = param.getJSONArray("members"); List members = new ArrayList<>(); - for (int i = 0; i < array.length(); i++) { - members.add(array.getString(i)); + if (param.has("members")){ + JSONArray array = param.getJSONArray("members"); + for (int i = 0; i < array.length(); i++) { + members.add(array.getString(i)); + } } EMClient.getInstance().groupManager().asyncUnblockUsers(groupId, members, @@ -427,7 +472,11 @@ private void unblockMembers(JSONObject param, String channelName, Result result) private void updateGroupSubject(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - String name = param.getString("name"); + + String name = ""; + if (param.has("name")){ + name = param.getString("name"); + } EMWrapperCallBack callBack = new EMWrapperCallBack(result, channelName, null) { @Override @@ -444,7 +493,10 @@ public void onSuccess() { private void updateDescription(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - String desc = param.getString("desc"); + String desc = ""; + if (param.has("desc")){ + desc = param.getString("desc"); + } EMWrapperCallBack callBack = new EMWrapperCallBack(result, channelName, null) { @Override @@ -544,13 +596,18 @@ public void onSuccess(EMGroup object) { private void muteMembers(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - int duration = param.getInt("duration"); - JSONArray array = param.getJSONArray("members"); + + int duration = 0; + if (param.has("duration")){ + duration = param.getInt("duration"); + } List members = new ArrayList<>(); - for (int i = 0; i < array.length(); i++) { - members.add(array.getString(i)); + if (param.has("members")){ + JSONArray array = param.getJSONArray("members"); + for (int i = 0; i < array.length(); i++) { + members.add(array.getString(i)); + } } - EMValueWrapperCallBack callBack = new EMValueWrapperCallBack(result, channelName) { @Override public void onSuccess(EMGroup object) { @@ -563,12 +620,13 @@ public void onSuccess(EMGroup object) { private void unMuteMembers(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - JSONArray array = param.getJSONArray("members"); List members = new ArrayList<>(); - for (int i = 0; i < array.length(); i++) { - members.add(array.getString(i)); + if (param.has("members")){ + JSONArray array = param.getJSONArray("members"); + for (int i = 0; i < array.length(); i++) { + members.add(array.getString(i)); + } } - EMValueWrapperCallBack callBack = new EMValueWrapperCallBack(result, channelName) { @Override public void onSuccess(EMGroup object) { @@ -607,31 +665,36 @@ public void onSuccess(EMGroup object) { private void addWhiteList(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - JSONArray array = param.getJSONArray("members"); List members = new ArrayList<>(); - for (int i = 0; i < array.length(); i++) { - members.add(array.getString(i)); + if (param.has("members")){ + JSONArray array = param.getJSONArray("members"); + for (int i = 0; i < array.length(); i++) { + members.add(array.getString(i)); + } } - EMClient.getInstance().groupManager().addToGroupWhiteList(groupId, members, new EMWrapperCallBack(result, channelName, true)); } private void removeWhiteList(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - JSONArray array = param.getJSONArray("members"); List members = new ArrayList<>(); - for (int i = 0; i < array.length(); i++) { - members.add(array.getString(i)); + if (param.has("members")){ + JSONArray array = param.getJSONArray("members"); + for (int i = 0; i < array.length(); i++) { + members.add(array.getString(i)); + } } - EMClient.getInstance().groupManager().removeFromGroupWhiteList(groupId, members, new EMWrapperCallBack(result, channelName, true)); } private void uploadGroupSharedFile(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - String filePath = param.getString("filePath"); + String filePath = null; + if (param.has("filePath")){ + filePath = param.getString("filePath"); + } EMClient.getInstance().groupManager().asyncUploadGroupSharedFile(groupId, filePath, new EMWrapperCallBack(result, channelName, true)); @@ -639,8 +702,14 @@ private void uploadGroupSharedFile(JSONObject param, String channelName, Result private void downloadGroupSharedFile(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - String fileId = param.getString("fileId"); - String savePath = param.getString("savePath"); + String fileId = null; + if (param.has("fileId")) { + fileId = param.getString("fileId"); + } + String savePath = null; + if (param.has("savePath")) { + savePath = param.getString("savePath"); + } EMClient.getInstance().groupManager().asyncDownloadGroupSharedFile(groupId, fileId, savePath, new EMWrapperCallBack(result, channelName, true)); @@ -648,15 +717,20 @@ private void downloadGroupSharedFile(JSONObject param, String channelName, Resul private void removeGroupSharedFile(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - String fileId = param.getString("fileId"); + String fileId = null; + if (param.has("fileId")) { + fileId = param.getString("fileId"); + } EMClient.getInstance().groupManager().asyncDeleteGroupSharedFile(groupId, fileId, new EMWrapperCallBack(result, channelName, true)); } private void updateGroupAnnouncement(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - String announcement = param.getString("announcement"); - + String announcement = null; + if (param.has("announcement")) { + announcement = param.getString("announcement"); + } EMWrapperCallBack callBack = new EMWrapperCallBack(result, channelName, null) { @Override public void onSuccess() { @@ -671,11 +745,15 @@ public void onSuccess() { private void updateGroupExt(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - String ext = param.getString("ext"); + String ext = null; + if (param.has("ext")) { + ext = param.getString("ext"); + } + String finalExt = ext; asyncRunnable(() -> { try { - EMGroup group = EMClient.getInstance().groupManager().updateGroupExtension(groupId, ext); + EMGroup group = EMClient.getInstance().groupManager().updateGroupExtension(groupId, finalExt); onSuccess(result, channelName, EMGroupHelper.toJson(group)); } catch (HyphenateException e) { onError(result, e); @@ -721,7 +799,11 @@ public void onSuccess() { private void acceptJoinApplication(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - String username = param.getString("username"); + + String username = null; + if (param.has("username")){ + username = param.getString("username"); + } EMWrapperCallBack callBack = new EMWrapperCallBack(result, channelName, null) { @Override @@ -737,7 +819,10 @@ public void onSuccess() { private void declineJoinApplication(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - String username = param.getString("username"); + String username = null; + if (param.has("username")){ + username = param.getString("username"); + } String reason = null; if (param.has("reason")){ reason = param.getString("reason"); @@ -757,8 +842,11 @@ public void onSuccess() { private void acceptInvitationFromGroup(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - String inviter = param.getString("inviter"); + String inviter = null; + if (param.has("inviter")){ + inviter = param.getString("inviter"); + } EMValueWrapperCallBack callBack = new EMValueWrapperCallBack(result, channelName) { @Override public void onSuccess(EMGroup object) { @@ -771,7 +859,10 @@ public void onSuccess(EMGroup object) { private void declineInvitationFromGroup(JSONObject param, String channelName, Result result) throws JSONException { String groupId = param.getString("groupId"); - String username = param.getString("username"); + String username = null; + if (param.has("username")){ + username = param.getString("username"); + } String reason = null; if (param.has("reason")){ reason = param.getString("reason"); diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMSDKMethod.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMSDKMethod.java index e7fe6284..e9651697 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMSDKMethod.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMSDKMethod.java @@ -6,9 +6,10 @@ public class EMSDKMethod { static final String createAccount = "createAccount"; static final String login = "login"; static final String loginWithAgoraToken = "loginWithAgoraToken"; + static final String renewToken = "renewToken"; static final String logout = "logout"; static final String changeAppKey = "changeAppKey"; - static final String updateCurrentUserNick = "updateCurrentUserNick"; + static final String uploadLog = "uploadLog"; static final String compressLogs = "compressLogs"; static final String kickDevice = "kickDevice"; @@ -83,14 +84,12 @@ public class EMSDKMethod { static final String onMessageSuccess = "onMessageSuccess"; static final String onMessageReadAck = "onMessageReadAck"; static final String onMessageDeliveryAck = "onMessageDeliveryAck"; - static final String onMessageStatusChanged = "onMessageStatusChanged"; /// EMConversation static final String getUnreadMsgCount = "getUnreadMsgCount"; static final String markAllMessagesAsRead = "markAllMessagesAsRead"; static final String markMessageAsRead = "markMessageAsRead"; static final String syncConversationExt = "syncConversationExt"; - static final String syncConversationName = "syncConversationName"; static final String removeMessage = "removeMessage"; static final String getLatestMessage = "getLatestMessage"; static final String getLatestMessageFromOthers = "getLatestMessageFromOthers"; @@ -160,7 +159,7 @@ public class EMSDKMethod { static final String getGroupMuteListFromServer = "getGroupMuteListFromServer"; static final String getGroupWhiteListFromServer = "getGroupWhiteListFromServer"; static final String isMemberInWhiteListFromServer = "isMemberInWhiteListFromServer"; - static final String getGroupFileListFromServer = "getGroupFileList"; + static final String getGroupFileListFromServer = "getGroupFileListFromServer"; static final String getGroupAnnouncementFromServer = "getGroupAnnouncementFromServer"; static final String addMembers = "addMembers"; static final String inviterUser = "inviterUser"; diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMUserInfoManagerWrapper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMUserInfoManagerWrapper.java index f2b24db4..16320582 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMUserInfoManagerWrapper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMUserInfoManagerWrapper.java @@ -85,7 +85,6 @@ private void updateOwnUserInfoWithType(JSONObject params, String channelName, Re EMValueWrapperCallBack callBack = new EMValueWrapperCallBack(result, channelName){ @Override public void onSuccess(final String object) { - EMLog.e("updateOwnUserInfoWithType", "object: "+object); if(object != null && object.length() > 0) { JSONObject obj = null; diff --git a/example/lib/pages/chat/chat_items/chat_item.dart b/example/lib/pages/chat/chat_items/chat_item.dart index 7261f424..da7e677f 100644 --- a/example/lib/pages/chat/chat_items/chat_item.dart +++ b/example/lib/pages/chat/chat_items/chat_item.dart @@ -44,7 +44,7 @@ class ChatItem extends StatefulWidget { class ChatItemState extends State { void initState() { super.initState(); - widget.msg.messageStatusCallBack = MessageStatusCallBack(onSuccess: () { + widget.msg.setMessageStatusCallBack(MessageStatusCallBack(onSuccess: () { if (mounted) { setState(() {}); } @@ -58,7 +58,7 @@ class ChatItemState extends State { } }, onProgress: (progress) { debugPrint("progress --- $progress"); - }); + })); } @override diff --git a/ios/Classes/EMChatManagerWrapper.m b/ios/Classes/EMChatManagerWrapper.m index 059b50b2..79d9b219 100644 --- a/ios/Classes/EMChatManagerWrapper.m +++ b/ios/Classes/EMChatManagerWrapper.m @@ -41,91 +41,91 @@ - (instancetype)initWithChannelName:(NSString *)aChannelName - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { - if ([EMMethodKeySendMessage isEqualToString:call.method]) { + if ([ChatSendMessage isEqualToString:call.method]) { [self sendMessage:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyResendMessage isEqualToString:call.method]) { + } else if ([ChatResendMessage isEqualToString:call.method]) { [self resendMessage:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyAckMessageRead isEqualToString:call.method]) { + } else if ([ChatAckMessageRead isEqualToString:call.method]) { [self ackMessageRead:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyAckGroupMessageRead isEqualToString:call.method]) { + } else if ([ChatAckGroupMessageRead isEqualToString:call.method]) { [self ackGroupMessageRead:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyAckConversationRead isEqualToString:call.method]) { + } else if ([ChatAckConversationRead isEqualToString:call.method]) { [self ackConversationRead:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyRecallMessage isEqualToString:call.method]) { + else if ([ChatRecallMessage isEqualToString:call.method]) { [self recallMessage:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyGetConversation isEqualToString:call.method]) { + } else if ([ChatGetConversation isEqualToString:call.method]) { [self getConversation:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyGetMessage isEqualToString:call.method]) { + } else if ([ChatGetMessage isEqualToString:call.method]) { [self getMessageWithMessageId:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyMarkAllChatMsgAsRead isEqualToString:call.method]) { + } else if ([ChatMarkAllChatMsgAsRead isEqualToString:call.method]) { [self markAllMessagesAsRead:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyGetUnreadMessageCount isEqualToString:call.method]) { + } else if ([ChatGetUnreadMessageCount isEqualToString:call.method]) { [self getUnreadMessageCount:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyUpdateChatMessage isEqualToString:call.method]) { + } else if ([ChatUpdateChatMessage isEqualToString:call.method]) { [self updateChatMessage:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyDownloadAttachment isEqualToString:call.method]) { + } else if ([ChatDownloadAttachment isEqualToString:call.method]) { [self downloadAttachment:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyDownloadThumbnail isEqualToString:call.method]) { + } else if ([ChatDownloadThumbnail isEqualToString:call.method]) { [self downloadThumbnail:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyImportMessages isEqualToString:call.method]) { + } else if ([ChatImportMessages isEqualToString:call.method]) { [self importMessages:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyLoadAllConversations isEqualToString:call.method]) { + } else if ([ChatLoadAllConversations isEqualToString:call.method]) { [self loadAllConversations:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyGetConversationsFromServer isEqualToString:call.method]) { + } else if ([ChatGetConversationsFromServer isEqualToString:call.method]) { [self getConversationsFromServer:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyDeleteConversation isEqualToString:call.method]) { + } else if ([ChatDeleteConversation isEqualToString:call.method]) { [self deleteConversation:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyFetchHistoryMessages isEqualToString:call.method]) { + } else if ([ChatFetchHistoryMessages isEqualToString:call.method]) { [self fetchHistoryMessages:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeySearchChatMsgFromDB isEqualToString:call.method]) { + } else if ([ChatSearchChatMsgFromDB isEqualToString:call.method]) { [self searchChatMsgFromDB:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyUpdateConversationsName isEqualToString:call.method]) { - [self updateConversationsName:call.arguments - channelName:call.method - result:result]; - } else if ([EMMethodKeyAsyncFetchGroupAcks isEqualToString:call.method]) { + } else if ([ChatAsyncFetchGroupAcks isEqualToString:call.method]) { [self fetchGroupReadAck:call.arguments channelName:call.method result:result]; + } else if ([ChatDeleteRemoteConversation isEqualToString:call.method]){ + [self deleteRemoteConversation:call.arguments + channelName:call.method + result:result]; } else { [super handleMethodCall:call result:result]; @@ -148,21 +148,21 @@ - (void)sendMessage:(NSDictionary *)param [EMClient.sharedClient.chatManager sendMessage:msg progress:^(int progress) { - [weakSelf.messageChannel invokeMethod:EMMethodKeyOnMessageProgressUpdate + [weakSelf.messageChannel invokeMethod:ChatOnMessageProgressUpdate arguments:@{ @"progress":@(progress), @"localTime":@(msg.localTime) }]; } completion:^(EMChatMessage *message, EMError *error) { if (error) { - [weakSelf.messageChannel invokeMethod:EMMethodKeyOnMessageError + [weakSelf.messageChannel invokeMethod:ChatOnMessageError arguments:@{ @"error":[error toJson], @"localTime":@(msg.localTime), @"message":[message toJson] }]; }else { - [weakSelf.messageChannel invokeMethod:EMMethodKeyOnMessageSuccess + [weakSelf.messageChannel invokeMethod:ChatOnMessageSuccess arguments:@{ @"message":[message toJson], @"localTime":@(msg.localTime) @@ -185,21 +185,21 @@ - (void)resendMessage:(NSDictionary *)param [EMClient.sharedClient.chatManager resendMessage:msg progress:^(int progress) { - [weakSelf.messageChannel invokeMethod:EMMethodKeyOnMessageProgressUpdate + [weakSelf.messageChannel invokeMethod:ChatOnMessageProgressUpdate arguments:@{ @"progress":@(progress), @"localTime":@(msg.localTime) }]; } completion:^(EMChatMessage *message, EMError *error) { if (error) { - [weakSelf.messageChannel invokeMethod:EMMethodKeyOnMessageError + [weakSelf.messageChannel invokeMethod:ChatOnMessageError arguments:@{ @"error":[error toJson], @"localTime":@(msg.localTime), @"message":[message toJson] }]; }else { - [weakSelf.messageChannel invokeMethod:EMMethodKeyOnMessageSuccess + [weakSelf.messageChannel invokeMethod:ChatOnMessageSuccess arguments:@{ @"message":[message toJson], @"localTime":@(msg.localTime) @@ -399,7 +399,7 @@ - (void)downloadAttachment:(NSDictionary *)param [EMClient.sharedClient.chatManager downloadMessageAttachment:needDownMSg progress:^(int progress) { - [weakSelf.messageChannel invokeMethod:EMMethodKeyOnMessageProgressUpdate + [weakSelf.messageChannel invokeMethod:ChatOnMessageProgressUpdate arguments:@{ @"progress":@(progress), @"localTime":@(msg.localTime) @@ -407,14 +407,14 @@ - (void)downloadAttachment:(NSDictionary *)param } completion:^(EMChatMessage *message, EMError *error) { if (error) { - [weakSelf.messageChannel invokeMethod:EMMethodKeyOnMessageError + [weakSelf.messageChannel invokeMethod:ChatOnMessageError arguments:@{ @"error":[error toJson], @"localTime":@(msg.localTime), @"message":[message toJson] }]; }else { - [weakSelf.messageChannel invokeMethod:EMMethodKeyOnMessageSuccess + [weakSelf.messageChannel invokeMethod:ChatOnMessageSuccess arguments:@{ @"message":[message toJson], @"localTime":@(msg.localTime) @@ -437,7 +437,7 @@ - (void)downloadThumbnail:(NSDictionary *)param [EMClient.sharedClient.chatManager downloadMessageThumbnail:needDownMSg progress:^(int progress) { - [weakSelf.messageChannel invokeMethod:EMMethodKeyOnMessageProgressUpdate + [weakSelf.messageChannel invokeMethod:ChatOnMessageProgressUpdate arguments:@{ @"progress":@(progress), @"localTime":@(msg.localTime) @@ -445,14 +445,14 @@ - (void)downloadThumbnail:(NSDictionary *)param } completion:^(EMChatMessage *message, EMError *error) { if (error) { - [weakSelf.messageChannel invokeMethod:EMMethodKeyOnMessageError + [weakSelf.messageChannel invokeMethod:ChatOnMessageError arguments:@{ @"error":[error toJson], @"localTime":@(msg.localTime), @"message":[message toJson] }]; }else { - [weakSelf.messageChannel invokeMethod:EMMethodKeyOnMessageSuccess + [weakSelf.messageChannel invokeMethod:ChatOnMessageSuccess arguments:@{ @"message":[message toJson], @"localTime":@(msg.localTime) @@ -566,7 +566,6 @@ - (void)fetchGroupReadAck:(NSDictionary *)param }]; } - - (void)searchChatMsgFromDB:(NSDictionary *)param channelName:(NSString *)aChannelName result:(FlutterResult)result { @@ -595,33 +594,6 @@ - (void)searchChatMsgFromDB:(NSDictionary *)param }]; } -- (void)updateConversationsName:(NSDictionary *)param - channelName:(NSString *)aChannelName - result:(FlutterResult)result { - __weak typeof(self) weakSelf = self; - NSDictionary *namesMap = param[@"name_map"]; - - NSArray *conversationsList = EMClient.sharedClient.chatManager.getAllConversations; - for (EMConversation *con in conversationsList) { - if (namesMap[con.conversationId]) { - NSMutableDictionary *ext = [con.ext mutableCopy]; - if (!ext) { - ext = [NSMutableDictionary dictionary]; - } - NSString *current = ext[@"con_name"] ?: @""; - if (![current isEqualToString:namesMap[@"con_name"]]) { - ext[@"con_name"] = namesMap[@"con_name"]; - con.ext = ext; - } - } - - } - [weakSelf wrapperCallBack:result - channelName:aChannelName - error:nil - object:@(true)]; -} - - (void)deleteRemoteConversation:(NSDictionary *)param channelName:(NSString *)aChannelName @@ -657,13 +629,13 @@ - (void)deleteRemoteConversation:(NSDictionary *)param - (void)conversationListDidUpdate:(NSArray *)aConversationList { - [self.channel invokeMethod:EMMethodKeyOnConversationUpdate + [self.channel invokeMethod:ChatOnConversationUpdate arguments:nil]; } - (void)onConversationRead:(NSString *)from to:(NSString *)to { - [self.channel invokeMethod:EMMethodKeyOnConversationHasRead + [self.channel invokeMethod:ChatOnConversationHasRead arguments:@{@"from":from, @"to": to}]; } @@ -673,7 +645,7 @@ - (void)messagesDidReceive:(NSArray *)aMessages { [msgList addObject:[msg toJson]]; } - [self.channel invokeMethod:EMMethodKeyOnMessagesReceived + [self.channel invokeMethod:ChatOnMessagesReceived arguments:msgList]; } @@ -683,7 +655,7 @@ - (void)cmdMessagesDidReceive:(NSArray *)aCmdMessages { [cmdMsgList addObject:[msg toJson]]; } - [self.channel invokeMethod:EMMethodKeyOnCmdMessagesReceived + [self.channel invokeMethod:ChatOnCmdMessagesReceived arguments:cmdMsgList]; } @@ -692,11 +664,11 @@ - (void)messagesDidRead:(NSArray *)aMessages { for (EMChatMessage *msg in aMessages) { NSDictionary *json = [msg toJson]; [list addObject:json]; - [self.messageChannel invokeMethod:EMMethodKeyOnMessageReadAck + [self.messageChannel invokeMethod:ChatOnMessageReadAck arguments:json]; } - [self.channel invokeMethod:EMMethodKeyOnMessagesRead arguments:list]; + [self.channel invokeMethod:ChatOnMessagesRead arguments:list]; } - (void)messagesDidDeliver:(NSArray *)aMessages { @@ -704,11 +676,11 @@ - (void)messagesDidDeliver:(NSArray *)aMessages { for (EMChatMessage *msg in aMessages) { NSDictionary *json = [msg toJson]; [list addObject:json]; - [self.messageChannel invokeMethod:EMMethodKeyOnMessageDeliveryAck + [self.messageChannel invokeMethod:ChatOnMessageDeliveryAck arguments:@{@"message":json}]; } - [self.channel invokeMethod:EMMethodKeyOnMessagesDelivered + [self.channel invokeMethod:ChatOnMessagesDelivered arguments:list]; } @@ -718,21 +690,10 @@ - (void)messagesDidRecall:(NSArray *)aMessages { [list addObject:[msg toJson]]; } - [self.channel invokeMethod:EMMethodKeyOnMessagesRecalled + [self.channel invokeMethod:ChatOnMessagesRecalled arguments:list]; } -- (void)messageStatusDidChange:(EMChatMessage *)aMessage - error:(EMError *)aError { - [self.messageChannel invokeMethod:EMMethodKeyOnMessageStatusChanged - arguments:@{@"message":[aMessage toJson]}]; -} - -// TODO: 安卓未找到对应回调 -- (void)messageAttachmentStatusDidChange:(EMChatMessage *)aMessage - error:(EMError *)aError { - -} - (void)groupMessageDidRead:(EMChatMessage *)aMessage groupAcks:(NSArray *)aGroupAcks { NSMutableArray *list = [NSMutableArray array]; @@ -741,7 +702,7 @@ - (void)groupMessageDidRead:(EMChatMessage *)aMessage groupAcks:(NSArray *)aGrou [list addObject:json]; } - [self.channel invokeMethod:EMMethodKeyOnGroupMessageRead + [self.channel invokeMethod:ChatOnGroupMessageRead arguments:list]; } diff --git a/ios/Classes/EMChatroomManagerWrapper.m b/ios/Classes/EMChatroomManagerWrapper.m index 85d6ad8d..45b29187 100644 --- a/ios/Classes/EMChatroomManagerWrapper.m +++ b/ios/Classes/EMChatroomManagerWrapper.m @@ -33,148 +33,148 @@ - (instancetype)initWithChannelName:(NSString *)aChannelName #pragma mark - FlutterPlugin - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { - if ([EMMethodKeyJoinChatRoom isEqualToString:call.method]) + if ([ChatJoinChatRoom isEqualToString:call.method]) { [self joinChatroom:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyLeaveChatRoom isEqualToString:call.method]) { + else if ([ChatLeaveChatRoom isEqualToString:call.method]) { [self leaveChatroom:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyGetChatroomsFromServer isEqualToString:call.method]) { + else if ([ChatGetChatroomsFromServer isEqualToString:call.method]) { [self getChatroomsFromServer:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyCreateChatRoom isEqualToString:call.method]) { + else if ([ChatCreateChatRoom isEqualToString:call.method]) { [self createChatroom:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyDestroyChatRoom isEqualToString:call.method]) { + else if ([ChatDestroyChatRoom isEqualToString:call.method]) { [self destroyChatRoom:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyFetchChatRoomFromServer isEqualToString:call.method]) { + else if ([ChatFetchChatRoomFromServer isEqualToString:call.method]) { [self fetchChatroomInfoFromServer:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyGetChatRoom isEqualToString:call.method]) { + else if ([ChatGetChatRoom isEqualToString:call.method]) { [self getChatroom:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyGetAllChatRooms isEqualToString:call.method]) { + else if ([ChatGetAllChatRooms isEqualToString:call.method]) { [self getAllChatrooms:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyGetChatroomMemberListFromServer isEqualToString:call.method]) { + else if ([ChatGetChatroomMemberListFromServer isEqualToString:call.method]) { [self getChatroomMemberListFromServer:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyFetchChatroomBlockListFromServer isEqualToString:call.method]) { + else if ([ChatFetchChatroomBlockListFromServer isEqualToString:call.method]) { [self fetchChatroomBlockListFromServer:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyGetChatroomMuteListFromServer isEqualToString:call.method]) { + else if ([ChatGetChatroomMuteListFromServer isEqualToString:call.method]) { [self getChatroomMuteListFromServer:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyFetchChatroomAnnouncement isEqualToString:call.method]) { + else if ([ChatFetchChatroomAnnouncement isEqualToString:call.method]) { [self fetchChatroomAnnouncement:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyChatRoomUpdateSubject isEqualToString:call.method]) { + else if ([ChatChatRoomUpdateSubject isEqualToString:call.method]) { [self chatRoomUpdateSubject:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyChatRoomUpdateDescription isEqualToString:call.method]) { + else if ([ChatChatRoomUpdateDescription isEqualToString:call.method]) { [self chatRoomUpdateDescription:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyChatRoomRemoveMembers isEqualToString:call.method]) { + else if ([ChatChatRoomRemoveMembers isEqualToString:call.method]) { [self chatRoomRemoveMembers:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyChatRoomBlockMembers isEqualToString:call.method]) { + else if ([ChatChatRoomBlockMembers isEqualToString:call.method]) { [self chatRoomBlockMembers:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyChatRoomUnblockMembers isEqualToString:call.method]) { + else if ([ChatChatRoomUnblockMembers isEqualToString:call.method]) { [self chatRoomUnblockMembers:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyChangeChatRoomOwner isEqualToString:call.method]) { + else if ([ChatChangeChatRoomOwner isEqualToString:call.method]) { [self chatRoomChangeOwner:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyChatRoomAddAdmin isEqualToString:call.method]) { + else if ([ChatChatRoomAddAdmin isEqualToString:call.method]) { [self chatRoomAddAdmin:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyChatRoomRemoveAdmin isEqualToString:call.method]) { + else if ([ChatChatRoomRemoveAdmin isEqualToString:call.method]) { [self chatRoomRemoveAdmin:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyChatRoomMuteMembers isEqualToString:call.method]) { + else if ([ChatChatRoomMuteMembers isEqualToString:call.method]) { [self chatRoomMuteMembers:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyChatRoomUnmuteMembers isEqualToString:call.method]) { + else if ([ChatChatRoomUnmuteMembers isEqualToString:call.method]) { [self chatRoomUnmuteMembers:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyUpdateChatRoomAnnouncement isEqualToString:call.method]) { + else if ([ChatUpdateChatRoomAnnouncement isEqualToString:call.method]) { [self updateChatroomAnnouncement:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyAddMembersToChatRoomWhiteList isEqualToString:call.method]) { + else if ([ChatAddMembersToChatRoomWhiteList isEqualToString:call.method]) { [self addMembersToChatRoomWhiteList:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyRemoveMembersFromChatRoomWhiteList isEqualToString:call.method]) { + else if ([ChatRemoveMembersFromChatRoomWhiteList isEqualToString:call.method]) { [self removeMembersFromChatRoomWhiteList:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyFetchChatRoomWhiteListFromServer isEqualToString:call.method]) { + else if ([ChatFetchChatRoomWhiteListFromServer isEqualToString:call.method]) { [self fetchChatRoomWhiteListFromServer:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyIsMemberInChatRoomWhiteListFromServer isEqualToString:call.method]) { + else if ([ChatIsMemberInChatRoomWhiteListFromServer isEqualToString:call.method]) { [self isMemberInChatRoomWhiteListFromServer:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyMuteAllChatRoomMembers isEqualToString:call.method]) { + else if ([ChatMuteAllChatRoomMembers isEqualToString:call.method]) { [self muteAllChatRoomMembers:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyUnMuteAllChatRoomMembers isEqualToString:call.method]) { + else if ([ChatUnMuteAllChatRoomMembers isEqualToString:call.method]) { [self unMuteAllChatRoomMembers:call.arguments channelName:call.method result:result]; @@ -666,7 +666,7 @@ - (void)userDidJoinChatroom:(EMChatroom *)aChatroom @"roomId":aChatroom.chatroomId, @"participant":aUsername }; - [self.channel invokeMethod:EMMethodKeyChatroomChanged + [self.channel invokeMethod:ChatChatroomChanged arguments:map]; } @@ -679,7 +679,7 @@ - (void)userDidLeaveChatroom:(EMChatroom *)aChatroom @"roomName":aChatroom.subject, @"participant":aUsername }; - [self.channel invokeMethod:EMMethodKeyChatroomChanged + [self.channel invokeMethod:ChatChatroomChanged arguments:map]; } @@ -704,7 +704,7 @@ - (void)didDismissFromChatroom:(EMChatroom *)aChatroom }; } - [self.channel invokeMethod:EMMethodKeyChatroomChanged + [self.channel invokeMethod:ChatChatroomChanged arguments:map]; } @@ -717,7 +717,7 @@ - (void)chatroomMuteListDidUpdate:(EMChatroom *)aChatroom @"mutes":aMutes, @"expireTime":[NSString stringWithFormat:@"%ld", aMuteExpire] }; - [self.channel invokeMethod:EMMethodKeyChatroomChanged + [self.channel invokeMethod:ChatChatroomChanged arguments:map]; } @@ -728,7 +728,7 @@ - (void)chatroomMuteListDidUpdate:(EMChatroom *)aChatroom @"roomId":aChatroom.chatroomId, @"mutes":aMutes }; - [self.channel invokeMethod:EMMethodKeyChatroomChanged + [self.channel invokeMethod:ChatChatroomChanged arguments:map]; } @@ -739,7 +739,7 @@ - (void)chatroomAdminListDidUpdate:(EMChatroom *)aChatroom @"roomId":aChatroom.chatroomId, @"admin":aAdmin }; - [self.channel invokeMethod:EMMethodKeyChatroomChanged + [self.channel invokeMethod:ChatChatroomChanged arguments:map]; } @@ -750,7 +750,7 @@ - (void)chatroomAdminListDidUpdate:(EMChatroom *)aChatroom @"roomId":aChatroom.chatroomId, @"admin":aAdmin }; - [self.channel invokeMethod:EMMethodKeyChatroomChanged + [self.channel invokeMethod:ChatChatroomChanged arguments:map]; } @@ -763,7 +763,7 @@ - (void)chatroomOwnerDidUpdate:(EMChatroom *)aChatroom @"newOwner":aNewOwner, @"oldOwner":aOldOwner }; - [self.channel invokeMethod:EMMethodKeyChatroomChanged + [self.channel invokeMethod:ChatChatroomChanged arguments:map]; } @@ -774,7 +774,7 @@ - (void)chatroomAnnouncementDidUpdate:(EMChatroom *)aChatroom @"roomId":aChatroom.chatroomId, @"announcement":aAnnouncement }; - [self.channel invokeMethod:EMMethodKeyChatroomChanged + [self.channel invokeMethod:ChatChatroomChanged arguments:map]; } @@ -785,7 +785,7 @@ - (void)chatroomWhiteListDidUpdate:(EMChatroom *)aChatroom @"roomId":aChatroom.chatroomId, @"whitelist":aMembers }; - [self.channel invokeMethod:EMMethodKeyChatroomChanged + [self.channel invokeMethod:ChatChatroomChanged arguments:map]; } @@ -797,7 +797,7 @@ - (void)chatroomWhiteListDidUpdate:(EMChatroom *)aChatroom @"roomId":aChatroom.chatroomId, @"whitelist":aMembers }; - [self.channel invokeMethod:EMMethodKeyChatroomChanged + [self.channel invokeMethod:ChatChatroomChanged arguments:map]; } @@ -809,7 +809,7 @@ - (void)chatroomAllMemberMuteChanged:(EMChatroom *)aChatroom @"roomId":aChatroom.chatroomId, @"isMuted":@(aMuted) }; - [self.channel invokeMethod:EMMethodKeyChatroomChanged + [self.channel invokeMethod:ChatChatroomChanged arguments:map]; } diff --git a/ios/Classes/EMClientWrapper.m b/ios/Classes/EMClientWrapper.m index 0d7f2c59..cec513b7 100644 --- a/ios/Classes/EMClientWrapper.m +++ b/ios/Classes/EMClientWrapper.m @@ -33,7 +33,7 @@ - (void)sendDataToFlutter:(NSDictionary *)aData { if (aData == nil) { return; } - [self.channel invokeMethod:EMMethodKeySendDataToFlutter + [self.channel invokeMethod:ChatSendDataToFlutter arguments:aData]; } @@ -59,113 +59,104 @@ - (instancetype)initWithChannelName:(NSString *)aChannelName #pragma mark - FlutterPlugin - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { - if ([EMMethodKeyInit isEqualToString:call.method]) + if ([ChatInit isEqualToString:call.method]) { [self initSDKWithDict:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyCreateAccount isEqualToString:call.method]) + else if ([ChatCreateAccount isEqualToString:call.method]) { [self createAccount:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyLogin isEqualToString:call.method]) + else if ([ChatLogin isEqualToString:call.method]) { [self login:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyLogout isEqualToString:call.method]) + else if ([ChatLogout isEqualToString:call.method]) { [self logout:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyChangeAppKey isEqualToString:call.method]) + else if ([ChatChangeAppKey isEqualToString:call.method]) { [self changeAppKey:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyUploadLog isEqualToString:call.method]) + else if ([ChatUploadLog isEqualToString:call.method]) { [self uploadLog:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyCompressLogs isEqualToString:call.method]) + else if ([ChatCompressLogs isEqualToString:call.method]) { [self compressLogs:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyGetLoggedInDevicesFromServer isEqualToString:call.method]) + else if ([ChatGetLoggedInDevicesFromServer isEqualToString:call.method]) { [self getLoggedInDevicesFromServer:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyKickDevice isEqualToString:call.method]) + else if ([ChatKickDevice isEqualToString:call.method]) { [self kickDevice:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyKickAllDevices isEqualToString:call.method]) + else if ([ChatKickAllDevices isEqualToString:call.method]) { [self kickAllDevices:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyIsLoggedInBefore isEqualToString:call.method]) + else if([ChatIsLoggedInBefore isEqualToString:call.method]) { [self isLoggedInBefore:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyGetCurrentUser isEqualToString:call.method]) + else if([ChatGetCurrentUser isEqualToString:call.method]) { [self getCurrentUser:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyGetToken isEqualToString:call.method]) + else if([ChatGetToken isEqualToString:call.method]) { [self getToken:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyLoginWithAgoraToken isEqualToString:call.method]) + else if ([ChatLoginWithAgoraToken isEqualToString:call.method]) { - [self loginWithAgoraToken:call.arguments result:result]; + [self loginWithAgoraToken:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyIsConnected isEqualToString:call.method]) + else if([ChatIsConnected isEqualToString:call.method]) { [self isConnected:call.arguments channelName:call.method result:result]; } + else if ([ChatRenewToken isEqualToString:call.method]){ + [self renewToken:call.arguments + channelName:call.method + result:result]; + } else { [super handleMethodCall:call result:result]; } } -- (void)getToken:(NSDictionary *)param channelName:(NSString *)aChannelName result:(FlutterResult)result{ - [self wrapperCallBack:result - channelName:aChannelName - error:nil - object:EMClient.sharedClient.accessUserToken]; -} - - -- (void)isConnected:(NSDictionary *)param channelName:(NSString *)aChannelName result:(FlutterResult)result{ - [self wrapperCallBack:result - channelName:aChannelName - error:nil - object:@(EMClient.sharedClient.isConnected)]; -} #pragma mark - Actions - (void)initSDKWithDict:(NSDictionary *)param channelName:(NSString *)aChannelName result:(FlutterResult)result { @@ -183,7 +174,7 @@ - (void)initSDKWithDict:(NSDictionary *)param channelName:(NSString *)aChannelNa [self _registerAPNs]; } [weakSelf wrapperCallBack:result - channelName:EMMethodKeyInit + channelName:ChatInit error:nil object:@{ @"currentUsername": EMClient.sharedClient.currentUsername ?: @"", @@ -230,7 +221,7 @@ - (void)login:(NSDictionary *)param channelName:(NSString *)aChannelName result: [EMClient.sharedClient loginWithUsername:username password:pwdOrToken completion:^(NSString *aUsername, EMError *aError){ - + [weakSelf wrapperCallBack:result channelName:aChannelName error:aError @@ -343,7 +334,7 @@ - (void)isLoggedInBefore:(NSDictionary *)param channelName:(NSString *)aChannelN } -- (void)loginWithAgoraToken:(NSDictionary *)param result:(FlutterResult)result { +- (void)loginWithAgoraToken:(NSDictionary *)param channelName:(NSString *)aChannelName result:(FlutterResult)result { __weak typeof(self) weakSelf = self; NSString *username = param[@"username"]; NSString *agoraToken = param[@"agoratoken"]; @@ -352,12 +343,37 @@ - (void)loginWithAgoraToken:(NSDictionary *)param result:(FlutterResult)result { completion:^(NSString *aUsername, EMError *aError) { [weakSelf wrapperCallBack:result - channelName:EMMethodKeyLoginWithAgoraToken + channelName:aChannelName error:aError object:EMClient.sharedClient.currentUsername]; }]; } + +- (void)getToken:(NSDictionary *)param channelName:(NSString *)aChannelName result:(FlutterResult)result{ + [self wrapperCallBack:result + channelName:aChannelName + error:nil + object:EMClient.sharedClient.accessUserToken]; +} + + +- (void)isConnected:(NSDictionary *)param channelName:(NSString *)aChannelName result:(FlutterResult)result{ + [self wrapperCallBack:result + channelName:aChannelName + error:nil + object:@(EMClient.sharedClient.isConnected)]; +} + +- (void)renewToken:(NSDictionary *)param channelName:(NSString *)aChannelName result:(FlutterResult)result{ + NSString *newAgoraToken = param[@"agora_token"]; + [EMClient.sharedClient renewToken:newAgoraToken]; + [self wrapperCallBack:result + channelName:aChannelName + error:nil + object:nil]; +} + - (void)onMultiDeviceEvent:(NSDictionary *)param channelName:(NSString *)aChannelName result:(FlutterResult)result { } - (void)getLoggedInDevicesFromServer:(NSDictionary *)param channelName:(NSString *)aChannelName result:(FlutterResult)result { @@ -403,13 +419,13 @@ - (void)autoLoginDidCompleteWithError:(EMError *)aError { // 声网token即将过期 - (void)tokenWillExpire:(int)aErrorCode { - [self.channel invokeMethod:EMMethodKeyOnTokenWillExpire + [self.channel invokeMethod:ChatOnTokenWillExpire arguments:nil]; } // 声网token过期 - (void)tokenDidExpire:(int)aErrorCode { - [self.channel invokeMethod:EMMethodKeyOnTokenDidExpire + [self.channel invokeMethod:ChatOnTokenDidExpire arguments:nil]; } @@ -445,12 +461,12 @@ - (void)multiDevicesGroupEventDidReceive:(EMMultiDevicesEvent)aEvent #pragma mark - Merge Android and iOS Method - (void)onConnected { - [self.channel invokeMethod:EMMethodKeyOnConnected + [self.channel invokeMethod:ChatOnConnected arguments:@{@"connected" : @(YES)}]; } - (void)onDisconnected:(int)errorCode { - [self.channel invokeMethod:EMMethodKeyOnDisconnected + [self.channel invokeMethod:ChatOnDisconnected arguments:@{@"errorCode" : @(errorCode)}]; } diff --git a/ios/Classes/EMContactManagerWrapper.m b/ios/Classes/EMContactManagerWrapper.m index 19d2e558..68498d15 100644 --- a/ios/Classes/EMContactManagerWrapper.m +++ b/ios/Classes/EMContactManagerWrapper.m @@ -27,47 +27,47 @@ - (instancetype)initWithChannelName:(NSString *)aChannelName - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { - if ([EMMethodKeyAddContact isEqualToString:call.method]) { + if ([ChatAddContact isEqualToString:call.method]) { [self addContact:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyDeleteContact isEqualToString:call.method]) { + } else if ([ChatDeleteContact isEqualToString:call.method]) { [self deleteContact:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyGetAllContactsFromServer isEqualToString:call.method]) { + } else if ([ChatGetAllContactsFromServer isEqualToString:call.method]) { [self getAllContactsFromServer:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyGetAllContactsFromDB isEqualToString:call.method]) { + } else if ([ChatGetAllContactsFromDB isEqualToString:call.method]) { [self getAllContactsFromDB:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyAddUserToBlockList isEqualToString:call.method]) { + } else if ([ChatAddUserToBlockList isEqualToString:call.method]) { [self addUserToBlockList:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyRemoveUserFromBlockList isEqualToString:call.method]) { + } else if ([ChatRemoveUserFromBlockList isEqualToString:call.method]) { [self removeUserFromBlockList:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyGetBlockListFromServer isEqualToString:call.method]) { + } else if ([ChatGetBlockListFromServer isEqualToString:call.method]) { [self getBlockListFromServer:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyGetBlockListFromDB isEqualToString:call.method]){ + } else if ([ChatGetBlockListFromDB isEqualToString:call.method]){ [self getBlockListFromDB:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyAcceptInvitation isEqualToString:call.method]) { + } else if ([ChatAcceptInvitation isEqualToString:call.method]) { [self acceptInvitation:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyDeclineInvitation isEqualToString:call.method]) { + } else if ([ChatDeclineInvitation isEqualToString:call.method]) { [self declineInvitation:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyGetSelfIdsOnOtherPlatform isEqualToString:call.method]) { + } else if ([ChatGetSelfIdsOnOtherPlatform isEqualToString:call.method]) { [self getSelfIdsOnOtherPlatform:call.arguments channelName:call.method result:result]; @@ -218,7 +218,7 @@ - (void)friendshipDidAddByUser:(NSString *)aUsername { @"type":@"onContactAdded", @"username":aUsername }; - [self.channel invokeMethod:EMMethodKeyOnContactChanged + [self.channel invokeMethod:ChatOnContactChanged arguments:map]; } @@ -227,7 +227,7 @@ - (void)friendshipDidRemoveByUser:(NSString *)aUsername { @"type":@"onContactDeleted", @"username":aUsername }; - [self.channel invokeMethod:EMMethodKeyOnContactChanged + [self.channel invokeMethod:ChatOnContactChanged arguments:map]; } @@ -238,7 +238,7 @@ - (void)friendRequestDidReceiveFromUser:(NSString *)aUsername @"username":aUsername, @"reason":aMessage }; - [self.channel invokeMethod:EMMethodKeyOnContactChanged + [self.channel invokeMethod:ChatOnContactChanged arguments:map]; } @@ -247,7 +247,7 @@ - (void)friendRequestDidApproveByUser:(NSString *)aUsername { @"type":@"onFriendRequestAccepted", @"username":aUsername }; - [self.channel invokeMethod:EMMethodKeyOnContactChanged + [self.channel invokeMethod:ChatOnContactChanged arguments:map]; } @@ -256,7 +256,7 @@ - (void)friendRequestDidDeclineByUser:(NSString *)aUsername { @"type":@"onFriendRequestDeclined", @"username":aUsername }; - [self.channel invokeMethod:EMMethodKeyOnContactChanged + [self.channel invokeMethod:ChatOnContactChanged arguments:map]; } diff --git a/ios/Classes/EMConversationWrapper.m b/ios/Classes/EMConversationWrapper.m index d4f50a58..34e8cdca 100644 --- a/ios/Classes/EMConversationWrapper.m +++ b/ios/Classes/EMConversationWrapper.m @@ -29,71 +29,67 @@ - (instancetype)initWithChannelName:(NSString *)aChannelName - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { - if ([EMMethodKeyLoadMsgWithId isEqualToString:call.method]) { + if ([ChatLoadMsgWithId isEqualToString:call.method]) { [self loadMsgWithId:call.arguments channelName:call.method result:result]; - } else if([EMMethodKeyLoadMsgWithStartId isEqualToString:call.method]){ + } else if([ChatLoadMsgWithStartId isEqualToString:call.method]){ [self loadMsgWithStartId:call.arguments channelName:call.method result:result]; - } else if([EMMethodKeyLoadMsgWithKeywords isEqualToString:call.method]){ + } else if([ChatLoadMsgWithKeywords isEqualToString:call.method]){ [self loadMsgWithKeywords:call.arguments channelName:call.method result:result]; - } else if([EMMethodKeyLoadMsgWithMsgType isEqualToString:call.method]){ + } else if([ChatLoadMsgWithMsgType isEqualToString:call.method]){ [self loadMsgWithMsgType:call.arguments channelName:call.method result:result]; - } else if([EMMethodKeyLoadMsgWithTime isEqualToString:call.method]){ + } else if([ChatLoadMsgWithTime isEqualToString:call.method]){ [self loadMsgWithTime:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyGetUnreadMsgCount isEqualToString:call.method]) { + } else if ([ChatGetUnreadMsgCount isEqualToString:call.method]) { [self getUnreadMsgCount:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyMarkAllMsgsAsRead isEqualToString:call.method]) { + } else if ([ChatMarkAllMsgsAsRead isEqualToString:call.method]) { [self markAllMessagesAsRead:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyMarkMsgAsRead isEqualToString:call.method]) { + } else if ([ChatMarkMsgAsRead isEqualToString:call.method]) { [self markMessageAsRead:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeySyncConversationExt isEqualToString:call.method]){ + } else if ([ChatSyncConversationExt isEqualToString:call.method]){ [self syncConversationExt:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeySyncConversationName isEqualToString:call.method]){ - [self syncConversationName:call.arguments - channelName:call.method - result:result]; - } else if ([EMMethodKeyRemoveMsg isEqualToString:call.method]) { + } else if ([ChatRemoveMsg isEqualToString:call.method]) { [self removeMessage:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyGetLatestMsg isEqualToString:call.method]) { + } else if ([ChatGetLatestMsg isEqualToString:call.method]) { [self getLatestMessage:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyGetLatestMsgFromOthers isEqualToString:call.method]) { + } else if ([ChatGetLatestMsgFromOthers isEqualToString:call.method]) { [self getLatestMessageFromOthers:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyClearAllMsg isEqualToString:call.method]) { + } else if ([ChatClearAllMsg isEqualToString:call.method]) { [self clearAllMessages:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyInsertMsg isEqualToString:call.method]) { + } else if ([ChatInsertMsg isEqualToString:call.method]) { [self insertMessage:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyAppendMsg isEqualToString:call.method]) { + } else if ([ChatAppendMsg isEqualToString:call.method]) { [self appendMessage:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyUpdateConversationMsg isEqualToString:call.method]) { + } else if ([ChatUpdateConversationMsg isEqualToString:call.method]) { [self updateConversationMessage:call.arguments channelName:call.method result:result]; @@ -183,28 +179,6 @@ - (void)markMessageAsRead:(NSDictionary *)param }]; } -- (void)syncConversationName:(NSDictionary *)param - channelName:(NSString *)aChannelName - result:(FlutterResult)result -{ - __weak typeof(self) weakSelf = self; - [self getConversationWithParam:param - completion:^(EMConversation *conversation) - { - NSString *name = param[@"con_name"]; - NSMutableDictionary *ext = [conversation.ext mutableCopy]; - if (!ext) { - ext = [NSMutableDictionary dictionary]; - } - ext[@"con_name"] = name; - conversation.ext = ext; - [weakSelf wrapperCallBack:result - channelName:aChannelName - error:nil - object:@(YES)]; - }]; -} - - (void)syncConversationExt:(NSDictionary *)param channelName:(NSString *)aChannelName result:(FlutterResult)result diff --git a/ios/Classes/EMGroupManagerWrapper.m b/ios/Classes/EMGroupManagerWrapper.m index 34e713bd..1a748ff3 100644 --- a/ios/Classes/EMGroupManagerWrapper.m +++ b/ios/Classes/EMGroupManagerWrapper.m @@ -33,275 +33,275 @@ - (instancetype)initWithChannelName:(NSString *)aChannelName - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { - if([EMMethodKeyGetGroupWithId isEqualToString:call.method]) { + if([ChatGetGroupWithId isEqualToString:call.method]) { [self getGroupWithId:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyGetJoinedGroups isEqualToString:call.method]) + else if ([ChatGetJoinedGroups isEqualToString:call.method]) { [self getJoinedGroups:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyGetGroupsWithoutPushNotification isEqualToString:call.method]) + else if ([ChatGetGroupsWithoutPushNotification isEqualToString:call.method]) { [self getGroupsWithoutPushNotification:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyGetJoinedGroupsFromServer isEqualToString:call.method]) + else if ([ChatGetJoinedGroupsFromServer isEqualToString:call.method]) { [self getJoinedGroupsFromServer:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyGetPublicGroupsFromServer isEqualToString:call.method]) + else if ([ChatGetPublicGroupsFromServer isEqualToString:call.method]) { [self getPublicGroupsFromServer:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyCreateGroup isEqualToString:call.method]) + else if ([ChatCreateGroup isEqualToString:call.method]) { [self createGroup:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyGetGroupSpecificationFromServer isEqualToString:call.method]) + else if ([ChatGetGroupSpecificationFromServer isEqualToString:call.method]) { [self getGroupSpecificationFromServer:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyGetGroupMemberListFromServer isEqualToString:call.method]) + else if ([ChatGetGroupMemberListFromServer isEqualToString:call.method]) { [self getGroupMemberListFromServer:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyGetGroupBlockListFromServer isEqualToString:call.method]) + else if ([ChatGetGroupBlockListFromServer isEqualToString:call.method]) { [self getGroupBlockListFromServer:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyGetGroupMuteListFromServer isEqualToString:call.method]) + else if ([ChatGetGroupMuteListFromServer isEqualToString:call.method]) { [self getGroupMuteListFromServer:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyGetGroupWhiteListFromServer isEqualToString:call.method]) + else if ([ChatGetGroupWhiteListFromServer isEqualToString:call.method]) { [self getGroupWhiteListFromServer:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyIsMemberInWhiteListFromServer isEqualToString:call.method]) + else if ([ChatIsMemberInWhiteListFromServer isEqualToString:call.method]) { [self isMemberInWhiteListFromServer:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyGetGroupFileListFromServer isEqualToString:call.method]) + else if ([ChatGetGroupFileListFromServer isEqualToString:call.method]) { [self getGroupFileListFromServer:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyGetGroupAnnouncementFromServer isEqualToString:call.method]) + else if ([ChatGetGroupAnnouncementFromServer isEqualToString:call.method]) { [self getGroupAnnouncementFromServer:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyAddMembers isEqualToString:call.method]) + else if ([ChatAddMembers isEqualToString:call.method]) { [self addMembers:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyInviterUser isEqualToString:call.method]){ + else if ([ChatInviterUser isEqualToString:call.method]){ [self inviterUsers:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyRemoveMembers isEqualToString:call.method]) + else if ([ChatRemoveMembers isEqualToString:call.method]) { [self removeMembers:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyBlockMembers isEqualToString:call.method]) + else if ([ChatBlockMembers isEqualToString:call.method]) { [self blockMembers:call.arguments channelName:call.method result:result]; } - else if ([EMMethodKeyUnblockMembers isEqualToString:call.method]) + else if ([ChatUnblockMembers isEqualToString:call.method]) { [self unblockMembers:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyUpdateGroupSubject isEqualToString:call.method]) + else if([ChatUpdateGroupSubject isEqualToString:call.method]) { [self updateGroupSubject:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyUpdateDescription isEqualToString:call.method]) + else if([ChatUpdateDescription isEqualToString:call.method]) { [self updateDescription:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyLeaveGroup isEqualToString:call.method]) + else if([ChatLeaveGroup isEqualToString:call.method]) { [self leaveGroup:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyDestroyGroup isEqualToString:call.method]) + else if([ChatDestroyGroup isEqualToString:call.method]) { [self destroyGroup:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyBlockGroup isEqualToString:call.method]) + else if([ChatBlockGroup isEqualToString:call.method]) { [self blockGroup:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyUnblockGroup isEqualToString:call.method]) + else if([ChatUnblockGroup isEqualToString:call.method]) { [self unblockGroup:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyUpdateGroupOwner isEqualToString:call.method]) + else if([ChatUpdateGroupOwner isEqualToString:call.method]) { [self updateGroupOwner:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyAddAdmin isEqualToString:call.method]) + else if([ChatAddAdmin isEqualToString:call.method]) { [self addAdmin:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyRemoveAdmin isEqualToString:call.method]) + else if([ChatRemoveAdmin isEqualToString:call.method]) { [self removeAdmin:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyMuteMembers isEqualToString:call.method]) + else if([ChatMuteMembers isEqualToString:call.method]) { [self muteMembers:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyUnMuteMembers isEqualToString:call.method]) + else if([ChatUnMuteMembers isEqualToString:call.method]) { [self unMuteMembers:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyMuteAllMembers isEqualToString:call.method]) + else if([ChatMuteAllMembers isEqualToString:call.method]) { [self muteAllMembers:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyUnMuteAllMembers isEqualToString:call.method]) + else if([ChatUnMuteAllMembers isEqualToString:call.method]) { [self unMuteAllMembers:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyAddWhiteList isEqualToString:call.method]) + else if([ChatAddWhiteList isEqualToString:call.method]) { [self addWhiteList:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyRemoveWhiteList isEqualToString:call.method]) + else if([ChatRemoveWhiteList isEqualToString:call.method]) { [self removeWhiteList:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyUploadGroupSharedFile isEqualToString:call.method]) + else if([ChatUploadGroupSharedFile isEqualToString:call.method]) { [self uploadGroupSharedFile:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyDownloadGroupSharedFile isEqualToString:call.method]) + else if([ChatDownloadGroupSharedFile isEqualToString:call.method]) { [self downloadGroupSharedFile:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyRemoveGroupSharedFile isEqualToString:call.method]) + else if([ChatRemoveGroupSharedFile isEqualToString:call.method]) { [self removeGroupSharedFile:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyUpdateGroupAnnouncement isEqualToString:call.method]) + else if([ChatUpdateGroupAnnouncement isEqualToString:call.method]) { [self updateGroupAnnouncement:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyUpdateGroupExt isEqualToString:call.method]) + else if([ChatUpdateGroupExt isEqualToString:call.method]) { [self updateGroupExt:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyJoinPublicGroup isEqualToString:call.method]) + else if([ChatJoinPublicGroup isEqualToString:call.method]) { [self joinPublicGroup:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyRequestToJoinPublicGroup isEqualToString:call.method]) + else if([ChatRequestToJoinPublicGroup isEqualToString:call.method]) { [self requestToJoinPublicGroup:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyAcceptJoinApplication isEqualToString:call.method]) + else if([ChatAcceptJoinApplication isEqualToString:call.method]) { [self acceptJoinApplication:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyDeclineJoinApplication isEqualToString:call.method]) + else if([ChatDeclineJoinApplication isEqualToString:call.method]) { [self declineJoinApplication:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyAcceptInvitationFromGroup isEqualToString:call.method]) + else if([ChatAcceptInvitationFromGroup isEqualToString:call.method]) { [self acceptInvitationFromGroup:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyDeclineInvitationFromGroup isEqualToString:call.method]) + else if([ChatDeclineInvitationFromGroup isEqualToString:call.method]) { [self declineInvitationFromGroup:call.arguments channelName:call.method result:result]; } - else if([EMMethodKeyIgnoreGroupPush isEqualToString:call.method]) + else if([ChatIgnoreGroupPush isEqualToString:call.method]) { [self ignoreGroupPush:call.arguments channelName:call.method @@ -946,7 +946,7 @@ - (void)groupInvitationDidReceive:(NSString *)aGroupId @"inviter":aInviter, @"message":aMessage }; - [self.channel invokeMethod:EMMethodKeyOnGroupChanged + [self.channel invokeMethod:ChatOnGroupChanged arguments:map]; } @@ -958,7 +958,7 @@ - (void)groupInvitationDidAccept:(EMGroup *)aGroup @"groupId":aGroup.groupId, @"invitee":aInvitee }; - [self.channel invokeMethod:EMMethodKeyOnGroupChanged + [self.channel invokeMethod:ChatOnGroupChanged arguments:map]; } @@ -972,7 +972,7 @@ - (void)groupInvitationDidDecline:(EMGroup *)aGroup @"invitee":aInvitee, @"reason":aReason }; - [self.channel invokeMethod:EMMethodKeyOnGroupChanged + [self.channel invokeMethod:ChatOnGroupChanged arguments:map]; } @@ -985,7 +985,7 @@ - (void)didJoinGroup:(EMGroup *)aGroup @"message":aMessage, @"inviter":aInviter }; - [self.channel invokeMethod:EMMethodKeyOnGroupChanged + [self.channel invokeMethod:ChatOnGroupChanged arguments:map]; } @@ -1002,7 +1002,7 @@ - (void)didLeaveGroup:(EMGroup *)aGroup @"groupId":aGroup.groupId, @"groupName":aGroup.groupName }; - [self.channel invokeMethod:EMMethodKeyOnGroupChanged + [self.channel invokeMethod:ChatOnGroupChanged arguments:map]; } @@ -1015,7 +1015,7 @@ - (void)joinGroupRequestDidReceive:(EMGroup *)aGroup @"applicant":aUsername, @"reason":aReason }; - [self.channel invokeMethod:EMMethodKeyOnGroupChanged + [self.channel invokeMethod:ChatOnGroupChanged arguments:map]; } @@ -1026,7 +1026,7 @@ - (void)joinGroupRequestDidDecline:(NSString *)aGroupId @"groupId":aGroupId, @"reason":aReason }; - [self.channel invokeMethod:EMMethodKeyOnGroupChanged + [self.channel invokeMethod:ChatOnGroupChanged arguments:map]; } @@ -1037,7 +1037,7 @@ - (void)joinGroupRequestDidApprove:(EMGroup *)aGroup { @"groupName":aGroup.groupName, @"accepter":aGroup.owner, }; - [self.channel invokeMethod:EMMethodKeyOnGroupChanged + [self.channel invokeMethod:ChatOnGroupChanged arguments:map]; } @@ -1050,7 +1050,7 @@ - (void)groupMuteListDidUpdate:(EMGroup *)aGroup @"mutes":aMutedMembers, @"muteExpire":[NSNumber numberWithInteger:aMuteExpire] }; - [self.channel invokeMethod:EMMethodKeyOnGroupChanged + [self.channel invokeMethod:ChatOnGroupChanged arguments:map]; } @@ -1061,7 +1061,7 @@ - (void)groupMuteListDidUpdate:(EMGroup *)aGroup @"groupId":aGroup.groupId, @"mutes":aMutedMembers }; - [self.channel invokeMethod:EMMethodKeyOnGroupChanged + [self.channel invokeMethod:ChatOnGroupChanged arguments:map]; } @@ -1072,7 +1072,7 @@ - (void)groupWhiteListDidUpdate:(EMGroup *)aGroup @"groupId":aGroup.groupId, @"whitelist":aMembers }; - [self.channel invokeMethod:EMMethodKeyOnGroupChanged + [self.channel invokeMethod:ChatOnGroupChanged arguments:map]; } @@ -1083,7 +1083,7 @@ - (void)groupWhiteListDidUpdate:(EMGroup *)aGroup @"groupId":aGroup.groupId, @"whitelist":aMembers }; - [self.channel invokeMethod:EMMethodKeyOnGroupChanged + [self.channel invokeMethod:ChatOnGroupChanged arguments:map]; } @@ -1094,7 +1094,7 @@ - (void)groupAllMemberMuteChanged:(EMGroup *)aGroup @"groupId":aGroup.groupId, @"isMuted":@(aMuted) }; - [self.channel invokeMethod:EMMethodKeyOnGroupChanged + [self.channel invokeMethod:ChatOnGroupChanged arguments:map]; } @@ -1105,7 +1105,7 @@ - (void)groupAdminListDidUpdate:(EMGroup *)aGroup @"groupId":aGroup.groupId, @"administrator":aAdmin }; - [self.channel invokeMethod:EMMethodKeyOnGroupChanged + [self.channel invokeMethod:ChatOnGroupChanged arguments:map]; } @@ -1116,7 +1116,7 @@ - (void)groupAdminListDidUpdate:(EMGroup *)aGroup @"groupId":aGroup.groupId, @"administrator":aAdmin }; - [self.channel invokeMethod:EMMethodKeyOnGroupChanged + [self.channel invokeMethod:ChatOnGroupChanged arguments:map]; } @@ -1129,7 +1129,7 @@ - (void)groupOwnerDidUpdate:(EMGroup *)aGroup @"newOwner":aNewOwner, @"oldOwner":aOldOwner }; - [self.channel invokeMethod:EMMethodKeyOnGroupChanged + [self.channel invokeMethod:ChatOnGroupChanged arguments:map]; } @@ -1140,7 +1140,7 @@ - (void)userDidJoinGroup:(EMGroup *)aGroup @"groupId":aGroup.groupId, @"member":aUsername }; - [self.channel invokeMethod:EMMethodKeyOnGroupChanged + [self.channel invokeMethod:ChatOnGroupChanged arguments:map]; } @@ -1151,7 +1151,7 @@ - (void)userDidLeaveGroup:(EMGroup *)aGroup @"groupId":aGroup.groupId, @"member":aUsername }; - [self.channel invokeMethod:EMMethodKeyOnGroupChanged + [self.channel invokeMethod:ChatOnGroupChanged arguments:map]; } @@ -1162,7 +1162,7 @@ - (void)groupAnnouncementDidUpdate:(EMGroup *)aGroup @"groupId":aGroup.groupId, @"announcement":aAnnouncement }; - [self.channel invokeMethod:EMMethodKeyOnGroupChanged + [self.channel invokeMethod:ChatOnGroupChanged arguments:map]; } @@ -1173,7 +1173,7 @@ - (void)groupFileListDidUpdate:(EMGroup *)aGroup @"groupId":aGroup.groupId, @"sharedFile":[aSharedFile toJson] }; - [self.channel invokeMethod:EMMethodKeyOnGroupChanged + [self.channel invokeMethod:ChatOnGroupChanged arguments:map]; } @@ -1184,7 +1184,7 @@ - (void)groupFileListDidUpdate:(EMGroup *)aGroup @"groupId":aGroup.groupId, @"fileId":aFileId }; - [self.channel invokeMethod:EMMethodKeyOnGroupChanged + [self.channel invokeMethod:ChatOnGroupChanged arguments:map]; } diff --git a/ios/Classes/EMPushManagerWrapper.m b/ios/Classes/EMPushManagerWrapper.m index 92934d02..4fc1b0c2 100644 --- a/ios/Classes/EMPushManagerWrapper.m +++ b/ios/Classes/EMPushManagerWrapper.m @@ -24,55 +24,55 @@ - (instancetype)initWithChannelName:(NSString *)aChannelName - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { - if ([EMMethodKeyGetImPushConfig isEqualToString:call.method]) { + if ([ChatGetImPushConfig isEqualToString:call.method]) { [self getImPushConfig:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyGetImPushConfigFromServer isEqualToString:call.method]) { + } else if ([ChatGetImPushConfigFromServer isEqualToString:call.method]) { [self getImPushConfigFromServer:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyUpdatePushNickname isEqualToString:call.method]) { + } else if ([ChatUpdatePushNickname isEqualToString:call.method]) { [self updatePushNickname:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyImPushNoDisturb isEqualToString:call.method]) { + } else if ([ChatImPushNoDisturb isEqualToString:call.method]) { [self setImPushNoDisturb:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyUpdateImPushStyle isEqualToString:call.method]) { + } else if ([ChatUpdateImPushStyle isEqualToString:call.method]) { [self updateImPushStyle:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyUpdateGroupPushService isEqualToString:call.method]) { + } else if ([ChatUpdateGroupPushService isEqualToString:call.method]) { [self updateGroupPushService:call.arguments - channelName:EMMethodKeyUpdateGroupPushService + channelName:call.method result:result]; - } else if ([EMMethodKeyGetNoDisturbGroups isEqualToString:call.method]) { + } else if ([ChatGetNoDisturbGroups isEqualToString:call.method]) { [self getNoDisturbGroups:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyBindDeviceToken isEqualToString:call.method]) { + } else if ([ChatBindDeviceToken isEqualToString:call.method]) { [self bindDeviceToken:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeySetNoDisturbUsers isEqualToString:call.method]) { + } else if ([ChatSetNoDisturbUsers isEqualToString:call.method]) { [self setNoDisturbUsers:call.arguments - channelName:EMMethodKeySetNoDisturbUsers + channelName:ChatSetNoDisturbUsers result:result]; - } else if ([EMMethodKeyGetNoDisturbUsersFromServer isEqualToString:call.method]) { + } else if ([ChatGetNoDisturbUsersFromServer isEqualToString:call.method]) { [self getNoDisturbUsersFromServer:call.arguments - channelName:EMMethodKeyGetNoDisturbUsersFromServer + channelName:call.method result:result]; - } else if ([EMMethodKeyEnablePush isEqualToString:call.method]) { + } else if ([ChatEnablePush isEqualToString:call.method]) { [self enablePush:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyDisablePush isEqualToString:call.method]) { + } else if ([ChatDisablePush isEqualToString:call.method]) { [self disablePush:call.arguments channelName:call.method result:result]; - } else if ([EMMethodKeyGetNoPushGroups isEqualToString:call.method]) { + } else if ([ChatGetNoPushGroups isEqualToString:call.method]) { [self getNoPushGroups:call.arguments channelName:call.method result:result]; diff --git a/ios/Classes/EMSDKMethod.h b/ios/Classes/EMSDKMethod.h index 2114a16d..21633671 100644 --- a/ios/Classes/EMSDKMethod.h +++ b/ios/Classes/EMSDKMethod.h @@ -2,235 +2,229 @@ // EMSDKMethod.h // // -// Created by 杜洁鹏 EMMethodKeyOn 2019/10/8. +// Created by 杜洁鹏 ChatOn 2019/10/8. // #import -static NSString *const EMMethodKeyDebugLog = @"debugLog"; -static NSString *const EMMethodKeyErrorLog = @"errorLog"; - - #pragma mark - EMClientWrapper -static NSString *const EMMethodKeyInit = @"init"; -static NSString *const EMMethodKeyCreateAccount = @"createAccount"; -static NSString *const EMMethodKeyLogin = @"login"; -static NSString *const EMMethodKeyLogout = @"logout"; -static NSString *const EMMethodKeyLoginWithAgoraToken = @"loginWithAgoraToken"; -static NSString *const EMMethodKeyChangeAppKey = @"changeAppKey"; -static NSString *const EMMethodKeyUploadLog = @"uploadLog"; -static NSString *const EMMethodKeyCompressLogs = @"compressLogs"; -static NSString *const EMMethodKeyKickDevice = @"kickDevice"; -static NSString *const EMMethodKeyKickAllDevices = @"kickAllDevices"; -static NSString *const EMMethodKeyGetLoggedInDevicesFromServer = @"getLoggedInDevicesFromServer"; - -static NSString *const EMMethodKeyGetToken = @"getToken"; -static NSString *const EMMethodKeyGetCurrentUser = @"getCurrentUser"; -static NSString *const EMMethodKeyIsLoggedInBefore = @"isLoggedInBefore"; -static NSString *const EMMethodKeyIsConnected = @"isConnected"; +static NSString *const ChatInit = @"init"; +static NSString *const ChatCreateAccount = @"createAccount"; +static NSString *const ChatLogin = @"login"; +static NSString *const ChatRenewToken = @"renewToken"; +static NSString *const ChatLoginWithAgoraToken = @"loginWithAgoraToken"; +static NSString *const ChatLogout = @"logout"; +static NSString *const ChatChangeAppKey = @"changeAppKey"; + +static NSString *const ChatUploadLog = @"uploadLog"; +static NSString *const ChatCompressLogs = @"compressLogs"; +static NSString *const ChatKickDevice = @"kickDevice"; +static NSString *const ChatKickAllDevices = @"kickAllDevices"; +static NSString *const ChatGetLoggedInDevicesFromServer = @"getLoggedInDevicesFromServer"; + +static NSString *const ChatGetToken = @"getToken"; +static NSString *const ChatGetCurrentUser = @"getCurrentUser"; +static NSString *const ChatIsLoggedInBefore = @"isLoggedInBefore"; +static NSString *const ChatIsConnected = @"isConnected"; #pragma mark - EMClientDelegate -static NSString *const EMMethodKeyOnConnected = @"onConnected"; -static NSString *const EMMethodKeyOnDisconnected = @"onDisconnected"; -static NSString *const EMMethodKeyOnMultiDeviceEvent = @"onMultiDeviceEvent"; +static NSString *const ChatOnConnected = @"onConnected"; +static NSString *const ChatOnDisconnected = @"onDisconnected"; -static NSString *const EMMethodKeySendDataToFlutter = @"onSendDataToFlutter"; +static NSString *const ChatSendDataToFlutter = @"onSendDataToFlutter"; -static NSString *const EMMethodKeyOnTokenWillExpire = @"onTokenWillExpire"; -static NSString *const EMMethodKeyOnTokenDidExpire = @"onTokenDidExpire"; +static NSString *const ChatOnTokenWillExpire = @"onTokenWillExpire"; +static NSString *const ChatOnTokenDidExpire = @"onTokenDidExpire"; #pragma mark - EMContactManagerWrapper -static NSString *const EMMethodKeyAddContact = @"addContact"; -static NSString *const EMMethodKeyDeleteContact = @"deleteContact"; -static NSString *const EMMethodKeyGetAllContactsFromServer = @"getAllContactsFromServer"; -static NSString *const EMMethodKeyGetAllContactsFromDB = @"getAllContactsFromDB"; -static NSString *const EMMethodKeyAddUserToBlockList = @"addUserToBlockList"; -static NSString *const EMMethodKeyRemoveUserFromBlockList = @"removeUserFromBlockList"; -static NSString *const EMMethodKeyGetBlockListFromServer = @"getBlockListFromServer"; -static NSString *const EMMethodKeyGetBlockListFromDB = @"getBlockListFromDB"; -static NSString *const EMMethodKeyAcceptInvitation = @"acceptInvitation"; -static NSString *const EMMethodKeyDeclineInvitation = @"declineInvitation"; -static NSString *const EMMethodKeyGetSelfIdsOnOtherPlatform = @"getSelfIdsOnOtherPlatform"; +static NSString *const ChatAddContact = @"addContact"; +static NSString *const ChatDeleteContact = @"deleteContact"; +static NSString *const ChatGetAllContactsFromServer = @"getAllContactsFromServer"; +static NSString *const ChatGetAllContactsFromDB = @"getAllContactsFromDB"; +static NSString *const ChatAddUserToBlockList = @"addUserToBlockList"; +static NSString *const ChatRemoveUserFromBlockList = @"removeUserFromBlockList"; +static NSString *const ChatGetBlockListFromServer = @"getBlockListFromServer"; +static NSString *const ChatGetBlockListFromDB = @"getBlockListFromDB"; +static NSString *const ChatAcceptInvitation = @"acceptInvitation"; +static NSString *const ChatDeclineInvitation = @"declineInvitation"; +static NSString *const ChatGetSelfIdsOnOtherPlatform = @"getSelfIdsOnOtherPlatform"; #pragma mark - EMContactDelegate -static NSString *const EMMethodKeyOnContactChanged = @"onContactChanged"; +static NSString *const ChatOnContactChanged = @"onContactChanged"; #pragma mark - EMChatManagerWrapper -static NSString *const EMMethodKeySendMessage = @"sendMessage"; -static NSString *const EMMethodKeyResendMessage = @"resendMessage"; -static NSString *const EMMethodKeyAckMessageRead = @"ackMessageRead"; -static NSString *const EMMethodKeyAckGroupMessageRead = @"ackGroupMessageRead"; -static NSString *const EMMethodKeyAckConversationRead = @"ackConversationRead"; -static NSString *const EMMethodKeyRecallMessage = @"recallMessage"; -static NSString *const EMMethodKeyGetConversation = @"getConversation"; -static NSString *const EMMethodKeyMarkAllChatMsgAsRead = @"markAllChatMsgAsRead"; -static NSString *const EMMethodKeyGetUnreadMessageCount = @"getUnreadMessageCount"; -static NSString *const EMMethodKeyUpdateChatMessage = @"updateChatMessage"; -static NSString *const EMMethodKeyDownloadAttachment = @"downloadAttachment"; -static NSString *const EMMethodKeyDownloadThumbnail = @"downloadThumbnail"; -static NSString *const EMMethodKeyImportMessages = @"importMessages"; -static NSString *const EMMethodKeyLoadAllConversations = @"loadAllConversations"; -static NSString *const EMMethodKeyGetConversationsFromServer = @"getConversationsFromServer"; - -static NSString *const EMMethodKeyDeleteConversation = @"deleteConversation"; -//static NSString * const EMMethodKeySetVoiceMessageListened = @"setVoiceMessageListened"; -//static NSString * const EMMethodKeyUpdateParticipant = @"updateParticipant"; -static NSString *const EMMethodKeyUpdateConversationsName = @"updateConversationsName"; -static NSString *const EMMethodKeyFetchHistoryMessages = @"fetchHistoryMessages"; -static NSString *const EMMethodKeySearchChatMsgFromDB = @"searchChatMsgFromDB"; -static NSString *const EMMethodKeyGetMessage = @"getMessage"; -static NSString *const EMMethodKeyAsyncFetchGroupAcks = @"asyncFetchGroupAcks"; +static NSString *const ChatSendMessage = @"sendMessage"; +static NSString *const ChatResendMessage = @"resendMessage"; +static NSString *const ChatAckMessageRead = @"ackMessageRead"; +static NSString *const ChatAckGroupMessageRead = @"ackGroupMessageRead"; +static NSString *const ChatAckConversationRead = @"ackConversationRead"; +static NSString *const ChatRecallMessage = @"recallMessage"; +static NSString *const ChatGetConversation = @"getConversation"; +static NSString *const ChatMarkAllChatMsgAsRead = @"markAllChatMsgAsRead"; +static NSString *const ChatGetUnreadMessageCount = @"getUnreadMessageCount"; +static NSString *const ChatUpdateChatMessage = @"updateChatMessage"; +static NSString *const ChatDownloadAttachment = @"downloadAttachment"; +static NSString *const ChatDownloadThumbnail = @"downloadThumbnail"; +static NSString *const ChatImportMessages = @"importMessages"; +static NSString *const ChatLoadAllConversations = @"loadAllConversations"; +static NSString *const ChatGetConversationsFromServer = @"getConversationsFromServer"; + +static NSString *const ChatDeleteConversation = @"deleteConversation"; +static NSString *const ChatFetchHistoryMessages = @"fetchHistoryMessages"; +static NSString *const ChatSearchChatMsgFromDB = @"searchChatMsgFromDB"; +static NSString *const ChatGetMessage = @"getMessage"; +static NSString *const ChatAsyncFetchGroupAcks = @"asyncFetchGroupAcks"; +static NSString *const ChatDeleteRemoteConversation = @"deleteRemoteConversation"; #pragma mark - EMChatManagerDelegate -static NSString *const EMMethodKeyOnMessagesReceived = @"onMessagesReceived"; -static NSString *const EMMethodKeyOnCmdMessagesReceived = @"onCmdMessagesReceived"; -static NSString *const EMMethodKeyOnMessagesRead = @"onMessagesRead"; -static NSString *const EMMethodKeyOnGroupMessageRead = @"onGroupMessageRead"; -static NSString *const EMMethodKeyOnMessagesDelivered = @"onMessagesDelivered"; -static NSString *const EMMethodKeyOnMessagesRecalled = @"onMessagesRecalled"; +static NSString *const ChatOnMessagesReceived = @"onMessagesReceived"; +static NSString *const ChatOnCmdMessagesReceived = @"onCmdMessagesReceived"; +static NSString *const ChatOnMessagesRead = @"onMessagesRead"; +static NSString *const ChatOnGroupMessageRead = @"onGroupMessageRead"; +static NSString *const ChatOnMessagesDelivered = @"onMessagesDelivered"; +static NSString *const ChatOnMessagesRecalled = @"onMessagesRecalled"; -static NSString *const EMMethodKeyOnConversationUpdate = @"onConversationUpdate"; -static NSString *const EMMethodKeyOnConversationHasRead = @"onConversationHasRead"; +static NSString *const ChatOnConversationUpdate = @"onConversationUpdate"; +static NSString *const ChatOnConversationHasRead = @"onConversationHasRead"; #pragma mark - EMMessageListener -static NSString *const EMMethodKeyOnMessageProgressUpdate = @"onMessageProgressUpdate"; -static NSString *const EMMethodKeyOnMessageSuccess = @"onMessageSuccess"; -static NSString *const EMMethodKeyOnMessageError = @"onMessageError"; -static NSString *const EMMethodKeyOnMessageReadAck = @"onMessageReadAck"; -static NSString *const EMMethodKeyOnMessageDeliveryAck = @"onMessageDeliveryAck"; -static NSString *const EMMethodKeyOnMessageStatusChanged = @"onMessageStatusChanged"; +static NSString *const ChatOnMessageProgressUpdate = @"onMessageProgressUpdate"; +static NSString *const ChatOnMessageSuccess = @"onMessageSuccess"; +static NSString *const ChatOnMessageError = @"onMessageError"; +static NSString *const ChatOnMessageReadAck = @"onMessageReadAck"; +static NSString *const ChatOnMessageDeliveryAck = @"onMessageDeliveryAck"; + #pragma mark - EMConversationWrapper -static NSString *const EMMethodKeyGetUnreadMsgCount = @"getUnreadMsgCount"; -static NSString *const EMMethodKeyMarkAllMsgsAsRead = @"markAllMessagesAsRead"; -static NSString *const EMMethodKeyMarkMsgAsRead = @"markMessageAsRead"; -static NSString *const EMMethodKeySyncConversationExt = @"syncConversationExt"; -static NSString *const EMMethodKeySyncConversationName = @"syncConversationName"; -static NSString *const EMMethodKeyRemoveMsg = @"removeMessage"; -static NSString *const EMMethodKeyGetLatestMsg = @"getLatestMessage"; -static NSString *const EMMethodKeyGetLatestMsgFromOthers = @"getLatestMessageFromOthers"; -static NSString *const EMMethodKeyClearAllMsg = @"clearAllMessages"; -static NSString *const EMMethodKeyInsertMsg = @"insertMessage"; -static NSString *const EMMethodKeyAppendMsg = @"appendMessage"; -static NSString *const EMMethodKeyUpdateConversationMsg = @"updateConversationMessage"; - -static NSString *const EMMethodKeyLoadMsgWithId = @"loadMsgWithId"; -static NSString *const EMMethodKeyLoadMsgWithStartId = @"loadMsgWithStartId"; -static NSString *const EMMethodKeyLoadMsgWithKeywords = @"loadMsgWithKeywords"; -static NSString *const EMMethodKeyLoadMsgWithMsgType = @"loadMsgWithMsgType"; -static NSString *const EMMethodKeyLoadMsgWithTime = @"loadMsgWithTime"; +static NSString *const ChatGetUnreadMsgCount = @"getUnreadMsgCount"; +static NSString *const ChatMarkAllMsgsAsRead = @"markAllMessagesAsRead"; +static NSString *const ChatMarkMsgAsRead = @"markMessageAsRead"; +static NSString *const ChatSyncConversationExt = @"syncConversationExt"; +static NSString *const ChatRemoveMsg = @"removeMessage"; +static NSString *const ChatGetLatestMsg = @"getLatestMessage"; +static NSString *const ChatGetLatestMsgFromOthers = @"getLatestMessageFromOthers"; +static NSString *const ChatClearAllMsg = @"clearAllMessages"; +static NSString *const ChatInsertMsg = @"insertMessage"; +static NSString *const ChatAppendMsg = @"appendMessage"; +static NSString *const ChatUpdateConversationMsg = @"updateConversationMessage"; + +static NSString *const ChatLoadMsgWithId = @"loadMsgWithId"; +static NSString *const ChatLoadMsgWithStartId = @"loadMsgWithStartId"; +static NSString *const ChatLoadMsgWithKeywords = @"loadMsgWithKeywords"; +static NSString *const ChatLoadMsgWithMsgType = @"loadMsgWithMsgType"; +static NSString *const ChatLoadMsgWithTime = @"loadMsgWithTime"; #pragma mark - EMChatroomManagerWrapper -static NSString *const EMMethodKeyJoinChatRoom = @"joinChatRoom"; -static NSString *const EMMethodKeyLeaveChatRoom = @"leaveChatRoom"; -static NSString *const EMMethodKeyGetChatroomsFromServer = @"fetchPublicChatRoomsFromServer"; -static NSString *const EMMethodKeyFetchChatRoomFromServer = @"fetchChatRoomInfoFromServer"; -static NSString *const EMMethodKeyGetChatRoom = @"getChatRoom"; -static NSString *const EMMethodKeyGetAllChatRooms = @"getAllChatRooms"; -static NSString *const EMMethodKeyCreateChatRoom = @"createChatRoom"; -static NSString *const EMMethodKeyDestroyChatRoom = @"destroyChatRoom"; -static NSString *const EMMethodKeyChatRoomUpdateSubject = @"changeChatRoomSubject"; -static NSString *const EMMethodKeyChatRoomUpdateDescription = @"changeChatRoomDescription"; -static NSString *const EMMethodKeyGetChatroomMemberListFromServer = @"fetchChatRoomMembers"; -static NSString *const EMMethodKeyChatRoomMuteMembers = @"muteChatRoomMembers"; -static NSString *const EMMethodKeyChatRoomUnmuteMembers = @"unMuteChatRoomMembers"; -static NSString *const EMMethodKeyChangeChatRoomOwner = @"changeChatRoomOwner"; -static NSString *const EMMethodKeyChatRoomAddAdmin = @"addChatRoomAdmin"; -static NSString *const EMMethodKeyChatRoomRemoveAdmin = @"removeChatRoomAdmin"; -static NSString *const EMMethodKeyGetChatroomMuteListFromServer = @"fetchChatRoomMuteList"; -static NSString *const EMMethodKeyChatRoomRemoveMembers = @"removeChatRoomMembers"; -static NSString *const EMMethodKeyChatRoomBlockMembers = @"blockChatRoomMembers"; -static NSString *const EMMethodKeyChatRoomUnblockMembers = @"unBlockChatRoomMembers"; -static NSString *const EMMethodKeyFetchChatroomBlockListFromServer = @"fetchChatRoomBlockList"; -static NSString *const EMMethodKeyUpdateChatRoomAnnouncement = @"updateChatRoomAnnouncement"; -static NSString *const EMMethodKeyFetchChatroomAnnouncement = @"fetchChatRoomAnnouncement"; - -static NSString *const EMMethodKeyAddMembersToChatRoomWhiteList = @"addMembersToChatRoomWhiteList"; -static NSString *const EMMethodKeyRemoveMembersFromChatRoomWhiteList = @"removeMembersFromChatRoomWhiteList"; -static NSString *const EMMethodKeyFetchChatRoomWhiteListFromServer = @"fetchChatRoomWhiteListFromServer"; -static NSString *const EMMethodKeyIsMemberInChatRoomWhiteListFromServer = @"isMemberInChatRoomWhiteListFromServer"; - -static NSString *const EMMethodKeyMuteAllChatRoomMembers = @"muteAllChatRoomMembers"; -static NSString *const EMMethodKeyUnMuteAllChatRoomMembers = @"unMuteAllChatRoomMembers"; - - -static NSString *const EMMethodKeyChatroomChanged = @"onChatRoomChanged"; +static NSString *const ChatJoinChatRoom = @"joinChatRoom"; +static NSString *const ChatLeaveChatRoom = @"leaveChatRoom"; +static NSString *const ChatGetChatroomsFromServer = @"fetchPublicChatRoomsFromServer"; +static NSString *const ChatFetchChatRoomFromServer = @"fetchChatRoomInfoFromServer"; +static NSString *const ChatGetChatRoom = @"getChatRoom"; +static NSString *const ChatGetAllChatRooms = @"getAllChatRooms"; +static NSString *const ChatCreateChatRoom = @"createChatRoom"; +static NSString *const ChatDestroyChatRoom = @"destroyChatRoom"; +static NSString *const ChatChatRoomUpdateSubject = @"changeChatRoomSubject"; +static NSString *const ChatChatRoomUpdateDescription = @"changeChatRoomDescription"; +static NSString *const ChatGetChatroomMemberListFromServer = @"fetchChatRoomMembers"; +static NSString *const ChatChatRoomMuteMembers = @"muteChatRoomMembers"; +static NSString *const ChatChatRoomUnmuteMembers = @"unMuteChatRoomMembers"; +static NSString *const ChatChangeChatRoomOwner = @"changeChatRoomOwner"; +static NSString *const ChatChatRoomAddAdmin = @"addChatRoomAdmin"; +static NSString *const ChatChatRoomRemoveAdmin = @"removeChatRoomAdmin"; +static NSString *const ChatGetChatroomMuteListFromServer = @"fetchChatRoomMuteList"; +static NSString *const ChatChatRoomRemoveMembers = @"removeChatRoomMembers"; +static NSString *const ChatChatRoomBlockMembers = @"blockChatRoomMembers"; +static NSString *const ChatChatRoomUnblockMembers = @"unBlockChatRoomMembers"; +static NSString *const ChatFetchChatroomBlockListFromServer = @"fetchChatRoomBlockList"; +static NSString *const ChatUpdateChatRoomAnnouncement = @"updateChatRoomAnnouncement"; +static NSString *const ChatFetchChatroomAnnouncement = @"fetchChatRoomAnnouncement"; + +static NSString *const ChatAddMembersToChatRoomWhiteList = @"addMembersToChatRoomWhiteList"; +static NSString *const ChatRemoveMembersFromChatRoomWhiteList = @"removeMembersFromChatRoomWhiteList"; +static NSString *const ChatFetchChatRoomWhiteListFromServer = @"fetchChatRoomWhiteListFromServer"; +static NSString *const ChatIsMemberInChatRoomWhiteListFromServer = @"isMemberInChatRoomWhiteListFromServer"; + +static NSString *const ChatMuteAllChatRoomMembers = @"muteAllChatRoomMembers"; +static NSString *const ChatUnMuteAllChatRoomMembers = @"unMuteAllChatRoomMembers"; + + +static NSString *const ChatChatroomChanged = @"onChatRoomChanged"; #pragma mark - EMGroupManagerWrapper -static NSString *const EMMethodKeyGetGroupWithId = @"getGroupWithId"; -static NSString *const EMMethodKeyGetJoinedGroups = @"getJoinedGroups"; -static NSString *const EMMethodKeyGetGroupsWithoutPushNotification = @"getGroupsWithoutPushNotification"; -static NSString *const EMMethodKeyGetJoinedGroupsFromServer = @"getJoinedGroupsFromServer"; -static NSString *const EMMethodKeyGetPublicGroupsFromServer = @"getPublicGroupsFromServer"; -static NSString *const EMMethodKeyCreateGroup = @"createGroup"; -static NSString *const EMMethodKeyGetGroupSpecificationFromServer = @"getGroupSpecificationFromServer"; -static NSString *const EMMethodKeyGetGroupMemberListFromServer = @"getGroupMemberListFromServer"; -static NSString *const EMMethodKeyGetGroupBlockListFromServer = @"getGroupBlockListFromServer"; -static NSString *const EMMethodKeyGetGroupMuteListFromServer = @"getGroupMuteListFromServer"; -static NSString *const EMMethodKeyGetGroupWhiteListFromServer = @"getGroupWhiteListFromServer"; -static NSString *const EMMethodKeyIsMemberInWhiteListFromServer = @"isMemberInWhiteListFromServer"; -static NSString *const EMMethodKeyGetGroupFileListFromServer = @"getGroupFileListFromServer"; -static NSString *const EMMethodKeyGetGroupAnnouncementFromServer = @"getGroupAnnouncementFromServer"; -static NSString *const EMMethodKeyAddMembers = @"addMembers"; -static NSString *const EMMethodKeyInviterUser = @"inviterUser"; -static NSString *const EMMethodKeyRemoveMembers = @"removeMembers"; -static NSString *const EMMethodKeyBlockMembers = @"blockMembers"; -static NSString *const EMMethodKeyUnblockMembers = @"unblockMembers"; -static NSString *const EMMethodKeyUpdateGroupSubject = @"updateGroupSubject"; -static NSString *const EMMethodKeyUpdateDescription = @"updateDescription"; -static NSString *const EMMethodKeyLeaveGroup = @"leaveGroup"; -static NSString *const EMMethodKeyDestroyGroup = @"destroyGroup"; -static NSString *const EMMethodKeyBlockGroup = @"blockGroup"; -static NSString *const EMMethodKeyUnblockGroup = @"unblockGroup"; -static NSString *const EMMethodKeyUpdateGroupOwner = @"updateGroupOwner"; -static NSString *const EMMethodKeyAddAdmin = @"addAdmin"; -static NSString *const EMMethodKeyRemoveAdmin = @"removeAdmin"; -static NSString *const EMMethodKeyMuteMembers = @"muteMembers"; -static NSString *const EMMethodKeyUnMuteMembers = @"unMuteMembers"; -static NSString *const EMMethodKeyMuteAllMembers = @"muteAllMembers"; -static NSString *const EMMethodKeyUnMuteAllMembers = @"unMuteAllMembers"; -static NSString *const EMMethodKeyAddWhiteList = @"addWhiteList"; -static NSString *const EMMethodKeyRemoveWhiteList = @"removeWhiteList"; -static NSString *const EMMethodKeyUploadGroupSharedFile = @"uploadGroupSharedFile"; -static NSString *const EMMethodKeyDownloadGroupSharedFile = @"downloadGroupSharedFile"; -static NSString *const EMMethodKeyRemoveGroupSharedFile = @"removeGroupSharedFile"; -static NSString *const EMMethodKeyUpdateGroupAnnouncement = @"updateGroupAnnouncement"; -static NSString *const EMMethodKeyUpdateGroupExt = @"updateGroupExt"; -static NSString *const EMMethodKeyJoinPublicGroup = @"joinPublicGroup"; -static NSString *const EMMethodKeyRequestToJoinPublicGroup = @"requestToJoinPublicGroup"; -static NSString *const EMMethodKeyAcceptJoinApplication = @"acceptJoinApplication"; -static NSString *const EMMethodKeyDeclineJoinApplication = @"declineJoinApplication"; -static NSString *const EMMethodKeyAcceptInvitationFromGroup = @"acceptInvitationFromGroup"; -static NSString *const EMMethodKeyDeclineInvitationFromGroup = @"declineInvitationFromGroup"; -static NSString *const EMMethodKeyIgnoreGroupPush = @"ignoreGroupPush"; - -static NSString *const EMMethodKeyOnGroupChanged = @"onGroupChanged"; +static NSString *const ChatGetGroupWithId = @"getGroupWithId"; +static NSString *const ChatGetJoinedGroups = @"getJoinedGroups"; +static NSString *const ChatGetGroupsWithoutPushNotification = @"getGroupsWithoutPushNotification"; +static NSString *const ChatGetJoinedGroupsFromServer = @"getJoinedGroupsFromServer"; +static NSString *const ChatGetPublicGroupsFromServer = @"getPublicGroupsFromServer"; +static NSString *const ChatCreateGroup = @"createGroup"; +static NSString *const ChatGetGroupSpecificationFromServer = @"getGroupSpecificationFromServer"; +static NSString *const ChatGetGroupMemberListFromServer = @"getGroupMemberListFromServer"; +static NSString *const ChatGetGroupBlockListFromServer = @"getGroupBlockListFromServer"; +static NSString *const ChatGetGroupMuteListFromServer = @"getGroupMuteListFromServer"; +static NSString *const ChatGetGroupWhiteListFromServer = @"getGroupWhiteListFromServer"; +static NSString *const ChatIsMemberInWhiteListFromServer = @"isMemberInWhiteListFromServer"; +static NSString *const ChatGetGroupFileListFromServer = @"getGroupFileListFromServer"; +static NSString *const ChatGetGroupAnnouncementFromServer = @"getGroupAnnouncementFromServer"; +static NSString *const ChatAddMembers = @"addMembers"; +static NSString *const ChatInviterUser = @"inviterUser"; +static NSString *const ChatRemoveMembers = @"removeMembers"; +static NSString *const ChatBlockMembers = @"blockMembers"; +static NSString *const ChatUnblockMembers = @"unblockMembers"; +static NSString *const ChatUpdateGroupSubject = @"updateGroupSubject"; +static NSString *const ChatUpdateDescription = @"updateDescription"; +static NSString *const ChatLeaveGroup = @"leaveGroup"; +static NSString *const ChatDestroyGroup = @"destroyGroup"; +static NSString *const ChatBlockGroup = @"blockGroup"; +static NSString *const ChatUnblockGroup = @"unblockGroup"; +static NSString *const ChatUpdateGroupOwner = @"updateGroupOwner"; +static NSString *const ChatAddAdmin = @"addAdmin"; +static NSString *const ChatRemoveAdmin = @"removeAdmin"; +static NSString *const ChatMuteMembers = @"muteMembers"; +static NSString *const ChatUnMuteMembers = @"unMuteMembers"; +static NSString *const ChatMuteAllMembers = @"muteAllMembers"; +static NSString *const ChatUnMuteAllMembers = @"unMuteAllMembers"; +static NSString *const ChatAddWhiteList = @"addWhiteList"; +static NSString *const ChatRemoveWhiteList = @"removeWhiteList"; +static NSString *const ChatUploadGroupSharedFile = @"uploadGroupSharedFile"; +static NSString *const ChatDownloadGroupSharedFile = @"downloadGroupSharedFile"; +static NSString *const ChatRemoveGroupSharedFile = @"removeGroupSharedFile"; +static NSString *const ChatUpdateGroupAnnouncement = @"updateGroupAnnouncement"; +static NSString *const ChatUpdateGroupExt = @"updateGroupExt"; +static NSString *const ChatJoinPublicGroup = @"joinPublicGroup"; +static NSString *const ChatRequestToJoinPublicGroup = @"requestToJoinPublicGroup"; +static NSString *const ChatAcceptJoinApplication = @"acceptJoinApplication"; +static NSString *const ChatDeclineJoinApplication = @"declineJoinApplication"; +static NSString *const ChatAcceptInvitationFromGroup = @"acceptInvitationFromGroup"; +static NSString *const ChatDeclineInvitationFromGroup = @"declineInvitationFromGroup"; +static NSString *const ChatIgnoreGroupPush = @"ignoreGroupPush"; + +static NSString *const ChatOnGroupChanged = @"onGroupChanged"; #pragma mark - EMPushManagerWrapper -static NSString *const EMMethodKeyGetImPushConfig = @"getImPushConfig"; -static NSString *const EMMethodKeyGetImPushConfigFromServer = @"getImPushConfigFromServer"; -static NSString *const EMMethodKeyUpdatePushNickname = @"updatePushNickname"; -static NSString *const EMMethodKeyBindDeviceToken = @"updateAPNsPushToken"; -static NSString *const EMMethodKeyEnablePush = @"enableOfflinePush"; -static NSString *const EMMethodKeyDisablePush = @"disableOfflinePush"; -static NSString *const EMMethodKeyGetNoPushGroups = @"getNoPushGroups"; - - -static NSString *const EMMethodKeyImPushNoDisturb = @"imPushNoDisturb"; -static NSString *const EMMethodKeyUpdateImPushStyle = @"updateImPushStyle"; -static NSString *const EMMethodKeyUpdateGroupPushService = @"updateGroupPushService"; -static NSString *const EMMethodKeyGetNoDisturbGroups = @"getNoDisturbGroups"; -static NSString *const EMMethodKeySetNoDisturbUsers = @"setNoDisturbUsers"; -static NSString *const EMMethodKeyGetNoDisturbUsersFromServer = @"getNoDisturbUsersFromServer"; +static NSString *const ChatGetImPushConfig = @"getImPushConfig"; +static NSString *const ChatGetImPushConfigFromServer = @"getImPushConfigFromServer"; +static NSString *const ChatUpdatePushNickname = @"updatePushNickname"; +static NSString *const ChatBindDeviceToken = @"updateAPNsPushToken"; +static NSString *const ChatEnablePush = @"enableOfflinePush"; +static NSString *const ChatDisablePush = @"disableOfflinePush"; +static NSString *const ChatGetNoPushGroups = @"getNoPushGroups"; + + +static NSString *const ChatImPushNoDisturb = @"imPushNoDisturb"; +static NSString *const ChatUpdateImPushStyle = @"updateImPushStyle"; +static NSString *const ChatUpdateGroupPushService = @"updateGroupPushService"; +static NSString *const ChatGetNoDisturbGroups = @"getNoDisturbGroups"; +static NSString *const ChatSetNoDisturbUsers = @"setNoDisturbUsers"; +static NSString *const ChatGetNoDisturbUsersFromServer = @"getNoDisturbUsersFromServer"; #pragma mark - EMUserInfoManagerWrapper -static NSString *const EMMethodKeyUpdateOwnUserInfo = @"updateOwnUserInfo"; -static NSString *const EMMethodKeyUpdateOwnUserInfoWithType = @"updateOwnUserInfoWithType"; -static NSString *const EMMethodKeyFetchUserInfoById = @"fetchUserInfoById"; -static NSString *const EMMethodKeyFetchUserInfoByIdWithType = @"fetchUserInfoByIdWithType"; +static NSString *const ChatUpdateOwnUserInfo = @"updateOwnUserInfo"; +static NSString *const ChatUpdateOwnUserInfoWithType = @"updateOwnUserInfoWithType"; +static NSString *const ChatFetchUserInfoById = @"fetchUserInfoById"; +static NSString *const ChatFetchUserInfoByIdWithType = @"fetchUserInfoByIdWithType"; diff --git a/ios/Classes/EMUserInfoManagerWrapper.m b/ios/Classes/EMUserInfoManagerWrapper.m index 00bebf22..ddd109f0 100644 --- a/ios/Classes/EMUserInfoManagerWrapper.m +++ b/ios/Classes/EMUserInfoManagerWrapper.m @@ -26,23 +26,23 @@ - (instancetype)initWithChannelName:(NSString *)aChannelName registrar:(NSObject #pragma mark - FlutterPlugin - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { - if ([call.method isEqualToString:EMMethodKeyUpdateOwnUserInfo]) { + if ([call.method isEqualToString:ChatUpdateOwnUserInfo]) { [self updateOwnUserInfo:call.arguments channelName:call.method result:result]; } - if ([call.method isEqualToString:EMMethodKeyUpdateOwnUserInfoWithType]) { + if ([call.method isEqualToString:ChatUpdateOwnUserInfoWithType]) { [self updateOwnUserInfoWithType:call.arguments channelName:call.method result:result]; } - if ([call.method isEqualToString:EMMethodKeyFetchUserInfoById]) { + if ([call.method isEqualToString:ChatFetchUserInfoById]) { [self fetchUserInfoById:call.arguments channelName:call.method result:result]; } - if ([call.method isEqualToString:EMMethodKeyFetchUserInfoByIdWithType]) { + if ([call.method isEqualToString:ChatFetchUserInfoByIdWithType]) { [self fetchUserInfoByIdWithType:call.arguments channelName:call.method result:result]; @@ -120,7 +120,7 @@ - (void)fetchUserInfoByIdWithType:(NSDictionary *)param channelName:(NSString *) [weakSelf wrapperCallBack:result - channelName:EMMethodKeyFetchUserInfoByIdWithType + channelName:ChatFetchUserInfoByIdWithType error:aError object:dic]; }]; diff --git a/lib/src/internal/chat_method_keys.dart b/lib/src/internal/chat_method_keys.dart index 27f33a3c..1b4ab8ff 100644 --- a/lib/src/internal/chat_method_keys.dart +++ b/lib/src/internal/chat_method_keys.dart @@ -1,145 +1,143 @@ class ChatMethodKeys { /// EMClient methods - static const String init = 'init'; - static const String createAccount = 'createAccount'; - static const String login = 'login'; - static const String loginWithAgoraToken = 'loginWithAgoraToken'; - static const String renewToken = 'renewToken'; - static const String logout = 'logout'; - static const String changeAppKey = 'changeAppKey'; - - static const String uploadLog = 'uploadLog'; - static const String compressLogs = 'compressLogs'; - static const String kickDevice = 'kickDevice'; - static const String kickAllDevices = 'kickAllDevices'; - static const String currentUser = 'currentUser'; + static const String init = "init"; + static const String createAccount = "createAccount"; + static const String login = "login"; + static const String loginWithAgoraToken = "loginWithAgoraToken"; + static const String renewToken = "renewToken"; + static const String logout = "logout"; + static const String changeAppKey = "changeAppKey"; + + static const String uploadLog = "uploadLog"; + static const String compressLogs = "compressLogs"; + static const String kickDevice = "kickDevice"; + static const String kickAllDevices = "kickAllDevices"; static const String getLoggedInDevicesFromServer = - 'getLoggedInDevicesFromServer'; + "getLoggedInDevicesFromServer"; - static const String getToken = 'getToken'; - static const String getCurrentUser = 'getCurrentUser'; - static const String isLoggedInBefore = 'isLoggedInBefore'; - static const String isConnected = 'isConnected'; + static const String getToken = "getToken"; + static const String getCurrentUser = "getCurrentUser"; + static const String isLoggedInBefore = "isLoggedInBefore"; + static const String isConnected = "isConnected"; /// EMClient listener - static const String onMultiDeviceEvent = 'onMultiDeviceEvent'; - static const String onConnected = 'onConnected'; - static const String onDisconnected = 'onDisconnected'; + static const String onMultiDeviceEvent = "onMultiDeviceEvent"; + static const String onConnected = "onConnected"; + static const String onDisconnected = "onDisconnected"; static const String onSendDataToFlutter = "onSendDataToFlutter"; - static const String onTokenWillExpire = 'onTokenWillExpire'; - static const String onTokenDidExpire = 'onTokenDidExpire'; + static const String onTokenWillExpire = "onTokenWillExpire"; + static const String onTokenDidExpire = "onTokenDidExpire"; /// EMContactManager methods - static const String addContact = 'addContact'; - static const String deleteContact = 'deleteContact'; - static const String getAllContactsFromServer = 'getAllContactsFromServer'; - static const String getAllContactsFromDB = 'getAllContactsFromDB'; - static const String addUserToBlockList = 'addUserToBlockList'; - static const String removeUserFromBlockList = 'removeUserFromBlockList'; - static const String getBlockListFromServer = 'getBlockListFromServer'; - static const String getBlockListFromDB = 'getBlockListFromDB'; - static const String acceptInvitation = 'acceptInvitation'; - static const String declineInvitation = 'declineInvitation'; - static const String getSelfIdsOnOtherPlatform = 'getSelfIdsOnOtherPlatform'; + static const String addContact = "addContact"; + static const String deleteContact = "deleteContact"; + static const String getAllContactsFromServer = "getAllContactsFromServer"; + static const String getAllContactsFromDB = "getAllContactsFromDB"; + static const String addUserToBlockList = "addUserToBlockList"; + static const String removeUserFromBlockList = "removeUserFromBlockList"; + static const String getBlockListFromServer = "getBlockListFromServer"; + static const String getBlockListFromDB = "getBlockListFromDB"; + static const String acceptInvitation = "acceptInvitation"; + static const String declineInvitation = "declineInvitation"; + static const String getSelfIdsOnOtherPlatform = "getSelfIdsOnOtherPlatform"; /// EMContactManager listener - static const String onContactChanged = 'onContactChanged'; + static const String onContactChanged = "onContactChanged"; /// EMChatManager methods - static const String sendMessage = 'sendMessage'; - static const String resendMessage = 'resendMessage'; - static const String ackMessageRead = 'ackMessageRead'; - static const String ackGroupMessageRead = 'ackGroupMessageRead'; - static const String ackConversationRead = 'ackConversationRead'; - static const String recallMessage = 'recallMessage'; - static const String getConversation = 'getConversation'; - static const String markAllChatMsgAsRead = 'markAllChatMsgAsRead'; - static const String getUnreadMessageCount = 'getUnreadMessageCount'; - static const String updateChatMessage = 'updateChatMessage'; - static const String downloadAttachment = 'downloadAttachment'; - static const String downloadThumbnail = 'downloadThumbnail'; - static const String importMessages = 'importMessages'; - static const String loadAllConversations = 'loadAllConversations'; - static const String getConversationsFromServer = 'getConversationsFromServer'; - static const String deleteConversation = 'deleteConversation'; - static const String updateConversationsName = 'updateConversationsName'; - static const String fetchHistoryMessages = 'fetchHistoryMessages'; - static const String searchChatMsgFromDB = 'searchChatMsgFromDB'; - static const String getMessage = 'getMessage'; - static const String asyncFetchGroupAcks = 'asyncFetchGroupAcks'; + static const String sendMessage = "sendMessage"; + static const String resendMessage = "resendMessage"; + static const String ackMessageRead = "ackMessageRead"; + static const String ackGroupMessageRead = "ackGroupMessageRead"; + static const String ackConversationRead = "ackConversationRead"; + static const String recallMessage = "recallMessage"; + static const String getConversation = "getConversation"; + static const String markAllChatMsgAsRead = "markAllChatMsgAsRead"; + static const String getUnreadMessageCount = "getUnreadMessageCount"; + static const String updateChatMessage = "updateChatMessage"; + static const String downloadAttachment = "downloadAttachment"; + static const String downloadThumbnail = "downloadThumbnail"; + static const String importMessages = "importMessages"; + static const String loadAllConversations = "loadAllConversations"; + static const String getConversationsFromServer = "getConversationsFromServer"; + static const String deleteConversation = "deleteConversation"; + + static const String fetchHistoryMessages = "fetchHistoryMessages"; + static const String searchChatMsgFromDB = "searchChatMsgFromDB"; + static const String getMessage = "getMessage"; + static const String asyncFetchGroupAcks = "asyncFetchGroupAcks"; static const String deleteRemoteConversation = "deleteRemoteConversation"; /// EMChatManager listener - static const String onMessagesReceived = 'onMessagesReceived'; - static const String onCmdMessagesReceived = 'onCmdMessagesReceived'; - static const String onMessagesRead = 'onMessagesRead'; - static const String onGroupMessageRead = 'onGroupMessageRead'; - static const String onMessagesDelivered = 'onMessagesDelivered'; - static const String onMessagesRecalled = 'onMessagesRecalled'; - static const String onMessageChanged = 'onMessageChanged'; + static const String onMessagesReceived = "onMessagesReceived"; + static const String onCmdMessagesReceived = "onCmdMessagesReceived"; + static const String onMessagesRead = "onMessagesRead"; + static const String onGroupMessageRead = "onGroupMessageRead"; + static const String onMessagesDelivered = "onMessagesDelivered"; + static const String onMessagesRecalled = "onMessagesRecalled"; + static const String onMessageChanged = "onMessageChanged"; - static const String onConversationUpdate = 'onConversationUpdate'; - static const String onConversationHasRead = 'onConversationHasRead'; + static const String onConversationUpdate = "onConversationUpdate"; + static const String onConversationHasRead = "onConversationHasRead"; /// EMMessage listener - static const String onMessageProgressUpdate = 'onMessageProgressUpdate'; - static const String onMessageError = 'onMessageError'; - static const String onMessageSuccess = 'onMessageSuccess'; - static const String onMessageReadAck = 'onMessageReadAck'; - static const String onMessageDeliveryAck = 'onMessageDeliveryAck'; - static const String onMessageStatusChanged = 'onMessageStatusChanged'; + static const String onMessageProgressUpdate = "onMessageProgressUpdate"; + static const String onMessageError = "onMessageError"; + static const String onMessageSuccess = "onMessageSuccess"; + static const String onMessageReadAck = "onMessageReadAck"; + static const String onMessageDeliveryAck = "onMessageDeliveryAck"; + static const String onMessageStatusChanged = "onMessageStatusChanged"; /// EMConversation - static const String getUnreadMsgCount = 'getUnreadMsgCount'; - static const String markAllMessagesAsRead = 'markAllMessagesAsRead'; - static const String markMessageAsRead = 'markMessageAsRead'; - static const String syncConversationExt = 'syncConversationExt'; - static const String syncConversationName = 'syncConversationName'; - static const String removeMessage = 'removeMessage'; - static const String getLatestMessage = 'getLatestMessage'; - static const String getLatestMessageFromOthers = 'getLatestMessageFromOthers'; - static const String clearAllMessages = 'clearAllMessages'; - static const String insertMessage = 'insertMessage'; - static const String appendMessage = 'appendMessage'; - static const String updateConversationMessage = 'updateConversationMessage'; + static const String getUnreadMsgCount = "getUnreadMsgCount"; + static const String markAllMessagesAsRead = "markAllMessagesAsRead"; + static const String markMessageAsRead = "markMessageAsRead"; + static const String syncConversationExt = "syncConversationExt"; + static const String removeMessage = "removeMessage"; + static const String getLatestMessage = "getLatestMessage"; + static const String getLatestMessageFromOthers = "getLatestMessageFromOthers"; + static const String clearAllMessages = "clearAllMessages"; + static const String insertMessage = "insertMessage"; + static const String appendMessage = "appendMessage"; + static const String updateConversationMessage = "updateConversationMessage"; // 根据消息id获取消息 - static const String loadMsgWithId = 'loadMsgWithId'; + static const String loadMsgWithId = "loadMsgWithId"; // 根据起始消息id获取消息 - static const String loadMsgWithStartId = 'loadMsgWithStartId'; + static const String loadMsgWithStartId = "loadMsgWithStartId"; // 根据关键字获取消息 - static const String loadMsgWithKeywords = 'loadMsgWithKeywords'; + static const String loadMsgWithKeywords = "loadMsgWithKeywords"; // 根据消息类型获取消息 - static const String loadMsgWithMsgType = 'loadMsgWithMsgType'; + static const String loadMsgWithMsgType = "loadMsgWithMsgType"; // 通过时间获取消息 - static const String loadMsgWithTime = 'loadMsgWithTime'; + static const String loadMsgWithTime = "loadMsgWithTime"; /// EMChatRoomManager methods - static const String joinChatRoom = 'joinChatRoom'; - static const String leaveChatRoom = 'leaveChatRoom'; + static const String joinChatRoom = "joinChatRoom"; + static const String leaveChatRoom = "leaveChatRoom"; static const String fetchPublicChatRoomsFromServer = - 'fetchPublicChatRoomsFromServer'; + "fetchPublicChatRoomsFromServer"; static const String fetchChatRoomInfoFromServer = - 'fetchChatRoomInfoFromServer'; - static const String getChatRoom = 'getChatRoom'; - static const String getAllChatRooms = 'getAllChatRooms'; - static const String createChatRoom = 'createChatRoom'; - static const String destroyChatRoom = 'destroyChatRoom'; - static const String changeChatRoomSubject = 'changeChatRoomSubject'; - static const String changeChatRoomDescription = 'changeChatRoomDescription'; - static const String fetchChatRoomMembers = 'fetchChatRoomMembers'; - static const String muteChatRoomMembers = 'muteChatRoomMembers'; - static const String unMuteChatRoomMembers = 'unMuteChatRoomMembers'; - static const String changeChatRoomOwner = 'changeChatRoomOwner'; - static const String addChatRoomAdmin = 'addChatRoomAdmin'; - static const String removeChatRoomAdmin = 'removeChatRoomAdmin'; - static const String fetchChatRoomMuteList = 'fetchChatRoomMuteList'; - static const String removeChatRoomMembers = 'removeChatRoomMembers'; - static const String blockChatRoomMembers = 'blockChatRoomMembers'; - static const String unBlockChatRoomMembers = 'unBlockChatRoomMembers'; - static const String fetchChatRoomBlockList = 'fetchChatRoomBlockList'; - static const String updateChatRoomAnnouncement = 'updateChatRoomAnnouncement'; - static const String fetchChatRoomAnnouncement = 'fetchChatRoomAnnouncement'; + "fetchChatRoomInfoFromServer"; + static const String getChatRoom = "getChatRoom"; + static const String getAllChatRooms = "getAllChatRooms"; + static const String createChatRoom = "createChatRoom"; + static const String destroyChatRoom = "destroyChatRoom"; + static const String changeChatRoomSubject = "changeChatRoomSubject"; + static const String changeChatRoomDescription = "changeChatRoomDescription"; + static const String fetchChatRoomMembers = "fetchChatRoomMembers"; + static const String muteChatRoomMembers = "muteChatRoomMembers"; + static const String unMuteChatRoomMembers = "unMuteChatRoomMembers"; + static const String changeChatRoomOwner = "changeChatRoomOwner"; + static const String addChatRoomAdmin = "addChatRoomAdmin"; + static const String removeChatRoomAdmin = "removeChatRoomAdmin"; + static const String fetchChatRoomMuteList = "fetchChatRoomMuteList"; + static const String removeChatRoomMembers = "removeChatRoomMembers"; + static const String blockChatRoomMembers = "blockChatRoomMembers"; + static const String unBlockChatRoomMembers = "unBlockChatRoomMembers"; + static const String fetchChatRoomBlockList = "fetchChatRoomBlockList"; + static const String updateChatRoomAnnouncement = "updateChatRoomAnnouncement"; + static const String fetchChatRoomAnnouncement = "fetchChatRoomAnnouncement"; static const String addMembersToChatRoomWhiteList = "addMembersToChatRoomWhiteList"; static const String removeMembersFromChatRoomWhiteList = @@ -153,89 +151,89 @@ class ChatMethodKeys { static const String unMuteAllChatRoomMembers = "unMuteAllChatRoomMembers"; /// EMChatRoomManagerListener - static const String chatRoomChange = 'onChatRoomChanged'; + static const String chatRoomChange = "onChatRoomChanged"; /// EMGroupManager - static const String getGroupWithId = 'getGroupWithId'; - static const String getJoinedGroups = 'getJoinedGroups'; + static const String getGroupWithId = "getGroupWithId"; + static const String getJoinedGroups = "getJoinedGroups"; static const String getGroupsWithoutPushNotification = - 'getGroupsWithoutPushNotification'; - static const String getJoinedGroupsFromServer = 'getJoinedGroupsFromServer'; - static const String getPublicGroupsFromServer = 'getPublicGroupsFromServer'; - static const String createGroup = 'createGroup'; + "getGroupsWithoutPushNotification"; + static const String getJoinedGroupsFromServer = "getJoinedGroupsFromServer"; + static const String getPublicGroupsFromServer = "getPublicGroupsFromServer"; + static const String createGroup = "createGroup"; static const String getGroupSpecificationFromServer = - 'getGroupSpecificationFromServer'; + "getGroupSpecificationFromServer"; static const String getGroupMemberListFromServer = - 'getGroupMemberListFromServer'; + "getGroupMemberListFromServer"; static const String getGroupBlockListFromServer = - 'getGroupBlockListFromServer'; - static const String getGroupMuteListFromServer = 'getGroupMuteListFromServer'; + "getGroupBlockListFromServer"; + static const String getGroupMuteListFromServer = "getGroupMuteListFromServer"; static const String getGroupWhiteListFromServer = - 'getGroupWhiteListFromServer'; + "getGroupWhiteListFromServer"; static const String isMemberInWhiteListFromServer = - 'isMemberInWhiteListFromServer'; - static const String getGroupFileListFromServer = 'getGroupFileList'; + "isMemberInWhiteListFromServer"; + static const String getGroupFileListFromServer = "getGroupFileListFromServer"; static const String getGroupAnnouncementFromServer = - 'getGroupAnnouncementFromServer'; - static const String addMembers = 'addMembers'; - static const String inviterUser = 'inviterUser'; - static const String removeMembers = 'removeMembers'; - static const String blockMembers = 'blockMembers'; - static const String unblockMembers = 'unblockMembers'; - static const String updateGroupSubject = 'updateGroupSubject'; - static const String updateDescription = 'updateDescription'; - static const String leaveGroup = 'leaveGroup'; - static const String destroyGroup = 'destroyGroup'; - static const String blockGroup = 'blockGroup'; - static const String unblockGroup = 'unblockGroup'; - static const String updateGroupOwner = 'updateGroupOwner'; - static const String addAdmin = 'addAdmin'; - static const String removeAdmin = 'removeAdmin'; - static const String muteMembers = 'muteMembers'; - static const String unMuteMembers = 'unMuteMembers'; - static const String muteAllMembers = 'muteAllMembers'; - static const String unMuteAllMembers = 'unMuteAllMembers'; - static const String addWhiteList = 'addWhiteList'; - static const String removeWhiteList = 'removeWhiteList'; - static const String uploadGroupSharedFile = 'uploadGroupSharedFile'; - static const String downloadGroupSharedFile = 'downloadGroupSharedFile'; - static const String removeGroupSharedFile = 'removeGroupSharedFile'; - static const String updateGroupAnnouncement = 'updateGroupAnnouncement'; - static const String updateGroupExt = 'updateGroupExt'; - static const String joinPublicGroup = 'joinPublicGroup'; - static const String requestToJoinPublicGroup = 'requestToJoinPublicGroup'; - static const String acceptJoinApplication = 'acceptJoinApplication'; - static const String declineJoinApplication = 'declineJoinApplication'; - static const String acceptInvitationFromGroup = 'acceptInvitationFromGroup'; - static const String declineInvitationFromGroup = 'declineInvitationFromGroup'; - static const String ignoreGroupPush = 'ignoreGroupPush'; + "getGroupAnnouncementFromServer"; + static const String addMembers = "addMembers"; + static const String inviterUser = "inviterUser"; + static const String removeMembers = "removeMembers"; + static const String blockMembers = "blockMembers"; + static const String unblockMembers = "unblockMembers"; + static const String updateGroupSubject = "updateGroupSubject"; + static const String updateDescription = "updateDescription"; + static const String leaveGroup = "leaveGroup"; + static const String destroyGroup = "destroyGroup"; + static const String blockGroup = "blockGroup"; + static const String unblockGroup = "unblockGroup"; + static const String updateGroupOwner = "updateGroupOwner"; + static const String addAdmin = "addAdmin"; + static const String removeAdmin = "removeAdmin"; + static const String muteMembers = "muteMembers"; + static const String unMuteMembers = "unMuteMembers"; + static const String muteAllMembers = "muteAllMembers"; + static const String unMuteAllMembers = "unMuteAllMembers"; + static const String addWhiteList = "addWhiteList"; + static const String removeWhiteList = "removeWhiteList"; + static const String uploadGroupSharedFile = "uploadGroupSharedFile"; + static const String downloadGroupSharedFile = "downloadGroupSharedFile"; + static const String removeGroupSharedFile = "removeGroupSharedFile"; + static const String updateGroupAnnouncement = "updateGroupAnnouncement"; + static const String updateGroupExt = "updateGroupExt"; + static const String joinPublicGroup = "joinPublicGroup"; + static const String requestToJoinPublicGroup = "requestToJoinPublicGroup"; + static const String acceptJoinApplication = "acceptJoinApplication"; + static const String declineJoinApplication = "declineJoinApplication"; + static const String acceptInvitationFromGroup = "acceptInvitationFromGroup"; + static const String declineInvitationFromGroup = "declineInvitationFromGroup"; + static const String ignoreGroupPush = "ignoreGroupPush"; /// EMGroupManagerListener - static const String onGroupChanged = 'onGroupChanged'; + static const String onGroupChanged = "onGroupChanged"; /// EMPushManager - static const String getImPushConfig = 'getImPushConfig'; - static const String getImPushConfigFromServer = 'getImPushConfigFromServer'; - static const String updatePushNickname = 'updatePushNickname'; - static const String updateHMSPushToken = 'updateHMSPushToken'; - static const String updateFCMPushToken = 'updateFCMPushToken'; - static const String updateAPNsPushToken = 'updateAPNsPushToken'; - static const String enableOfflinePush = 'enableOfflinePush'; - static const String disableOfflinePush = 'disableOfflinePush'; - static const String getNoPushGroups = 'getNoPushGroups'; + static const String getImPushConfig = "getImPushConfig"; + static const String getImPushConfigFromServer = "getImPushConfigFromServer"; + static const String updatePushNickname = "updatePushNickname"; + static const String updateHMSPushToken = "updateHMSPushToken"; + static const String updateFCMPushToken = "updateFCMPushToken"; + static const String updateAPNsPushToken = "updateAPNsPushToken"; + static const String enableOfflinePush = "enableOfflinePush"; + static const String disableOfflinePush = "disableOfflinePush"; + static const String getNoPushGroups = "getNoPushGroups"; /// ImPushConfig - static const String imPushNoDisturb = 'imPushNoDisturb'; - static const String updateImPushStyle = 'updateImPushStyle'; - static const String updateGroupPushService = 'updateGroupPushService'; - static const String getNoDisturbGroups = 'getNoDisturbGroups'; - static const String setNoDisturbUsers = 'setNoDisturbUsers'; + static const String imPushNoDisturb = "imPushNoDisturb"; + static const String updateImPushStyle = "updateImPushStyle"; + static const String updateGroupPushService = "updateGroupPushService"; + static const String getNoDisturbGroups = "getNoDisturbGroups"; + static const String setNoDisturbUsers = "setNoDisturbUsers"; static const String getNoDisturbUsersFromServer = - 'getNoDisturbUsersFromServer'; + "getNoDisturbUsersFromServer"; /// EMUserInfoManager methods - static const String updateOwnUserInfo = 'updateOwnUserInfo'; - static const String updateOwnUserInfoWithType = 'updateOwnUserInfoWithType'; - static const String fetchUserInfoById = 'fetchUserInfoById'; - static const String fetchUserInfoByIdWithType = 'fetchUserInfoByIdWithType'; + static const String updateOwnUserInfo = "updateOwnUserInfo"; + static const String updateOwnUserInfoWithType = "updateOwnUserInfoWithType"; + static const String fetchUserInfoById = "fetchUserInfoById"; + static const String fetchUserInfoByIdWithType = "fetchUserInfoByIdWithType"; } diff --git a/lib/src/internal/em_message_state_handle.dart b/lib/src/internal/em_message_state_handle.dart index 528107ea..cc06e2ce 100644 --- a/lib/src/internal/em_message_state_handle.dart +++ b/lib/src/internal/em_message_state_handle.dart @@ -5,7 +5,6 @@ class EMMessageStateHandle { final void Function(Map)? onMessageSuccess; final void Function(Map)? onMessageReadAck; final void Function(Map)? onMessageDeliveryAck; - final void Function(Map)? onMessageStatusChanged; EMMessageStateHandle( this.messageKey, { @@ -14,6 +13,5 @@ class EMMessageStateHandle { this.onMessageSuccess, this.onMessageReadAck, this.onMessageDeliveryAck, - this.onMessageStatusChanged, }); } diff --git a/lib/src/models/em_message.dart b/lib/src/models/em_message.dart index 19d1904a..20e0e842 100644 --- a/lib/src/models/em_message.dart +++ b/lib/src/models/em_message.dart @@ -214,13 +214,6 @@ class EMMessage { return null; } - void _onMessageStatusChanged(Map map) { - EMMessage msg = EMMessage.fromJson(map); - this.status = msg.status; - _messageStatusCallBack?.onStatusChanged?.call(); - return null; - } - /// /// Creates a text message for sending. /// @@ -533,8 +526,6 @@ class MessageCallBackManager { return handle?._onMessageReadAck(argMap); } else if (call.method == ChatMethodKeys.onMessageDeliveryAck) { return handle?._onMessageDeliveryAck(argMap); - } else if (call.method == ChatMethodKeys.onMessageStatusChanged) { - return handle?._onMessageStatusChanged(argMap); } return null; }); diff --git a/lib/src/tools/em_message_callback_manager.dart b/lib/src/tools/em_message_callback_manager.dart index 2dff6390..819671af 100644 --- a/lib/src/tools/em_message_callback_manager.dart +++ b/lib/src/tools/em_message_callback_manager.dart @@ -28,8 +28,6 @@ class MessageCallBackManager { return handle?.onMessageReadAck?.call(argMap); } else if (call.method == ChatMethodKeys.onMessageDeliveryAck) { return handle?.onMessageDeliveryAck?.call(argMap); - } else if (call.method == ChatMethodKeys.onMessageStatusChanged) { - return handle?.onMessageStatusChanged?.call(argMap); } return null; }); From 6e2fe4a54894beebb581e3ea142752f70bc22e0b Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Fri, 8 Apr 2022 20:10:11 +0800 Subject: [PATCH 46/56] ios add onMultiDeviceEvent --- ios/Classes/EMClientWrapper.m | 34 ++++++++++++++++++++-------------- ios/Classes/EMSDKMethod.h | 1 + 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/ios/Classes/EMClientWrapper.m b/ios/Classes/EMClientWrapper.m index cec513b7..43ad93e8 100644 --- a/ios/Classes/EMClientWrapper.m +++ b/ios/Classes/EMClientWrapper.m @@ -221,7 +221,7 @@ - (void)login:(NSDictionary *)param channelName:(NSString *)aChannelName result: [EMClient.sharedClient loginWithUsername:username password:pwdOrToken completion:^(NSString *aUsername, EMError *aError){ - + [weakSelf wrapperCallBack:result channelName:aChannelName error:aError @@ -352,30 +352,28 @@ - (void)loginWithAgoraToken:(NSDictionary *)param channelName:(NSString *)aChann - (void)getToken:(NSDictionary *)param channelName:(NSString *)aChannelName result:(FlutterResult)result{ [self wrapperCallBack:result - channelName:aChannelName - error:nil - object:EMClient.sharedClient.accessUserToken]; + channelName:aChannelName + error:nil + object:EMClient.sharedClient.accessUserToken]; } - (void)isConnected:(NSDictionary *)param channelName:(NSString *)aChannelName result:(FlutterResult)result{ [self wrapperCallBack:result - channelName:aChannelName - error:nil - object:@(EMClient.sharedClient.isConnected)]; + channelName:aChannelName + error:nil + object:@(EMClient.sharedClient.isConnected)]; } - (void)renewToken:(NSDictionary *)param channelName:(NSString *)aChannelName result:(FlutterResult)result{ NSString *newAgoraToken = param[@"agora_token"]; [EMClient.sharedClient renewToken:newAgoraToken]; [self wrapperCallBack:result - channelName:aChannelName - error:nil - object:nil]; + channelName:aChannelName + error:nil + object:nil]; } -- (void)onMultiDeviceEvent:(NSDictionary *)param channelName:(NSString *)aChannelName result:(FlutterResult)result { -} - (void)getLoggedInDevicesFromServer:(NSDictionary *)param channelName:(NSString *)aChannelName result:(FlutterResult)result { __weak typeof(self)weakSelf = self; NSString *username = param[@"username"]; @@ -450,13 +448,21 @@ - (void)userAccountDidForcedToLogout:(EMError *)aError { - (void)multiDevicesContactEventDidReceive:(EMMultiDevicesEvent)aEvent username:(NSString *)aUsername ext:(NSString *)aExt { - + NSMutableDictionary *data = [NSMutableDictionary dictionary]; + data[@"event"] = @(aEvent); + data[@"target"] = aUsername; + data[@"ext"] = aExt; + [self.channel invokeMethod:ChatOnMultiDeviceEvent arguments:data]; } - (void)multiDevicesGroupEventDidReceive:(EMMultiDevicesEvent)aEvent groupId:(NSString *)aGroupId ext:(id)aExt { - + NSMutableDictionary *data = [NSMutableDictionary dictionary]; + data[@"event"] = @(aEvent); + data[@"target"] = aGroupId; + data[@"userNames"] = aExt; + [self.channel invokeMethod:ChatOnMultiDeviceEvent arguments:data]; } #pragma mark - Merge Android and iOS Method diff --git a/ios/Classes/EMSDKMethod.h b/ios/Classes/EMSDKMethod.h index 21633671..205d6593 100644 --- a/ios/Classes/EMSDKMethod.h +++ b/ios/Classes/EMSDKMethod.h @@ -30,6 +30,7 @@ static NSString *const ChatIsConnected = @"isConnected"; #pragma mark - EMClientDelegate static NSString *const ChatOnConnected = @"onConnected"; static NSString *const ChatOnDisconnected = @"onDisconnected"; +static NSString *const ChatOnMultiDeviceEvent = @"onMultiDeviceEvent"; static NSString *const ChatSendDataToFlutter = @"onSendDataToFlutter"; From 5248b86317756290e5b605cd20bf704ef84c1b88 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Fri, 8 Apr 2022 21:12:06 +0800 Subject: [PATCH 47/56] fix android fetch mute list wrong. --- .../com/easemob/im_flutter_sdk/EMChatRoomManagerWrapper.java | 2 +- ios/Classes/EMChatroomManagerWrapper.m | 2 +- lib/src/internal/chat_method_keys.dart | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMChatRoomManagerWrapper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMChatRoomManagerWrapper.java index b48d0fc7..d8ffa869 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMChatRoomManagerWrapper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMChatRoomManagerWrapper.java @@ -365,7 +365,7 @@ private void fetchChatRoomMuteList(JSONObject param, String channelName, MethodC asyncRunnable(() -> { try { Map map = EMClient.getInstance().chatroomManager().fetchChatRoomMuteList(roomId, pageNum, pageSize); - onSuccess(result, channelName, map); + onSuccess(result, channelName, map.keySet().toArray()); } catch (HyphenateException e) { onError(result, e); } diff --git a/ios/Classes/EMChatroomManagerWrapper.m b/ios/Classes/EMChatroomManagerWrapper.m index 45b29187..d9f8768b 100644 --- a/ios/Classes/EMChatroomManagerWrapper.m +++ b/ios/Classes/EMChatroomManagerWrapper.m @@ -715,7 +715,7 @@ - (void)chatroomMuteListDidUpdate:(EMChatroom *)aChatroom @"type":@"onMuteListAdded", @"roomId":aChatroom.chatroomId, @"mutes":aMutes, - @"expireTime":[NSString stringWithFormat:@"%ld", aMuteExpire] + @"expireTime":[NSString stringWithFormat:@"%ld", (long)aMuteExpire] }; [self.channel invokeMethod:ChatChatroomChanged arguments:map]; diff --git a/lib/src/internal/chat_method_keys.dart b/lib/src/internal/chat_method_keys.dart index 1b4ab8ff..e847cd83 100644 --- a/lib/src/internal/chat_method_keys.dart +++ b/lib/src/internal/chat_method_keys.dart @@ -86,7 +86,6 @@ class ChatMethodKeys { static const String onMessageSuccess = "onMessageSuccess"; static const String onMessageReadAck = "onMessageReadAck"; static const String onMessageDeliveryAck = "onMessageDeliveryAck"; - static const String onMessageStatusChanged = "onMessageStatusChanged"; /// EMConversation static const String getUnreadMsgCount = "getUnreadMsgCount"; From 3ef926369753941b9a4c49cb84bf6b20f23507e9 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Fri, 8 Apr 2022 22:00:06 +0800 Subject: [PATCH 48/56] update api referance. --- lib/src/em_chat_manager.dart | 207 +++++++++-------- lib/src/em_chat_room_manager.dart | 156 ++++++------- lib/src/em_client.dart | 120 +++++----- lib/src/em_contact_manager.dart | 66 +++--- lib/src/em_group_manager.dart | 207 +++++++++-------- lib/src/em_userInfo_manager.dart | 32 ++- lib/src/models/em_chat_enums.dart | 73 +++--- lib/src/models/em_chat_room.dart | 54 +++-- lib/src/models/em_cmd_message_body.dart | 6 +- lib/src/models/em_conversation.dart | 130 ++++++----- lib/src/models/em_cursor_result.dart | 9 +- lib/src/models/em_custom_message_body.dart | 3 +- lib/src/models/em_deviceInfo.dart | 4 +- lib/src/models/em_error.dart | 2 +- lib/src/models/em_file_message_body.dart | 20 +- lib/src/models/em_group.dart | 73 +++--- lib/src/models/em_group_message_ack.dart | 24 +- lib/src/models/em_group_options.dart | 44 ++-- lib/src/models/em_group_shared_file.dart | 20 +- lib/src/models/em_image_message_body.dart | 24 +- lib/src/models/em_location_message_body.dart | 4 +- lib/src/models/em_message.dart | 131 +++++++---- lib/src/models/em_options.dart | 227 +++++++++++-------- lib/src/models/em_page_result.dart | 4 +- lib/src/models/em_push_config.dart | 2 +- lib/src/models/em_text_message_body.dart | 4 +- lib/src/models/em_userInfo.dart | 101 ++++++--- lib/src/models/em_video_message_body.dart | 18 +- lib/src/models/em_voice_message_body.dart | 8 +- 29 files changed, 955 insertions(+), 818 deletions(-) diff --git a/lib/src/em_chat_manager.dart b/lib/src/em_chat_manager.dart index 7dc053ac..7431c081 100644 --- a/lib/src/em_chat_manager.dart +++ b/lib/src/em_chat_manager.dart @@ -5,12 +5,12 @@ import 'internal/em_transform_tools.dart'; import 'tools/em_extension.dart'; import '../im_flutter_sdk.dart'; import 'internal/chat_method_keys.dart'; +import 'tools/em_message_callback_manager.dart'; /// -/// The chat manager. This class is responsible for managing conversations. -/// (such as: load, delete), sending messages, downloading attachments and so on. +/// The chat manager class, responsible for sending and receiving messages, loading and deleting conversations, and downloading attachments. /// -/// Such as, send a text message: +/// The sample code for sending a text message: /// /// ```dart /// EMMessage msg = EMMessage.createTxtSendMessage( @@ -27,6 +27,7 @@ class EMChatManager { /// @nodoc EMChatManager() { + MessageCallBackManager.getInstance; _channel.setMethodCallHandler((MethodCall call) async { if (call.method == ChatMethodKeys.onMessagesReceived) { return _onMessagesReceived(call.arguments); @@ -52,15 +53,15 @@ class EMChatManager { /// /// Sends a message. /// - /// Reference: - /// If the message is voice, picture and other message with attachment, the SDK will automatically upload the attachment. - /// You can set whether to upload the attachment to the chat sever by {@link EMOptions#serverTransfer(boolean)}. + /// **Note** + /// For attachment messages such as voice, image, or video messages, the SDK automatically uploads the attachment. + /// You can set whether to upload the attachment to the chat sever using {@link EMOptions#serverTransfer(boolean)}. /// - /// To listen for the status of sending messages, call {@link EMMessage#setMessageStatusListener(StatusListener)}. + /// To listen for the status of sending messages, call {@link EMMessage#setMessageStatusListener(EMMessageStatusListener)}. /// - /// Param [message] The message object to be sent + /// Param [message] The message object to be sent: {@link EMMessage}. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future sendMessage(EMMessage message) async { message.status = MessageStatus.PROGRESS; @@ -78,7 +79,8 @@ class EMChatManager { } } - /// 重发消息 [message]. + /// Resends a message. + /// Param [message] The message object to be resent: {@link EMMessage}. Future resendMessage(EMMessage message) async { message.status = MessageStatus.PROGRESS; Map result = await _channel.invokeMethod( @@ -100,16 +102,17 @@ class EMChatManager { /// /// This method applies to one-to-one chats only. /// - /// Precondition: set {@link EMOptions#requireAck(bool)}. + /// **Warning** + /// This method only takes effect if you set {@link EMOptions#requireAck(bool)} as `true`. /// - /// Reference: + /// **Note** /// To send the group message read receipt, call {@link #sendGroupMessageReadAck(String, String, String)}. /// - /// We recommend that you call {@link #sendConversationReadAck(String)} when entering a chat page, and call this method in other cases to reduce the number of method calls. + /// We recommend that you call {@link #sendConversationReadAck(String)} when entering a chat page, and call this method to reduce the number of method calls. /// - /// Param [message] The message. + /// Param [message] The message body: {@link EMMessage}. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future sendMessageReadAck(EMMessage message) async { Map req = {"to": message.from, "msg_id": message.msgId}; @@ -126,19 +129,20 @@ class EMChatManager { /// /// Sends the group message receipt to the server. /// - /// You can only call the method after setting the following method: {@link EMOptions#requireAck(bool)} and {@link EMMessage#needGroupAck(bool)}. + /// You can call the method only after setting the following method: {@link EMOptions#requireAck(bool)} and {@link EMMessage#needGroupAck(bool)}. + /// + /// **Note** + /// - This method takes effect only after you set {@link EMOptions#requireAck} and {@link EMMessage#needGroupAck} as `true`. + /// - This method applies to group messages only. To send a one-to-one chat message receipt, call `sendMessageReadAck`; to send a conversation receipt, call `sendConversationReadAck`. /// - /// Reference: - /// To send the one-to-one chat message receipt to server, call {@link #sendMessageReadAck(EMMessage)}; - /// To send the conversation receipt to the server, call {@link #sendConversationReadAck(String)}. /// /// Param [msgId] The message ID. /// /// Param [groupId] The group ID. /// - /// Param [content] The extension information. Developer self-defined command string that can be used for specifying custom action/command. + /// Param [content] The extension information, which is a custom keyword that specifies a custom action or command. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future sendGroupMessageReadAck( String msgId, @@ -163,17 +167,16 @@ class EMChatManager { } /// - /// Sends the conversation read receipt to the server. This method is only for one-to-one chat conversation. + /// Sends the conversation read receipt to the server. This method is only for one-to-one chat conversations. /// - /// This method will inform the sever to set the unread message count of the conversation to 0, and conversation list (with multiple devices) will receive - /// a callback method from {@link EMChatManagerListener#onConversationRead(String, String)}. + /// This method informs the server to set the unread message count of the conversation to 0. In multi-device scenarios, all the devices receive the {@link EMChatManagerListener#onConversationRead(String, String)} callback. /// - /// Reference: - /// To send the group message read receipt, call {@link #sendGroupMessageReadAck(String, String, String)}. + /// **Note** + /// This method applies to one-to-one chat conversations only. To send a group message read receipt, call `sendGroupMessageReadAck`. /// /// Param [conversationId] The conversation ID. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future sendConversationReadAck(String conversationId) async { Map req = {"con_id": conversationId}; @@ -190,9 +193,9 @@ class EMChatManager { /// /// Recalls the sent message. /// - /// Param [messageId] The message id. + /// Param [messageId] The message ID. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future recallMessage(String messageId) async { Map req = {"msg_id": messageId}; @@ -206,13 +209,13 @@ class EMChatManager { } /// - /// Fetches message for local database by message ID. + /// Loads a message from the local database by message ID. /// /// Param [messageId] The message ID. /// - /// **return** The message object obtained by the specified ID. Returns null if the message doesn't exist. + /// **Return** The message object specified by the message ID. Returns null if the message does not exist. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future loadMessage(String messageId) async { Map req = {"msg_id": messageId}; @@ -233,20 +236,17 @@ class EMChatManager { /// /// Gets the conversation by conversation ID and conversation type. /// - /// The SDK wil return null if the conversation is not found. - /// /// Param [conversationId] The conversation ID. /// - /// Param [type] The conversation type, see {@link EMConversationType}. - /// - /// Param [createIfNeed] Whether to create a conversation if not find the specified conversation. + /// Param [type] The conversation type: {@link EMConversationType}. /// - /// `true` (default) means create one. - /// `false` means not. + /// Param [createIfNeed] Whether to create a conversation is the specified conversation is not found: + /// - `true`: Yes. + /// - `false`: No. /// - /// **return** The conversation object found according to the ID and type. Returns null if the conversation is not found. + /// **Return** The conversation object found according to the ID and type. Returns null if the conversation is not found. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future getConversation( String conversationId, [ @@ -276,7 +276,7 @@ class EMChatManager { /// /// This method is for the local conversations only. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future markAllConversationsAsRead() async { Map result = @@ -289,11 +289,11 @@ class EMChatManager { } /// - /// Gets the unread message count. + /// Gets the count of the unread messages. /// - /// **return** The count of unread messages. + /// **Return** The count of the unread messages. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future getUnreadMessageCount() async { Map result = @@ -313,9 +313,9 @@ class EMChatManager { /// /// Updates the local message. /// - /// Will update the memory and the local database at the same time. + /// The message will be updated both in the cache and local database. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future updateMessage(EMMessage message) async { Map req = {"message": message.toJson()}; @@ -331,13 +331,13 @@ class EMChatManager { /// /// Imports messages to the local database. /// - /// Make sure the message's sender or receiver is the current user before option. + /// Before importing, ensure that the sender or receiver of the message is the current user. /// - /// Recommends import less than 1,000 messages per operation. + /// For each method call, we recommends to import less than 1,000 messages. /// /// Param [messages] The message list. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future importMessages(List messages) async { List list = []; @@ -359,9 +359,9 @@ class EMChatManager { /// /// You can call the method again if the attachment download fails. /// - /// Param [message] The message to be download the attachment. + /// Param [message] The message with the attachment that is to be downloaded. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future downloadAttachment(EMMessage message) async { Map result = await _channel.invokeMethod( @@ -374,11 +374,11 @@ class EMChatManager { } /// - /// Downloads the thumbnail if the msg is not downloaded before or the download failed. + /// Downloads the thumbnail if the message has not been downloaded before or if the download fails. /// /// Param [message] The message object. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future downloadThumbnail(EMMessage message) async { Map result = await _channel.invokeMethod( @@ -393,11 +393,11 @@ class EMChatManager { /// /// Gets all conversations from the local database. /// - /// Conversations will be loaded from memory first, if no conversation is found then the SDk loads from the local database. + /// Conversations will be first loaded from the cache. If no conversation is found, the SDK loads from the local database. /// - /// **return** Returns all the conversations from the memory or local database. + /// **Return** All the conversations from the cache or local database. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future> loadAllConversations() async { Map result = @@ -415,13 +415,13 @@ class EMChatManager { } /// - /// Fetches the conversation list from the server. + /// Gets the conversation list from the server. /// - /// The default maximum return is 100. + /// To use this function, you need to contact our business manager to activate it. After this function is activated, users can pull 10 conversations within 7 days by default (each convesation contains the latest historical message). If you want to adjust the number of conversations or time limit, please contact our business manager. /// - /// **return** Returns the conversation list of the current user. + /// **Return** The conversation list of the current user. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future> getConversationsFromServer() async { Map result = @@ -439,20 +439,21 @@ class EMChatManager { } /// - /// Deletes conversation and messages from the local database. + /// Deletes a conversation and its related messages from the local database. /// - /// If you set `deleteMessages` to `true`, delete the local chat history when delete the conversation. + /// If you set `deleteMessages` to `true`, the local historical messages are deleted when the conversation is deleted. /// /// Param [conversationId] The conversation ID. /// - /// Param [deleteMessages] Whether to delete the chat history when delete the conversation. + /// Param [deleteMessages] Whether to delete the historical messages when deleting the conversation. + /// - `true`: (default) Yes. + /// - `false`: No. /// - /// `true`: (default) means delete the chat history when delete the conversation. - /// `false`: means not. + /// **Return** Whether the conversation is successfully deleted. + /// - `true`: Yes; + /// - `false`: No. /// - /// **return** The result of deleting. `True` means success, `false` means failure. - /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future deleteConversation( String conversationId, [ @@ -470,11 +471,9 @@ class EMChatManager { } /// - /// Adds the message listener. - /// - /// Receives new messages and so on can set the method to listen, see {@link EMChatManagerListener}. + /// Adds the message listener. After calling this method, you can listen for new messages when they arrive. /// - /// Param [listener] The message listener which is used to listen the incoming messages, see {@link EMChatManagerListener} + /// Param [listener] The message listener that listens for new messages. See {@link EMChatManagerListener}. /// void addChatManagerListener(EMChatManagerListener listener) { _messageListeners.add(listener); @@ -483,9 +482,9 @@ class EMChatManager { /// /// Removes the message listener. /// - /// You should call this method after set {@link #addMessageListener(addChatManagerListener)} . + /// After adding a chat manager listener, you can remove this listener if you do not want to listen for it. /// - /// Param [listener] The message listener to be removed. + /// Param [listener] The message listener to be removed. See {@link EMChatManagerListener}. /// void removeChatManagerListener(EMChatManagerListener listener) { if (_messageListeners.contains(listener)) { @@ -494,21 +493,20 @@ class EMChatManager { } /// - /// Fetches history messages of the conversation from the server. + /// Gets historical messages of the conversation from the server with pagination. /// - /// Fetches by page. /// /// Param [conversationId] The conversation ID. /// - /// Param [type] The conversation type which select to fetch roam message, see {@link EMConversationType} + /// Param [type] The conversation type. See {@link EMConversationType}. /// - /// Param [pageSize] The number of records per page. + /// Param [pageSize] The number of messages per page. /// - /// Param [startMsgId] The start search roam message, if the param is empty, fetches from the server latest message. + /// Param [startMsgId] The ID of the message from which you start to get the historical messages. If `null` is passed, the SDK gets messages in reverse chronological order. /// - /// **return** Returns the messages and the cursor for next fetch action. + /// **Return** The obtained messages and the cursor for the next fetch action. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future> fetchHistoryMessages( String conversationId, { @@ -536,21 +534,22 @@ class EMChatManager { } /// - /// Searches messages from the database according to the parameters. + /// Retrieves messages from the database according to the parameters. /// - /// Note: Cautious about the memory usage when the maxCount is large, currently the limited number is 400 entries at a time. + /// **Note** + /// Pay attention to the memory usage when the maxCount is large. Currently, a maximum of 400 historical messages can be retrieved each time. /// /// Param [keywords] The keywords in message. /// - /// Param [timeStamp] The timestamp for search, Unix timestamp, in milliseconds. + /// Param [timeStamp] The Unix timestamp for search, in milliseconds. /// - /// Param [maxCount] The max number of message to search at a time. + /// Param [maxCount] The maximum number of messages to retrieve each time. /// - /// Param [from] A user ID or a group ID searches for messages, usually refers to the conversation ID. + /// Param [from] A username or group ID at which the retrieval is targeted. Usually, it is the conversation ID. /// - /// **return** The list of messages. + /// **Return** The list of messages. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future> searchMsgFromDB( String keywords, { @@ -581,22 +580,20 @@ class EMChatManager { } /// - /// Fetches the ack details for group messages from server. + /// Gets read receipts for group messages from the server with pagination. /// - /// Fetches by page. - /// - /// Reference: - /// If you want to send group message receipt, see {@link {@link #sendConversationReadAck(String)}. + /// See also: + /// For how to send read receipts for group messages, see {@link {@link #sendConversationReadAck(String)}. /// /// Param [msgId] The message ID. /// - /// Param [startAckId] The start ID for fetch receipts, can be null. If you set it as null, the SDK will start from the server's latest receipt. + /// Param [startAckId] The starting read receipt ID for query. If you set it as null, the SDK retrieves the read receipts in the in reverse chronological order. /// - /// Param [pageSize] The number of records per page. + /// Param [pageSize] The number of read receipts per page. /// - /// **return** The group acks cursor result. + /// **Return** The list of obtained read receipts and the cursor for next query. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future> fetchGroupAcks( String msgId, { @@ -629,18 +626,18 @@ class EMChatManager { } /// - /// Deletes the conversation of a specified ID and it's chat records on the server. + /// Deletes the specified conversation and the related historical messages from the server. /// - /// Param [conversationId] Conversation ID. + /// Param [conversationId] The conversation ID. /// - /// Param [conversationType] Conversation type {@link EMConversationType} + /// Param [conversationType] The conversation type. See {@link EMConversationType}. /// - /// Param [isDeleteMessage] Whether to delete the server chat records when delete conversation. + /// Param [isDeleteMessage] Whether to delete the chat history when deleting the conversation. + /// - `true`: (default) Yes. + /// - `false`: No. /// - /// `true`:(default) means to delete the chat history when delete the conversation; - /// `false`: means not. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future deleteRemoteConversation( String conversationId, { diff --git a/lib/src/em_chat_room_manager.dart b/lib/src/em_chat_room_manager.dart index d3a41a0d..63edbd24 100644 --- a/lib/src/em_chat_room_manager.dart +++ b/lib/src/em_chat_room_manager.dart @@ -7,8 +7,8 @@ import 'internal/chat_method_keys.dart'; import '../im_flutter_sdk.dart'; /// -/// The chat room manager, which manages users joining and existing the chat room and getting the chat room list, and manages member privileges. -/// For example, joining a chat room: +/// The chat room manager class, which manages user joining and exiting the chat room, retrieving the chat room list, and managing member privileges. +/// The sample code for joining a chat room: /// ```dart /// try { /// await EMClient.getInstance.chatRoomManager.joinChatRoom(chatRoomId); @@ -36,10 +36,9 @@ class EMChatRoomManager { /// /// Registers a chat room event listener. - /// Chat room destruction, member entry and exit, mute, and allowlist entry addition among other operations can be listened by setting - /// {@link EMChatRoomEventListener}. + /// After registering the chat room event listener, you can listen for events in {@link EMChatRoomEventListener}, for example, users joining and exiting the chat room, adding the specified member to the chat group mute list, updating the chat room allow list, and destroying the chat room. /// - /// Chat room event listeners registered with this method can be removed by calling {@link #removeChatRoomListener(EMChatRoomEventListener)}. + /// To stop listening for chat room events, call {@link #removeChatRoomListener(EMChatRoomEventListener)}. /// /// Param [listener] A chat room listener. See {@link EMChatRoomEventListener}. /// @@ -143,7 +142,7 @@ class EMChatRoomManager { /// /// Param [roomId] The ID of the chat room to join. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future joinChatRoom(String roomId) async { Map result = await _channel @@ -156,11 +155,11 @@ class EMChatRoomManager { } /// - /// Leaves a chat room. + /// Leaves the chat room. /// /// Param [roomId] The ID of the chat room to leave. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future leaveChatRoom(String roomId) async { Map result = await _channel @@ -179,9 +178,9 @@ class EMChatRoomManager { /// /// Param [pageSize] The number of records per page. /// - /// **return** Chat room data. See {@link EMPageResult}. + /// **Return** Chat room data. See {@link EMPageResult}. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future> fetchPublicChatRoomsFromServer({ int pageNum = 1, @@ -203,27 +202,18 @@ class EMChatRoomManager { } /// - /// Gets details of a chat room from the server, excluding the member list by default. - /// The member list, if required, can contain at most 200 members if need. For more members, - /// call {@link EMChatRoomManager#fetchChatRoomMembers(String, String?, int?)}. + /// Gets the details of the chat room from the server. + /// By default, the details do not include the chat room member list. /// /// Param [roomId] The chat room ID. /// - /// Param [fetchMembers] Whether to get chat room members, default is false. + /// **Return** The chat room instance. /// - /// **return** The chat room instance. + /// **Throws** A description of the exception. See {@link EMError}. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} - /// - Future fetchChatRoomInfoFromServer( - String roomId, { - bool fetchMembers = false, - }) async { - Map result = await _channel - .invokeMethod(ChatMethodKeys.fetchChatRoomInfoFromServer, { - "roomId": roomId, - "fetchMembers": fetchMembers, - }); + Future fetchChatRoomInfoFromServer(String roomId) async { + Map result = await _channel.invokeMethod( + ChatMethodKeys.fetchChatRoomInfoFromServer, {"roomId": roomId}); try { EMError.hasErrorFromResult(result); return EMChatRoom.fromJson( @@ -238,9 +228,9 @@ class EMChatRoomManager { /// /// Param [roomId] The chat room ID. /// - /// **return** The chat room instance. Returns null if the chat room is not found in the cache. + /// **Return** The chat room instance. Returns null if the chat room is not found in the cache. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future getChatRoomWithId(String roomId) async { Map result = await _channel @@ -261,7 +251,7 @@ class EMChatRoomManager { /// /// Gets the list of chat rooms in the cache. /// - /// **return** The list of chat rooms maintained by EMChatRoomManager. + /// **Return** The list of chat rooms maintained by EMChatRoomManager. @Deprecated("") Future> getAllChatRooms() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getAllChatRooms); @@ -283,15 +273,15 @@ class EMChatRoomManager { /// /// Param [desc] The chat room description. /// - /// Param [welcomeMsg] A welcome message inviting members to join the chat room. + /// Param [welcomeMsg] A welcome message that invites users to join the chat room. /// /// Param [maxUserCount] The maximum number of members allowed to join the chat room. /// /// Param [members] The list of members invited to join the chat room. /// - /// **return** The chat room instance created successfully. + /// **Return** The chat room instance. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future createChatRoom( String subject, { @@ -323,7 +313,7 @@ class EMChatRoomManager { /// /// Param [roomId] The chat room ID. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future destroyChatRoom( String roomId, @@ -347,7 +337,7 @@ class EMChatRoomManager { /// /// Param [subject] The new subject of the chat room. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future changeChatRoomSubject( String roomId, @@ -372,7 +362,7 @@ class EMChatRoomManager { /// /// Param [description] The new description of the chat room. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future changeChatRoomDescription( String roomId, @@ -391,21 +381,19 @@ class EMChatRoomManager { /// /// Gets the chat room member list. /// - /// When EMCursorResult.cursor is an empty string ("") amid the result, all data is fetched. - /// /// Param [roomId] The chat room ID. /// /// Param [cursor] The cursor position from which to start getting data. /// /// Param [pageSize] The number of members per page. /// - /// **return** The list of chat room members. See {@link EMCursorResult}. + /// **Return** The list of chat room members. See {@link EMCursorResult}. If `EMCursorResult.cursor` is an empty string (""), all data is fetched. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future> fetchChatRoomMembers( String roomId, { - String? cursor, + String cursor = '', int pageSize = 200, }) async { Map req = {"roomId": roomId, "pageSize": pageSize}; @@ -423,7 +411,7 @@ class EMChatRoomManager { } /// - /// Mutes members in a chat room. + /// Mutes the specified members in a chat room. /// /// Only the chat room owner or admin can call this method. /// @@ -433,7 +421,7 @@ class EMChatRoomManager { /// /// Param [duration] The mute duration in milliseconds. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future muteChatRoomMembers( String roomId, @@ -455,7 +443,7 @@ class EMChatRoomManager { } /// - /// Unmutes members in a chat room. + /// Unmutes the specified members in a chat room. /// /// Only the chat room owner or admin can call this method. /// @@ -463,7 +451,7 @@ class EMChatRoomManager { /// /// Param [unMuteMembers] The list of members to be unmuted. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future unMuteChatRoomMembers( String roomId, @@ -484,11 +472,11 @@ class EMChatRoomManager { /// /// Only the chat room owner can call this method. /// - /// Param [roomId] A chat room ID. + /// Param [roomId] The chat room ID. /// /// Param [newOwner] The ID of the new chat room owner. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future changeOwner( String roomId, @@ -509,11 +497,11 @@ class EMChatRoomManager { /// /// Only the chat room owner can call this method. /// - /// Param [roomId] A chat room ID. + /// Param [roomId] The chat room ID. /// /// Param [admin] The ID of the chat room admin to be added. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future addChatRoomAdmin( String roomId, @@ -536,7 +524,7 @@ class EMChatRoomManager { /// /// Param [admin] The ID of admin whose privileges are to be removed. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future removeChatRoomAdmin( String roomId, @@ -557,15 +545,15 @@ class EMChatRoomManager { /// /// Only the chat room owner or admin can call this method. /// - /// Param [roomId] The chat room ID + /// Param [roomId] The chat room ID. /// /// Param [pageNum] The page number, starting from 1. /// /// Param [pageSize] The number of muted members per page. /// - /// **return** The muted member list. + /// **Return** The muted member list. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future?> fetchChatRoomMuteList( String roomId, { @@ -584,15 +572,15 @@ class EMChatRoomManager { } /// - /// Removes members from a chat room. + /// Removes the specified members from a chat room. /// /// Only the chat room owner or admin can call this method. /// - /// Param [roomId] The chat room ID + /// Param [roomId] The chat room ID. /// - /// Param [members] The members list to be removed. + /// Param [members] The list of the members to be removed. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future removeChatRoomMembers( String roomId, @@ -609,20 +597,19 @@ class EMChatRoomManager { } /// - /// Adds members to the chat room's block list. + /// Adds the specified members to the block list of the chat room. /// /// Only the chat room owner or admin can call this method. /// - /// For members added to block list, note the following: - /// 1. A member, once added to the chat room block list, will be removed from the chat room by the server. - /// 2. The method {@link EMChatRoomEventListener#onRemovedFromChatRoom(String, String?, String?)} occurs. - /// 3. Members added to the block list are banned from rejoining the chat room. + /// **Note** + /// - Chat room members added to the block list are removed from the chat room by the server, and cannot re-join the chat room. + /// - The removed members receive the {@link EMChatRoomEventListener#onRemovedFromChatRoom(String, String?, String)} callback. /// /// Param [roomId] The chat room ID. /// /// Param [members] The list of members to be added to block list. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future blockChatRoomMembers( String roomId, @@ -639,7 +626,7 @@ class EMChatRoomManager { } /// - /// Removes members from the chat room's block list. + /// Removes the specified members from the block list of the chat room. /// /// Only the chat room owner or admin can call this method. /// @@ -647,7 +634,7 @@ class EMChatRoomManager { /// /// Param [members] The list of members to be removed from the block list. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future unBlockChatRoomMembers( String roomId, @@ -674,9 +661,9 @@ class EMChatRoomManager { /// /// Param [pageSize] The number of users on the block list per page. /// - /// **return** The chat room's block list. + /// **Return** The list of the blocked chat room members. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future?> fetchChatRoomBlockList( String roomId, [ @@ -703,7 +690,7 @@ class EMChatRoomManager { /// /// Param [announcement] The announcement content. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future updateChatRoomAnnouncement( String roomId, @@ -724,9 +711,9 @@ class EMChatRoomManager { /// /// Param [roomId] The chat room ID. /// - /// **return** The chat room announcement. + /// **Return** The chat room announcement. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future fetchChatRoomAnnouncement( String roomId, @@ -743,15 +730,15 @@ class EMChatRoomManager { } /// - /// Gets the while list from the server. + /// Gets the allow list from the server. /// /// Only the chat room owner or admin can call this method. /// /// Param [roomId] The chat room ID. /// - /// **return** The chat room while list. + /// **Return** The chat room allow list. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future?> fetchChatRoomWhiteListFromServer(String roomId) async { Map req = {"roomId": roomId}; @@ -766,13 +753,14 @@ class EMChatRoomManager { } /// - /// Checks whether the member is on the while list. + /// Checks whether the member is on the allow list. /// /// Param [roomId] The chat room ID. /// - /// **return** Current member is in while list. - /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Return** Whether the member is on the allow list. + /// - `true`: Yes; + /// - `false`: No. + /// **Throws** A description of the exception. See {@link EMError}. /// Future isMemberInChatRoomWhiteList(String roomId) async { Map req = {"roomId": roomId}; @@ -790,9 +778,9 @@ class EMChatRoomManager { /// /// Param [roomId] The chat room ID. /// - /// Param [members] The list of members to be added to the while list. + /// Param [members] The list of members to be added to the allow list. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future addMembersToChatRoomWhiteList( String roomId, @@ -811,15 +799,15 @@ class EMChatRoomManager { } /// - /// Removes members from the while list. + /// Removes members from the allow list. /// /// Only the chat room owner or admin can call this method. /// /// Param [roomId] The chat room ID. /// - /// Param [members] The list of members to be removed from the while list. + /// Param [members] The list of members to be removed from the allow list. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future removeMembersFromChatRoomWhiteList( String roomId, @@ -841,11 +829,11 @@ class EMChatRoomManager { /// /// Only the chat room owner or admin can call this method. /// - /// This method does not work for the chat room owner, admin, and members added to the block list. + /// This method does not work for the chat room owner, admin, and members added to the allow list. /// /// Param [roomId] The chat room ID. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future muteAllChatRoomMembers(String roomId) async { Map req = {"roomId": roomId}; @@ -863,7 +851,7 @@ class EMChatRoomManager { /// /// Param [roomId] The chat room ID. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future unMuteAllChatRoomMembers(String roomId) async { Map req = {"roomId": roomId}; diff --git a/lib/src/em_client.dart b/lib/src/em_client.dart index 9b709e9c..4145b578 100644 --- a/lib/src/em_client.dart +++ b/lib/src/em_client.dart @@ -9,7 +9,7 @@ import 'internal/chat_method_keys.dart'; import 'tools/em_log.dart'; /// -/// The EMClient, which is the entry point of the Chat SDK. You can log in, log out, and access other functionalities such as group and chatroom with this class. +/// The EMClient class, which is the entry point of the Chat SDK. With this class, you can log in, log out, and access other functionalities such as group and chatroom. /// class EMClient { static const _channelPrefix = 'com.chat.im'; @@ -28,12 +28,12 @@ class EMClient { EMOptions? _options; - /// 获取配置信息[EMOptions]. + /// Gets the configurations. EMOptions? get options => _options; String? _currentUsername; - /// 获取当前登录的环信id + /// Gets the current logged-in username. String? get currentUsername => _currentUsername; static EMClient get getInstance => @@ -100,7 +100,7 @@ class EMClient { } } - /// 获取已登录账号的环信Token + /// Gets the token of the current logged-in user. Future getAccessToken() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getToken); try { @@ -114,7 +114,7 @@ class EMClient { /// /// Initializes the SDK. /// - /// Param [options] The configurations. Make sure to set the param. + /// Param [options] The configurations: {@link EMOptions}. Ensure that you set this parameter. /// Future init(EMOptions options) async { _options = options; @@ -124,7 +124,7 @@ class EMClient { } /// - /// Register a new user with your chat network. + /// Register a new user. /// /// Param [username] The username. The maximum length is 64 characters. Ensure that you set this parameter. /// Supported characters include the 26 English letters (a-z), the ten numbers (0-9), the underscore (_), the hyphen (-), @@ -133,7 +133,7 @@ class EMClient { /// /// Param [password] The password. The maximum length is 64 characters. Ensure that you set this parameter. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future createAccount(String username, String password) async { EMLog.v('create account: $username : $password'); @@ -147,17 +147,17 @@ class EMClient { } /// - /// An app user logs in to the chat server with a password or token + /// An app user logs in to the chat server with a password or token. /// - /// Param [username] The unique chat user ID, the same as username. + /// Param [username] The username. /// /// Param [pwdOrToken] The password or token. /// - /// Param [isPassword] login With password or token. - /// `true`: (default) login with password. - /// `false`: login with token. + /// Param [isPassword] Whether to log in with password or token. + /// `true`: (default) Log in with password. + /// `false`: Log in with token. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future login(String username, String pwdOrToken, [bool isPassword = true]) async { @@ -177,15 +177,15 @@ class EMClient { } /// - /// An app user logs in to the chat server by user ID and Agora token. This method supports automatic login. + /// An app user logs in to the chat server by username and Agora token. This method supports automatic login. /// - /// Reference: Another method to login to chat server is to login with user ID and token, see {@link #login(String, String, bool)}. + /// See also: Another method to login to chat server is to login with user ID and token, see {@link #login(String, String, bool)}. /// - /// Param [username] The user ID. + /// Param [username] The username. /// /// Param [agoraToken] The Agora token. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future loginWithAgoraToken(String username, String agoraToken) async { Map req = { @@ -204,13 +204,13 @@ class EMClient { } /// - /// When a user is in the Agora token login state and receives a callback notification of the token is to be expired - /// in the {@link EMConnectionListener} implementation class, - /// this API can be called to update the token to avoid unknown problems caused by the token invalidation. + /// Renews the Agora token. /// - /// Param [agoraToken] The new token. + /// If a user is logged in with an Agora token, when the token expires, you need to call this method to update the token. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// Param [agoraToken] The new Agora token. + /// + /// **Throws** A description of the exception. See {@link EMError}. /// Future renewAgoraToken(String agoraToken) async { Map req = {"agora_token": agoraToken}; @@ -224,14 +224,14 @@ class EMClient { } /// - /// An app user logs out and returns the result. + /// An app user logs out. /// - /// Param [unbindDeviceToken] Whether to unbind the token. + /// Param [unbindDeviceToken] Whether to unbind the token when logout. /// - /// `true` (default) means to unbind the device token when logout. - /// `false` means to not unbind the device token when logout. + /// `true` (default) Yes. + /// `false` No. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future logout([ bool unbindDeviceToken = true, @@ -248,15 +248,15 @@ class EMClient { } /// - /// Update the App Key, which is the unique identifier used to access Agora Chat. + /// Updates the App Key, which is the unique identifier to access Agora Chat. /// - /// You retrieve the new App Key from Agora Console. + /// You can retrieve the new App Key from Agora Console. /// /// As this key controls all access to Agora Chat for your app, you can only update the key when the current user is logged out. /// - /// Param [newAppKey] The App Key, make sure to set the param. + /// Param [newAppKey] The App Key. Ensure that you set this parameter. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future changeAppKey({required String newAppKey}) async { EMLog.v('changeAppKey: $newAppKey'); @@ -275,9 +275,9 @@ class EMClient { /// /// Best practice is to delete this debug archive as soon as it is no longer used. /// - /// **return** The path of the compressed gz file. + /// **Return** The path of the compressed gzip file. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future compressLogs() async { EMLog.v('compressLogs:'); @@ -293,13 +293,13 @@ class EMClient { /// /// Gets all the information about the logged in devices under the specified account. /// - /// Param [username] The user ID you want to get the device information. + /// Param [username] The username you want to get the device information. /// /// Param [password] The password. /// - /// **return** The list of the online devices. + /// **Return** TThe list of the logged-in devices. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future> getLoggedInDevicesFromServer( {required String username, required String password}) async { @@ -320,15 +320,15 @@ class EMClient { } /// - /// Force the specified account to logout from the specified device, to fetch the device ID: {@link EMDeviceInfo#resource}. + /// Forces the specified account to log out from the specified device. /// /// Param [username] The account you want to force logout. /// /// Param [password] The account's password. /// - /// Param [resource] The device ID, see {@link EMDeviceInfo#resource}. + /// Param [resource] The device ID. For how to fetch the device ID, ee {@link EMDeviceInfo#resource}. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future kickDevice( {required String username, @@ -354,9 +354,9 @@ class EMClient { /// /// Param [username] The account you want to log out from all the devices. /// - /// Param [password] The account's password. + /// Param [password] The password. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future kickAllDevices( {required String username, required String password}) async { @@ -376,7 +376,7 @@ class EMClient { /// /// Adds the multi-device listener. /// - /// Param [listener] See {EMMultiDeviceListener} + /// Param [listener] The listener to be added: {EMMultiDeviceListener}. /// void addMultiDeviceListener(EMMultiDeviceListener listener) { _multiDeviceListeners.add(listener); @@ -385,7 +385,7 @@ class EMClient { /// /// Removes the multi-device listener. /// - /// Param [listener] See {EMMultiDeviceListener} + /// Param [listener] The listener to be removed: {EMMultiDeviceListener}. /// void removeMultiDeviceListener(EMMultiDeviceListener listener) { if (_multiDeviceListeners.contains(listener)) { @@ -396,7 +396,7 @@ class EMClient { /// /// Adds the connection listener of chat server. /// - /// Param [listener] The chat server connection listener. + /// Param [listener] The chat server connection listener to be added. /// void addConnectionListener(EMConnectionListener listener) { _connectionListeners.add(listener); @@ -405,7 +405,7 @@ class EMClient { /// /// Removes the chat server connection listener. /// - /// Param [listener] The chat server connection listener. + /// Param [listener] The chat server connection listener to be removed. /// void removeConnectionListener(EMConnectionListener listener) { if (_connectionListeners.contains(listener)) { @@ -414,11 +414,9 @@ class EMClient { } /// - /// Adds the custom listener of native. + /// Adds a custom listener to receive data from iOS or Android devices. /// - /// 你可以从原生发送数据到flutter. - /// - /// Param [listener] The custom native listener. + /// Param [listener] The custom native listener to be added. /// void addCustomListener(EMCustomListener listener) { _customListeners.add(listener); @@ -486,54 +484,54 @@ class EMClient { } /// - /// Gets the `EMChatManager` class. Make sure to call it after EMClient has been initialized, see {@link EMClient#init(EMOptions)} + /// Gets the `EMChatManager` class. Make sure to call it after EMClient has been initialized. /// - /// **return** The `EMChatManager` class. + /// **Return** The `EMChatManager` class. /// EMChatManager get chatManager { return _chatManager; } /// - /// Gets the `EMContactManager` class. Make sure to call it after the EMClient has been initialized, see {@link EMClient#init(EMOptions)} + /// Gets the `EMContactManager` class. Make sure to call it after the EMClient has been initialized. /// - /// **return** The `EMContactManager` class. + /// **Return** The `EMContactManager` class. /// EMContactManager get contactManager { return _contactManager; } /// - /// Gets the `ChatRoomManager` class. Make sure to call it after the EMClient has been initialized, see {@link EMClient#init(EMOptions)} + /// Gets the `ChatRoomManager` class. Make sure to call it after the EMClient has been initialized. /// - /// **return** The `EMChatRoomManager` class. + /// **Return** The `EMChatRoomManager` class. /// EMChatRoomManager get chatRoomManager { return _chatRoomManager; } /// - /// Gets the `EMGroupManager` class. Make sure to call it after the EMClient has been initialized, see {@link EMClient#init(EMOptions)} + /// Gets the `EMGroupManager` class. Make sure to call it after the EMClient has been initialized. /// - /// **return** The `EMGroupManager` class. + /// **Return** The `EMGroupManager` class. /// EMGroupManager get groupManager { return _groupManager; } /// - /// Gets the `EMPushManager` class. Make sure to call it after the EMClient has been initialized, see {@link EMClient#init(EMOptions)} + /// Gets the `EMPushManager` class. Make sure to call it after the EMClient has been initialized. /// - /// **return** The `EMPushManager` class. + /// **Return** The `EMPushManager` class. /// EMPushManager get pushManager { return _pushManager; } /// - /// Gets the `EMUserInfoManager` class. Make sure to call it after the EMClient has been initialized, see {@link EMClient#init(EMOptions)} + /// Gets the `EMUserInfoManager` class. Make sure to call it after the EMClient has been initialized. /// - /// **return** The `EMUserInfoManager` class. + /// **Return** The `EMUserInfoManager` class. /// EMUserInfoManager get userInfoManager { return _userInfoManager; diff --git a/lib/src/em_contact_manager.dart b/lib/src/em_contact_manager.dart index e4b0fbf1..4e9f9e23 100644 --- a/lib/src/em_contact_manager.dart +++ b/lib/src/em_contact_manager.dart @@ -8,7 +8,7 @@ import 'internal/em_event_keys.dart'; import 'models/em_error.dart'; /// -/// The `EMContactManager` is used to record, query, and modify contacts. +/// The contact manager class, which manages chat contacts such as adding, deleting, retrieving, and modifying contacts. /// class EMContactManager { static const _channelPrefix = 'com.chat.im'; @@ -59,9 +59,9 @@ class EMContactManager { /// /// Param [username] The user to be added. /// - /// Param [reason] (optional) The invitation message. Set the parameter as null if you want to ignore the information. + /// Param [reason] (optional) The invitation message. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future addContact( String username, [ @@ -77,15 +77,15 @@ class EMContactManager { } /// - /// Deletes a contact and all the conversations associated. + /// Deletes a contact and all the related conversations. /// /// Param [username] The contact to be deleted. /// - /// Param [keepConversation] Whether to keep the associated conversation and messages. - /// `true`: keep conversation and messages. - /// `false`: (default) delete conversation and messages. + /// Param [keepConversation] Whether to retain conversations of the deleted contact. + /// - `true`: Yes. + /// - `false`: (default) No. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future deleteContact( String username, [ @@ -101,11 +101,11 @@ class EMContactManager { } /// - /// Get all contacts from the server. + /// Gets all the contacts from the server. /// - /// **return** The list of contacts. + /// **Return** The list of contacts. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future> getAllContactsFromServer() async { Map result = @@ -125,9 +125,9 @@ class EMContactManager { /// /// Gets the contact list from the local database. /// - /// **return** The contact list. + /// **Return** The contact list. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future> getAllContactsFromDB() async { Map result = @@ -146,12 +146,12 @@ class EMContactManager { } /// - /// Adds a user to block list. - /// You can send message to the user in block list, but you can not receive the message sent by the other. + /// Adds a user to the block list. + /// You can send messages to the users on the block list, but cannot receive messages from them. /// - /// Param [username] The user to be blocked. + /// Param [username] The user to be added to the block list. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future addUserToBlockList( String username, @@ -171,9 +171,9 @@ class EMContactManager { /// /// Removes the contact from the block list. /// - /// Param [username] The user to be removed from the block list. + /// Param [username] The contact to be removed from the block list. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future removeUserFromBlockList(String username) async { Map req = {'username': username}; @@ -187,11 +187,11 @@ class EMContactManager { } /// - /// Get all block list from the server. + /// Gets the block list from the server. /// - /// **return** The block list from the server. + /// **Return** The block list obtained from the server. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future> getBlockListFromServer() async { Map result = @@ -209,11 +209,11 @@ class EMContactManager { } /// - /// Gets the local database block list. + /// Gets the block list from the local database. /// - /// **return** The block list. + /// **Return** The block list obtained from the local database. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future> getBlockListFromDB() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getBlockListFromDB); @@ -232,9 +232,9 @@ class EMContactManager { /// /// Accepts a friend invitation。 /// - /// Param [username] The user who initiates the friend request. + /// Param [username] The user who sends the friend invitation. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future acceptInvitation(String username) async { Map req = {'username': username}; @@ -250,9 +250,9 @@ class EMContactManager { /// /// Declines a friend invitation. /// - /// Param [username] The user who initiates the invitation. + /// Param [username] The user who sends the friend invitation. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future declineInvitation(String username) async { Map req = {'username': username}; @@ -266,11 +266,11 @@ class EMContactManager { } /// - /// Get the unique IDs of current user on the other devices. The ID is username + "/" + resource. + /// Gets the unique IDs of the current user on the other devices. The ID is in the format of username + "/" + resource. /// - /// **return** The unique device ID list on the other devices if the method succeeds. + /// **Return** The list of unique IDs of users on the other devices if the method succeeds. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future?> getSelfIdsOnOtherPlatform() async { Map result = @@ -288,7 +288,7 @@ class EMContactManager { /// /// Registers a new contact listener. /// - /// Param [contactListener] The contact listener to be registered. + /// Param [contactListener] The contact listener to be registered: {@link EMContactEventListener}. /// void addContactListener(EMContactManagerListener contactListener) { _contactManagerListeners.add(contactListener); diff --git a/lib/src/em_group_manager.dart b/lib/src/em_group_manager.dart index 8aa7299e..973c6ee2 100644 --- a/lib/src/em_group_manager.dart +++ b/lib/src/em_group_manager.dart @@ -13,7 +13,7 @@ import 'tools/em_extension.dart'; import 'internal/chat_method_keys.dart'; /// -/// The group manager for management of group creation and deletion and member management. +/// The group manager class, which manages group creation and deletion, user joining and exiting the group, etc. /// class EMGroupManager { static const _channelPrefix = 'com.chat.im'; @@ -39,9 +39,9 @@ class EMGroupManager { /// /// Param [groupId] The group ID. /// - /// **return** The group instance. Returns null if the group does not exist. + /// **Return** The group instance. Returns null if the group does not exist. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future getGroupWithId(String groupId) async { Map req = {'groupId': groupId}; @@ -60,11 +60,11 @@ class EMGroupManager { } /// - /// Gets all groups of the current user (from the cache). + /// Gets all groups of the current user from the cache. /// - /// **return** The group list. + /// **Return** The group list. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future> getJoinedGroups() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getJoinedGroups); @@ -88,11 +88,11 @@ class EMGroupManager { /// /// Gets all groups of the current user from the server. /// - /// This method returns a group list which does not contain member information. If you want to update information of a group to include its member information, call {@link getGroupSpecificationFromServer(String groupId)}. + /// This method returns a group list which does not contain member information. If you want to update information of a group to include its member information, call {@link #getGroupSpecificationFromServer(String groupId)}. /// - /// **return** The list of groups that the current user joins. + /// **Return** The list of groups that the current user joins. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future> getJoinedGroupsFromServer({ int pageSize = 200, @@ -111,15 +111,14 @@ class EMGroupManager { /// /// Gets public groups from the server with pagination. /// - /// /// Param [pageSize] The number of public groups per page. /// /// Param [cursor] The cursor position from which to start to get data next time. Sets the parameter as null for the first time. /// - /// **return** The result of {@link EMCursorResult}, including the cursor for getting data next time and the group list. - /// For the last page, the return value of cursor is an empty string. + /// **Return** The result of {@link EMCursorResult}, including the cursor for getting data next time and the group list. + /// If `EMCursorResult.cursor` is an empty string (""), all data is fetched. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future> getPublicGroupsFromServer({ int pageSize = 200, @@ -144,11 +143,10 @@ class EMGroupManager { /// /// Creates a group instance. /// - /// After the group is created, the data in the cache and database will be updated and multiple devices will receive the notification event and - /// update the group to the cache and database. - /// You can set {@link EMMultiDeviceListener} to listen on the event. The event callback function - /// is {@link EMMultiDeviceListener#onGroupEvent(EMContactGroupEvent, String, List)}, where the first parameter is the event, - /// for example, {@link EMContactGroupEvent#GROUP_CREATE} for the group creation event. + /// After the group is created, the data in the cache and database will be updated and multiple devices will receive the notification event and update the group data to the cache and database. + /// You can set {@link com.EMMultiDeviceListener} to listen for the event. If an event occurs, the callback function + /// {@link EMMultiDeviceListener#onGroupEvent(int, String, List)} is triggered, where the first parameter is the event which is + /// {@link EMContactGroupEvent#GROUP_CREATE} for a group creation event. /// /// Param [groupName] The group name. /// @@ -162,12 +160,12 @@ class EMGroupManager { /// The options are as follows: /// - The maximum number of group members. The default value is 200. /// - The group style. See {@link EMGroupManager.EMGroupStyle}. The default value is {@link EMGroupStyle#PrivateOnlyOwnerInvite}. - /// - Whether to ask for permission when inviting a user to join the group. The default value is false, indicating that invitees are automaticall added to the group without their permission. + /// - Whether to ask for permission when inviting a user to join the group. The default value is `false`, indicating that invitees are automatically added to the group without their permission. /// - The group detail extensions. /// - /// **return** The created group instance. + /// **Return** The created group instance. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future createGroup({ String? groupName, @@ -198,9 +196,9 @@ class EMGroupManager { /// /// Param [groupId] The group ID. /// - /// **return** The group instance. + /// **Return** The group instance. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future getGroupSpecificationFromServer(String groupId) async { Map req = {'groupId': groupId}; @@ -218,8 +216,6 @@ class EMGroupManager { /// /// Gets a group's member list with pagination. /// - /// When EMCursorResult.cursor is an empty string ("") in the result, there is no more data. - /// /// For example: /// ```dart /// EMCursorResult result = await EMClient.getInstance.groupManager.getGroupMemberListFromServer(groupId); // search 1 @@ -232,10 +228,10 @@ class EMGroupManager { /// /// Param [cursor] The cursor position from which to start to get data next time. Sets the parameter as null for the first time. /// - /// **return** The result of {@link EMCursorResult}, including the cursor for getting data next time and the group member list. - /// For the last page, the return value of cursor is an empty string. + /// **Return** The result of {@link EMCursorResult}, including the cursor for getting data next time and the group member list. + /// If `EMCursorResult.cursor` is an empty string (""), all data is fetched. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future> getGroupMemberListFromServer( String groupId, { @@ -272,9 +268,9 @@ class EMGroupManager { /// /// Param [pageNum] The page number, starting from 1. /// - /// **return** The group block list. + /// **Return** The group block list. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future?> getBlockListFromServer( String groupId, { @@ -299,13 +295,13 @@ class EMGroupManager { /// /// Param [groupId] The group ID. /// - /// Param [pageSize] The number of groups per page. + /// Param [pageSize] The number of muted members per page. /// /// Param [pageNum] The page number, starting from 1. /// - /// **return** The group mute list. + /// **Return** The group mute list. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future?> getMuteListFromServer( String groupId, { @@ -324,15 +320,15 @@ class EMGroupManager { } /// - /// Gets the allow list of group from the server. + /// Gets the allow list of the group from the server. /// /// Only the group owner or admin can call this method. /// /// Param [groupId] The group ID. /// - /// **return** return the group allow list. + /// **Return** The allow list of the group. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future?> getWhiteListFromServer(String groupId) async { Map req = {'groupId': groupId}; @@ -347,13 +343,13 @@ class EMGroupManager { } /// - /// Gets whether the member is on the allow list. + /// Gets whether the member is on the allow list of the group. /// /// Param [groupId] The group ID. /// - /// **return** returns a Boolean value to indicate whether the current user is on the group allow list; + /// **Return** A Boolean value to indicate whether the current user is on the allow list of the group; /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future isMemberInWhiteListFromServer(String groupId) async { Map req = {'groupId': groupId}; @@ -368,17 +364,17 @@ class EMGroupManager { } /// - /// Gets the shared files of group from the server. + /// Gets the shared files of the group from the server. /// /// Param [groupId] The group ID. /// - /// Param [pageSize] The number of groups per page. + /// Param [pageSize] The number of shared files per page. /// /// Param [pageNum] The page number, starting from 1. /// - /// **return** The shared files. + /// **Return** The shared files. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future?> getGroupFileListFromServer( String groupId, { @@ -407,9 +403,9 @@ class EMGroupManager { /// /// Param [groupId] The group ID. /// - /// **return** The group announcement. + /// **Return** The group announcement. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future getGroupAnnouncementFromServer(String groupId) async { Map req = {'groupId': groupId}; @@ -434,7 +430,7 @@ class EMGroupManager { /// /// Param [welcome] The welcome message. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future addMembers( String groupId, @@ -452,17 +448,19 @@ class EMGroupManager { } /// - /// Adds users to the group. + /// Invites users to join the group. /// - /// 群类型是 PrivateOnlyOwnerInvite / PrivateMemberCanInvite / PublicJoinNeedApproval 的群组可以邀请用户加入 + /// This method works only for groups with the style of `PrivateOnlyOwnerInvite`, `PrivateMemberCanInvite`, or `PublicJoinNeedApproval`. + /// For a group with the PrivateOnlyOwnerInvite style, only the group owner can invite users to join the group; + /// For a group with the PrivateMemberCanInvite style, each group member can invite users to join the group. /// /// Param [groupId] The group ID. /// /// Param [members] The array of new members to invite. /// - /// Param [reason] The invite reason. + /// Param [reason] The invitation reason. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future inviterUser( String groupId, @@ -496,9 +494,9 @@ class EMGroupManager { /// /// Param [groupId] The group ID. /// - /// Param [members] The user IDs of members to be removed. + /// Param [members] The username of the member to be removed. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future removeMembers( String groupId, @@ -514,9 +512,9 @@ class EMGroupManager { } /// - /// Adds the user to the group block list. + /// Adds the user to the block list of the group. /// - /// Users will be first removed from the group they have joined before being added to the group block list. The users on the group block list can not join the group again. + /// Users will be first removed from the group they have joined before being added to the block list of the group. The users on the group block list cannot join the group again. /// /// Only the group owner or admin can call this method. /// @@ -524,7 +522,7 @@ class EMGroupManager { /// /// Param [members] The list of users to be added to the block list. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future blockMembers( String groupId, @@ -548,7 +546,7 @@ class EMGroupManager { /// /// Param [members] The users to be removed from the group block list. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future unblockMembers( String groupId, @@ -573,7 +571,7 @@ class EMGroupManager { /// /// Param [name] The new group name. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future changeGroupName( String groupId, @@ -598,7 +596,7 @@ class EMGroupManager { /// /// Param [desc] The new group description. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future changeGroupDescription( String groupId, @@ -619,7 +617,7 @@ class EMGroupManager { /// /// Param [groupId] The group ID. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future leaveGroup(String groupId) async { Map req = {'groupId': groupId}; @@ -638,7 +636,7 @@ class EMGroupManager { /// /// Param [groupId] The group ID. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future destroyGroup(String groupId) async { Map req = {'groupId': groupId}; @@ -657,7 +655,7 @@ class EMGroupManager { /// /// Param [groupId] The group ID. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future blockGroup(String groupId) async { Map req = {'groupId': groupId}; @@ -674,7 +672,7 @@ class EMGroupManager { /// /// Param [groupId] The group ID. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future unblockGroup(String groupId) async { Map req = {'groupId': groupId}; @@ -695,9 +693,9 @@ class EMGroupManager { /// /// Param [newOwner] The new owner ID. /// - /// **return** The updated group instance. + /// **Return** The updated group instance. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future changeOwner( String groupId, @@ -717,15 +715,15 @@ class EMGroupManager { /// /// Adds a group admin. /// - /// Only the group owner can call this method and admin can not. + /// Only the group owner can call this method and group admins cannot. /// /// Param [groupId] The group ID. /// - /// Param [memberId] The admin ID to add. + /// Param [memberId] The username of the admin to add. /// - /// **return** The updated group instance. + /// **Return** The updated group instance. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future addAdmin( String groupId, @@ -748,11 +746,11 @@ class EMGroupManager { /// /// Param [groupId] The group ID. /// - /// Param [adminId] The admin ID to remove. + /// Param [adminId] The username of the admin to remove. /// - /// **return** The updated group instance. + /// **Return** The updated group instance. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future removeAdmin( String groupId, @@ -779,9 +777,9 @@ class EMGroupManager { /// /// Param [duration] The mute duration in milliseconds. /// - /// **return** The updated group instance. + /// **Return** The updated group instance. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future muteMembers( String groupId, @@ -807,7 +805,7 @@ class EMGroupManager { /// /// Param [members] The list of members to be muted. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future unMuteMembers( String groupId, @@ -829,7 +827,7 @@ class EMGroupManager { /// /// Param [groupId] The group ID. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future muteAllMembers(String groupId) async { Map req = {'groupId': groupId}; @@ -849,7 +847,7 @@ class EMGroupManager { /// /// Param [groupId] The group ID. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future unMuteAllMembers(String groupId) async { Map req = {'groupId': groupId}; @@ -863,15 +861,15 @@ class EMGroupManager { } /// - /// Adds members to the allowlist. + /// Adds members to the allow list of the group. /// /// Only the group owner or admin can call this method. /// /// Param [groupId] The group ID. /// - /// Param [members] The members to be added to the allowlist. + /// Param [members] The members to be added to the allow list of the group. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future addWhiteList( String groupId, @@ -887,15 +885,15 @@ class EMGroupManager { } /// - /// Removes members from the allowlist. + /// Removes members from the allow list of the group. /// /// Only the group owner or admin can call this method. /// /// Param [groupId] The group ID. /// - /// Param [members] The members to be removed from the allowlist. + /// Param [members] The members to be removed from the allow list of the group. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future removeWhiteList( String groupId, @@ -914,13 +912,13 @@ class EMGroupManager { /// /// Uploads the shared file to the group. /// - /// Note: The callback is only used for progress callback. + /// When a shared file is uploaded, the upload progress callback will be triggered. /// /// Param [groupId] The group ID. /// - /// Param [filePath] The local file path. + /// Param [filePath] The local path of the shared file. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future uploadGroupSharedFile( String groupId, @@ -945,9 +943,9 @@ class EMGroupManager { /// /// Param [fileId] The ID of the shared file. /// - /// Param [savePath] The local file path. + /// Param [savePath] The local path of the shared file. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future downloadGroupSharedFile( String groupId, @@ -971,9 +969,9 @@ class EMGroupManager { /// /// Param [groupId] The group ID. /// - /// Param [fileId] The shared file ID. + /// Param [fileId] The ID of the shared file. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future removeGroupSharedFile( String groupId, @@ -998,7 +996,7 @@ class EMGroupManager { /// /// Param [announcement] The group announcement. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future updateGroupAnnouncement( String groupId, @@ -1024,7 +1022,7 @@ class EMGroupManager { /// /// Param [extension] The group extension field. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future updateGroupExtension( String groupId, @@ -1043,12 +1041,12 @@ class EMGroupManager { /// /// Joins a public group. /// - /// For a group that requires no authentication,users can join it freely without the need of having permission. - /// For a group that requires authentication, users need to wait for the owner to agree before joining the group. For details, see {@link EMGroupStyle}. + /// For a group that requires no authentication,users can join it freely without obtaining permissions from the group owner. + /// For a group that requires authentication, users need to wait for the group owner to agree before joining the group. For details, see {@link EMGroupStyle}. /// ///Param [groupId] The group ID. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future joinPublicGroup( String groupId, @@ -1066,14 +1064,13 @@ class EMGroupManager { /// /// Requests to join a group. /// - /// Note: The group style is {@link EMGroupStyle#PublicJoinNeedApproval}, which is a public group - /// requiring authentication. + /// This method works only for public groups requiring authentication, i.e., groups with the style of {@link EMGroupStyle#PublicJoinNeedApproval}. /// /// Param [groupId] The group ID. /// /// Param [reason] The reason for requesting to join the group. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future requestToJoinPublicGroup( String groupId, [ @@ -1097,9 +1094,9 @@ class EMGroupManager { /// /// Param [groupId] The group ID. /// - /// Param [username] The ID of the user who sends a request to join the group. + /// Param [username] The username of the user who sends a request to join the group. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future acceptJoinApplication( String groupId, @@ -1122,11 +1119,11 @@ class EMGroupManager { /// /// Param [groupId] The group ID. /// - /// Param [username] The ID of the user who sends a request to join the group. + /// Param [username] The username of the user who sends a request to join the group. /// /// Param [reason] The reason of declining. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future declineJoinApplication( String groupId, @@ -1152,9 +1149,9 @@ class EMGroupManager { /// /// Param [inviter] The user who initiates the invitation. /// - /// **return** The group instance which the user has accepted the invitation to join. + /// **Return** The group instance which the user has accepted the invitation to join. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future acceptInvitation( String groupId, @@ -1176,11 +1173,11 @@ class EMGroupManager { /// /// Param [groupId] The group ID. /// - /// Param [inviter] The inviter. + /// Param [inviter] The username of the inviter. /// /// Param [reason] The reason of declining. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future declineInvitation( String groupId, diff --git a/lib/src/em_userInfo_manager.dart b/lib/src/em_userInfo_manager.dart index 24dde92e..9990da71 100644 --- a/lib/src/em_userInfo_manager.dart +++ b/lib/src/em_userInfo_manager.dart @@ -7,7 +7,7 @@ import 'models/em_error.dart'; import 'models/em_userInfo.dart'; /// -/// The user information manager for updating and getting user properties. +/// The user attribute manager class, which gets and sets the user attributes. /// class EMUserInfoManager { static const _channelPrefix = 'com.chat.im'; @@ -16,17 +16,17 @@ class EMUserInfoManager { EMUserInfo? _ownUserInfo; - //有效的联系人map + // The map of effective contacts. Map _effectiveUserInfoMap = Map(); /// - /// Modifies the current user's information. + /// Modifies the user attributes of the current user. /// - /// Param [userInfo] userInfo The user information to be modified. + /// Param [userInfo] The user attributes to be modified. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// - Future updateOwnInfo(EMUserInfo userInfo) async { + Future updateOwnUserInfo(EMUserInfo userInfo) async { Map req = {'userInfo': userInfo.toJson()}; Map result = await _channel.invokeMethod(ChatMethodKeys.updateOwnUserInfo, req); @@ -38,14 +38,13 @@ class EMUserInfoManager { } /// - /// Get the current user's information from server. + /// Gets the current user's attributes from the server. /// - /// Param [expireTime] expire time, Units are seconds. If the last fetch is less than the expiration time, it is directly fetched from the local cache; - /// otherwise, it is fetched from the server. + /// Param [expireTime] The time period(seconds) when the user attibutes in the cache expire. If the interval between two calles is less than or equal to the value you set in the parameter, user attributes are obtained directly from the local cache; otherwise, they are obtained from the server. For example, if you set this parameter to 120(2 minutes), once this method is called again within 2 minutes, the SDK returns the attributes obtained last time. /// - /// **return** user properties. See {@link EMUserInfo} + /// **Return** The user properties that are obtained. See {@link EMUserInfo}. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future fetchOwnInfo({int expireTime = 0}) async { String? currentUser = await EMClient.getInstance.getCurrentUsername(); @@ -64,16 +63,15 @@ class EMUserInfoManager { } /// - /// Gets user information with user ID. + /// Gets user attributes of the specified users. /// - /// Param [userIds] The user ID array. + /// Param [userIds] The username array. /// - /// Param [expireTime] expire time, Units are seconds. If the last fetch is less than the expiration time, it is directly fetched from the local cache; - /// otherwise, it is fetched from the server. + /// Param [expireTime] The time period(seconds) when the user attibutes in the cache expire. If the interval between two calles is less than or equal to the value you set in the parameter, user attributes are obtained directly from the local cache; otherwise, they are obtained from the server. For example, if you set this parameter to 120(2 minutes), once this method is called again within 2 minutes, the SDK returns the attributes obtained last time. /// - /// **return** Map of User ids and user properties. key is user id and value is user properties. + /// **Return** A map that contains key-value pairs where the key is the user ID and the value is user attributes. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future> fetchUserInfoById( List userIds, { diff --git a/lib/src/models/em_chat_enums.dart b/lib/src/models/em_chat_enums.dart index 01c98c0a..a67ff915 100644 --- a/lib/src/models/em_chat_enums.dart +++ b/lib/src/models/em_chat_enums.dart @@ -1,18 +1,17 @@ /// -/// The group styles. +/// The enumeration of group types. /// enum EMGroupStyle { - /// Private groups. Only the group owner can invite users to join. + /// Private groups where only the the group owner can invite users to join. PrivateOnlyOwnerInvite, - /// Private groups. Both the group owner and group members can invite users to join. + /// Private groups where all group members can invite users to join. PrivateMemberCanInvite, - /// Public groups. Only the owner can invite users to join. - /// A user can join a group only after the owner approves the user's group request; + /// Public groups where users can join only after receiving an invitation from the group owner(admin) or the joining request being approved by the group owner(admin). PublicJoinNeedApproval, - /// Public groups. A user can join a group without the group owner approving user's group request. + /// Public groups where users can join freely. PublicOpenJoin, } @@ -35,7 +34,7 @@ enum EMPushStyle { } /// -/// The enumeration of the chat type. +/// The enumeration of chat types. /// /// There are three chat types: one-to-one chat, group chat, and chat room. /// @@ -51,28 +50,26 @@ enum ChatType { } /// -/// The enumeration of the message MessageDirection. +/// The enumeration of the message directions. /// /// Whether the message is sent or received. /// enum MessageDirection { - /// This message is sent from the local client. + /// This message is sent from the local user. SEND, - /// The message is received by the local client. + /// The message is received by the local user. RECEIVE, } /// /// The enumeration of the message sending/reception status. /// -/// The states include success, failure, being sent/being received, and created to be sent. -/// enum MessageStatus { - /// The message is created to be sent. + /// The message is created. CREATE, - /// The message is being delivered/receiving. + /// The message is being delivered/received. PROGRESS, /// The message is successfully delivered/received. @@ -83,56 +80,56 @@ enum MessageStatus { } /// -/// The download status of the attachment file . +/// The download status of the attachment file. /// enum DownloadStatus { - /// File message download is pending. + /// The file message download is pending. PENDING, - /// The SDK is downloading the file message. + /// The file message is being downloaded. DOWNLOADING, - /// The SDK successfully downloads the file message. + /// The file message download succeeds. SUCCESS, - /// The SDK fails to download the file message. + /// The file message download fails. FAILED, } /// -/// The enumeration of the message type. +/// The enumeration of message types. /// enum MessageType { - /// Text message. + /// The text message. TXT, - /// Image message. + /// The image message. IMAGE, - /// Video message. + /// The video message. VIDEO, - /// Location message. + /// The location message. LOCATION, - /// Voice message. + /// The voice message. VOICE, - /// File message. + /// The file message. FILE, - /// Command message. + /// The command message. CMD, - /// Customized message. + /// The custom message. CUSTOM, } /// -/// The enum of the group permission types. +/// The enumeration of group permission types. /// enum EMGroupPermissionType { - /// The unknown type. + /// Unknown. None, /// The group member. @@ -146,30 +143,30 @@ enum EMGroupPermissionType { } /// -/// Chat room role types. +/// The enumeration of chat room role types. /// enum EMChatRoomPermissionType { - /// Unknown type. + /// Unknown. None, - /// Regular member. + /// The chat room member. Member, - /// Chat room admin. + /// The chat room admin. Admin, - /// Chat room owner. + /// The chat room owner. Owner, } /// -/// The message search direction type. +/// The enumeration of message search directions. /// enum EMSearchDirection { - /// The search older messages type + /// Messages are retrieved in the reverse chronological order of when the server receives the message. Up, - /// The search newer messages type. + /// Messages are retrieved in the chronological order of when the server receives the message. Down, } diff --git a/lib/src/models/em_chat_room.dart b/lib/src/models/em_chat_room.dart index 03aa7167..2691b8b4 100644 --- a/lib/src/models/em_chat_room.dart +++ b/lib/src/models/em_chat_room.dart @@ -4,7 +4,10 @@ import '../../src/tools/em_extension.dart'; import 'em_chat_enums.dart'; /// -/// Chat room types. +/// The chat room instance class. +/// +/// **Note** +/// To get the correct value, ensure that you call {@ link EMChatRoomManager#fetchChatRoomInfoFromServer(String)} before calling this method. /// class EMChatRoom { EMChatRoom._private({ @@ -64,41 +67,49 @@ class EMChatRoom { } /// - /// The chat room ID. + /// Gets the chat room ID. + /// + /// **Note** + /// To get the correct value, ensure that you call {@ link EMChatRoomManager#fetchChatRoomInfoFromServer(String)} before calling this method. /// final String roomId; /// - /// The chat room name from the memory. + /// Gets the chat room name from the memory. /// + /// **Note** /// To get the correct value, ensure that you call {@ link EMChatRoomManager#fetchChatRoomInfoFromServer(String)} before calling this method. /// final String? name; /// - /// The the chat room description from the memory. + /// Gets the chat room description from the memory. /// + /// **Note** /// To get the correct value, ensure that you call {@ link EMChatRoomManager#fetchChatRoomInfoFromServer(String)} before calling this method. /// final String? description; /// - /// The chat room owner ID. If this method returns an empty string, the SDK fails to get chat room details. + /// Gets the chat room owner ID. If this method returns an empty string, the SDK fails to get chat room details. /// + /// **Note** /// To get the correct value, ensure that you call {@ link EMChatRoomManager#fetchChatRoomInfoFromServer(String)} before calling this method. /// final String? owner; /// - /// Get the chat room announcement in the chat room from the memory. + /// Gets the chat room announcement in the chat room from the memory. /// - /// Ensure that you call {@ link EMChatRoomManager#fetchChatRoomAnnouncement(String)} before calling this method. Otherwise, the return value may not be correct. + /// **Note** + /// To get the correct value, ensure that you call {@ link EMChatRoomManager#fetchChatRoomAnnouncement(String)} before calling this method. Otherwise, the return value may not be correct. /// final String? announcement; /// - /// The number of online members from the memory. + /// Gets the number of online members from the memory. /// + /// **Note** /// To get the correct value, ensure that you call {@ link EMChatRoomManager#fetchChatRoomInfoFromServer(String)} before calling this method. /// final int? memberCount; @@ -106,34 +117,39 @@ class EMChatRoom { /// /// Gets the maximum number of members in the chat room from the memory, which is set/specified when the chat room is created. /// + /// **Note** /// To get the correct value, ensure that you call {@ link EMChatRoomManager#fetchChatRoomInfoFromServer(String)} before calling this method. /// final int? maxUsers; /// - /// The chat room admin list. + /// Gets the chat room admin list. + /// + /// **Note** + /// To get the correct value, ensure that you call {@ link EMChatRoomManager#fetchChatRoomInfoFromServer(String)} before calling this method. /// final List? adminList; /// - /// The member list. + /// Gets the member list. /// - /// You can get the member list in the following ways: - /// When there are less than 200 members, use {@link EMChatRoomManager#fetchChatRoomInfoFromServer(String, bool?)} to get them. - /// If true is passed to the second parameter, you can get up to 200 members. + /// **Note** + /// To get the correct value, ensure that you call {@link EMChatRoomManager#fetchChatRoomMembers(String, bool?)} /// final List? memberList; /// - /// The chat room block list. + /// Gets the chat room block list. /// + /// **Note** /// To get the block list, you can call {@link EMChatRoomManager#fetchChatRoomBlockList(String, int?, int?)}. /// final List? blockList; /// - /// The mute list of the chat room. + /// Gets the mute list of the chat room. /// + /// **Note** /// To get the mute list, you can call {@link EMChatRoomManager#fetchChatRoomMuteList(String, int?, int?)}. /// final List? muteList; @@ -141,14 +157,16 @@ class EMChatRoom { /// /// Checks whether all members are muted in the chat room from the memory. /// - /// To get the correct value, ensure that you call {@ link EMChatRoomManager#fetchChatRoomInfoFromServer(String)} before calling this method. + /// **Note** + /// To get the correct value, ensure that you call {@link EMChatRoomManager#fetchChatRoomInfoFromServer(String)} before calling this method. /// final bool? isAllMemberMuted; /// - /// The current user's role in the chat room, see {@link EMChatRoomPermissionType}. + /// Gets the current user's role in the chat room. The role types: {@link EMChatRoomPermissionType}. /// - /// To get the correct value, ensure that you call {@ link EMChatRoomManager#fetchChatRoomInfoFromServer(String)} before calling this method. + /// **Note** + /// To get the correct value, ensure that you call {@link EMChatRoomManager#fetchChatRoomInfoFromServer(String)} before calling this method. /// final EMChatRoomPermissionType permissionType; } diff --git a/lib/src/models/em_cmd_message_body.dart b/lib/src/models/em_cmd_message_body.dart index ea854666..53919ff6 100644 --- a/lib/src/models/em_cmd_message_body.dart +++ b/lib/src/models/em_cmd_message_body.dart @@ -33,10 +33,10 @@ class EMCmdMessageBody extends EMMessageBody { late final String action; /// - /// Checks whether this cmd message is only delivered to online users. + /// Checks whether this command message is only delivered to online users. /// - /// `true`: Only delivers to online users. - /// `false`: Delivers to all users. + /// - `true`: Yes. + /// - `false`: No. /// bool deliverOnlineOnly = false; } diff --git a/lib/src/models/em_conversation.dart b/lib/src/models/em_conversation.dart index 02472a0c..0e670863 100644 --- a/lib/src/models/em_conversation.dart +++ b/lib/src/models/em_conversation.dart @@ -7,7 +7,7 @@ import '../internal/chat_method_keys.dart'; import '../internal/em_transform_tools.dart'; /// -/// The conversation class, which represents a conversation with a user/group/chat room and contains the messages that are sent and received. +/// The conversation class, indicating a one-to-one chat, a group chat, or a converation chat. It contains the messages that are sent and received within the converation. /// /// The following code shows how to get the number of the unread messages from the conversation. /// ```dart @@ -46,12 +46,10 @@ class EMConversation { /// /// The conversation ID. /// - /// For one-to-one chat,the conversation ID is the same with the other side's name. - /// For group chat, the conversation ID is the group ID, different with group name. - /// For chat room, the conversation ID is the chatroom ID, different with chat room name. - /// For help desk, it is the same with one-to-one chat, the conversation ID is also the other chat user's name. - /// - /// The conversation ID. + /// For one-to-one chat,the conversation ID is the username of the other party. + /// For group chat, the conversation ID is the group ID, not the group name. + /// For chat room, the conversation ID is the chat room ID, not the chat room name. + /// For help desk, the conversation ID is the username of the other party. /// final String id; @@ -83,13 +81,13 @@ extension EMConversationExtension on EMConversation { } /// - /// Gets the last message from the conversation. + /// Gets the lastest message from the conversation. /// /// The operation does not change the unread message count. /// - /// Gets from the cache first, if no message is found, loads from the local database and then put it in the cache. + /// The SDK gets the latest message from the local memory first. If no message is found, the SDK loads the message from the local database and then puts it in the memory. /// - /// **return** The message instance. + /// **Return** The message instance. /// Future latestMessage() async { Map req = this._toJson(); @@ -110,7 +108,7 @@ extension EMConversationExtension on EMConversation { /// /// Gets the latest message from the conversation. /// - /// **return** The message instance. + /// **Return** The message instance. /// Future lastReceivedMessage() async { Map req = this._toJson(); @@ -130,11 +128,11 @@ extension EMConversationExtension on EMConversation { } /// - /// Gets the number of unread messages of the conversation. + /// Gets the unread message count of the conversation. /// - /// **return** The unread message count of the conversation. + /// **Return** The unread message count of the conversation. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future unreadCount() async { Map req = this._toJson(); @@ -157,7 +155,7 @@ extension EMConversationExtension on EMConversation { /// /// Param [messageId] The message ID. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future markMessageAsRead(String messageId) async { Map req = this._toJson(); @@ -185,13 +183,13 @@ extension EMConversationExtension on EMConversation { } /// - /// Inserts a message to a conversation in local database and SDK will update the last message automatically. + /// Inserts a message to a conversation in the local database and the SDK will automatically update the lastest message. /// - /// The conversation ID of the message should be the same as conversation ID of the conversation in order to insert the message into the conversation correctly. The inserting message will be inserted based on timestamp. + /// Make sure you set the conversation ID as that of the conversation where you want to insert the message. /// /// Param [message] The message instance. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future insertMessage(EMMessage message) async { Map req = this._toJson(); @@ -208,11 +206,11 @@ extension EMConversationExtension on EMConversation { /// /// Inserts a message to the end of a conversation in the local database. /// - /// The `conversationId` of the message should be the same as the `conversationId` of the conversation in order to insert the message into the conversation correctly. And the `latestMessage` and other properties of the session should be updated. + /// Make sure you set the conversation ID as that of the conversation where you want to insert the message. /// /// Param [message] The message instance. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future appendMessage(EMMessage message) async { Map req = this._toJson(); @@ -227,13 +225,13 @@ extension EMConversationExtension on EMConversation { } /// - /// Uses this method to update a message in local database. Changing properties will affect data in database. + /// Updates a message in the local database. /// - /// The latestMessage of the conversation and other properties will be updated accordingly. The messageID of the message cannot be updated. + /// The latestMessage of the conversation and other properties will be updated accordingly. The message ID of the message, however, remains the same. /// /// Param [message] The message to be updated. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future updateMessage(EMMessage message) async { Map req = this._toJson(); @@ -251,11 +249,12 @@ extension EMConversationExtension on EMConversation { /// /// Deletes a message in the local database. /// - /// Note: Operates only on the local database. + /// **Note** + /// After this method is called, the message is only deleted both from the memory and the local database. /// - /// Param [messageId] The message id to be deleted. + /// Param [messageId] The ID of message to be deleted. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future deleteMessage(String messageId) async { Map req = this._toJson(); @@ -270,9 +269,9 @@ extension EMConversationExtension on EMConversation { } /// - /// Deletes all the messages of the conversation from the memory cache and local database. + /// Deletes all the messages of the conversation from both the memory and local database. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future deleteAllMessages() async { Map result = await _emConversationChannel.invokeMethod( @@ -285,16 +284,15 @@ extension EMConversationExtension on EMConversation { } /// - /// Gets the message with message ID. + /// Gets the message with a specific message ID. /// - /// If the message already loaded into the memory cache, the message will be directly returned, - /// otherwise the message will be loaded from the local database, and be set into the cache. + /// If the message is already loaded into the memory cache, the message will be directly returned; otherwise, the message will be loaded from the local database and loaded in the memory. /// /// Param [messageId] The message ID. /// - /// **return** The message instance. + /// **Return** The message instance. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future loadMessage(String messageId) async { Map req = this._toJson(); @@ -314,26 +312,26 @@ extension EMConversationExtension on EMConversation { } /// - /// Searches messages from the local database according the following parameters: the message type, the Unix timestamp, max count, sender. + /// Retrieves messages from the database according to the following parameters: the message type, the Unix timestamp, max count, sender. /// - /// Note: + /// **Note** /// Be cautious about the memory usage when the maxCount is large. /// - /// Param [type] The message type, including TXT、VOICE、IMAGE and so on. + /// Param [type] The message type, including TXT, VOICE, IMAGE, and so on. /// - /// Param [timestamp] The Unix timestamp for search. + /// Param [timestamp] The Unix timestamp for the search. /// - /// Param [count] The max number of message to search. + /// Param [count] The max number of messages to search. /// - /// Param [sender] The sender of the message. The param can also be used to search in group chat. + /// Param [sender] The sender of the message. The param can also be used to search in group chat or chat room. /// /// Param [direction] The direction in which the message is loaded: EMSearchDirection. - /// `EMSearchDirection.Up`: get aCount of messages before the timestamp of the specified message ID; - /// `EMSearchDirection.Down`: get aCount of messages after the timestamp of the specified message ID. + /// - `EMSearchDirection.Up`: Messages are retrieved in the reverse chronological order of when the server received messages. + /// - `EMSearchDirection.Down`: Messages are retrieved in the chronological order of when the server received messages. /// - /// **return** The message list. + /// **Return** The message list. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future?> loadMessagesWithMsgType({ required MessageType type, @@ -364,24 +362,24 @@ extension EMConversationExtension on EMConversation { } /// - /// Loads more messages from the local database. + /// Loads multiple messages from the local database. /// /// Loads messages from the local database before the specified message. /// - /// The messages will also be stored in to current conversation's memory cache. - /// So when next time calling {@link #getAllMessages()}, the result will contain those messages. + /// The loaded messages will also join the existing messages of the conversation stored in the memory. + /// The {@link #getAllMessages()} method returns all messages of the conversation loaded in the memory. /// - /// Param [startMsgId] The specified message ID. If the `startMsgId` is set as "" or null, the SDK will load latest messages in database. + /// Param [startMsgId] The starting message ID. Message loaded in the memory before this message ID will be loaded. If the `startMsgId` is set as "" or null, the SDK will first load the latest messages in the database. /// - /// Param [loadCount] The number of records in a page. + /// Param [loadCount] The number of messages per page. /// /// Param [direction] The direction in which the message is loaded: EMSearchDirection. - /// `EMSearchDirection.Up`: get aCount of messages before the timestamp of the specified message ID; - /// `EMSearchDirection.Down`: get aCount of messages after the timestamp of the specified message ID. + /// - `EMSearchDirection.Up`: Messages are retrieved in the reverse chronological order of when the server received messages. + /// - `EMSearchDirection.Down`: Messages are retrieved in the chronological order of when the server received messages. /// - /// **return** The message list. + /// **Return** The message list. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future?> loadMessages({ String startMsgId = '', @@ -409,9 +407,9 @@ extension EMConversationExtension on EMConversation { } /// - /// Searches messages from the local database by the following parameters: keywords, timestamp, max count, sender, search direction. + /// Loads messages from the local database by the following parameters: keywords, timestamp, max count, sender, search direction. /// - /// Note: Be cautious about memory usage when the maxCount is large. + /// **Note** Pay attention to the memory usage when the maxCount is large. /// /// Param [keywords] The keywords in message. /// @@ -419,15 +417,15 @@ extension EMConversationExtension on EMConversation { /// /// Param [timestamp] The timestamp for search. /// - /// Param [count] The max number of message to search. + /// Param [count] The maximum number of messages to search. /// /// Param [direction] The direction in which the message is loaded: EMSearchDirection. - /// `EMSearchDirection.Up`: get aCount of messages before the timestamp of the specified message ID; - /// `EMSearchDirection.Down`: get aCount of messages after the timestamp of the specified message ID. + /// `EMSearchDirection.Up`: Gets the messages loaded before the timestamp of the specified message ID. + /// `EMSearchDirection.Down`: Gets the messages loaded after the timestamp of the specified message ID. /// - /// **returns** The list of searched messages. + /// **Returns** The list of retrieved messages. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future> loadMessagesWithKeyword( String keywords, { @@ -461,19 +459,19 @@ extension EMConversationExtension on EMConversation { } /// - /// Searches messages from the local database according the following parameters. + /// Loads messages from the local database according the following parameters: start timestamp, end timestamp, count. /// - /// Note: Be cautious about the memory usage when the maxCount is large. + /// **Note** Pay attention to the memory usage when the maxCount is large. /// - /// Param [startTime] The start Unix timestamp to search. + /// Param [startTime] The starting Unix timestamp for search. /// - /// Param [endTime] The end Unix timestamp to search. + /// Param [endTime] The ending Unix timestamp for search. /// - /// Param [count] The max number of message to search. + /// Param [count] The maximum number of message to retrieve. /// - /// **returns** The list of searched messages. + /// **Returns** The list of searched messages. /// - /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// **Throws** A description of the exception. See {@link EMError}. /// Future> loadMessagesFromTime({ required int startTime, diff --git a/lib/src/models/em_cursor_result.dart b/lib/src/models/em_cursor_result.dart index 1802acdf..adfd10b0 100644 --- a/lib/src/models/em_cursor_result.dart +++ b/lib/src/models/em_cursor_result.dart @@ -1,10 +1,9 @@ typedef CursorResultCallback = Object Function(dynamic obj); /// -/// This is a generic class with cursors and paging to get results. -/// Returns an instance with the list and the cursor. +/// The EMCursorResult class, which specifies the cursor from which to query results. +/// When querying using this class, the SDK returns the queried instance and the cursor. /// -/// For example: /// ```dart /// String? cursor; /// EMCursorResult result = await EMClient.getInstance.groupManager.getPublicGroupsFromServer(pageSize: 10, cursor: cursor); @@ -28,9 +27,9 @@ class EMCursorResult { return result; } - /// The cursor. + /// Gets the cursor. final String? cursor; - /// The data; + /// Gets the data list. final List data; } diff --git a/lib/src/models/em_custom_message_body.dart b/lib/src/models/em_custom_message_body.dart index 2d098bf6..5fbd39a0 100644 --- a/lib/src/models/em_custom_message_body.dart +++ b/lib/src/models/em_custom_message_body.dart @@ -14,7 +14,6 @@ class EMCustomMessageBody extends EMMessageBody { required this.event, this.params, }) : super(type: MessageType.CUSTOM); - EMCustomMessageBody.fromJson({required Map map}) : super.fromJson(map: map, type: MessageType.CUSTOM) { this.event = map["event"]; @@ -33,6 +32,6 @@ class EMCustomMessageBody extends EMMessageBody { /// The event. late final String event; - /// The params map. + /// The custom params map. Map? params; } diff --git a/lib/src/models/em_deviceInfo.dart b/lib/src/models/em_deviceInfo.dart index cffb2849..faf78bb7 100644 --- a/lib/src/models/em_deviceInfo.dart +++ b/lib/src/models/em_deviceInfo.dart @@ -1,7 +1,7 @@ import '../tools/em_extension.dart'; /// -/// The Multi-device information. +/// The EMDeviceInfo class, which contains the multi-device information. /// class EMDeviceInfo { EMDeviceInfo._private( @@ -29,7 +29,7 @@ class EMDeviceInfo { ); } - /// The other devices‘ information. + /// The information of other login devices. final String? resource; /// The UUID of the device. diff --git a/lib/src/models/em_error.dart b/lib/src/models/em_error.dart index 7c1aa620..8947b402 100644 --- a/lib/src/models/em_error.dart +++ b/lib/src/models/em_error.dart @@ -1,5 +1,5 @@ /// -/// The error defined by the SDK. +/// The error class defined by the SDK. /// class EMError { EMError._private(this.code, this.description); diff --git a/lib/src/models/em_file_message_body.dart b/lib/src/models/em_file_message_body.dart index 98a76cd2..075401ee 100644 --- a/lib/src/models/em_file_message_body.dart +++ b/lib/src/models/em_file_message_body.dart @@ -5,18 +5,18 @@ import 'em_chat_enums.dart'; import 'em_message_body.dart'; /// -/// The file message. +/// The base class of file messages. /// class EMFileMessageBody extends EMMessageBody { - /// Creates an file message body with an file. + /// Creates a message with an attachment. /// /// Param [localPath] The path of the image file. /// - /// Param [displayName] The file name. like "file.doc" + /// Param [displayName] The file name. /// /// Param [fileSize] The size of the file in bytes. /// - /// Param [type] The body type. + /// Param [type] The file type. /// EMFileMessageBody({ required this.localPath, @@ -52,22 +52,22 @@ class EMFileMessageBody extends EMMessageBody { return data; } - /// The localPath of the attachment file. + /// The local path of the attachment. late final String localPath; - /// The file's token. + /// The token used to get the attachment. String? secret; - /// The path of the attachment file in the server. + /// The attachment path in the server. String? remotePath; - /// The download status of the attachment file . + /// The download status of the attachment. DownloadStatus fileStatus = DownloadStatus.PENDING; - /// The size of the file in bytes. + /// The size of the attachment in bytes. int? fileSize; - /// The file name. like "file.doc" + /// The attachment name. String? displayName; static DownloadStatus downloadStatusFromInt(int? status) { diff --git a/lib/src/models/em_group.dart b/lib/src/models/em_group.dart index 948dac01..e96b1f51 100644 --- a/lib/src/models/em_group.dart +++ b/lib/src/models/em_group.dart @@ -5,7 +5,7 @@ import 'em_chat_enums.dart'; import 'em_group_options.dart'; /// -/// The group class. +/// The EMGroup class, which contains the information of the chat group. /// class EMGroup { EMGroup._private(); @@ -35,21 +35,24 @@ class EMGroup { /// /// Gets the group name. /// - /// To get the correct value, ensure that you call {@ link EMGroupManager#getGroupSpecificationFromServer(String groupId)} before calling this method. + /// **Note** + /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupSpecificationFromServer(String groupId)} before calling this method. /// String? get name => _name; /// /// Gets the group description. /// - /// To get the correct value, ensure that you call {@ link EMGroupManager#getGroupSpecificationFromServer(String groupId)} before calling this method. + /// **Note** + /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupSpecificationFromServer(String groupId)} before calling this method. /// String? get description => _description; /// /// Gets the user ID of the group owner. /// - /// To get the correct value, ensure that you call {@ link EMGroupManager#getGroupSpecificationFromServer(String groupId)} before calling this method. + /// **Note** + /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupSpecificationFromServer(String groupId)} before calling this method. /// String? get owner => _owner; @@ -57,39 +60,43 @@ class EMGroup { String? get announcement => _announcement; /// - /// Get the member count of the group. + /// Gets the member count of the group. /// - /// To get the correct value, ensure that you call {@ link EMGroupManager#getGroupSpecificationFromServer(String groupId)} before calling this method. + /// **Note** + /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupSpecificationFromServer(String groupId)} before calling this method. /// int? get memberCount => _memberCount; /// - /// Get the member list of the group. + /// Gets the member list of the group. /// - /// To get the correct value, ensure that you call {@ link EMGroupManager#getGroupMemberListFromServer(String, int?, String?)} before calling this method. + /// **Note** + /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupMemberListFromServer(String, int?, String?)} before calling this method. /// List? get memberList => _memberList; /// - /// Get the admin list of the group. + /// Gets the admin list of the group. /// - /// To get the correct value, ensure that you call {@ link EMGroupManager#getGroupSpecificationFromServer(String)} before calling this method. + /// **Note** + /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupSpecificationFromServer(String)} before calling this method. /// List? get adminList => _adminList; /// - /// Get the block list of the group. + /// Gets the block list of the group. /// /// If no block list is found from the server, the return may be empty. /// - /// Reference: + /// **Note** /// To get the correct value, ensure that you call {@link EMGroupManager#getBlockListFromServer(String, int?, int?)} before calling this method. /// List? get blockList => _blockList; /// - /// Get the mute list of the group. + /// Gets the mute list of the group. /// + /// **Note** /// To get the correct value, ensure that you call {@link EMGroupManager#getMuteListFromServer(String, int?, int?)} before calling this method. /// List? get muteList => _muteList; @@ -100,6 +107,7 @@ class EMGroup { /// /// Gets whether the group message is blocked. /// + /// **Note** /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupSpecificationFromServer(String)} before calling this method. /// bool? get messageBlocked => _messageBlocked; @@ -107,6 +115,7 @@ class EMGroup { /// /// Gets Whether all members are muted. /// + /// **Note** /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupSpecificationFromServer(String)} before calling this method. /// bool? get isAllMemberMuted => _isAllMemberMuted; @@ -116,35 +125,33 @@ class EMGroup { EMGroupOptions? get settings => _options; /// - /// Get the current user's role in group. + /// Gets the current user's role in group. /// + /// **Note** /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupSpecificationFromServer(String)} before calling this method. /// EMGroupPermissionType? get permissionType => _permissionType; /// - /// Get the max number of group members allowed in a group. The param is set when the group is created. + /// Gets the maximum number of group members allowed in a group. The parameter is set when the group is created. /// + /// **Note** /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupSpecificationFromServer(String)} before calling this method. /// int? get maxUserCount => _options?.maxCount; /// - /// Fetches the group property: whether users can auto join the group VS need requesting or invitation from a group member to join the group. - /// + /// Checks whether users cannot join a chat group freely: + /// - `true`: Yes. Needs the approval from the group owner(admin) or being invited by group members(PrivateOnlyOwnerInvite, PrivateMemberCanInvite, PublicJoinNeedApproval). + /// - `false`: No. Users can join freely(PublicOpenJoin). /// - /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupSpecificationFromServer(String)} before calling this method. + /// **Note** + /// There are four types of group properties used to define the style of a group: {@link EMGroupManager.EMGroupStyle}. /// - /// There are four types of group properties used to define the style of a group, - /// and `isMemberOnly` contains three types including: - /// PrivateOnlyOwnerInvite, - /// PrivateMemberCanInvite, - /// PublicJoinNeedApproval. - /// And do not include {@link EMGroupManager.EMGroupStyle#PublicOpenJoin}. - /// - /// **return** - /// `true`: Users can not join the group freely. Needs the invitation from the group owner or members, or the application been approved by the group owner or admins. - /// `false`: Users can join freely without the group owner or member‘s invitation or the new joiner’s application been approved. + /// **Return** + /// Whether users can join a chat group with only the approval of the group owner(admin): + /// - `true`: Yes. Needs the approval from the group owner(admin) or being invited by group members. + /// - `false`: No. /// bool get isMemberOnly { if (_options == null) { @@ -160,14 +167,14 @@ class EMGroup { } /// - /// Gets whether the group member is allowed to invite other users to join the group. - /// + /// Checks whether a group member is allowed to invite other users to join the group. /// + /// **Note** /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupSpecificationFromServer(String)} before calling this method. /// - /// **return** - /// `true`: The group member can invite other users to join the group; - /// `false`: Do not allow the group member invite other users to join the group. + /// **Return** + /// - `true`: Yes; + /// - `false`: No. Only the group owner or admin can invite others to join the group. /// bool get isMemberAllowToInvite { if (_options == null) { diff --git a/lib/src/models/em_group_message_ack.dart b/lib/src/models/em_group_message_ack.dart index c34eff72..846d92d4 100644 --- a/lib/src/models/em_group_message_ack.dart +++ b/lib/src/models/em_group_message_ack.dart @@ -1,9 +1,9 @@ import '../tools/em_extension.dart'; /// -/// Returns read recipients for group messages. +/// The class for group message read receipts. /// -/// Calls {@link EMChatManager#fetchGroupAcks(String, String?, int)} to return the requested result, for example: +/// To get the chat group message receipts, call {@link EMChatManager#fetchGroupAcks(String, String?, int)}. /// /// ```dart /// EMCursorResult result = await EMClient.getInstance.chatManager.fetchGroupAcks("msgId"); @@ -13,44 +13,44 @@ class EMGroupMessageAck { /// /// Gets the group message ID. /// - /// **return** The group message ID. + /// **Return** The group message ID. /// final String messageId; /// - /// Gets the read receipt ID of group messages. + /// Gets the ID of the group message read receipt. /// - /// **return** The read receipt ID. + /// **Return** The read receipt ID. /// final String ackId; /// - /// Gets the ID of user who sends the read receipt. + /// Gets the username of the user who sends the read receipt. /// - /// **return** The read receipt sender ID. + /// **Return** The username of the read receipt sender. /// final String from; /// /// Gets the read receipt extension. /// - /// Sends the read receipt passed as the third parameter in {@link EMChatManager#sendGroupMessageReadAck(String, String, String?)}. + /// For how to set the extension, see {@link EMChatManager#sendGroupMessageReadAck(String, String, String?)}. /// - /// **return** The read receipt extension. + /// **Return** The read receipt extension. /// final String? content; /// - /// Gets the count in which read receipts of group messages are sent. + /// Gets the number read receipts of group messages. /// - /// **return** The count in which read receipts of group messages are sent. + /// **Return** The count in which read receipts of group messages are sent. /// final int readCount; /// /// Gets the timestamp of sending read receipts of group messages. /// - /// **return** The timestamp of sending read receipts of group messages. + /// **Return** The timestamp of sending read receipts of group messages. final int timestamp; /// @nodoc diff --git a/lib/src/models/em_group_options.dart b/lib/src/models/em_group_options.dart index 78c5b1da..26d0d58c 100644 --- a/lib/src/models/em_group_options.dart +++ b/lib/src/models/em_group_options.dart @@ -4,21 +4,26 @@ import 'em_chat_enums.dart'; import '../tools/em_extension.dart'; /// -/// Group property options to be configured during group creation. +/// The group options to be configured when the chat group is created. /// class EMGroupOptions { EMGroupOptions._private(); /// - /// Create a group property options + /// Sets the group options. /// - /// Param [style] The group style. see {EMGroupStyle} + /// Param [style] The group style: {EMGroupStyle}. /// - /// Param [count] The maximum number of members in a group. default is 200. + /// Param [count] The maximum number of members in a group. The default value is 200. /// - /// Param [inviteNeedConfirm] + /// Param [inviteNeedConfirm] Whether you can automatically add a user to the chat group depends on the settings of {GroupOptions#inviteNeedConfirm} and {EMOptions#autoAcceptGroupInvitation}. /// - /// Param [extension] + /// - If `inviteNeedConfirm` is set to `false`, you can add the invitee directly to the chat group, regardless of the settings of `EMOptions#autoAcceptGroupInvitation`. + /// - If `inviteNeedConfirm` is set to `true`, whether the invitee automatically joins the chat group or not depends on the settings of {@link EMOptions#autoAcceptGroupInvitation(boolean)} on the invitee's client. + /// - If `autoAcceptGroupInvitation` is set to `true`, the invitee automatically joins the chat group. + /// - If `autoAcceptGroupInvitation` is set to `false`, the invitee does not join the chat group until this invitee approves the group invitation. + /// + /// Param [extension] Group detail extensions which can be in the JSON format to contain more group information. /// EMGroupOptions({ EMGroupStyle style = EMGroupStyle.PrivateOnlyOwnerInvite, @@ -38,35 +43,30 @@ class EMGroupOptions { String? _ext; /// - /// Gets the group style. see {EMGroupStyle} + /// Gets the group style. /// - /// **return** The group style. see {EMGroupStyle} + /// **Return** The group style. See {EMGroupStyle}. /// EMGroupStyle? get style => _style; /// - /// Get maximum number of members in a group. + /// Gets the maximum number of members in a group. /// - /// **return** The maximum number of members in a group. + /// **Return** The maximum number of members in a group. /// int? get maxCount => _maxCount; /// - /// This option defines whether to ask for content when inviting a user to join a group. + /// Whether you need the approval from the user when adding this user to the chat group. /// - /// Whether automatically accepting the invitation to join a group depends on two settings: inviteNeedConfirm, an option during group creation, - /// and {@link EMOptions#autoAcceptGroupInvitation(boolean)} which determines whether to automatically accept an invitation to join the group. - /// There are two cases: - /// (1) If inviteNeedConfirm is set to 'false', adds the invitee directly to the group on the server side - /// regardless of the setting of {@link EMOptions#autoAcceptGroupInvitation(boolean)}. + /// Whether you can automatically add a user to the chat group depends on the settings of {GroupOptions#inviteNeedConfirm} and {EMOptions#autoAcceptGroupInvitation}. /// - /// (2) If inviteNeedConfirm is set to 'true', the user automatically joins a group or decides whether to join, depending on the setting of {@link EMOptions#autoAcceptGroupInvitation(boolean)}. - /// {@link EMOptions#autoAcceptGroupInvitation(boolean)} is an SDK-level operation. If it is set to true, - /// SDK calls the API for agreeing to join the group to automatically accept the joining invitation. - /// If inviteNeedConfirm is set to false, SDK does not automatically accept its invitation, - /// but the user decides to accept or reject the invitation. + /// - If `inviteNeedConfirm` is set to `false`, you can add the invitee directly to the chat group, regardless of the settings of `EMOptions#autoAcceptGroupInvitation`. + /// - If `inviteNeedConfirm` is set to `true`, whether the invitee automatically joins the chat group or not depends on the settings of {@link EMOptions#autoAcceptGroupInvitation(boolean)} on the invitee's client. + /// - If `autoAcceptGroupInvitation` is set to `true`, the invitee automatically joins the chat group. + /// - If `autoAcceptGroupInvitation` is set to `false`, the invitee does not join the chat group until this invitee approves the group invitation. /// - /// **return** The whether to ask for content when inviting a user to join a group. + /// **Return** Whether you need the approval from the user when adding this user to the chat group. /// bool? get inviteNeedConfirm => _inviteNeedConfirm; String? get ext => _ext; diff --git a/lib/src/models/em_group_shared_file.dart b/lib/src/models/em_group_shared_file.dart index e6d149f9..73e816a5 100644 --- a/lib/src/models/em_group_shared_file.dart +++ b/lib/src/models/em_group_shared_file.dart @@ -1,11 +1,9 @@ import '../tools/em_extension.dart'; /// -/// The shared file info class. +/// The EMGroupSharedFile class, which manages the chat group shared files. /// -/// For example: -/// You can use the following method to get information about the group shared file -/// through {@link EMGroupManager#getGroupFileListFromServer(String, int?, int?)} +/// To get the information of the chat group shared file, call {@link EMGroupManager#getGroupFileListFromServer(String, int?, int?)}. /// /// ```dart /// List? list = await EMClient.getInstance.groupManager.getGroupFileListFromServer(groupId); @@ -22,35 +20,35 @@ class EMGroupSharedFile { /// /// Gets the shared file ID. /// - /// **return** The shared file ID. + /// **Return** The shared file ID. /// String? get fileId => _fileId; /// /// Gets the shared file name. /// - /// **return** The shared file name. + /// **Return** The shared file name. /// String? get fileName => _fileName; /// - /// Gets the username who uploads the shared file. + /// Gets the username that uploads the shared file. /// - /// **return** The username who uploads the shared file. + /// **Return** The username that uploads the shared file. /// String? get fileOwner => _fileOwner; /// - /// Gets the update Unix timestamp of the shared file, in ms. + /// Gets the Unix timestamp for uploading the shared file, in milliseconds. /// - /// **return** The update Unix timestamp of the shared file, in ms. + /// **Return** The Unix timestamp for uploading the shared file, in milliseconds. /// int? get createTime => _createTime; /// /// Gets the data length of the shared file, in bytes. /// - /// **return** The data length of the shared file, in bytes. + /// **Return** The data length of the shared file, in bytes. /// int? get fileSize => _fileSize; diff --git a/lib/src/models/em_image_message_body.dart b/lib/src/models/em_image_message_body.dart index 9cee4f9b..b2bfd432 100644 --- a/lib/src/models/em_image_message_body.dart +++ b/lib/src/models/em_image_message_body.dart @@ -12,19 +12,19 @@ class EMImageMessageBody extends EMFileMessageBody { /// /// Creates an image message body with an image file. /// - /// Param [localPath] The path of the image file. + /// Param [localPath] The local path of the image file. /// - /// Param [displayName] The image name. like "img.jpeg" + /// Param [displayName] The image name. /// /// Param [thumbnailLocalPath] The local path of the image thumbnail. /// - /// Param [sendOriginalImage] The original image when sending an image. + /// Param [sendOriginalImage] The original image included in the image message to be sent. /// /// Param [fileSize] The size of the image file in bytes. /// - /// Param [width] The image width. + /// Param [width] The image width in pixels. /// - /// Param [height] The image height. + /// Param [height] The image height in pixels. /// EMImageMessageBody({ required String localPath, @@ -41,6 +41,7 @@ class EMImageMessageBody extends EMFileMessageBody { type: MessageType.IMAGE, ); + /// nodoc EMImageMessageBody.fromJson({required Map map}) : super.fromJson(map: map, type: MessageType.IMAGE) { this.thumbnailLocalPath = map.getStringValue("thumbnailLocalPath"); @@ -57,6 +58,7 @@ class EMImageMessageBody extends EMFileMessageBody { ); } + /// nodoc @override Map toJson() { final Map data = super.toJson(); @@ -72,14 +74,14 @@ class EMImageMessageBody extends EMFileMessageBody { } /// - /// Sets whether to send the original image when sending an image. + /// Whether to send the original image. /// - /// `false`: (default) Send the thumbnail(image with size larger than 100k will be compressed); - /// `true`: Send the original image. + /// - `false`: (default) No. The original image will be compressed if it exceeds 100 KB and the thumbnail will be sent. + /// - `true`: Yes. /// bool sendOriginalImage = false; - /// The local path or the URI of the thumbnail as a string. + /// The local path or the URI (a string) of the thumbnail. String? thumbnailLocalPath; /// The URL of the thumbnail on the server. @@ -91,9 +93,9 @@ class EMImageMessageBody extends EMFileMessageBody { /// The download status of the thumbnail. DownloadStatus thumbnailStatus = DownloadStatus.PENDING; - /// The image width. + /// The image width in pixels. double? width; - /// The image height. + /// The image height in pixels. double? height; } diff --git a/lib/src/models/em_location_message_body.dart b/lib/src/models/em_location_message_body.dart index aa9f0c22..944fd891 100644 --- a/lib/src/models/em_location_message_body.dart +++ b/lib/src/models/em_location_message_body.dart @@ -4,11 +4,11 @@ import 'em_chat_enums.dart'; import 'em_message_body.dart'; /// -/// The location message body. +/// The location message class. /// class EMLocationMessageBody extends EMMessageBody { /// - /// Creates a location message body. + /// Creates a location message body instance. /// /// Param [latitude] The latitude. /// diff --git a/lib/src/models/em_message.dart b/lib/src/models/em_message.dart index 20e0e842..a74de509 100644 --- a/lib/src/models/em_message.dart +++ b/lib/src/models/em_message.dart @@ -4,15 +4,16 @@ import 'package:flutter/services.dart'; import '../internal/chat_method_keys.dart'; import '../internal/em_transform_tools.dart'; - +import '../tools/em_log.dart'; +import '../tools/em_message_callback_manager.dart'; import '../tools/em_extension.dart'; import '../../im_flutter_sdk.dart'; +import '../internal/em_message_state_handle.dart'; /// -/// The message instance, which represents a sent/received message. +/// The message class. /// -/// For example: -/// Constructs a text message to send: +/// The sample code for constructing a text message to send is as follows. /// /// ```dart /// EMMessage msg = EMMessage.createTxtSendMessage( @@ -140,11 +141,11 @@ class EMMessage { EMMessage._private(); /// - /// Creates a new received message instance. + /// Creates a received message instance. /// /// Param [body] The message body. /// - /// **return** The message instance. + /// **Return** The message instance. /// EMMessage.createReceiveMessage({ required this.body, @@ -157,9 +158,12 @@ class EMMessage { /// /// Param [body] The message body. /// - /// Param [to] Sets the user ID of the message recipient. + /// Param [to] The ID of the message recipient. + /// - For a one-to-one chat, it is the username of the peer user. + /// - For a group chat, it is the group ID. + /// - For a chat room, it is the chat room ID. /// - /// **return** The message instance. + /// **Return** The message instance. /// EMMessage.createSendMessage({ required this.body, @@ -217,11 +221,14 @@ class EMMessage { /// /// Creates a text message for sending. /// - /// Param [username] The ID of the message recipient(user or group). + /// Param [username] The ID of the message recipient. + /// - For a one-to-one chat, it is the username of the peer user. + /// - For a group chat, it is the group ID. + /// - For a chat room, it is the chat room ID. /// /// Param [content] The text content. /// - /// **return** The message instance. + /// **Return** The message instance. /// EMMessage.createTxtSendMessage({ required String username, @@ -232,17 +239,20 @@ class EMMessage { ); /// - /// Creates a message to send a regular file. + /// Creates a file message for sending. /// - /// Param [username] The ID of the message recipient(user or group). + /// Param [username] The ID of the message recipient. + /// - For a one-to-one chat, it is the username of the peer user. + /// - For a group chat, it is the group ID. + /// - For a chat room, it is the chat room ID. /// /// Param [filePath] The file path. /// - /// Param [displayName] The file name. like 'readme.doc' + /// Param [displayName] The file name. /// - /// Param [fileSize] The file size. + /// Param [fileSize] The file size in bytes. /// - /// **return** The message instance. + /// **Return** The message instance. /// EMMessage.createFileSendMessage({ required String username, @@ -260,25 +270,28 @@ class EMMessage { /// /// Creates an image message for sending. /// - /// Param [username] The ID of the message recipient(user or group). + /// Param [username] The ID of the message recipient. + /// - For a one-to-one chat, it is the username of the peer user. + /// - For a group chat, it is the group ID. + /// - For a chat room, it is the chat room ID. /// /// Param [filePath] The image path. /// - /// Param [displayName] The image name. like 'image.jpeg' + /// Param [displayName] The image name. /// - /// Param [thumbnailLocalPath] The image thumbnail path. + /// Param [thumbnailLocalPath] The local path of the image thumbnail. /// /// Param [sendOriginalImage] Whether to send the original image. - /// `true`: Send the original image. - /// `false`: (default) For an image greater than 100 KB, the SDK will compress it. + /// - `true`: Yes. + /// - `false`: (default) No. For an image greater than 100 KB, the SDK will compress it and send the thumbnail. /// - /// Param [fileSize] The image file size. + /// Param [fileSize] The image file size in bytes. /// - /// Param [width] The image width. + /// Param [width] The image width in pixels. /// - /// Param [height] The image height. + /// Param [height] The image height in pixels. /// - /// **return** The message instance. + /// **Return** The message instance. /// EMMessage.createImageSendMessage({ required String username, @@ -303,23 +316,26 @@ class EMMessage { /// /// Creates a video message instance for sending. /// - /// Param [username] The ID of the message recipient(user or group). + /// Param [username] The ID of the message recipient. + /// - For a one-to-one chat, it is the username of the peer user. + /// - For a group chat, it is the group ID. + /// - For a chat room, it is the chat room ID. /// /// Param [filePath] The path of the video file. /// - /// Param [displayName] The video name. like 'video.mp4' + /// Param [displayName] The video name. /// /// Param [duration] The video duration in seconds. /// - /// Param [fileSize] The video file size. + /// Param [fileSize] The video file size in bytes. /// - /// Param [thumbnailLocalPath] The path of the thumbnail of the first frame of video. + /// Param [thumbnailLocalPath] The local path of the thumbnail, which is usually the first frame of video. /// - /// Param [width] The video thumbnail image width. + /// Param [width] The width of the video thumbnail, in pixels. /// - /// Param [height] The video thumbnail image height. + /// Param [height] The height of the video thumbnail, in pixels. /// - /// **return** The message instance. + /// **Return** The message instance. /// EMMessage.createVideoSendMessage({ required String username, @@ -345,17 +361,20 @@ class EMMessage { /// /// Creates a voice message for sending. /// - /// Param [username] The ID of the message recipient(user or group). + /// Param [username] The ID of the message recipient. + /// - For a one-to-one chat, it is the username of the peer user. + /// - For a group chat, it is the group ID. + /// - For a chat room, it is the chat room ID. /// /// Param [filePath] The path of the voice file. /// /// Param [duration] The voice duration in seconds. /// - /// Param [fileSize] The voice file size. + /// Param [fileSize] The size of the voice file, in bytes. /// - /// Param [displayName] The voice name. like 'voice.mp3' + /// Param [displayName] The name of the voice file which ends with a suffix that indicates the format of the file. For example "voice.mp3". /// - /// **return** The message instance. + /// **Return** The message instance. /// EMMessage.createVoiceSendMessage({ required String username, @@ -374,13 +393,21 @@ class EMMessage { /// /// Creates a location message for sending. /// - /// Param [username] The ID of the message recipient(user or group). + /// Param [username] The ID of the message recipient. + /// - For a one-to-one chat, it is the username of the peer user. + /// - For a group chat, it is the group ID. + /// - For a chat room, it is the chat room ID. + /// + /// Param [latitude] The latitude. + /// + /// Param [longitude] The longitude. + /// + /// Param [address] The address. /// - /// The latitude. + /// Param [buildingName] The building name. /// - /// The longitude. + /// **Return** The message instance. /// - /// The location details. EMMessage.createLocationSendMessage({ required String username, required double latitude, @@ -395,12 +422,34 @@ class EMMessage { address: address, )); - /// 构造发送的cmd消息 + /// Creates a command message for sending. + /// + /// Param [username] The ID of the message recipient. + /// - For a one-to-one chat, it is the username of the peer user. + /// - For a group chat, it is the group ID. + /// - For a chat room, it is the chat room ID. + /// + /// Param [action] The command action. + /// + /// **Return** The message instance. + /// EMMessage.createCmdSendMessage({required String username, required action}) : this.createSendMessage( to: username, body: EMCmdMessageBody(action: action)); - /// 构造发送的自定义消息 + /// Creates a custom message for sending. + /// + /// Param [username] The ID of the message recipient. + /// - For a one-to-one chat, it is the username of the peer user. + /// - For a group chat, it is the group ID. + /// - For a chat room, it is the chat room ID. + /// + /// Param [event] The event. + /// + /// Param [Map? params] The params map. + /// + /// **Return** The message instance. + /// EMMessage.createCustomSendMessage( {required String username, required event, Map? params}) : this.createSendMessage( diff --git a/lib/src/models/em_options.dart b/lib/src/models/em_options.dart index 32d5673f..53d88312 100644 --- a/lib/src/models/em_options.dart +++ b/lib/src/models/em_options.dart @@ -2,133 +2,144 @@ import '../tools/em_extension.dart'; import 'em_push_config.dart'; /// -/// The settings of the chat SDK. -/// You can set parameters and options of the SDK. -/// For example, whether to encrypt the messages before sending, whether to automatically accept the friend invitations. +/// The EMOptions class, which contains the settings of the Chat SDK. +/// +/// For example, whether to encrypt the messages before sending and whether to automatically accept the friend invitations. /// class EMOptions { - /// The app key you got from the console when create an app. + /// The app key that you get from the console when creating the app. late final String appKey; /// - /// Enables/Disables automatic login. + /// Whether to enable automatic login. /// - /// `true`: (default) Enables automatic login; - /// `false`: Disables automatic login. + /// - `true`: (Default) Yes; + /// - `false`: No. /// final bool autoLogin; + /// + /// Whether to output the debug information. Make sure to call the method after initializing the EMClient using {@link #init(Context, EMOptions)}. + /// + /// - `true`: Yes. + /// - `false`: (Default)No. + /// final bool debugModel; /// /// Whether to accept friend invitations from other users automatically. /// - /// `true`: (default) Accepts friend invitations automatically; - /// `false`: Do not accept friend invitations automatically. + /// - `true`: (Default) Yes; + /// - `false`: No. final bool acceptInvitationAlways; /// /// Whether to accept group invitations automatically. /// - /// `true`: (default) Accepts group invitations automatically; - /// `false`: Do not accept group invitations automatically. + /// - `true`: (Default) Yes; + /// - `false`: No. /// final bool autoAcceptGroupInvitation; /// - /// Whether the read receipt is required. + /// Whether to require read receipt after sending a message. /// - /// `true`: (default) The read receipt is required; - /// `false`: The read receipt is not required. + /// - `true`: (Default) Yes; + /// - `false`: No. /// final bool requireAck; /// - /// Whether the delivery receipt is required. + /// Whether to require the delivery receipt after sending a message. /// - /// `true`: (default) The read receipt is required; - /// `false`: The read receipt is not required. + /// - `true`: (Default) Yes; + /// - `false`: No. /// final bool requireDeliveryAck; /// - /// Whether to delete the group message when leaving a group. + /// Whether to delete the group messages when leaving a group. /// - /// `true`: (default) Delete the messages when leaving the group. - /// `false`: Do not delete the messages when leaving a group. + /// - `true`: (Default) Yes; + /// - `false`: No. /// final bool deleteMessagesAsExitGroup; /// - /// Whether to delete the chat room message when leaving the chat room. + /// Whether to delete the chat room messages when leaving the chat room. /// - /// `true`: (default) Delete the chat room related message record when leaving the chat room. - /// `false`: Do not delete the chat room related message record when leaving the chat room. + /// - `true`: (Default) Yes; + /// - `false`: No. /// final bool deleteMessagesAsExitChatRoom; /// /// Whether to allow the chat room owner to leave the chat room. /// - /// `true`: (default) Allow the chat room owner to leave the chat room. - /// `false`: Do not allow the chat room owner to leave the chat room. + /// - `true`: (Default) Yes; + /// - `false`: No. /// final bool isChatRoomOwnerLeaveAllowed; /// - /// Whether to sort messages by the server received time. + /// Whether to sort the messages by the time when the messages are received by the server. /// - /// `true`: (default) Sort messages by the server received time; - /// `false`: Do not sort messages by the server received time. + /// - `true`: (Default) Yes; + /// - `false`: No. /// final bool sortMessageByServerTime; /// - /// Sets whether only HTTPS is used for REST operations. + /// Whether only HTTPS is used for REST operations. /// - /// `true`: (default) Only HTTPS is used. - /// `false`: Allow to use both HTTP and HTTPS. + /// - `true`: (Default) Only HTTPS is used. + /// - `false`: Both HTTP and HTTPS are allowed. /// final bool usingHttpsOnly; /// /// Whether to upload the message attachments automatically to the chat server. /// - /// `true`: (default) Use the default way to upload and download the message attachments by chat server; - /// `false`: Do not use the default way to upload and download the message attachments by chat server, using a customized path instead. + /// - `true`: (Default) Yes; + /// - `false`: No. Message attachments are uploaded to a custom path. /// final bool serverTransfer; /// - /// Whether to auto download the thumbnail. + /// Whether to automatically download the thumbnail. /// - /// `true`: (default) Download the thumbnail automatically; - /// `false`: Do not download the thumbnail automatically. + /// - `true`: (Default) Yes; + /// - `false`: No. /// final bool isAutoDownloadThumbnail; /// - /// Sets whether to disable DNS. + /// Whether to enable DNS. /// - /// `true`: (default) Enable DNS; - /// `false`: Do not enable DNS. + /// - `true`: (Default) Yes; + /// - `false`: No. /// final bool enableDNSConfig; - /// The DNS url. + /// The DNS URL. final String? dnsUrl; /// The custom REST server. final String? restServer; - /// The custom im message server url. + /// The custom IM message server url. final String? imServer; - /// The custom im server port. + /// The custom IM server port. final int? imPort; EMPushConfig _pushConfig = EMPushConfig(); + /// Enable OPPO PUSH on OPPO devices. + /// + /// Param [appId] The app ID for OPPO PUSH. + /// + /// Param [appKey] The app key for OPPO PUSH. /// void enableOppoPush(String appKey, String secret) { _pushConfig.enableOppoPush = true; @@ -137,11 +148,11 @@ class EMOptions { } /// - /// Passes the app ID and app key of Mi push to enable Mi push on Mi devices. + /// Enable Mi Push on Mi devices. /// - /// Param [appId] The Xiaomi Push App ID. + /// Param [appId] The app ID for Mi Push. /// - /// Param [appKey] The Xiaomi push app key. + /// Param [appKey] The app key for Mi Push. /// void enableMiPush(String appId, String appKey) { _pushConfig.enableMiPush = true; @@ -150,33 +161,39 @@ class EMOptions { } /// - /// Sets the FCM sender ID. + /// Enable Firebase Cloud Messaging (FCM) push on devices that support Google Play. + /// + /// Param [appId] The app ID for FCM push. /// void enableFCM(String appId) { _pushConfig.enableFCM = true; _pushConfig.fcmId = appId; } + /// Enable vivo Push on vivo devices. + /// + /// Param [appId] The app ID for vivo Push. /// - /// Be sure to set the app ID and app key in AndroidManifest in order to make Vivo push available on Vivo devices. + /// Param [appKey] The app key for vivo Push. /// void enableVivoPush() { _pushConfig.enableVivoPush = true; } + /// Enable Huawei Push on Huawei devices. /// - /// Enables Huawei push on Huawei devices. + /// Param [appId] The app ID for HuaWei Push. /// - /// Be sure to set app ID in AndroidManifest or to set agconnect-services.json. + /// Param [appKey] The app key for HuaWei Push. /// void enableHWPush() { _pushConfig.enableHWPush = true; } /// - /// Enables ios push on ios devices. + /// Enables Apple Push Notification service (APNs) on iOS devices. /// - /// Param [certName] The ios device push cert name. + /// Param [certName] The APNs certificate name. void enableAPNs(String certName) { _pushConfig.enableAPNS = true; _pushConfig.apnsCertName = certName; @@ -185,64 +202,92 @@ class EMOptions { /// /// Sets the app options. /// - /// Param [appKey] The app key you got from the console when create an app. - /// - /// Param [autoLogin] Enables/Disables automatic login. default is `true`. - /// - /// Param [debugModel] - /// - /// Param [acceptInvitationAlways] Whether to accept friend invitations from other users automatically. default is `false`. - /// - /// Param [autoAcceptGroupInvitation] Whether to accept group invitations automatically. default is `false`. - /// - /// Param [requireAck] Whether the read receipt is required. default is `true`. - /// - /// Param [requireDeliveryAck] Whether the delivery receipt is required. default is `true`. - /// - /// Param [deleteMessagesAsExitGroup] Whether to delete the group message when leaving a group. default is `true`. - /// - /// Param [deleteMessagesAsExitChatRoom] Whether to delete the chat room message when leaving the chat room. default is `true`. - /// - /// Param [isChatRoomOwnerLeaveAllowed] Whether to allow the chat room owner to leave the chat room. default is `true`. - /// - /// Param [sortMessageByServerTime] Whether to sort messages by the server received time. default is `true`. - /// - /// Param [usingHttpsOnly] Sets whether only HTTPS is used for REST operations. default is `true`. - /// - /// Param [serverTransfer] Whether to upload the message attachments automatically to the chat server. default is `true`. - /// - /// Param [isAutoDownloadThumbnail] Whether to auto download the thumbnail. default is `true`. - /// - /// Param [enableDNSConfig] Sets whether to disable DNS. - /// - /// Param [dnsUrl] The DNS url. - /// - /// Param [restServer] The custom REST server. - /// - /// Param [imPort] The custom im server port. - /// - /// Param [imServer] The custom im message server url. - /// - /// EMOptions( - {required this.appKey, + { + + /// Param [appKey] The app key that you get from the console when creating an app. + required this.appKey, + + /// Param [autoLogin] Whether to enable automatic login. + /// - `true`: (Default) Yes; + /// - `false`: No. this.autoLogin = true, + + /// Param [debugModel] Whether to output the debug information. Make sure to call the method after the EMClient is initialized. See {@link #init(Context, EMOptions)}. + /// - `true`: Yes. + /// - `false`: (Default) No. this.debugModel = false, + + /// Param [acceptInvitationAlways] Whether to accept friend invitations from other users automatically. + /// - `true`: Yes; + /// - `false`: (Default) No. this.acceptInvitationAlways = false, + + /// Param [autoAcceptGroupInvitation] Whether to accept group invitations automatically. + /// - `true`: Yes; + /// - `false`: (Default) No. this.autoAcceptGroupInvitation = false, + + /// Param [requireAck] Whether the read receipt is required. + /// - `true`: (Default) Yes; + /// - `false`: No. this.requireAck = true, + + /// Param [requireDeliveryAck] Whether the delivery receipt is required. + /// - `true`: Yes; + /// - `false`: (Default) No. this.requireDeliveryAck = false, + + /// Param [deleteMessagesAsExitGroup] Whether to delete the related group messages when leaving a group. + /// - `true`: (Default) Yes; + /// - `false`: No. this.deleteMessagesAsExitGroup = true, + + /// Param [deleteMessagesAsExitChatRoom] Whether to delete the related chat room messages when leaving the chat room. + /// - `true`: (Default) Yes; + /// - `false`: No. this.deleteMessagesAsExitChatRoom = true, + + /// Param [isChatRoomOwnerLeaveAllowed] Whether to allow the chat room owner to leave the chat room. + /// - `true`: (Default) Yes; + /// - `false`: No. this.isChatRoomOwnerLeaveAllowed = true, + + /// Param [sortMessageByServerTime] Whether to sort the messages by the time the server receives messages. + /// - `true`: (Default) Yes; + /// - `false`: No. this.sortMessageByServerTime = true, + + /// Param [usingHttpsOnly] Whether only HTTPS is used for REST operations. + /// - `true`: (Default) Yes; + /// - `false`: No. this.usingHttpsOnly = true, + + /// Param [serverTransfer] Whether to upload the message attachments automatically to the chat server. + /// - `true`: (Default) Yes; + /// - `false`: No. this.serverTransfer = true, + + /// Param [isAutoDownloadThumbnail] Whether to automatically download the thumbnail. + /// - `true`: (Default) Yes; + /// - `false`: No. this.isAutoDownloadThumbnail = true, + + /// Param [enableDNSConfig] Whether to enable DNS. + /// - `true`: (Default) Yes; + /// - `false`: No. this.enableDNSConfig = true, + + /// Param [dnsUrl] The DNS url. this.dnsUrl, + + /// Param [restServer] The REST server for private deployments. this.restServer, + + /// Param [imPort] The IM server port for private deployments. this.imPort, + + /// Param [imServer] The IM server URL for private deployment. this.imServer}); factory EMOptions.fromJson(Map json) { diff --git a/lib/src/models/em_page_result.dart b/lib/src/models/em_page_result.dart index 40867192..422231cd 100644 --- a/lib/src/models/em_page_result.dart +++ b/lib/src/models/em_page_result.dart @@ -1,8 +1,8 @@ typedef PageResultCallback = Object Function(dynamic obj); /// -///This object instance is returned when calling the method of fetching by pages. -/// Returns the next page count and the data count of next page. If the pageCount is less than the count you set, there is no more data on server. +/// The EMPageResult class, which is returned when calling the methods that fetch data by pagination. +/// The SDK also returns the number of remaining pages and the data count of the next page. If the dada count is less than the count you set, there is no more data on server. /// /// Param [T] Generics. /// diff --git a/lib/src/models/em_push_config.dart b/lib/src/models/em_push_config.dart index 9b9f0fb0..f7524425 100644 --- a/lib/src/models/em_push_config.dart +++ b/lib/src/models/em_push_config.dart @@ -1,6 +1,6 @@ import '../tools/em_extension.dart'; -/// @nodoc +/// The push configuration class, which contains the push configuration information, such as the push style. class EMPushConfig { String? mzAppId = ''; String? mzAppKey = ''; diff --git a/lib/src/models/em_text_message_body.dart b/lib/src/models/em_text_message_body.dart index dc207dee..0ba675f9 100644 --- a/lib/src/models/em_text_message_body.dart +++ b/lib/src/models/em_text_message_body.dart @@ -4,11 +4,11 @@ import 'em_chat_enums.dart'; import 'em_message_body.dart'; /// -/// Text message body. +/// The text message class. /// class EMTextMessageBody extends EMMessageBody { /// - /// Creates a text message body. + /// Creates a text message. /// /// Param [content] The text content. /// diff --git a/lib/src/models/em_userInfo.dart b/lib/src/models/em_userInfo.dart index b28b9822..94a29c6a 100644 --- a/lib/src/models/em_userInfo.dart +++ b/lib/src/models/em_userInfo.dart @@ -1,13 +1,13 @@ import '../tools/em_extension.dart'; /// -/// The user attribute class that contains user attributes. +/// The EMUserInfo class, which contains the user attributes, such as the nickname, description, and avatar. /// class EMUserInfo { /// - /// Creates a userInfo. + /// Creates a user attribute. /// - /// Param [userId] The user Id. + /// Param [userId] The username. /// EMUserInfo( this.userId, { @@ -50,34 +50,36 @@ class EMUserInfo { } /// - /// Set user attribute. + /// Sets user attributes. /// - /// Param [nickName] The user's nickname. - /// - /// Param [avatarUrl] The avatar URL of the user. - /// - /// Param [mail] The email address of the user. - /// - /// Param [phone] The phone number of the user. - /// - /// Param [gender] The user's gender. The value can only be 0, 1, or 2. 0: default; 1: male; 2: female. Other values are invalid. - /// - /// Param [sign] The user's signature. - /// - /// Param [birth] The user's birthday. - /// - /// Param [ext] The user's extension information. You can set it to an empty string or type custom information and encapsulate them as a JSON string. - /// - /// **return** The new userInfo instance. + /// **Return** The new user information instance. /// EMUserInfo copyWith({ + /// Param [nickName] The user's nickname. String? nickName, + + /// Param [avatarUrl] The avatar URL of the user. String? avatarUrl, + + /// Param [mail] The email address of the user. String? mail, + + /// Param [phone] The phone number of the user. String? phone, + + /// Param [gender] The user's gender. The value can only be `0`, `1`, or `2`. Other values are invalid. + /// - `0`: (Default) Unknow; + /// - `1`: Male; + /// - `2`: Female. int? gender, + + /// Param [sign] The user's signature. String? sign, + + /// Param [birth] The user's data of birth. String? birth, + + /// Param [ext] The user's extension information. You can set it to an empty string or type custom information and encapsulate them as a JSON string. String? ext, }) { return EMUserInfo._private( @@ -123,32 +125,77 @@ class EMUserInfo { return data; } - /// The user ID. + /// Gets the username. + /// + /// **Return** + /// The user's username. + /// final String userId; - /// The user's nickname. + /// Gets the user's nickname. + /// + /// **Return** + /// The user's nickname. + /// final String? nickName; + /// Gets the avatar URL of the user. + /// + /// **Return** /// The avatar URL of the user. + /// final String? avatarUrl; + /// Gets the email address of the user. + /// + /// **Return** /// The email address of the user. + /// final String? mail; - /// The phone number of the user. + /// Gets the mobile numbers of the user. + /// + /// **Return** + /// The mobile numbers of the user. + /// final String? phone; - /// The user's gender. The value can only be 0, 1, or 2. 0: default; 1: male; 2: female. Other values are invalid. + /// Gets the user's gender. + /// + /// **Return** + /// The user's gender: + /// - `0`: (Default) Unknow; + /// - `1`: Male; + /// - `2`: Female. + /// final int gender; + /// Gets the user's signature. + /// + /// **Return** /// The user's signature. + /// final String? sign; - /// The user's birthday. + /// Gets the user's data of birth. + /// + /// **Return** + /// The user's data of birth. + /// final String? birth; - /// The user's extension information. You can set it to an empty string or type custom information and encapsulate them as a JSON string. + /// Gets the user's extension information. + /// + /// **Return** + /// The user's extension information. + /// final String? ext; + /// Gets the time period(seconds) when the user attibutes in the cache expire. + /// If the interval between two calles is less than or equal to the value you set in the parameter, user attributes are obtained directly from the local cache; otherwise, they are obtained from the server. For example, if you set this parameter to 120(2 minutes), once this method is called again within 2 minutes, the SDK returns the attributes obtained last time. + /// + /// **Return** + /// The time period(seconds) when the user attibutes in the cache expire. + /// final int expireTime = DateTime.now().millisecondsSinceEpoch; } diff --git a/lib/src/models/em_video_message_body.dart b/lib/src/models/em_video_message_body.dart index 1703c031..aec8e371 100644 --- a/lib/src/models/em_video_message_body.dart +++ b/lib/src/models/em_video_message_body.dart @@ -5,15 +5,15 @@ import 'em_chat_enums.dart'; import 'em_file_message_body.dart'; /// -/// The video message body. +/// The video message body class. /// class EMVideoMessageBody extends EMFileMessageBody { /// - /// Creates a video message body. + /// Creates a video message. /// - /// Param [localPath] The path of the video file. + /// Param [localPath] The local path of the video file. /// - /// Param [displayName] The video name. like "video.mp4" + /// Param [displayName] The video name. /// /// Param [duration] The video duration in seconds. /// @@ -21,9 +21,9 @@ class EMVideoMessageBody extends EMFileMessageBody { /// /// Param [thumbnailLocalPath] The local path of the video thumbnail. /// - /// Param [height] The video height. + /// Param [height] The video height in pixels. /// - /// Param [width] The video width. + /// Param [width] The video width in pixels. /// EMVideoMessageBody({ required String localPath, @@ -68,7 +68,7 @@ class EMVideoMessageBody extends EMFileMessageBody { } /// The video duration in seconds. - late final int duration; + int? duration; /// The local path of the video thumbnail. String? thumbnailLocalPath; @@ -82,9 +82,9 @@ class EMVideoMessageBody extends EMFileMessageBody { /// The download status of the video thumbnail. DownloadStatus thumbnailStatus = DownloadStatus.PENDING; - /// The video width. + /// The video width in pixels. double? width; - /// The video height. + /// The video height in pixels. double? height; } diff --git a/lib/src/models/em_voice_message_body.dart b/lib/src/models/em_voice_message_body.dart index f8aa1b2d..6d1502a5 100644 --- a/lib/src/models/em_voice_message_body.dart +++ b/lib/src/models/em_voice_message_body.dart @@ -4,15 +4,15 @@ import 'em_file_message_body.dart'; import 'em_chat_enums.dart'; /// -/// The voice message body. +/// The voice message body class. /// class EMVoiceMessageBody extends EMFileMessageBody { /// - /// Creates a voice message body. + /// Creates a voice message. /// - /// Param [localPath] The path of the voice file. + /// Param [localPath] The local path of the voice file. /// - /// Param [displayName] The voice name. like "voice.mp3" + /// Param [displayName] The name of the voice file. /// /// Param [fileSize] The size of the voice file in bytes. /// From 4d094db2d1f226874e62b5a4eb0b131772ff8dba Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Fri, 8 Apr 2022 22:09:30 +0800 Subject: [PATCH 49/56] delete unused files. --- lib/src/em_chat_manager.dart | 2 - lib/src/internal/em_message_state_handle.dart | 17 -------- lib/src/models/em_message.dart | 3 -- .../tools/em_message_callback_manager.dart | 43 ------------------- 4 files changed, 65 deletions(-) delete mode 100644 lib/src/internal/em_message_state_handle.dart delete mode 100644 lib/src/tools/em_message_callback_manager.dart diff --git a/lib/src/em_chat_manager.dart b/lib/src/em_chat_manager.dart index 7431c081..e48e0b98 100644 --- a/lib/src/em_chat_manager.dart +++ b/lib/src/em_chat_manager.dart @@ -5,7 +5,6 @@ import 'internal/em_transform_tools.dart'; import 'tools/em_extension.dart'; import '../im_flutter_sdk.dart'; import 'internal/chat_method_keys.dart'; -import 'tools/em_message_callback_manager.dart'; /// /// The chat manager class, responsible for sending and receiving messages, loading and deleting conversations, and downloading attachments. @@ -27,7 +26,6 @@ class EMChatManager { /// @nodoc EMChatManager() { - MessageCallBackManager.getInstance; _channel.setMethodCallHandler((MethodCall call) async { if (call.method == ChatMethodKeys.onMessagesReceived) { return _onMessagesReceived(call.arguments); diff --git a/lib/src/internal/em_message_state_handle.dart b/lib/src/internal/em_message_state_handle.dart deleted file mode 100644 index cc06e2ce..00000000 --- a/lib/src/internal/em_message_state_handle.dart +++ /dev/null @@ -1,17 +0,0 @@ -class EMMessageStateHandle { - final String messageKey; - final void Function(Map)? onMessageError; - final void Function(Map)? onMessageProgressChanged; - final void Function(Map)? onMessageSuccess; - final void Function(Map)? onMessageReadAck; - final void Function(Map)? onMessageDeliveryAck; - - EMMessageStateHandle( - this.messageKey, { - this.onMessageError, - this.onMessageProgressChanged, - this.onMessageSuccess, - this.onMessageReadAck, - this.onMessageDeliveryAck, - }); -} diff --git a/lib/src/models/em_message.dart b/lib/src/models/em_message.dart index a74de509..5ff049e9 100644 --- a/lib/src/models/em_message.dart +++ b/lib/src/models/em_message.dart @@ -4,11 +4,8 @@ import 'package:flutter/services.dart'; import '../internal/chat_method_keys.dart'; import '../internal/em_transform_tools.dart'; -import '../tools/em_log.dart'; -import '../tools/em_message_callback_manager.dart'; import '../tools/em_extension.dart'; import '../../im_flutter_sdk.dart'; -import '../internal/em_message_state_handle.dart'; /// /// The message class. diff --git a/lib/src/tools/em_message_callback_manager.dart b/lib/src/tools/em_message_callback_manager.dart deleted file mode 100644 index 819671af..00000000 --- a/lib/src/tools/em_message_callback_manager.dart +++ /dev/null @@ -1,43 +0,0 @@ -import 'package:flutter/services.dart'; -import '../internal/em_message_state_handle.dart'; - -import '../internal/chat_method_keys.dart'; - -class MessageCallBackManager { - static const _channelPrefix = 'com.chat.im'; - static const MethodChannel _emMessageChannel = - const MethodChannel('$_channelPrefix/chat_message', JSONMethodCodec()); - Map cacheHandleMap = {}; - static MessageCallBackManager? _instance; - static MessageCallBackManager get getInstance => - _instance = _instance ?? MessageCallBackManager._internal(); - - MessageCallBackManager._internal() { - _emMessageChannel.setMethodCallHandler((MethodCall call) async { - Map argMap = call.arguments; - int? localTime = argMap['localTime']; - EMMessageStateHandle? handle = cacheHandleMap[localTime.toString()]; - - if (call.method == ChatMethodKeys.onMessageProgressUpdate) { - return handle?.onMessageProgressChanged?.call(argMap); - } else if (call.method == ChatMethodKeys.onMessageError) { - return handle?.onMessageError?.call(argMap); - } else if (call.method == ChatMethodKeys.onMessageSuccess) { - return handle?.onMessageSuccess?.call(argMap); - } else if (call.method == ChatMethodKeys.onMessageReadAck) { - return handle?.onMessageReadAck?.call(argMap); - } else if (call.method == ChatMethodKeys.onMessageDeliveryAck) { - return handle?.onMessageDeliveryAck?.call(argMap); - } - return null; - }); - } - - addMessage(String key, EMMessageStateHandle message) { - cacheHandleMap[key] = message; - } - - removeMessage(String key) { - cacheHandleMap.remove(key); - } -} From 968845b019cd8afab31f9831e3259aceccdd8a46 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Tue, 12 Apr 2022 15:05:13 +0800 Subject: [PATCH 50/56] =?UTF-8?q?ios=20=E5=8E=BB=E6=8E=89=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=B3=A8=E5=86=8CdeviceToken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ios/Classes/EMClientWrapper.m | 56 ++-------------------------- ios/Classes/EMConversation+Flutter.m | 3 -- ios/Classes/EMGroup+Flutter.m | 4 +- ios/Classes/EMOptions+Flutter.m | 24 ++++++------ ios/Classes/EMUserInfo+Flutter.m | 4 +- ios/Classes/ImFlutterSdkPlugin.m | 11 ------ lib/src/models/em_chat_room.dart | 5 ++- lib/src/models/em_conversation.dart | 8 ++-- lib/src/models/em_group.dart | 3 +- lib/src/models/em_options.dart | 5 +-- 10 files changed, 29 insertions(+), 94 deletions(-) diff --git a/ios/Classes/EMClientWrapper.m b/ios/Classes/EMClientWrapper.m index 43ad93e8..638cd6f2 100644 --- a/ios/Classes/EMClientWrapper.m +++ b/ios/Classes/EMClientWrapper.m @@ -164,22 +164,16 @@ - (void)initSDKWithDict:(NSDictionary *)param channelName:(NSString *)aChannelNa __weak typeof(self) weakSelf = self; EMOptions *options = [EMOptions fromJson:param]; - // options.enableConsoleLog = YES; + [EMClient.sharedClient initializeSDKWithOptions:options]; [EMClient.sharedClient addDelegate:self delegateQueue:nil]; [EMClient.sharedClient addMultiDevicesDelegate:self delegateQueue:nil]; [self registerManagers]; - // 如果有证书名,说明要使用Apns - if (options.apnsCertName.length > 0) { - [self _registerAPNs]; - } + [weakSelf wrapperCallBack:result channelName:ChatInit error:nil - object:@{ - @"currentUsername": EMClient.sharedClient.currentUsername ?: @"", - @"isLoginBefore": @(EMClient.sharedClient.isLoggedIn) - }]; + object:nil]; } @@ -477,48 +471,4 @@ - (void)onDisconnected:(int)errorCode { } -#pragma mark - register APNs -- (void)_registerAPNs { - UIApplication *application = [UIApplication sharedApplication]; - application.applicationIconBadgeNumber = 0; - - if (NSClassFromString(@"UNUserNotificationCenter")) { - // [UNUserNotificationCenter currentNotificationCenter].delegate = self; - [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert completionHandler:^(BOOL granted, NSError *error) { - if (granted) { -#if !TARGET_IPHONE_SIMULATOR - dispatch_async(dispatch_get_main_queue(), ^{ - [application registerForRemoteNotifications]; - }); -#endif - } - }]; - return; - } - - if([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { - UIUserNotificationType notificationTypes = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert; - UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:notificationTypes categories:nil]; - [application registerUserNotificationSettings:settings]; - } - -#if !TARGET_IPHONE_SIMULATOR - if ([application respondsToSelector:@selector(registerForRemoteNotifications)]) { - [application registerForRemoteNotifications]; - } -#endif -} - -#pragma mark - AppDelegate - -//- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { -// -// return YES; -//} -// -//- (void)applicationDidBecomeActive:(UIApplication *)application { -// -//} - - @end diff --git a/ios/Classes/EMConversation+Flutter.m b/ios/Classes/EMConversation+Flutter.m index 9ddc90db..1c205410 100644 --- a/ios/Classes/EMConversation+Flutter.m +++ b/ios/Classes/EMConversation+Flutter.m @@ -13,10 +13,7 @@ - (NSDictionary *)toJson { NSMutableDictionary *ret = [NSMutableDictionary dictionary]; ret[@"con_id"] = self.conversationId; ret[@"type"] = @([self.class typeToInt:self.type]); - ret[@"unreadCount"] = @(self.unreadMessagesCount); ret[@"ext"] = self.ext; - ret[@"latestMessage"] = [self.latestMessage toJson]; - ret[@"lastReceivedMessage"] = [self.lastReceivedMessage toJson]; return ret; } diff --git a/ios/Classes/EMGroup+Flutter.m b/ios/Classes/EMGroup+Flutter.m index 251a6028..f39d521e 100644 --- a/ios/Classes/EMGroup+Flutter.m +++ b/ios/Classes/EMGroup+Flutter.m @@ -94,7 +94,7 @@ + (EMGroupPermissionType)premissionTypeFromInt:(int)type { @implementation EMGroupOptions (Flutter) - (NSDictionary *)toJson { NSMutableDictionary *ret = [NSMutableDictionary dictionary]; - ret[@"maxCount"] = @(self.maxUsersCount); + ret[@"maxCount"] = @(self.maxUsers); ret[@"ext"] = self.ext; ret[@"style"] = @([EMGroupOptions styleToInt:self.style]); ret[@"inviteNeedConfirm"] = @(self.IsInviteNeedConfirm); @@ -103,7 +103,7 @@ - (NSDictionary *)toJson { + (EMGroupOptions *)formJson:(NSDictionary *)dict { EMGroupOptions *options = [[EMGroupOptions alloc] init]; - options.maxUsersCount = [dict[@"maxCount"] intValue]; + options.maxUsers = [dict[@"maxCount"] intValue]; options.ext = dict[@"ext"]; options.IsInviteNeedConfirm = [dict[@"inviteNeedConfirm"] boolValue]; options.style = [EMGroupOptions styleFromInt:[dict[@"style"] intValue]]; diff --git a/ios/Classes/EMOptions+Flutter.m b/ios/Classes/EMOptions+Flutter.m index 36695887..094c83dd 100644 --- a/ios/Classes/EMOptions+Flutter.m +++ b/ios/Classes/EMOptions+Flutter.m @@ -17,12 +17,12 @@ - (NSDictionary *)toJson { data[@"requireAck"] = @(self.enableRequireReadAck); data[@"requireDeliveryAck"] = @(self.enableDeliveryAck); data[@"sortMessageByServerTime"] = @(self.sortMessageByServerTime); - data[@"acceptInvitationAlways"] = @(self.isAutoAcceptFriendInvitation); - data[@"autoAcceptGroupInvitation"] = @(self.isAutoAcceptGroupInvitation); - data[@"deleteMessagesAsExitGroup"] = @(self.isDeleteMessagesWhenExitGroup); - data[@"deleteMessagesAsExitChatRoom"] = @(self.isDeleteMessagesWhenExitChatRoom); - data[@"isAutoDownload"] = @(self.isAutoDownloadThumbnail); - data[@"isChatRoomOwnerLeaveAllowed"] = @(self.isChatroomOwnerLeaveAllowed); + data[@"acceptInvitationAlways"] = @(self.autoAcceptFriendInvitation); + data[@"autoAcceptGroupInvitation"] = @(self.autoAcceptGroupInvitation); + data[@"deleteMessagesAsExitGroup"] = @(self.deleteMessagesOnLeaveGroup); + data[@"deleteMessagesAsExitChatRoom"] = @(self.deleteMessagesOnLeaveChatroom); + data[@"isAutoDownload"] = @(self.autoDownloadThumbnail); + data[@"isChatRoomOwnerLeaveAllowed"] = @(self.canChatroomOwnerLeave); data[@"serverTransfer"] = @(self.isAutoTransferMessageAttachments); data[@"usingHttpsOnly"] = @(self.usingHttpsOnly); data[@"pushConfig"] = @{@"pushConfig": @{@"apnsCertName": self.apnsCertName}}; @@ -41,12 +41,12 @@ + (EMOptions *)fromJson:(NSDictionary *)aJson { options.enableRequireReadAck = [aJson[@"requireAck"] boolValue]; options.enableDeliveryAck = [aJson[@"requireDeliveryAck"] boolValue]; options.sortMessageByServerTime = [aJson[@"sortMessageByServerTime"] boolValue]; - options.isAutoAcceptFriendInvitation = [aJson[@"acceptInvitationAlways"] boolValue]; - options.isAutoAcceptGroupInvitation = [aJson[@"autoAcceptGroupInvitation"] boolValue]; - options.isDeleteMessagesWhenExitGroup = [aJson[@"deleteMessagesAsExitGroup"] boolValue]; - options.isDeleteMessagesWhenExitChatRoom = [aJson[@"deleteMessagesAsExitChatRoom"] boolValue]; - options.isAutoDownloadThumbnail = [aJson[@"isAutoDownload"] boolValue]; - options.isChatroomOwnerLeaveAllowed = [aJson[@"isChatRoomOwnerLeaveAllowed"] boolValue]; + options.autoAcceptFriendInvitation = [aJson[@"acceptInvitationAlways"] boolValue]; + options.autoAcceptGroupInvitation = [aJson[@"autoAcceptGroupInvitation"] boolValue]; + options.deleteMessagesOnLeaveGroup = [aJson[@"deleteMessagesAsExitGroup"] boolValue]; + options.deleteMessagesOnLeaveChatroom = [aJson[@"deleteMessagesAsExitChatRoom"] boolValue]; + options.autoDownloadThumbnail = [aJson[@"isAutoDownload"] boolValue]; + options.canChatroomOwnerLeave = [aJson[@"isChatRoomOwnerLeaveAllowed"] boolValue]; options.isAutoTransferMessageAttachments = [aJson[@"serverTransfer"] boolValue]; options.usingHttpsOnly = [aJson[@"usingHttpsOnly"] boolValue]; options.apnsCertName = aJson[@"pushConfig"][@"apnsCertName"]; diff --git a/ios/Classes/EMUserInfo+Flutter.m b/ios/Classes/EMUserInfo+Flutter.m index 3e05bda7..682a0c10 100644 --- a/ios/Classes/EMUserInfo+Flutter.m +++ b/ios/Classes/EMUserInfo+Flutter.m @@ -12,7 +12,7 @@ @implementation EMUserInfo (Flutter) - (NSDictionary *)toJson { NSMutableDictionary *ret = [NSMutableDictionary dictionary]; ret[@"userId"] = self.userId; - ret[@"nickName"] = self.nickName; + ret[@"nickName"] = self.nickname; ret[@"avatarUrl"] = self.avatarUrl; ret[@"mail"] = self.mail; ret[@"phone"] = self.phone; @@ -28,7 +28,7 @@ - (NSDictionary *)toJson { + (EMUserInfo *)fromJson:(NSDictionary *)aJson { EMUserInfo *userInfo = EMUserInfo.new; userInfo.userId = aJson[@"userId"] ?: @""; - userInfo.nickName = aJson[@"nickName"] ?: @""; + userInfo.nickname = aJson[@"nickName"] ?: @""; userInfo.avatarUrl = aJson[@"avatarUrl"] ?: @""; userInfo.mail = aJson[@"mail"] ?: @""; userInfo.phone = aJson[@"phone"] ?: @""; diff --git a/ios/Classes/ImFlutterSdkPlugin.m b/ios/Classes/ImFlutterSdkPlugin.m index 58a61cf2..e23a2dbe 100644 --- a/ios/Classes/ImFlutterSdkPlugin.m +++ b/ios/Classes/ImFlutterSdkPlugin.m @@ -37,16 +37,5 @@ - (void)applicationWillEnterForeground:(UIApplication *)application [[EMClient sharedClient] applicationWillEnterForeground:application]; } -- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken -{ - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - [[EMClient sharedClient] bindDeviceToken:deviceToken]; - }); -} - -- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { - NSLog(@"注册推送失败 --- %@", error); -} - @end diff --git a/lib/src/models/em_chat_room.dart b/lib/src/models/em_chat_room.dart index 2691b8b4..719c4c5b 100644 --- a/lib/src/models/em_chat_room.dart +++ b/lib/src/models/em_chat_room.dart @@ -42,8 +42,9 @@ class EMChatRoom { blockList: map.listValue("blockList"), muteList: map.listValue("muteList"), announcement: map.getStringValue("announcement"), - permissionType: chatRoomPermissionTypeFromInt(map.getIntValue("key")), - isAllMemberMuted: map.boolValue('isAllMemberMuted')); + permissionType: + chatRoomPermissionTypeFromInt(map.getIntValue("permissionType")), + isAllMemberMuted: map.boolValue("isAllMemberMuted")); } /// @nodoc diff --git a/lib/src/models/em_conversation.dart b/lib/src/models/em_conversation.dart index 0e670863..17eff08b 100644 --- a/lib/src/models/em_conversation.dart +++ b/lib/src/models/em_conversation.dart @@ -25,10 +25,10 @@ class EMConversation { /// @nodoc factory EMConversation.fromJson(Map map) { - Map? ext = map['ext']?.cast(); + Map? ext = map["ext"]?.cast(); EMConversation ret = EMConversation._private( map["con_id"], - conversationTypeFromInt(map['type']), + conversationTypeFromInt(map["type"]), ext, ); @@ -38,8 +38,8 @@ class EMConversation { /// @nodoc Map _toJson() { final Map data = new Map(); - data['type'] = conversationTypeToInt(this.type); - data['con_id'] = this.id; + data["type"] = conversationTypeToInt(this.type); + data["con_id"] = this.id; return data; } diff --git a/lib/src/models/em_group.dart b/lib/src/models/em_group.dart index e96b1f51..940c2e2a 100644 --- a/lib/src/models/em_group.dart +++ b/lib/src/models/em_group.dart @@ -195,7 +195,7 @@ class EMGroup { .._description = map.stringValue("desc") .._owner = map.stringValue("owner") .._announcement = map.stringValue("announcement") - .._memberCount = map['memberCount'] + .._memberCount = map["memberCount"] .._memberList = map.listValue("memberList") .._adminList = map.listValue("adminList") .._blockList = map.listValue("blockList") @@ -219,7 +219,6 @@ class EMGroup { data.setValueWithOutNull("adminList", _adminList); data.setValueWithOutNull("blockList", _blockList); data.setValueWithOutNull("muteList", _muteList); - data.setValueWithOutNull("owner", _owner); data.setValueWithOutNull("noticeEnable", _noticeEnable); data.setValueWithOutNull("messageBlocked", _messageBlocked); data.setValueWithOutNull("isAllMemberMuted", _isAllMemberMuted); diff --git a/lib/src/models/em_options.dart b/lib/src/models/em_options.dart index 53d88312..0dfa208b 100644 --- a/lib/src/models/em_options.dart +++ b/lib/src/models/em_options.dart @@ -352,9 +352,8 @@ class EMOptions { "sortMessageByServerTime", sortMessageByServerTime); data.setValueWithOutNull("usingHttpsOnly", usingHttpsOnly); - data['sortMessageByServerTime'] = this.sortMessageByServerTime; - data['usingHttpsOnly'] = this.usingHttpsOnly; - data['pushConfig'] = this._pushConfig.toJson(); + data["usingHttpsOnly"] = this.usingHttpsOnly; + data["pushConfig"] = this._pushConfig.toJson(); return data; } From 9f62e2e3644d8933a69ae021e3831a19dc954320 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Tue, 12 Apr 2022 15:50:20 +0800 Subject: [PATCH 51/56] update api referance. --- lib/src/em_group_manager.dart | 4 +- lib/src/em_listeners.dart | 212 +++++++++++++++++++++++++++----- lib/src/em_push_manager.dart | 25 ++-- lib/src/em_status_listener.dart | 12 +- lib/src/models/em_message.dart | 39 +++--- 5 files changed, 225 insertions(+), 67 deletions(-) diff --git a/lib/src/em_group_manager.dart b/lib/src/em_group_manager.dart index 973c6ee2..483f9cbf 100644 --- a/lib/src/em_group_manager.dart +++ b/lib/src/em_group_manager.dart @@ -190,7 +190,7 @@ class EMGroupManager { } /// - /// Gets group information from the server. + /// Gets the group information from the server. /// /// This method does not get member information. If member information is required, call {@link #getGroupMemberListFromServer(String, int?, String?)}. /// @@ -214,7 +214,7 @@ class EMGroupManager { } /// - /// Gets a group's member list with pagination. + /// Gets the member list of the group with pagination. /// /// For example: /// ```dart diff --git a/lib/src/em_listeners.dart b/lib/src/em_listeners.dart index 281200a1..a3ba8e37 100644 --- a/lib/src/em_listeners.dart +++ b/lib/src/em_listeners.dart @@ -81,7 +81,7 @@ abstract class EMMultiDeviceListener { /// /// Param [groupId] The group ID. /// - /// Param [usernames] The userIds. + /// Param [usernames] The array of usernames. /// void onGroupEvent( EMMultiDevicesEvent event, @@ -97,15 +97,15 @@ abstract class EMCustomListener { /// /// The contact updates listener. /// -/// Listen for the contact changes, including requests to add friends, notifications to delete friends, +/// Occurs when the contact changes, including requests to add friends, notifications to delete friends, /// requests to accept friends, and requests to reject friends. /// -/// Register listener: +/// Register the listener: /// ```dart /// EMClient.getInstance.contactManager.addContactListener(contactListener); /// ``` /// -/// Unregister listener: +/// Unregister the listener: /// ```dart /// EMClient.getInstance.contactManager.removeContactListener(contactListener); /// ``` @@ -156,12 +156,12 @@ abstract class EMContactManagerListener { /// /// The chat room change listener. /// -/// Register chat room change listener: +/// Register the chat room change listener: /// ```dart /// EMClient.getInstance.chatRoomManager.addChatRoomChangeListener(listener); /// ``` /// -///Unregister chat room change listener: +///Unregister the chat room change listener: /// ```dart /// EMClient.getInstance.chatRoomManager.removeChatRoomListener(listener); /// ``` @@ -300,92 +300,240 @@ abstract class EMChatRoomEventListener { /// Param [roomId] The chatroom ID. /// /// Param [isAllMuted] Whether all chat room members is muted or unmuted. + /// - `true`: Yes; + /// - `false`: No. /// void onAllChatRoomMemberMuteStateChanged(String roomId, bool isAllMuted); } @Deprecated('Use EMGroupEventListener.') abstract class EMGroupChangeListener { - /// id是[groupId], 名称是[groupName]的群邀请被[inviter]拒绝,理由是[reason] + /// + /// Occurs when an invitation is rejected by the inviter. + /// + /// Param [groupId] The group ID. + /// + /// Param [groupName] The group name. + /// + /// Param [inviter] The username of the inviter. + /// + /// Param [reason] The reason. + /// void onInvitationReceivedFromGroup( String groupId, String? groupName, String inviter, String? reason); - /// 收到用户[applicant]申请加入id是[groupId], 名称是[groupName]的群,原因是[reason] + /// + /// Occurs when a group join application is received from an applicant. + /// + /// Param [groupId] The group ID. + /// + /// Param [groupName] The group name. + /// + /// Param [applicant] The username of the applicant. + /// + /// Param [reason] The reason. + /// void onRequestToJoinReceivedFromGroup( String groupId, String? groupName, String applicant, String? reason); - /// 入群申请被同意 + /// + /// Occurs when a group-join application is accepted. + /// + /// Param [groupId] The group ID. + /// + /// Param [groupName] The group name. + /// + /// Param [accepter] The username of the accepter. + /// void onRequestToJoinAcceptedFromGroup( String groupId, String? groupName, String accepter); - /// 入群申请被拒绝 + /// + /// Occurs when a group-join application is declined. + /// + /// Param [groupId] The group ID. + /// + /// Param [groupName] The group name. + /// + /// Param [decliner] The username of the decliner. + /// + /// Param [reason] The reason. + /// void onRequestToJoinDeclinedFromGroup( String groupId, String? groupName, String decliner, String? reason); - /// 入群邀请被同意 + /// + /// Occurs when a group invitation is approved. + /// + /// Param [groupId] The group ID. + /// + /// Param [groupName] The group name. + /// + /// Param [invitee] The username of the invitee. + /// + /// Param [reason] The reason. + /// void onInvitationAcceptedFromGroup( String groupId, String invitee, String? reason); - /// 入群邀请被拒绝 + /// + /// Occurs when a group invitation is declined. + /// + /// Param [groupId] The group ID. + /// + /// Param [invitee] The username of the invitee. + /// + /// Param [reason] The reason. + /// void onInvitationDeclinedFromGroup( String groupId, String invitee, String? reason); - /// 被移出群组 + /// Occurs when a group member is removed from the group. + /// + /// Param [groupId] The group ID. + /// + /// Param [groupName] The group name. + /// void onUserRemovedFromGroup(String groupId, String? groupName); - /// 群组解散 + /// Occurs when a group is destroyed. + /// + /// Param [groupId] The group ID. + /// + /// Param [groupName] The group name. + /// void onGroupDestroyed(String groupId, String? groupName); - /// @nodoc 自动同意加群 + /// Occurs when the group invitation is accepted automatically. + /// The SDK will join the group before notifying the app of the acceptance of the group invitation. + /// For settings, see {@link EMOptions#autoAcceptGroupInvitation(boolean value)}. + /// + /// Param [groupId] The group ID. + /// Param [inviter] The inviter ID. + /// Param [inviteMessage] The invitation message. + /// void onAutoAcceptInvitationFromGroup( String groupId, String inviter, String? inviteMessage); - /// 群禁言列表增加 + /// Occurs when members are added to the mute list of the group. + /// + /// Param [groupId] The group ID. + /// + /// Param [mutes] The members to be muted. + /// + /// Param [muteExpire] Reserved parameter. The time when the mute state expires. + /// void onMuteListAddedFromGroup( String groupId, List mutes, int? muteExpire); - /// 群禁言列表减少 + /// Occurs when members are removed from the mute list of the group. + /// + /// Param [groupId] The group ID. + /// + /// Param [mutes] The members to be removed from the mute list. + /// void onMuteListRemovedFromGroup(String groupId, List mutes); - /// 群管理增加 + /// + /// Occurs when members are changed to admins. + /// + /// Param [groupId] The group ID. + /// + /// Param [admin] The members changed to be admins. + /// void onAdminAddedFromGroup(String groupId, String admin); - /// 群管理被移除 + /// + /// Occurs when an admin permission is removed. + /// + /// Param [groupId] The group ID. + /// + /// Param [admin] The member whose admin permission is removed. void onAdminRemovedFromGroup(String groupId, String admin); - /// 群所有者变更 + /// + /// Occurs when the chat room ownership is transferred. + /// + /// Param [groupId] The group ID. + /// + /// Param [newOwner] The new owner. + /// + /// Param [oldOwner] The previous owner. void onOwnerChangedFromGroup( String groupId, String newOwner, String oldOwner); - /// 有用户加入群 + /// + /// Occurs when a member joins the group. + /// + /// Param [groupId] The group ID. + /// + /// Param [member] The new member. void onMemberJoinedFromGroup(String groupId, String member); - /// 有用户离开群 + /// + /// Occurs when a member exits the group. + /// + /// Param [groupId] The group ID. + /// + /// Param [member] The member who exits the group. void onMemberExitedFromGroup(String groupId, String member); - /// 群公告变更 + /// + /// Occurs when the announcement changed. + /// + /// Param [groupId] The group ID. + /// + /// Param [member] The new announcement. void onAnnouncementChangedFromGroup(String groupId, String announcement); - /// 群共享文件增加 + /// Occurs when a shared file is added to the group. + /// + /// Param [groupId] The group ID. + /// + /// Param [member] The new shared File. + /// void onSharedFileAddedFromGroup(String groupId, EMGroupSharedFile sharedFile); - /// 群共享文件被删除 + /// + /// Occurs when a shared file is deleted. + /// + /// Param [groupId] The group ID. + /// + /// Param [member] The ID of the shared file that is deleted. + /// void onSharedFileDeletedFromGroup(String groupId, String fileId); - /// 有用户被添加到群组白名单 + /// + /// Occurs when one or more group members are added to the allow list. + /// + /// Param [groupId] The group ID. + /// + /// Param [members] The members that are added to the allow list. void onWhiteListAddedFromGroup(String groupId, List members); - /// 有用户从群组白名单被移除 + /// + /// Occurs when one or more group members are removed from the allow list. + /// + /// Param [groupId] The group ID. + /// + /// Param [members] The members that are removed from the allow list. void onWhiteListRemovedFromGroup(String groupId, List members); - /// 群组禁言状态发生变化 + /// Occurs when all group members are muted or unmuted. + /// + /// Param [groupId] The group ID. + /// + /// Param [isAllMuted] Whether all group members are muted or unmuted. + /// - `true`: Yes; + /// - `false`: No. + void onAllGroupMemberMuteStateChanged(String groupId, bool isAllMuted); } /// /// The group change listener. /// -/// Listens for group events such as requesting to join a group, approving or declining a group request, and kicking a user out of a group. +/// Occurs when the following group events happens: requesting to join a group, approving or declining a group request, and kicking a user out of a group. /// /// Registers a group change listener: /// ```dart @@ -637,7 +785,9 @@ abstract class EMGroupEventListener { /// /// Param [groupId] The group ID. /// - /// Param [isAllMuted] Whether all group members are muted or unmuted. true: all group members are muted; false: all group members are unmuted. + /// Param [isAllMuted] Whether all group members are muted or unmuted. + /// - `true`: Yes; + /// - `false`: No. /// void onAllGroupMemberMuteStateChanged(String groupId, bool isAllMuted); } @@ -713,7 +863,7 @@ abstract class EMChatManagerListener { void onConversationsUpdate() {} /// - /// Occurs when received conversation read receipt. + /// Occurs when a conversation read receipt is received. /// /// Occurs in the following scenarios: /// (1) The message is read by the receiver (The conversation receipt is sent). diff --git a/lib/src/em_push_manager.dart b/lib/src/em_push_manager.dart index f1e0ec87..e90d08f8 100644 --- a/lib/src/em_push_manager.dart +++ b/lib/src/em_push_manager.dart @@ -6,15 +6,14 @@ import 'models/em_error.dart'; import 'models/em_push_configs.dart'; /// -/// The push message presentation style: Simple represents the presentation of a simple message, +/// The push styles. /// -/// and Summary represents the presentation of message content. /// enum DisplayStyle { - /// 显示 ”您有一条新消息“ + /// The push message presentation style: SimpleBanner represents the presentation of a simple message. Simple, - /// 显示推送内容详情 + /// The push message presentation style: MessageSummary represents the presentation of message content. Summary, } @@ -36,7 +35,7 @@ class EMPushManager { } } - /// 从服务器获取 `EMPushConfigs` + /// Gets the push configurations from the server. Future getPushConfigsFromServer() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getImPushConfigFromServer); @@ -66,9 +65,9 @@ class EMPushManager { /// /// Do not push the offline messages within the specified time period (24-hour clock). /// - /// Param [start] The start hour. + /// Param [start] The start hour(24-hour clock). /// - /// Param [end] The end hour. + /// Param [end] The end hour(24-hour clock). /// /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// @@ -150,7 +149,7 @@ class EMPushManager { } /// - /// Update the push message style. The default value is {@link DisplayStyle#Simple}. + /// Updates the push message style. The default value is {@link DisplayStyle#Simple}. /// /// Param [displayStyle] The push message display style. /// @@ -168,7 +167,7 @@ class EMPushManager { } /// - /// Update the HMS push token. + /// Updates the HMS push token. /// /// Param [token] The HMS push token. /// @@ -188,7 +187,7 @@ class EMPushManager { } /// - /// Update the FCM push token. + /// Updates the FCM push token. /// /// Param [token] The FCM push token. /// @@ -208,7 +207,7 @@ class EMPushManager { } /// - /// Update the APNs push token. + /// Updates the APNs push token. /// /// Param [token] The APNs push token. /// @@ -227,7 +226,7 @@ class EMPushManager { } } - /// 从本地获取ImPushConfig + /// Gets push options from the local database. @Deprecated('use - getPushConfigsFromCache method instead.') Future getImPushConfig() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getImPushConfig); @@ -239,7 +238,7 @@ class EMPushManager { } } - /// 从服务器获取ImPushConfig + /// Gets push options from the server. @Deprecated('use - getPushConfigsFromServer method instead.') Future getImPushConfigFromServer() async { Map result = diff --git a/lib/src/em_status_listener.dart b/lib/src/em_status_listener.dart index 3df75a15..bec97136 100644 --- a/lib/src/em_status_listener.dart +++ b/lib/src/em_status_listener.dart @@ -2,21 +2,21 @@ import 'models/em_error.dart'; @Deprecated("Switch to using MessageStatusCallBack instead.") abstract class StatusListener { - /// 消息进度 + /// The status of a message. void onProgress(int progress) {} - /// 消息发送失败 + /// The message fails to be delivered. void onError(EMError error) {} - /// 消息发送成功 + /// The message is successfully delivered. void onSuccess() {} - /// 消息已读 + /// The message is read. void onReadAck() {} - /// 消息已送达 + /// The message is delivered. void onDeliveryAck() {} - /// 消息状态发生改变 + /// Occurs when the status of the message changes. void onStatusChanged() {} } diff --git a/lib/src/models/em_message.dart b/lib/src/models/em_message.dart index 5ff049e9..c2919349 100644 --- a/lib/src/models/em_message.dart +++ b/lib/src/models/em_message.dart @@ -22,7 +22,7 @@ import '../../im_flutter_sdk.dart'; class EMMessage { int _groupAckCount = 0; - /// 消息id + /// 消息 ID。 String? _msgId; String _msgLocalId = DateTime.now().millisecondsSinceEpoch.toString() + Random().nextInt(99999).toString(); @@ -39,44 +39,53 @@ class EMMessage { String? conversationId; /// - /// The user ID of the message sender. + /// The ID of the message sender. + /// - For a one-to-one chat, it is the username of the peer user. + /// - For a group chat, it is the group ID. + /// - For a chat room, it is the chat room ID. /// String? from = ''; /// - /// The user ID of the message recipient. + /// The ID of the message recipient. + /// - For a one-to-one chat, it is the username of the peer user. + /// - For a group chat, it is the group ID. + /// - For a chat room, it is the chat room ID. /// String? to = ''; /// - /// The local timestamp of the message. + /// The local timestamp when the message is created on the local device, in milliseconds. /// int localTime = DateTime.now().millisecondsSinceEpoch; /// - /// The local timestamp of the message. + /// The timestamp when the message is received by the server. /// int serverTime = DateTime.now().millisecondsSinceEpoch; /// /// The delivery receipt, which is to check whether the other party has received the message. /// - /// Whether the other party has received the message. - /// `true`:the message has been delivered to the other party. + /// Whether the recipient has received the message. + /// - `true`: Yes. + /// - `false`: No. /// bool hasDeliverAck = false; /// - /// Whether the other party has read the message. - /// `true`: The message has been read by the other party. + /// Whether the recipient has read the message. + /// - `true`: Yes. + /// - `false`: No. /// bool hasReadAck = false; /// - /// Sets whether read receipts are required for group messages. + /// Whether read receipts are required for group messages. + /// + /// - `true`: Yes. + /// - `false`: No. /// - /// `true`: Read receipts are required; - /// `false`: Read receipts are NOT required. /// bool needGroupAck = false; @@ -86,10 +95,10 @@ class EMMessage { int get groupAckCount => _groupAckCount; /// - /// Checks whether the message is read. + /// Whether the message is read. + /// - `true`: Yes. + /// - `false`: No. /// - /// `true`: The message is read. - /// `false`: The message is unread. /// bool hasRead = false; From 27de3b795e498d81a3bbf4eafe4701835979ab4f Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Tue, 12 Apr 2022 20:55:09 +0800 Subject: [PATCH 52/56] change api referance. --- .../{models => internal}/em_push_config.dart | 2 + lib/src/models/em_cmd_message_body.dart | 2 + lib/src/models/em_cursor_result.dart | 1 + lib/src/models/em_custom_message_body.dart | 1 + lib/src/models/em_file_message_body.dart | 2 + lib/src/models/em_group.dart | 1 + lib/src/models/em_image_message_body.dart | 4 +- lib/src/models/em_location_message_body.dart | 2 + lib/src/models/em_message_body.dart | 1 + lib/src/models/em_options.dart | 4 +- lib/src/models/em_page_result.dart | 1 + lib/src/models/em_push_configs.dart | 74 ++++++++++++------- lib/src/models/em_text_message_body.dart | 1 + lib/src/models/em_userInfo.dart | 4 +- lib/src/models/em_video_message_body.dart | 2 + lib/src/models/em_voice_message_body.dart | 2 + 16 files changed, 71 insertions(+), 33 deletions(-) rename lib/src/{models => internal}/em_push_config.dart (98%) diff --git a/lib/src/models/em_push_config.dart b/lib/src/internal/em_push_config.dart similarity index 98% rename from lib/src/models/em_push_config.dart rename to lib/src/internal/em_push_config.dart index f7524425..acfbd6f2 100644 --- a/lib/src/models/em_push_config.dart +++ b/lib/src/internal/em_push_config.dart @@ -28,6 +28,7 @@ class EMPushConfig { EMPushConfig(); + /// @nodoc void updateFromJson(Map json) { miAppId = json.stringValue("mzAppId"); mzAppKey = json.stringValue("mzAppKey"); @@ -46,6 +47,7 @@ class EMPushConfig { enableAPNS = json.boolValue('enableAPNS'); } + /// @nodoc Map toJson() { final Map data = new Map(); data.setValueWithOutNull("mzAppId", mzAppId); diff --git a/lib/src/models/em_cmd_message_body.dart b/lib/src/models/em_cmd_message_body.dart index 53919ff6..fcfb17ef 100644 --- a/lib/src/models/em_cmd_message_body.dart +++ b/lib/src/models/em_cmd_message_body.dart @@ -13,6 +13,7 @@ class EMCmdMessageBody extends EMMessageBody { EMCmdMessageBody({required this.action, this.deliverOnlineOnly = false}) : super(type: MessageType.CMD); + /// @nodoc EMCmdMessageBody.fromJson({required Map map}) : super.fromJson(map: map, type: MessageType.CMD) { this.action = map["action"]; @@ -20,6 +21,7 @@ class EMCmdMessageBody extends EMMessageBody { map.getBoolValue("deliverOnlineOnly", defaultValue: false)!; } + /// @nodoc @override Map toJson() { final Map data = super.toJson(); diff --git a/lib/src/models/em_cursor_result.dart b/lib/src/models/em_cursor_result.dart index adfd10b0..e85aa49f 100644 --- a/lib/src/models/em_cursor_result.dart +++ b/lib/src/models/em_cursor_result.dart @@ -17,6 +17,7 @@ class EMCursorResult { this.data, ); + /// @nodoc factory EMCursorResult.fromJson(Map map, {dataItemCallback: CursorResultCallback}) { List list = []; diff --git a/lib/src/models/em_custom_message_body.dart b/lib/src/models/em_custom_message_body.dart index 5fbd39a0..047ba8d3 100644 --- a/lib/src/models/em_custom_message_body.dart +++ b/lib/src/models/em_custom_message_body.dart @@ -20,6 +20,7 @@ class EMCustomMessageBody extends EMMessageBody { this.params = map["params"]?.cast(); } + /// @nodoc @override Map toJson() { final Map data = super.toJson(); diff --git a/lib/src/models/em_file_message_body.dart b/lib/src/models/em_file_message_body.dart index 075401ee..35ed2ddd 100644 --- a/lib/src/models/em_file_message_body.dart +++ b/lib/src/models/em_file_message_body.dart @@ -25,6 +25,7 @@ class EMFileMessageBody extends EMMessageBody { MessageType type = MessageType.FILE, }) : super(type: type); + /// @nodoc EMFileMessageBody.fromJson( {required Map map, MessageType type = MessageType.FILE}) : super.fromJson(map: map, type: type) { @@ -38,6 +39,7 @@ class EMFileMessageBody extends EMMessageBody { ); } + /// @nodoc @override Map toJson() { final Map data = super.toJson(); diff --git a/lib/src/models/em_group.dart b/lib/src/models/em_group.dart index 940c2e2a..430006ba 100644 --- a/lib/src/models/em_group.dart +++ b/lib/src/models/em_group.dart @@ -207,6 +207,7 @@ class EMGroup { .._permissionType = permissionTypeFromInt(map['permissionType']); } + /// @nodoc Map toJson() { Map data = Map(); data.setValueWithOutNull("id", _groupId); diff --git a/lib/src/models/em_image_message_body.dart b/lib/src/models/em_image_message_body.dart index b2bfd432..a6da6246 100644 --- a/lib/src/models/em_image_message_body.dart +++ b/lib/src/models/em_image_message_body.dart @@ -41,7 +41,7 @@ class EMImageMessageBody extends EMFileMessageBody { type: MessageType.IMAGE, ); - /// nodoc + /// @nodoc EMImageMessageBody.fromJson({required Map map}) : super.fromJson(map: map, type: MessageType.IMAGE) { this.thumbnailLocalPath = map.getStringValue("thumbnailLocalPath"); @@ -58,7 +58,7 @@ class EMImageMessageBody extends EMFileMessageBody { ); } - /// nodoc + /// @nodoc @override Map toJson() { final Map data = super.toJson(); diff --git a/lib/src/models/em_location_message_body.dart b/lib/src/models/em_location_message_body.dart index 944fd891..d9ac9143 100644 --- a/lib/src/models/em_location_message_body.dart +++ b/lib/src/models/em_location_message_body.dart @@ -28,6 +28,7 @@ class EMLocationMessageBody extends EMMessageBody { _buildingName = buildingName; } + /// @nodoc EMLocationMessageBody.fromJson({required Map map}) : super.fromJson(map: map, type: MessageType.LOCATION) { this.latitude = map.getDoubleValue("latitude", defaultValue: 0.0)!; @@ -36,6 +37,7 @@ class EMLocationMessageBody extends EMMessageBody { this._buildingName = map.getStringValue("buildingName"); } + /// @nodoc @override Map toJson() { final Map data = super.toJson(); diff --git a/lib/src/models/em_message_body.dart b/lib/src/models/em_message_body.dart index e36f1415..5ec9c221 100644 --- a/lib/src/models/em_message_body.dart +++ b/lib/src/models/em_message_body.dart @@ -5,6 +5,7 @@ import 'em_chat_enums.dart'; abstract class EMMessageBody { EMMessageBody({required this.type}); + /// @nodoc EMMessageBody.fromJson({ required Map map, required this.type, diff --git a/lib/src/models/em_options.dart b/lib/src/models/em_options.dart index 0dfa208b..69622ab1 100644 --- a/lib/src/models/em_options.dart +++ b/lib/src/models/em_options.dart @@ -1,5 +1,5 @@ import '../tools/em_extension.dart'; -import 'em_push_config.dart'; +import '../internal/em_push_config.dart'; /// /// The EMOptions class, which contains the settings of the Chat SDK. @@ -290,6 +290,7 @@ class EMOptions { /// Param [imServer] The IM server URL for private deployment. this.imServer}); + /// @nodoc factory EMOptions.fromJson(Map json) { var ret = EMOptions( appKey: json['appKey'], @@ -323,6 +324,7 @@ class EMOptions { return ret; } + /// @nodoc Map toJson() { Map data = new Map(); data.setValueWithOutNull("appKey", appKey); diff --git a/lib/src/models/em_page_result.dart b/lib/src/models/em_page_result.dart index 422231cd..8067dccd 100644 --- a/lib/src/models/em_page_result.dart +++ b/lib/src/models/em_page_result.dart @@ -9,6 +9,7 @@ typedef PageResultCallback = Object Function(dynamic obj); class EMPageResult { EMPageResult._private(); + /// @nodoc factory EMPageResult.fromJson(Map map, {dataItemCallback: PageResultCallback}) { EMPageResult result = EMPageResult._private(); diff --git a/lib/src/models/em_push_configs.dart b/lib/src/models/em_push_configs.dart index 883f8a4f..ecb93533 100644 --- a/lib/src/models/em_push_configs.dart +++ b/lib/src/models/em_push_configs.dart @@ -6,47 +6,65 @@ import 'em_chat_enums.dart'; import 'em_error.dart'; import '../em_push_manager.dart'; -/// The push configs info class. +/// The push configuration information class. class EMPushConfigs { - EMPushConfigs._private(); + EMPushConfigs._private({ + this.displayStyle = DisplayStyle.Simple, + this.noDisturb = false, + this.noDisturbStartHour = -1, + this.noDisturbEndHour = -1, + }); + /// + /// Gets the offline push display type. + /// The offline push display type. + /// + final DisplayStyle displayStyle; + + /// + /// Gets whether to enable offline push without disturbing. + /// Sets it by {@link EMPushManager#disableOfflinePush(int, int)}. + /// Whether to enable offline push without disturbing. + /// + final bool noDisturb; + + /// + /// Gets the start hour of the offline push without disturbing. + /// The start hour of the offline push without disturbing. + /// + final int noDisturbStartHour; + + /// + /// Gets the end hour of the offline push without disturbing. + /// The end hour of the offline push without disturbing. + /// + final int noDisturbEndHour; + + // ignore: unused_field DisplayStyle? _displayStyle; - @Deprecated("Switch to using DisplayStyle instead") - EMPushStyle? _pushStyle; + // ignore: unused_field bool? _noDisturb; + // ignore: unused_field int? _noDisturbStartHour; + // ignore: unused_field int? _noDisturbEndHour; + // ignore: unused_field List? _noDisturbGroups = []; - @Deprecated("Switch to using DisplayStyle instead") - EMPushStyle? get pushStyle => _pushStyle; - - DisplayStyle? get displayStyle => _displayStyle; - - bool? get noDisturb => _noDisturb; - int? get noDisturbStartHour => _noDisturbStartHour; - int? get noDisturbEndHour => _noDisturbEndHour; - List? get noDisturbGroups => _noDisturbGroups; + /// @nodoc factory EMPushConfigs.fromJson(Map map) { - return EMPushConfigs._private() - .._displayStyle = - map['pushStyle'] == 0 ? DisplayStyle.Simple : DisplayStyle.Summary - .._noDisturb = map.boolValue('noDisturb') - .._noDisturbStartHour = map['noDisturbStartHour'] - .._noDisturbEndHour = map['noDisturbEndHour']; - } - - Map toJson() { - Map data = Map(); - data['pushStyle'] = _displayStyle == DisplayStyle.Simple; - data['noDisturb'] = _noDisturb; - data['noDisturbStartHour'] = _noDisturbStartHour; - data['noDisturbEndHour'] = _noDisturbEndHour; - return data; + return EMPushConfigs._private( + displayStyle: + map['pushStyle'] == 0 ? DisplayStyle.Simple : DisplayStyle.Summary, + noDisturb: map.boolValue('noDisturb'), + noDisturbStartHour: map['noDisturbStartHour'], + noDisturbEndHour: map['noDisturbEndHour'], + ); } } +/// @nodoc extension EMPushConfigsExtension on EMPushConfigs { // channel的命名与pushManager中的channel一致,本质上还是一个channel。 static const MethodChannel _channel = diff --git a/lib/src/models/em_text_message_body.dart b/lib/src/models/em_text_message_body.dart index 0ba675f9..670c144e 100644 --- a/lib/src/models/em_text_message_body.dart +++ b/lib/src/models/em_text_message_body.dart @@ -14,6 +14,7 @@ class EMTextMessageBody extends EMMessageBody { /// EMTextMessageBody({required this.content}) : super(type: MessageType.TXT); + /// @nodoc EMTextMessageBody.fromJson({required Map map}) : super.fromJson(map: map, type: MessageType.TXT) { this.content = map.getStringValue("content", defaultValue: "")!; diff --git a/lib/src/models/em_userInfo.dart b/lib/src/models/em_userInfo.dart index 94a29c6a..9018989c 100644 --- a/lib/src/models/em_userInfo.dart +++ b/lib/src/models/em_userInfo.dart @@ -33,7 +33,7 @@ class EMUserInfo { this.ext, }); - /// @nodac + /// @nodoc factory EMUserInfo.fromJson(Map map) { EMUserInfo info = EMUserInfo( map["userId"], @@ -95,7 +95,7 @@ class EMUserInfo { ); } - /// @nodac + /// @nodoc Map toJson() { Map data = Map(); data['userId'] = userId; diff --git a/lib/src/models/em_video_message_body.dart b/lib/src/models/em_video_message_body.dart index aec8e371..c628032d 100644 --- a/lib/src/models/em_video_message_body.dart +++ b/lib/src/models/em_video_message_body.dart @@ -40,6 +40,7 @@ class EMVideoMessageBody extends EMFileMessageBody { type: MessageType.VIDEO, ); + /// @nodoc EMVideoMessageBody.fromJson({required Map map}) : super.fromJson(map: map, type: MessageType.VIDEO) { this.duration = map.getIntValue("duration", defaultValue: 0)!; @@ -52,6 +53,7 @@ class EMVideoMessageBody extends EMFileMessageBody { map.getIntValue("thumbnailStatus")); } + /// @nodoc @override Map toJson() { final Map data = super.toJson(); diff --git a/lib/src/models/em_voice_message_body.dart b/lib/src/models/em_voice_message_body.dart index 6d1502a5..c818c778 100644 --- a/lib/src/models/em_voice_message_body.dart +++ b/lib/src/models/em_voice_message_body.dart @@ -30,11 +30,13 @@ class EMVoiceMessageBody extends EMFileMessageBody { type: MessageType.VOICE, ); + /// @nodoc EMVoiceMessageBody.fromJson({required Map map}) : super.fromJson(map: map, type: MessageType.VOICE) { this.duration = map.getIntValue("duration", defaultValue: 0)!; } + /// @nodoc @override Map toJson() { final Map data = super.toJson(); From 78cb23afc9bb07f36757f5fb3887010f2c152f69 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Tue, 12 Apr 2022 20:56:34 +0800 Subject: [PATCH 53/56] update --- lib/src/em_push_manager.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/em_push_manager.dart b/lib/src/em_push_manager.dart index e90d08f8..69b9d399 100644 --- a/lib/src/em_push_manager.dart +++ b/lib/src/em_push_manager.dart @@ -86,7 +86,7 @@ class EMPushManager { } /// - /// Sets wether to turn on or turn off the push notification for the the specified groups. + /// Sets whether to turn on or turn off the push notification for the the specified groups. /// /// [groupIds] The list of groups to be set. /// From ab0092ee727bc459df6eb8b2cbedefd9afd408fc Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Thu, 14 Apr 2022 12:29:57 +0800 Subject: [PATCH 54/56] update files. --- README.md | 1181 ++++++++--------- android/src/main/AndroidManifest.xml | 5 - .../im_flutter_sdk/EMPushManagerWrapper.java | 87 +- .../easemob/im_flutter_sdk/EMSDKMethod.java | 20 +- example/lib/pages/group/group_info_page.dart | 3 +- .../lib/pages/group/public_groups_page.dart | 8 +- ios/Classes/EMClientWrapper.m | 3 + ios/Classes/EMPushManagerWrapper.m | 137 +- ios/Classes/EMSDKMethod.h | 15 +- lib/src/em_chat_manager.dart | 3 +- lib/src/em_chat_room_manager.dart | 4 +- lib/src/em_group_manager.dart | 318 ++++- lib/src/em_push_manager.dart | 59 +- lib/src/internal/chat_method_keys.dart | 21 +- lib/src/models/em_cursor_result.dart | 2 +- lib/src/models/em_group.dart | 26 +- lib/src/models/em_group_shared_file.dart | 4 +- lib/src/models/em_push_configs.dart | 11 +- 18 files changed, 1003 insertions(+), 904 deletions(-) diff --git a/README.md b/README.md index 0281ba99..9c97827d 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,7 @@ 源码地址: [Github](https://github.com/easemob/im_flutter_sdk) 任何问题可以通过 [Github Issues](https://github.com/easemob/im_flutter_sdk/issues) 提问 -Demo中使用的音视频是针对声网音视频封装的[EaseCallKit](https://github.com/easemob/ease_call_kit),如果问题,可以通过 [EaseCallKit Issues](https://github.com/easemob/ease_call_kit/issues) 提问 -[常见问题](https://github.com/easemob/im_flutter_sdk/blob/stable/docs/flutter_QA.md) - -**QQ群: 535134817** ## 前期准备 @@ -29,7 +25,7 @@ Demo中使用的音视频是针对声网音视频封装的[EaseCallKit](https:// ```dart dependencies: - im_flutter_sdk: ^3.8.3+9 + im_flutter_sdk: ^3.9.0 ``` 2. 执行`flutter pub get`; @@ -49,7 +45,7 @@ dependencies: im_flutter_sdk: git: url: https://github.com/easemob/im_flutter_sdk.git - ref: dev_3.9.0 + ref: flutter2_stable ``` 2. 执行`flutter pub get`; @@ -74,8 +70,7 @@ import 'package:im_flutter_sdk/im_flutter_sdk.dart' #### 初始化 ```dart -EMOptions options = EMOptions(appKey: 'easemob-demo#chatdemoui'); -options.enableAPNs("chatdemoui_dev"); +var options = EMOptions(appKey: "easemob-demo#easeim"); await EMClient.getInstance.init(options); ``` @@ -88,7 +83,7 @@ await EMClient.getInstance.init(options); try { await EMClient.getInstance.createAccount(username, password); } on EMError catch (e) { - print('操作失败,原因是: $e'); + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -100,24 +95,23 @@ try { try { await EMClient.getInstance.login(username, password); } on EMError catch (e) { - print('操作失败,原因是: $e'); + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 获取当前登录环信id ```dart -EMClient.getInstance.currentUsername; +String? currentUsername = await EMClient.getInstance.getCurrentUsername(); ``` #### 退出 ```dart try { - // true: 是否解除deviceToken绑定。 await EMClient.getInstance.logout(true); } on EMError catch (e) { - print('操作失败,原因是: $e'); + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -127,33 +121,32 @@ try { #### 监听服务器连接状态 ```dart -class _MyAppState extends State implements EMConnectionListener{ - +class _PageState extends State implements EMConnectionListener { @override void initState() { super.initState(); - // 添加连接监听 EMClient.getInstance.addConnectionListener(this); } - ... - @override - void onConnected() { - // 网络已连接 + Widget build(BuildContext context) { + return Container(); } + @override + void onConnected() {} @override - void onDisconnected(int errorCode) { - // 连接失败,原因是[errorCode] - } + void onDisconnected(int? errorCode) {} - ... + @override + void onTokenDidExpire() {} + + @override + void onTokenWillExpire() {} @override void dispose() { - // 移除连接监听 EMClient.getInstance.removeConnectionListener(this); super.dispose(); } @@ -163,25 +156,17 @@ class _MyAppState extends State implements EMConnectionListener{ #### 获取当前连接状态 ```dart -EMClient.getInstance.connected; +bool isConnected = await EMClient.getInstance.isConnected(); ``` -#### 获取flutter sdk版本号 -```dart -EMClient.getInstance.flutterSDKVersion; -``` ### EMChatManager #### 获取会话列表 ```dart -try { - List conList = await EMClient.getInstance.chatManager.loadAllConversations(); -} on EMError catch (e) { - print('操作失败,原因是: $e'); -} +List conversations = await EMClient.getInstance.chatManager.loadAllConversations(); ``` > 会话列表是存在本地的一种消息管理对象,如果您会话中没有消息,则表示会话不存在。 @@ -189,12 +174,7 @@ try { #### 获取会话 ```dart -try { - // emId: 会话对应环信id, 如果是群组或者聊天室,则为群组id或者聊天室id - EMConversation conv = await EMClient.getInstance.chatManager.getConversation(emId); -} on EMError catch (e) { - print('操作失败,原因是: $e'); -} +EMConversation? conversation = await EMClient.getInstance.chatManager.getConversation(conversationId); ``` > 获取会话,如果会话目前不存在会创建。 @@ -202,69 +182,47 @@ try { #### 获取会话中的消息 ```dart -try { - List msgs = con.loadMessages(); -} on EMError catch (e) { - print('操作失败,原因是: $e'); -} +List? messages = await conversation.loadMessages(); ``` #### 获取会话中未读消息数 ```dart -con.unreadCount; +int unreadCount = await conversation.unreadCount(); ``` #### 设置单条消息为已读 ```dart -try { - con.markMessageAsRead(msg.msgId); -} on EMError catch (e) { - print('操作失败,原因是: $e'); -} +await conversation.markMessageAsRead(messageId); ``` #### 设置所有消息为已读 ```dart -try { - con.markAllMessagesAsRead(); -} on EMError catch (e) { - print('操作失败,原因是: $e'); -} +await conversation.markAllMessagesAsRead(); ``` #### 发送消息已读状态 ```dart try { - await EMClient.getInstance.chatManager.sendMessageReadAck(msg); + await EMClient.getInstance.chatManager.sendMessageReadAck(message); } on EMError catch (e) { - print('操作失败,原因是: $e'); + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 删除会话中的消息 ```dart -try{ - // 删除会话中所有消息 - await conv.deleteAllMessages(); -} on EMError catch (e) { - print('操作失败,原因是: $e'); -} +await conversation.deleteAllMessages(); ``` #### 插入消息 ```dart -try{ - // 向会话中插入一条消息 - await conv.insertMessage(msg); -} on EMError catch (e) { - print('操作失败,原因是: $e'); -} +await conversation.insertMessage(message); ``` > SDK在您发送和接收消息(_cmd类型消息除外_)后会自动将消息插入数据库中,并不需要您自己将消息插入数据库,但如果您需要自己插入一条消息时可以调用该api。 @@ -272,32 +230,19 @@ try{ #### 更新消息 ```dart -try{ - await conv.updateMessage(msg); -} on EMError catch (e) { - print('操作失败,原因是: $e'); -} +await conversation.updateMessage(message); ``` #### 删除消息 ```dart -try{ - // 删除会话中某一条消息 - await conv.deleteMessage(msg.msgId); -} on EMError catch (e) { - print('操作失败,原因是: $e'); -} +await conversation.deleteMessage(messageId); ``` #### 删除会话 ```dart -try { - await EMClient.getInstance.chatManager.deleteConversation(conversation.id); -} on EMError catch (e) { - print('操作失败,原因是: $e'); -} +await EMClient.getInstance.chatManager.deleteConversation(conversationId); ``` ​ @@ -333,84 +278,40 @@ EMMessage msg = EMMessage.createCustomSendMessage(username: '接收方id', event #### 发送消息 ```dart -try{ - await EMClient.getInstance.chatManager.sendMessage(msg); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.chatManager.sendMessage(message); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 监听消息发送状态 ```dart -class ChatItemState extends State implements EMMessageStatusListener { - - EMMessage msg; - ... - - void initState() { - super.initState(); - // 添加监听 - msg.setMessageListener(this); - } - - ... - - // 消息进度 - @override - void onProgress(int progress) { - } - - // 消息发送失败 - @override - void onError(EMError error) { - } - - // 消息发送成功 - @override - void onSuccess() { - } - - // 消息已读 - @override - void onReadAck() { - } - - // 消息已送达 - @override - void onDeliveryAck() { - } - - // 消息状态发生改变 - @override - void onStatusChanged() { - } - - dispose(){ - msg.setMessageListener(null); - super.dispose(); - } - -} +message.setMessageStatusCallBack(MessageStatusCallBack( + onError: (error) => {}, + onProgress: (progress) => {}, + onSuccess: () => {}, +)); ``` #### 重发消息 ```dart -try{ +try { await EMClient.getInstance.chatManager.resendMessage(message); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 撤回消息 ```dart -try{ - await EMClient.getInstance.chatManager.recallMessage(msg.msgId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.chatManager.recallMessage(messageId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -419,86 +320,69 @@ try{ #### 收消息监听 ```dart -class _ChatPageState extends State implements EMChatManagerListener { - +class _PageState extends State implements EMChatManagerListener { @override void initState() { super.initState(); - // 添加收消息监听 - EMClient.getInstance.chatManager.addListener(this); + EMClient.getInstance.chatManager.addChatManagerListener(this); } - - // 收到cmd消息回调 @override - onCmdMessagesReceived(List messages) { + Widget build(BuildContext context) { + return Container(); } - // 会话列表数量变更 @override - onConversationsUpdate() { + void dispose() { + EMClient.getInstance.chatManager.removeChatManagerListener(this); + super.dispose(); } - // 消息已送达回调 @override - onMessagesDelivered(List messages) { - } + void onCmdMessagesReceived(List messages) {} - // 消息已读回调 @override - onMessagesRead(List messages) { - } + void onConversationRead(String from, String to) {} - // 消息被撤回回调 @override - onMessagesRecalled(List messages) { - } + void onConversationsUpdate() {} - // 会话已读回执 @override - onConversationRead(String from, String to) { - } + void onGroupMessageRead(List groupMessageAcks) {} - // 收消息回调 @override - onMessagesReceived(List messages) { - } + void onMessagesDelivered(List messages) {} - // 群消息已读回执 @override - void onGroupMessageRead(List groupMessageAcks) { - } + void onMessagesRead(List messages) {} @override - void dispose() { - // 移除收消息监听 - EMClient.getInstance.chatManager.removeListener(this); - super.dispose(); - } + void onMessagesRecalled(List messages) {} + + @override + void onMessagesReceived(List messages) {} } ``` -#### 会话列表漫游 +#### 从服务器拉取会话列表 ```dart try { - List conversations = - await EMClient.getInstance.chatManager.getConversationsFromServer(); + List? conversations = await EMClient.getInstance.chatManager.getConversationsFromServer(); } on EMError catch (e) { - debugPrint("error: ${e.code}"); + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` > 会话列表漫游为增值服务,需要单独开通。 -#### 消息漫游 +#### 从服务器拉取消息 ```dart try { - EMCursorResult result = await EMClient.getInstance.chatManager - .fetchHistoryMessages(conversationId); + EMCursorResult result = await EMClient.getInstance.chatManager.fetchHistoryMessages(conversationId); } on EMError catch (e) { - debugPrint("error: ${e.code}"); + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -509,10 +393,11 @@ try { #### 从服务器获取通讯录中的用户列表 ```dart -try{ - List contactsList = await EMClient.getInstance.contactManager.getAllContactsFromServer(); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + List contacts = + await EMClient.getInstance.contactManager.getAllContactsFromServer(); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -521,10 +406,10 @@ try{ #### 发送添加申请 ```dart -try{ - await EMClient.getInstance.contactManager.addContact(friendEmId, '您好,我想添加您为好友'); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.contactManager.addContact(userId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -533,30 +418,30 @@ try{ #### 删除通讯录中的成员 ```dart -try{ - await EMClient.getInstance.contactManager.deleteContact(friendEmId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.contactManager.deleteContact(userId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 从服务器获取黑名单 ```dart -try{ - List blockList = await EMClient.getInstance.contactManager.getBlockListFromServer(); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + ListblockList = await EMClient.getInstance.contactManager.getBlockListFromServer(); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 添加用户到黑名单中 ```dart -try{ - await EMClient.getInstance.contactManager.addUserToBlockList(emId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.contactManager.addUserToBlockList(userId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -565,56 +450,57 @@ try{ #### 将用户从黑名单中删除 ```dart -try{ - await EMClient.getInstance.contactManager.removeUserFromBlockList(emId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.contactManager.removeUserFromBlockList(userId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 通讯录监听 ```dart -class _ContactPageState extends State implements EMContactEventListener { - +class _PageState extends State implements EMContactManagerListener { @override void initState() { super.initState(); - // 添加通讯录监听 EMClient.getInstance.contactManager.addContactListener(this); } + @override + Widget build(BuildContext context) { + return Container(); + } - // [userName]添加您为好友 @override - onContactAdded(String userName) { + void dispose() { + EMClient.getInstance.contactManager.removeContactListener(this); + super.dispose(); } - // [userName]将您从好友中删除 @override - onContactDeleted(String userName) { + void onContactAdded(String userName) { + } - // 收到[userName]的好友申请,原因是[reason] @override - onContactInvited(String userName, String reason) { + void onContactDeleted(String? userName) { + } - // 发出的好友申请被[userName]同意 @override - onFriendRequestAccepted(String userName) { + void onContactInvited(String userName, String? reason) { + } - // 发出的好友申请被[userName]拒绝 @override - onFriendRequestDeclined(String userName) { + void onFriendRequestAccepted(String userName) { + } @override - void dispose() { - // 移除通讯录监听 - EMClient.getInstance.contactManager.removeContactListener(this); - super.dispose(); + void onFriendRequestDeclined(String userName) { + } } ``` @@ -622,20 +508,20 @@ class _ContactPageState extends State implements EMContactEventList #### 同意添加申请 ```dart -try{ - await EMClient.getInstance.contactManager.acceptInvitation(emId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.contactManager.acceptInvitation(userId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 拒绝添加申请 ```dart -try{ - await EMClient.getInstance.contactManager.declineInvitation(emId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.contactManager.declineInvitation(userId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -644,40 +530,41 @@ try{ #### 从服务器获取已加入群组列表 ```dart -try{ - List groupsList = await EMClient.getInstance.groupManager.getJoinedGroupsFromServer(); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + List groups = await EMClient.getInstance.groupManager.fetchJoinedGroupsFromServer(); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 从缓存中获取已加入群组列表 ```dart -try{ - List groupsList = await EMClient.getInstance.groupManager.getJoinedGroups(); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + List groups = await EMClient.getInstance.groupManager.getJoinedGroups(); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 从服务器获取公开群组列表 ```dart -try{ - List groupsList = await EMClient.getInstance.groupManager.getPublicGroupsFromServer(); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + EMCursorResult groups = await EMClient.getInstance.groupManager.fetchPublicGroupsFromServer(); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 创建群组 ```dart -try{ - EMGroup group = await EMClient.getInstance.groupManager.createGroup('群组名称', settings: EMGroupOptions()); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + EMGroup group = await EMClient.getInstance.groupManager + .createGroup(options: EMGroupOptions(), groupName: groupName); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -690,30 +577,30 @@ try{ #### 获取群组详情 ```dart -try{ - EMGroup group = await EMClient.getInstance.groupManager.getGroupSpecificationFromServer(group.groupId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + EMGroup group = await EMClient.getInstance.groupManager.fetchGroupInfoFromServer(groupId) +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 获取群成员列表 ```dart -try{ - EMCursorResult result = await EMClient.getInstance.groupManager.getGroupMemberListFromServer(group.groupId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + EMCursorResult result = await EMClient.getInstance.groupManager.fetchMemberListFromServer(groupId) +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 加入公开群组 ```dart -try{ - await EMClient.getInstance.groupManager.joinPublicGroup(groupId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.joinPublicGroup(groupId) +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -722,10 +609,10 @@ try{ #### 申请加入公开群 ```dart -try{ +try { await EMClient.getInstance.groupManager.requestToJoinPublicGroup(groupId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -734,10 +621,10 @@ try{ #### 邀请用户入群 ```dart -try{ - await EMClient.getInstance.groupManager.inviterUser(groupId, inviteMembers); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.inviterUser(groupId, members); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -747,10 +634,10 @@ try{ > 被邀请方会收到邀请通知,同意后进群。邀请通知并不会以推送的形式发出,如果用户不在线,等上线后会收到,用户同意后入群。 ```dart -try{ - EMClient.getInstance.groupManager.addMembers(groupId, members); -} on EMError catch(e){ - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.addMembers(groupId, members); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -761,10 +648,10 @@ try{ #### 从群组中移除用户 ```dart -try{ +try { await EMClient.getInstance.groupManager.removeMembers(groupId, members); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -773,10 +660,10 @@ try{ #### 添加管理员 ```dart -try{ +try { await EMClient.getInstance.groupManager.addAdmin(groupId, memberId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -785,10 +672,10 @@ try{ #### 移除管理员 ```dart -try{ +try { await EMClient.getInstance.groupManager.removeAdmin(groupId, memberId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -797,20 +684,20 @@ try{ #### 退出群组 ```dart -try{ +try { await EMClient.getInstance.groupManager.leaveGroup(groupId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 解散群组 ```dart -try{ +try { await EMClient.getInstance.groupManager.destroyGroup(groupId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -819,10 +706,10 @@ try{ #### 转移群组 ```dart -try{ - await EMClient.getInstance.groupManager.changeGroupOwner(groupId, newOwner); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.changeOwner(groupId, newOwnerId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -831,20 +718,20 @@ try{ #### 获取群组黑名单列表 ```dart -try{ - List blockList = await EMClient.getInstance.groupManager.getGroupBlocklistFromServer(group.groupId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + List? blockList = await EMClient.getInstance.groupManager.fetchBlockListFromServer(groupId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 将群成员添加到群黑名单 ```dart -try{ - await EMClient.getInstance.groupManager.blockMembers(group.groupId, blockList); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.blockMembers(groupId, members); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -853,10 +740,10 @@ try{ #### 将用户从黑名单移除 ```dart -try{ - await EMClient.getInstance.groupManager.unblockMembers(group.groupId, unBlockList); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.unblockMembers(groupId, members); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -865,20 +752,21 @@ try{ #### 获取群禁言列表 ```dart -try{ - List mutesList = await EMClient.getInstance.groupManager.getGroupMuteListFromServer(group.groupId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + List? list = await EMClient.getInstance.groupManager + .fetchMuteListFromServer(groupId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 对成员禁言 ```dart -try{ - await EMClient.getInstance.groupManager.muteMembers(group.groupId, mutesList); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.muteMembers(groupId, members); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -887,10 +775,10 @@ try{ #### 对成员解除禁言 ```dart -try{ - await EMClient.getInstance.groupManager.unMuteMembers(group.groupId, unMutesList); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.unMuteMembers(groupId, members); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -899,10 +787,10 @@ try{ #### 对所有成员禁言 ```dart -try{ - await EMClient.getInstance.groupManager.muteAllMembers(group.groupId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.muteAllMembers(groupId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -911,10 +799,10 @@ try{ #### 对所有成员解除禁言 ```dart -try{ - await EMClient.getInstance.groupManager.unMuteAllMembers(group.groupId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.unMuteAllMembers(groupId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -923,20 +811,20 @@ try{ #### 获取白名单列表 ```dart -try{ - List whiteList = await EMClient.getInstance.groupManager.getGroupWhiteListFromServer(group.groupId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + List? list = await EMClient.getInstance.groupManager.fetchWhiteListFromServer(groupId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 将用户添加到白名单中 ```dart -try{ - await EMClient.getInstance.groupManager.addWhiteList(group.groupId, whiteList); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.addWhiteList(groupId, members); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -945,10 +833,10 @@ try{ #### 将用户从白名单中移除 ```dart -try{ - await EMClient.getInstance.groupManager.removeWhiteList(group.groupId, whiteList); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.removeWhiteList(groupId, members); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -957,20 +845,20 @@ try{ #### 判断自己是否在白名单中 ```dart -try{ - bool inWhiteList = await EMClient.getInstance.groupManager.isMemberInWhiteListFromServer(group.groupId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + bool inWhiteList = await EMClient.getInstance.groupManager.isMemberInWhiteListFromServer(groupId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 不接收群消息 ```dart -try{ - await EMClient.getInstance.groupManager.blockGroup(group.groupId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.blockGroup(groupId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -979,20 +867,21 @@ try{ #### 恢复接收群消息 ```dart -try{ - await EMClient.getInstance.groupManager.unblockGroup(group.groupId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.unblockGroup(groupId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 消息免打扰 ```dart -try{ - await EMClient.getInstance.groupManager.ignoreGroupPush(group.groupId, true); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.pushManager.updatePushServiceForGroup( + groupIds: groupIds, enablePush: false); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1001,10 +890,10 @@ try{ #### 更新群名称 ```dart -try{ - await EMClient.getInstance.groupManager.changeGroupName(group.groupId, newName); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.changeGroupName(groupId, newName); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1013,10 +902,10 @@ try{ #### 更新群描述 ```dart -try{ - await EMClient.getInstance.groupManager.changeGroupDescription(group.groupId, newDescription); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.changeGroupDescription(groupId, newDesc); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1025,20 +914,20 @@ try{ #### 获取群组公告 ```dart -try{ - String announcement = await EMClient.getInstance.groupManager.getGroupAnnouncementFromServer(group.groupId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + String? announcement =await EMClient.getInstance.groupManager.fetchAnnouncementFromServer(groupId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 更新群公告 ```dart -try{ - await EMClient.getInstance.groupManager.updateGroupAnnouncement(group.groupId, announcement); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.updateGroupAnnouncement(groupId, newAnnouncement); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1047,40 +936,40 @@ try{ #### 获取群共享文件列表 ```dart -try{ - List filesList = await EMClient.getInstance.groupManager.getGroupFileListFromServer(group.groupId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + List fileList =await EMClient.getInstance.groupManager.fetchGroupFileListFromServer(groupId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 上传群共享文件 ```dart -try{ - await EMClient.getInstance.groupManager.uploadGroupSharedFile(group.groupId, filePath); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.uploadGroupSharedFile(groupId, filePath); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 下载群共享文件 ```dart -try{ - await EMClient.getInstance.groupManager.uploadGroupSharedFile(group.groupId, groupSharedFile.fileId, savePath: path); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.downloadGroupSharedFile(groupId, filePath, savePath); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 删除群共享文件 ```dart -try{ - await EMClient.getInstance.groupManager.removeGroupSharedFile(group.groupId, groupSharedFile.fileId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.removeGroupSharedFile(groupId, fileId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1089,111 +978,110 @@ try{ #### 群回调监听 ```dart -class _GroupPageState extends State implements EMGroupEventListener { - +class _PageState extends State implements EMGroupEventListener { @override void initState() { super.initState(); - // 添加群组监听 EMClient.getInstance.groupManager.addGroupChangeListener(this); } - ... - - // id是[groupId], 名称是[groupName]的群邀请被[inviter]拒绝,理由是[reason] - void onInvitationReceived(String groupId, String groupName, String inviter, String reason) { + @override + Widget build(BuildContext context) { + return Container(); } - // 收到用户[applicant]申请加入id是[groupId], 名称是[groupName]的群,原因是[reason] - void onRequestToJoinReceived(String groupId, String groupName, String applicant, String reason) { + @override + void dispose() { + EMClient.getInstance.groupManager.removeGroupChangeListener(this); + super.dispose(); } - // 入群申请被同意 - void onRequestToJoinAccepted(String groupId, String groupName, String accepter) { - } + @override + void onAdminAddedFromGroup(String groupId, String admin) {} - // 入群申请被拒绝 - void onRequestToJoinDeclined(String groupId, String groupName, String decliner, String reason) { - } + @override + void onAdminRemovedFromGroup(String groupId, String admin) {} - // 入群邀请被同意 - void onInvitationAccepted(String groupId, String invitee, String reason) { - } + @override + void onAllGroupMemberMuteStateChanged(String groupId, bool isAllMuted) {} - // 入群邀请被拒绝 - void onInvitationDeclined(String groupId, String invitee, String reason) { - } + @override + void onAnnouncementChangedFromGroup(String groupId, String announcement) {} - // 被移出群组 - void onUserRemoved(String groupId, String groupName) { - } + @override + void onAutoAcceptInvitationFromGroup( + String groupId, String inviter, String? inviteMessage) {} - // 群组解散 - void onGroupDestroyed(String groupId, String groupName) { - } + @override + void onGroupDestroyed(String groupId, String? groupName) {} - // 自动同意加群 - void onAutoAcceptInvitationFromGroup(String groupId, String inviter, String inviteMessage) { - } + @override + void onInvitationAcceptedFromGroup( + String groupId, String invitee, String? reason) {} - // 群禁言列表增加 - void onMuteListAdded(String groupId, List mutes, int muteExpire) { - } + @override + void onInvitationDeclinedFromGroup( + String groupId, String invitee, String? reason) {} - // 群禁言列表减少 - void onMuteListRemoved(String groupId, List mutes) { - } + @override + void onInvitationReceivedFromGroup( + String groupId, String? groupName, String inviter, String? reason) {} - // 群管理增加 - void onAdminAdded(String groupId, String administrator) { - } + @override + void onMemberExitedFromGroup(String groupId, String member) {} - // 群管理被移除 - void onAdminRemoved(String groupId, String administrator) { - } + @override + void onMemberJoinedFromGroup(String groupId, String member) {} - // 群所有者变更 - void onOwnerChanged(String groupId, String newOwner, String oldOwner) { - } + @override + void onMuteListAddedFromGroup( + String groupId, List mutes, int? muteExpire) {} - // 有用户加入群 - void onMemberJoined(String groupId, String member) { - } + @override + void onMuteListRemovedFromGroup(String groupId, List mutes) {} - // 有用户离开群 - void onMemberExited(String groupId, String member) { - } + @override + void onOwnerChangedFromGroup( + String groupId, String newOwner, String oldOwner) {} - // 群公告变更 - void onAnnouncementChanged(String groupId, String announcement) { - } + @override + void onRequestToJoinAcceptedFromGroup( + String groupId, String? groupName, String accepter) {} - // 群共享文件增加 - void onSharedFileAdded(String groupId, EMGroupSharedFile sharedFile) { - } + @override + void onRequestToJoinDeclinedFromGroup( + String groupId, String? groupName, String decliner, String? reason) {} - // 群共享文件被删除 - void onSharedFileDeleted(String groupId, String fileId) { - } + @override + void onRequestToJoinReceivedFromGroup( + String groupId, String? groupName, String applicant, String? reason) {} - ... + @override + void onSharedFileAddedFromGroup( + String groupId, EMGroupSharedFile sharedFile) {} @override - void dispose() { - // 移除群组监听 - EMClient.getInstance.groupManager.removeGroupChangeListener(this); - super.dispose(); - } + void onSharedFileDeletedFromGroup(String groupId, String fileId) {} + + @override + void onUserRemovedFromGroup(String groupId, String? groupName) {} + + @override + void onWhiteListAddedFromGroup(String groupId, List members) {} + + @override + void onWhiteListRemovedFromGroup(String groupId, List members) {} } + ``` #### 同意加群申请 ```dart -try{ - await EMClient.getInstance.groupManager.acceptJoinApplication(group.groupId, username); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.acceptJoinApplication(groupId, userId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1202,10 +1090,10 @@ try{ #### 拒绝加群申请 ```dart -try{ - await EMClient.getInstance.groupManager.declineJoinApplication(group.groupId, username); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.declineJoinApplication(groupId, userId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1214,20 +1102,20 @@ try{ #### 同意加群邀请 ```dart -try{ - await EMClient.getInstance.groupManager.declineJoinApplication(group.groupId, inviter); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.acceptInvitation(groupId, userId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 拒绝加群邀请 ```dart -try{ - await EMClient.getInstance.groupManager.declineInvitationFromGroup(group.groupId, inviter); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.groupManager.declineInvitation(groupId, userId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1236,30 +1124,20 @@ try{ #### 从服务器获取聊天室列表 ```dart -try{ - EMPageResult result = await EMClient.getInstance.roomManager.fetchPublicChatRoomsFromServer(); -} on EMError catch(e) { - print('操作失败,原因是: $e'); -} -``` - -#### 获取本地缓存聊天室列表 - -```dart -try{ - List list = await EMClient.getInstance.roomManager.getAllChatRooms(); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + EMPageResult result = await EMClient.getInstance.chatRoomManager.fetchPublicChatRoomsFromServer(); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 创建聊天室 ```dart -try{ - EMChatRoom room = await EMClient.getInstance.roomManager.createChatRoom('聊天室名称'); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + EMChatRoom room = await EMClient.getInstance.chatRoomManager.createChatRoom(subject); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1268,30 +1146,30 @@ try{ #### 加入聊天室 ```dart -try{ - await EMClient.getInstance.roomManager.joinChatRoom(roomId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.chatRoomManager.joinChatRoom(roomId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 离开聊天室 ```dart -try{ - await EMClient.getInstance.roomManager.leaveChatRoom(roomId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.chatRoomManager.leaveChatRoom(roomId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 销毁聊天室 ```dart -try{ - await EMClient.getInstance.roomManager.destroyChatRoom(roomId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.chatRoomManager.destroyChatRoom(roomId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1300,10 +1178,10 @@ try{ #### 转移聊天室 ```dart -try{ - await EMClient.getInstance.roomManager.changeOwner(roomId, newOwner); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.chatRoomManager.changeOwner(roomId, newOwnerId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1312,20 +1190,20 @@ try{ #### 获取聊天室详情 ```dart -try{ - await EMClient.getInstance.roomManager.fetchChatRoomInfoFromServer(roomId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + EMChatRoom room =await EMClient.getInstance.chatRoomManager.fetchChatRoomInfoFromServer(roomId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 获取聊天室成员 ```dart -try{ - EMCursorResult result = await EMClient.getInstance.roomManager.fetchChatRoomMembers(roomId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + EMCursorResult result = await EMClient.getInstance.chatRoomManager.fetchChatRoomMembers(roomId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1344,10 +1222,10 @@ try{ #### 添加管理员 ```dart -try{ - await EMClient.getInstance.roomManager.addChatRoomAdmin(roomId, memberId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.chatRoomManager.addChatRoomAdmin(roomId, memberId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1356,10 +1234,10 @@ try{ #### 移除管理员 ```dart -try{ - await EMClient.getInstance.roomManager.removeChatRoomAdmin(roomId, adminId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.chatRoomManager.removeChatRoomAdmin(roomId, AdminId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1368,20 +1246,20 @@ try{ #### 获取禁言列表 ```dart -try{ - List mutesList = await EMClient.getInstance.roomManager.fetchChatRoomMuteList(roomId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + List? list =await EMClient.getInstance.chatRoomManager.fetchChatRoomMuteList(roomId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 设置禁言 ```dart -try{ - await EMClient.getInstance.roomManager.muteChatRoomMembers(roomId, membersList); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.chatRoomManager.muteChatRoomMembers(roomId, memberIds); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1390,10 +1268,10 @@ try{ #### 解除禁言 ```dart -try{ - await EMClient.getInstance.roomManager.unMuteChatRoomMembers(roomId, membersList); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.chatRoomManager.unMuteChatRoomMembers(roomId, memberIds); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1402,20 +1280,20 @@ try{ #### 获取黑名单列表 ```dart -try{ - List blockList = await EMClient.getInstance.roomManager.fetchChatRoomBlockList(roomId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + List? list = await EMClient.getInstance.chatRoomManager.fetchChatRoomBlockList(roomId); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 添加黑名单 ```dart -try{ - List blockList = await EMClient.getInstance.roomManager.blockChatRoomMembers(roomId, membersList); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.chatRoomManager.blockChatRoomMembers(roomId, memberIds); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1424,10 +1302,10 @@ try{ #### 移除黑名单 ```dart -try{ - List blockList = await EMClient.getInstance.roomManager.unBlockChatRoomMembers(roomId, membersList); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.chatRoomManager.unBlockChatRoomMembers(roomId, memberIds); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1436,10 +1314,10 @@ try{ #### 修改聊天室标题 ```dart -try{ - await EMClient.getInstance.roomManager.changeChatRoomSubject(roomId, subject); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.chatRoomManager.changeChatRoomSubject(roomId, newSubject); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1460,20 +1338,20 @@ try{ #### 获取聊天室公告 ```dart -try{ - String announcement = await EMClient.getInstance.roomManager.fetchChatRoomAnnouncement(roomId); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.chatRoomManager.changeChatRoomDescription(omId, newDesc); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 修改聊天室公告 ```dart -try{ - await EMClient.getInstance.roomManager.updateChatRoomAnnouncement(roomId, announcement); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.chatRoomManager.updateChatRoomAnnouncement(chatRoomId, newAnnouncement); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1482,62 +1360,68 @@ try{ #### 添加聊天室监听 ```dart -class _RoomPageState extends State implements EMChatRoomEventListener { - +class _PageState extends State implements EMChatRoomEventListener { @override void initState() { super.initState(); - // 添加聊天室监听 - EMClient.getInstance.roomManager.addChatRoomChangeListener(this); + EMClient.getInstance.chatRoomManager.addChatRoomChangeListener(this); } - /// id是[roomId],名称是[roomName]的聊天室被销毁 - void onChatRoomDestroyed(String roomId, String roomName) { + @override + Widget build(BuildContext context) { + return Container(); } - /// 有用户[participant]加入id是[roomId]的聊天室 - void onMemberJoined(String roomId, String participant) { + @override + void dispose() { + EMClient.getInstance.chatRoomManager.removeChatRoomListener(this); + super.dispose(); } - /// 有用户[participant]离开id是[roomId],名字是[roomName]的聊天室 - void onMemberExited(String roomId, String roomName, String participant) { - } + @override + void onAdminAddedFromChatRoom(String roomId, String admin) {} - /// 用用户[participant]被id是[roomId],名称[roomName]的聊天室删除,删除原因是[reason] - void onRemovedFromChatRoom(int reason, String roomId, String roomName, String participant) { - } + @override + void onAdminRemovedFromChatRoom(String roomId, String admin) {} - /// id是[roomId]的聊天室禁言列表[mutes]有增加 - void onMuteListAdded(String roomId, List mutes, String expireTime) { - } + @override + void onAllChatRoomMemberMuteStateChanged(String roomId, bool isAllMuted) {} - /// id是[roomId]的聊天室禁言列表[mutes]有减少 - void onMuteListRemoved(String roomId, List mutes) { - } + @override + void onAnnouncementChangedFromChatRoom(String roomId, String announcement) {} - /// id是[roomId]的聊天室增加id是[admin]管理员 - void onAdminAdded(String roomId, String admin) { - } + @override + void onChatRoomDestroyed(String roomId, String? roomName) {} - /// id是[roomId]的聊天室移除id是[admin]管理员 - void onAdminRemoved(String roomId, String admin) { - } + @override + void onMemberExitedFromChatRoom( + String roomId, String? roomName, String participant) {} - /// id是[roomId]的聊天室所有者由[oldOwner]变更为[newOwner] - void onOwnerChanged(String roomId, String newOwner, String oldOwner) { - } + @override + void onMemberJoinedFromChatRoom(String roomId, String participant) {} - /// id是[roomId]的聊天室公告变为[announcement] - void onAnnouncementChanged(String roomId, String announcement) { - } + @override + void onMuteListAddedFromChatRoom( + String roomId, List mutes, String? expireTime) {} - @override - void dispose() { - // 移除聊天室监听 - EMClient.getInstance.roomManager.removeChatRoomListener(this); - super.dispose(); - } + @override + void onMuteListRemovedFromChatRoom(String roomId, List mutes) {} + + @override + void onOwnerChangedFromChatRoom( + String roomId, String newOwner, String oldOwner) {} + + @override + void onRemovedFromChatRoom( + String roomId, String? roomName, String? participant) {} + + @override + void onWhiteListAddedFromChatRoom(String roomId, List members) {} + + @override + void onWhiteListRemovedFromChatRoom(String roomId, List members) {} } + ``` ### 推送 @@ -1545,10 +1429,10 @@ class _RoomPageState extends State implements EMChatRoomEventListener #### 设置推送昵称 ```dart -try{ - await EMClient.getInstance.pushManager.updatePushNickname(pushName); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.pushManager.updatePushNickname(pushDisplayName); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1557,30 +1441,26 @@ try{ #### 从服务器获取推送配置 ```dart -try{ - EMPushConfigs pushConfigs = await EMClient.getInstance.pushManager.getPushConfigsFromServer(); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + EMPushConfigs configs = await EMClient.getInstance.pushManager.fetchPushConfigsFromServer(); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 从本地缓存获取推送配置 ```dart -try{ - EMPushConfigs pushConfigs = await EMClient.getInstance.pushManager.getPushConfigsFromCache(); -} on EMError catch(e) { - print('操作失败,原因是: $e'); -} +EMPushConfigs? configs = await EMClient.getInstance.pushManager.getPushConfigsFromCache(); ``` #### 设置推送显示样式 ```dart -try{ +try { await EMClient.getInstance.pushManager.updatePushDisplayStyle(DisplayStyle.Simple); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1591,10 +1471,10 @@ try{ #### 设置消息免打扰 ```dart -try{ - await EMClient.getInstance.pushManager.disableOfflinePush(10, 22); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.pushManager.disableOfflinePush(start: 10, end: 22); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` @@ -1603,64 +1483,73 @@ try{ #### 关闭消息免打扰 ```dart -try{ +try { await EMClient.getInstance.pushManager.enableOfflinePush(); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 设置群组免打扰 ```dart -try{ - await EMClient.getInstance.pushManager.updatePushServiceForGroup(groupId, false); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +try { + await EMClient.getInstance.pushManager.updatePushServiceForGroup(groupIds: groupIds, enablePush: false); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` #### 获取免打扰群组列表 ```dart -try{ - List groupIdsList = await EMClient.getInstance.pushManager.getNoPushGroupsFromCache(); -} on EMError catch(e) { - print('操作失败,原因是: $e'); +List list = await EMClient.getInstance.pushManager.getNoPushGroupsFromCache(); +``` + +#### 设置用户免打扰 + +```dart +try { + await EMClient.getInstance.pushManager.updatePushServiceFroUsers(userIds: userIds, enablePush: false); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); } ``` +#### 获取免打扰用户列表 + +```dart +List list = await EMClient.getInstance.pushManager.getNoPushUsersFromCache(); +``` + + + + + ### EMUserInfoManager #### 更新自己的用户属性 ```dart - try { - EMUserInfo info = EMUserInfo(EMClient.getInstance.currentUsername); - info.copyWith( - sign: "修改签名", - nickName: "用户属性昵称", - mail: "xxx@easemob.com", - ); - await EMClient.getInstance.userInfoManager.updateOwnUserInfo(info); - } on EMError catch (e) { - print('操作失败,原因是: $e'); - } +String? currentUser = await EMClient.getInstance.getCurrentUsername(); +if (currentUser == null) { + return; +} +try { + EMUserInfo userInfo = EMUserInfo(currentUser); + userInfo = userInfo.copyWith(nickName: nickname, avatarUrl: avatarUrl); + await EMClient.getInstance.userInfoManager.updateOwnUserInfo(userInfo); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); +} ``` #### 获取多用户的用户属性 ```dart - try { - String userId = EMClient.getInstance.currentUsername; - List userIds =[]; - userIds.add(userId); - userIds.add('xxx'); - - Map userInfoMap = await EMClient.getInstance.userInfoManager - .fetchUserInfoByIdWithExpireTime(userIds, expireTime: 3600); - - } on EMError catch (e) { - print('操作失败,原因是: $e'); - } +try { + Map map = await EMClient.getInstance.userInfoManager.fetchUserInfoById(userIds); +} on EMError catch (e) { + debugPrint("error code: ${e.code}, desc: ${e.description}"); +} ``` diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 55dc9640..0d003bbe 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,17 +1,12 @@ - - - - - diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMPushManagerWrapper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMPushManagerWrapper.java index 83105d9e..771b1738 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMPushManagerWrapper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMPushManagerWrapper.java @@ -41,30 +41,18 @@ else if(EMSDKMethod.getImPushConfigFromServer.equals(call.method)){ else if(EMSDKMethod.updatePushNickname.equals(call.method)){ updatePushNickname(param, call.method, result); } - else if(EMSDKMethod.imPushNoDisturb.equals(call.method)){ - imPushNoDisturb(param, call.method, result); - } else if(EMSDKMethod.updateImPushStyle.equals(call.method)){ updateImPushStyle(param, call.method, result); } else if(EMSDKMethod.updateGroupPushService.equals(call.method)){ updateGroupPushService(param, call.method, result); } - else if(EMSDKMethod.getNoDisturbGroups.equals(call.method)){ - getNoDisturbGroups(param, call.method, result); - } else if(EMSDKMethod.updateHMSPushToken.equals(call.method)){ updateHMSPushToken(param, call.method, result); } else if(EMSDKMethod.updateFCMPushToken.equals(call.method)){ updateFCMPushToken(param, call.method, result); } - else if(EMSDKMethod.setNoDisturbUsers.equals(call.method)) { - setNoDisturbUsers(param, EMSDKMethod.setNoDisturbUsers, result); - } - else if(EMSDKMethod.getNoDisturbUsersFromServer.equals(call.method)) { - getNoDisturbUsersFromServer(param, EMSDKMethod.getNoDisturbUsersFromServer, result); - } else if (EMSDKMethod.enableOfflinePush.equals(call.method)) { enableOfflinePush(param, call.method, result); } @@ -74,6 +62,12 @@ else if (EMSDKMethod.disableOfflinePush.equals(call.method)){ else if (EMSDKMethod.getNoPushGroups.equals(call.method)) { getNoPushGroups(param, call.method, result); } + else if (EMSDKMethod.updateUserPushService.equals(call.method)) { + updateUserPushService(param, call.method, result); + } + else if (EMSDKMethod.getNoPushUsers.equals(call.method)) { + getNoPushUsers(param, call.method, result); + } else { super.onMethodCall(call, result); } @@ -111,22 +105,6 @@ private void updatePushNickname(JSONObject params, String channelName, Result r }); } - private void imPushNoDisturb(JSONObject params, String channelName, Result result) throws JSONException { - boolean noDisturb = params.getBoolean("noDisturb"); - int startTime = params.getInt("startTime"); - int endTime = params.getInt("endTime"); - asyncRunnable(()-> { - try { - if (noDisturb) { - EMClient.getInstance().pushManager().disableOfflinePush(startTime, endTime); - }else{ - EMClient.getInstance().pushManager().enableOfflinePush(); - } - } catch (HyphenateException e) { - - } - }); - } private void enableOfflinePush(JSONObject params, String channelName, Result result) throws JSONException { @@ -159,7 +137,13 @@ private void getNoPushGroups(JSONObject params, String channelName, Result resul List groups = EMClient.getInstance().pushManager().getNoPushGroups(); onSuccess(result, channelName, groups); }); + } + private void getNoPushUsers(JSONObject params, String channelName, Result result) throws JSONException { + asyncRunnable(()->{ + List list = EMClient.getInstance().pushManager().getNoPushUsers(); + onSuccess(result, channelName, list); + }); } private void updateImPushStyle(JSONObject params, String channelName, Result result) throws JSONException { @@ -186,48 +170,23 @@ private void updateGroupPushService(JSONObject params, String channelName, Resu }); } - private void getNoDisturbGroups(JSONObject params, String channelName, Result result) throws JSONException { - - asyncRunnable(()->{ - try{ - EMClient.getInstance().pushManager().getPushConfigsFromServer(); - List groupIds = EMClient.getInstance().pushManager().getNoPushGroups(); - onSuccess(result, channelName, groupIds); - } catch (HyphenateException e) { - onError(result, e); - } - }); - } + private void updateUserPushService(JSONObject params, String channelName, Result result) throws JSONException { + JSONArray groupIds = params.getJSONArray("user_ids"); + boolean noPush = params.getBoolean("noPush"); - private void setNoDisturbUsers(JSONObject params, String channelName, Result result) throws JSONException { - JSONArray jsonMembers = params.getJSONArray("members"); - Boolean disable = params.getBoolean("disable"); - List members = new ArrayList<>(); - for (int i = 0; i < jsonMembers.length(); i++) { - String memberId = jsonMembers.getString(i); - members.add(memberId); + List userList = new ArrayList<>(); + for (int i = 0; i < groupIds.length(); i++) { + String userId = groupIds.getString(i); + userList.add(userId); } - asyncRunnable(()->{ - try{ - EMClient.getInstance().pushManager().updatePushServiceForUsers(members, disable); + asyncRunnable(()-> { + try { + EMClient.getInstance().pushManager().updatePushServiceForUsers(userList, noPush); onSuccess(result, channelName, null); - } catch (HyphenateException e) { - onError(result, e); - } - }); - } - - private void getNoDisturbUsersFromServer(JSONObject params, String channelName, Result result) throws JSONException { - asyncRunnable(()->{ - try{ - EMClient.getInstance().pushManager().getPushConfigsFromServer(); - List userIds = EMClient.getInstance().pushManager().getNoPushUsers(); - onSuccess(result, channelName, userIds); - } catch (HyphenateException e) { + } catch(HyphenateException e) { onError(result, e); } }); - } private void updateHMSPushToken(JSONObject params, String channelName, Result result) throws JSONException { diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMSDKMethod.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMSDKMethod.java index e9651697..e6c52867 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMSDKMethod.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMSDKMethod.java @@ -200,20 +200,20 @@ public class EMSDKMethod { /// EMPushManager static final String getImPushConfig = "getImPushConfig"; static final String getImPushConfigFromServer = "getImPushConfigFromServer"; - static final String updatePushNickname = "updatePushNickname"; - static final String updateHMSPushToken = "updateHMSPushToken"; - static final String updateFCMPushToken = "updateFCMPushToken"; static final String enableOfflinePush = "enableOfflinePush"; static final String disableOfflinePush = "disableOfflinePush"; - static final String getNoPushGroups = "getNoPushGroups"; - - /// ImPushConfig - static final String imPushNoDisturb = "imPushNoDisturb"; static final String updateImPushStyle = "updateImPushStyle"; + static final String updatePushNickname = "updatePushNickname"; + static final String updateGroupPushService = "updateGroupPushService"; - static final String getNoDisturbGroups = "getNoDisturbGroups"; - static final String setNoDisturbUsers = "setNoDisturbUsers"; - static final String getNoDisturbUsersFromServer = "getNoDisturbUsersFromServer"; + static final String getNoPushGroups = "getNoPushGroups"; + static final String updateUserPushService = "updateUserPushService"; + static final String getNoPushUsers = "getNoPushUsers"; + + + static final String updateHMSPushToken = "updateHMSPushToken"; + static final String updateFCMPushToken = "updateFCMPushToken"; + /// EMUserInfoManager diff --git a/example/lib/pages/group/group_info_page.dart b/example/lib/pages/group/group_info_page.dart index e8940981..5ddcf148 100644 --- a/example/lib/pages/group/group_info_page.dart +++ b/example/lib/pages/group/group_info_page.dart @@ -195,8 +195,7 @@ class GroupInfoPageState extends State { _fetchGroupInfo() async { try { SmartDialog.showLoading(msg: '获取中...'); - _group = await EMClient.getInstance.groupManager - .getGroupSpecificationFromServer( + _group = await EMClient.getInstance.groupManager.fetchGroupInfoFromServer( widget.group.groupId, ); diff --git a/example/lib/pages/group/public_groups_page.dart b/example/lib/pages/group/public_groups_page.dart index 4b0f88f3..a1472377 100644 --- a/example/lib/pages/group/public_groups_page.dart +++ b/example/lib/pages/group/public_groups_page.dart @@ -145,7 +145,7 @@ class PublicGroupsPageState extends State { _loadMorePublicGroups() async { try { EMCursorResult cursor = - await EMClient.getInstance.groupManager.getPublicGroupsFromServer( + await EMClient.getInstance.groupManager.fetchPublicGroupsFromServer( pageSize: _pageSize, cursor: _cursor ?? "", ); @@ -170,7 +170,7 @@ class PublicGroupsPageState extends State { _isEnd = false; EMCursorResult cursor = - await EMClient.getInstance.groupManager.getPublicGroupsFromServer( + await EMClient.getInstance.groupManager.fetchPublicGroupsFromServer( pageSize: _pageSize, ); _refreshController.refreshCompleted(); @@ -201,8 +201,8 @@ class PublicGroupsPageState extends State { if (std.length == 0) return; try { SmartDialog.showLoading(msg: '搜索中...'); - _searchedGroup = await EMClient.getInstance.groupManager - .getGroupSpecificationFromServer(std); + _searchedGroup = + await EMClient.getInstance.groupManager.fetchGroupInfoFromServer(std); } on EMError catch (e) { SmartDialog.showToast('搜索失败: $e'); } finally { diff --git a/ios/Classes/EMClientWrapper.m b/ios/Classes/EMClientWrapper.m index 638cd6f2..9fb00e79 100644 --- a/ios/Classes/EMClientWrapper.m +++ b/ios/Classes/EMClientWrapper.m @@ -166,6 +166,9 @@ - (void)initSDKWithDict:(NSDictionary *)param channelName:(NSString *)aChannelNa EMOptions *options = [EMOptions fromJson:param]; [EMClient.sharedClient initializeSDKWithOptions:options]; + + [EMClient.sharedClient removeDelegate:self]; + [EMClient.sharedClient removeMultiDevicesDelegate:self]; [EMClient.sharedClient addDelegate:self delegateQueue:nil]; [EMClient.sharedClient addMultiDevicesDelegate:self delegateQueue:nil]; [self registerManagers]; diff --git a/ios/Classes/EMPushManagerWrapper.m b/ios/Classes/EMPushManagerWrapper.m index 4fc1b0c2..83ba801c 100644 --- a/ios/Classes/EMPushManagerWrapper.m +++ b/ios/Classes/EMPushManagerWrapper.m @@ -36,10 +36,6 @@ - (void)handleMethodCall:(FlutterMethodCall*)call [self updatePushNickname:call.arguments channelName:call.method result:result]; - } else if ([ChatImPushNoDisturb isEqualToString:call.method]) { - [self setImPushNoDisturb:call.arguments - channelName:call.method - result:result]; } else if ([ChatUpdateImPushStyle isEqualToString:call.method]) { [self updateImPushStyle:call.arguments channelName:call.method @@ -48,22 +44,10 @@ - (void)handleMethodCall:(FlutterMethodCall*)call [self updateGroupPushService:call.arguments channelName:call.method result:result]; - } else if ([ChatGetNoDisturbGroups isEqualToString:call.method]) { - [self getNoDisturbGroups:call.arguments - channelName:call.method - result:result]; } else if ([ChatBindDeviceToken isEqualToString:call.method]) { [self bindDeviceToken:call.arguments channelName:call.method result:result]; - } else if ([ChatSetNoDisturbUsers isEqualToString:call.method]) { - [self setNoDisturbUsers:call.arguments - channelName:ChatSetNoDisturbUsers - result:result]; - } else if ([ChatGetNoDisturbUsersFromServer isEqualToString:call.method]) { - [self getNoDisturbUsersFromServer:call.arguments - channelName:call.method - result:result]; } else if ([ChatEnablePush isEqualToString:call.method]) { [self enablePush:call.arguments channelName:call.method @@ -76,6 +60,14 @@ - (void)handleMethodCall:(FlutterMethodCall*)call [self getNoPushGroups:call.arguments channelName:call.method result:result]; + } else if ([ChatUpdateUserPushService isEqualToString:call.method]){ + [self updateUserPushService:call.arguments + channelName:call.method + result:result]; + } else if ([ChatGetNoPushUsers isEqualToString:call.method]){ + [self getNoPushUsers:call.arguments + channelName:call.method + result:result]; } else{ [super handleMethodCall:call result:result]; @@ -123,33 +115,6 @@ - (void)updatePushNickname:(NSDictionary *)param } -- (void)setImPushNoDisturb:(NSDictionary *)param - channelName:(NSString *)aChannelName - result:(FlutterResult)result { - __weak typeof(self) weakSelf = self; - - bool noDisturb = [param[@"noDisturb"] boolValue]; - int startTime = [param[@"startTime"] intValue]; - int endTime = [param[@"endTime"] intValue]; - - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - EMError *aError = nil; - if (noDisturb) { - aError = [EMClient.sharedClient.pushManager disableOfflinePushStart:startTime end:endTime]; - }else { - aError = [EMClient.sharedClient.pushManager enableOfflinePush]; - } - - dispatch_async(dispatch_get_main_queue(), ^{ - [weakSelf wrapperCallBack:result - channelName:aChannelName - error:aError - object:@(!aError)]; - }); - }); - - -} - (void)updateImPushStyle:(NSDictionary *)param channelName:(NSString *)aChannelName @@ -187,61 +152,6 @@ - (void)updateGroupPushService:(NSDictionary *)param }]; } -- (void)getNoDisturbGroups:(NSDictionary *)param - channelName:(NSString *)aChannelName - result:(FlutterResult)result { - __weak typeof(self) weakSelf = self; - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - EMError *aError = nil; - [EMClient.sharedClient.pushManager getPushOptionsFromServerWithError:&aError]; - NSArray *list = [EMClient.sharedClient.pushManager noPushGroups]; - dispatch_async(dispatch_get_main_queue(), ^{ - [weakSelf wrapperCallBack:result - channelName:aChannelName - error:aError - object:list]; - }); - }); -} - -- (void)setNoDisturbUsers:(NSDictionary *)param - channelName:(NSString *)aChannelName - result:(FlutterResult)result { - __weak typeof(self) weakSelf = self; - NSArray *members = param[@"members"]; - BOOL disablePush = [param[@"disable"] boolValue]; - [EMClient.sharedClient.pushManager updatePushServiceForUsers:members - disablePush:disablePush - completion:^(EMError * _Nonnull aError) - { - [EMClient.sharedClient.pushManager updatePushServiceForUsers:members - disablePush:disablePush - completion:^(EMError * _Nonnull aError) - { - [weakSelf wrapperCallBack:result - channelName:aChannelName - error:aError - object:nil]; - }]; - }]; -} - -- (void)getNoDisturbUsersFromServer:(NSDictionary *)param - channelName:(NSString *)aChannelName - result:(FlutterResult)result { - __weak typeof(self) weakSelf = self; - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - EMError *aError = nil; - [EMClient.sharedClient.pushManager getPushOptionsFromServerWithError:&aError]; - NSArray *list = [EMClient.sharedClient.pushManager noPushUIds]; - dispatch_async(dispatch_get_main_queue(), ^{ - [weakSelf wrapperCallBack:result - channelName:aChannelName - error:aError - object:list]; - }); - }); -} - (void)bindDeviceToken:(NSDictionary *)param channelName:(NSString *)aChannelName @@ -307,4 +217,35 @@ - (void)getNoPushGroups:(NSDictionary *)param }); } + +- (void)updateUserPushService:(NSDictionary *)param + channelName:(NSString *)aChannelName + result:(FlutterResult)result { + __weak typeof(self) weakSelf = self; + NSArray *userIds = param[@"user_ids"]; + bool noPush = [param[@"noPush"] boolValue]; + + [EMClient.sharedClient.pushManager updatePushServiceForUsers:userIds disablePush:noPush completion:^(EMError * _Nonnull aError) { + [weakSelf wrapperCallBack:result + channelName:aChannelName + error:aError + object:nil]; + }]; +} + +- (void)getNoPushUsers:(NSDictionary *)param + channelName:(NSString *)aChannelName + result:(FlutterResult)result { + __weak typeof(self) weakSelf = self; + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + NSArray* userIds = [EMClient.sharedClient.pushManager noPushUIds]; + dispatch_async(dispatch_get_main_queue(), ^{ + [weakSelf wrapperCallBack:result + channelName:aChannelName + error:nil + object:userIds]; + }); + }); +} + @end diff --git a/ios/Classes/EMSDKMethod.h b/ios/Classes/EMSDKMethod.h index 205d6593..700f1a12 100644 --- a/ios/Classes/EMSDKMethod.h +++ b/ios/Classes/EMSDKMethod.h @@ -207,19 +207,18 @@ static NSString *const ChatOnGroupChanged = @"onGroupChanged"; #pragma mark - EMPushManagerWrapper static NSString *const ChatGetImPushConfig = @"getImPushConfig"; static NSString *const ChatGetImPushConfigFromServer = @"getImPushConfigFromServer"; -static NSString *const ChatUpdatePushNickname = @"updatePushNickname"; -static NSString *const ChatBindDeviceToken = @"updateAPNsPushToken"; static NSString *const ChatEnablePush = @"enableOfflinePush"; static NSString *const ChatDisablePush = @"disableOfflinePush"; +static NSString *const ChatUpdateImPushStyle = @"updateImPushStyle"; +static NSString *const ChatUpdatePushNickname = @"updatePushNickname"; + +static NSString *const ChatUpdateGroupPushService = @"updateGroupPushService"; static NSString *const ChatGetNoPushGroups = @"getNoPushGroups"; +static NSString *const ChatUpdateUserPushService = @"updateUserPushService"; +static NSString *const ChatGetNoPushUsers = @"getNoPushUsers"; -static NSString *const ChatImPushNoDisturb = @"imPushNoDisturb"; -static NSString *const ChatUpdateImPushStyle = @"updateImPushStyle"; -static NSString *const ChatUpdateGroupPushService = @"updateGroupPushService"; -static NSString *const ChatGetNoDisturbGroups = @"getNoDisturbGroups"; -static NSString *const ChatSetNoDisturbUsers = @"setNoDisturbUsers"; -static NSString *const ChatGetNoDisturbUsersFromServer = @"getNoDisturbUsersFromServer"; +static NSString *const ChatBindDeviceToken = @"updateAPNsPushToken"; #pragma mark - EMUserInfoManagerWrapper static NSString *const ChatUpdateOwnUserInfo = @"updateOwnUserInfo"; diff --git a/lib/src/em_chat_manager.dart b/lib/src/em_chat_manager.dart index e48e0b98..c1af025e 100644 --- a/lib/src/em_chat_manager.dart +++ b/lib/src/em_chat_manager.dart @@ -195,12 +195,11 @@ class EMChatManager { /// /// **Throws** A description of the exception. See {@link EMError}. /// - Future recallMessage(String messageId) async { + Future recallMessage(String messageId) async { Map req = {"msg_id": messageId}; Map result = await _channel.invokeMethod(ChatMethodKeys.recallMessage, req); try { EMError.hasErrorFromResult(result); - return result.boolValue(ChatMethodKeys.recallMessage); } on EMError catch (e) { throw e; } diff --git a/lib/src/em_chat_room_manager.dart b/lib/src/em_chat_room_manager.dart index 63edbd24..0249c3f8 100644 --- a/lib/src/em_chat_room_manager.dart +++ b/lib/src/em_chat_room_manager.dart @@ -391,7 +391,7 @@ class EMChatRoomManager { /// /// **Throws** A description of the exception. See {@link EMError}. /// - Future> fetchChatRoomMembers( + Future> fetchChatRoomMembers( String roomId, { String cursor = '', int pageSize = 200, @@ -402,7 +402,7 @@ class EMChatRoomManager { await _channel.invokeMethod(ChatMethodKeys.fetchChatRoomMembers, req); try { EMError.hasErrorFromResult(result); - return EMCursorResult.fromJson( + return EMCursorResult.fromJson( result[ChatMethodKeys.fetchChatRoomMembers], dataItemCallback: (obj) => obj); } on EMError catch (e) { diff --git a/lib/src/em_group_manager.dart b/lib/src/em_group_manager.dart index 483f9cbf..a25cfd79 100644 --- a/lib/src/em_group_manager.dart +++ b/lib/src/em_group_manager.dart @@ -88,13 +88,13 @@ class EMGroupManager { /// /// Gets all groups of the current user from the server. /// - /// This method returns a group list which does not contain member information. If you want to update information of a group to include its member information, call {@link #getGroupSpecificationFromServer(String groupId)}. + /// This method returns a group list which does not contain member information. If you want to update information of a group to include its member information, call {@link #fetchGroupInfoFromServer(String groupId)}. /// /// **Return** The list of groups that the current user joins. /// /// **Throws** A description of the exception. See {@link EMError}. /// - Future> getJoinedGroupsFromServer({ + Future> fetchJoinedGroupsFromServer({ int pageSize = 200, int pageNum = 1, }) async { @@ -120,7 +120,7 @@ class EMGroupManager { /// /// **Throws** A description of the exception. See {@link EMError}. /// - Future> getPublicGroupsFromServer({ + Future> fetchPublicGroupsFromServer({ int pageSize = 200, String? cursor, }) async { @@ -192,7 +192,7 @@ class EMGroupManager { /// /// Gets the group information from the server. /// - /// This method does not get member information. If member information is required, call {@link #getGroupMemberListFromServer(String, int?, String?)}. + /// This method does not get member information. If member information is required, call {@link #fetchMemberListFromServer(String, int?, String?)}. /// /// Param [groupId] The group ID. /// @@ -200,7 +200,7 @@ class EMGroupManager { /// /// **Throws** A description of the exception. See {@link EMError}. /// - Future getGroupSpecificationFromServer(String groupId) async { + Future fetchGroupInfoFromServer(String groupId) async { Map req = {'groupId': groupId}; Map result = await _channel.invokeMethod( ChatMethodKeys.getGroupSpecificationFromServer, req); @@ -218,8 +218,8 @@ class EMGroupManager { /// /// For example: /// ```dart - /// EMCursorResult result = await EMClient.getInstance.groupManager.getGroupMemberListFromServer(groupId); // search 1 - /// result = await EMClient.getInstance.groupManager.getGroupMemberListFromServer(groupId, cursor: result.cursor); // search 2 + /// EMCursorResult result = await EMClient.getInstance.groupManager.fetchMemberListFromServer(groupId); // search 1 + /// result = await EMClient.getInstance.groupManager.fetchMemberListFromServer(groupId, cursor: result.cursor); // search 2 /// ``` /// /// Param [groupId] The group ID. @@ -233,7 +233,7 @@ class EMGroupManager { /// /// **Throws** A description of the exception. See {@link EMError}. /// - Future> getGroupMemberListFromServer( + Future> fetchMemberListFromServer( String groupId, { int pageSize = 200, String? cursor, @@ -272,7 +272,7 @@ class EMGroupManager { /// /// **Throws** A description of the exception. See {@link EMError}. /// - Future?> getBlockListFromServer( + Future?> fetchBlockListFromServer( String groupId, { int pageSize = 200, int pageNum = 1, @@ -303,7 +303,7 @@ class EMGroupManager { /// /// **Throws** A description of the exception. See {@link EMError}. /// - Future?> getMuteListFromServer( + Future?> fetchMuteListFromServer( String groupId, { int pageSize = 200, int pageNum = 1, @@ -330,7 +330,7 @@ class EMGroupManager { /// /// **Throws** A description of the exception. See {@link EMError}. /// - Future?> getWhiteListFromServer(String groupId) async { + Future?> fetchWhiteListFromServer(String groupId) async { Map req = {'groupId': groupId}; Map result = await _channel.invokeMethod( ChatMethodKeys.getGroupWhiteListFromServer, req); @@ -376,7 +376,7 @@ class EMGroupManager { /// /// **Throws** A description of the exception. See {@link EMError}. /// - Future?> getGroupFileListFromServer( + Future> fetchGroupFileListFromServer( String groupId, { int pageSize = 200, int pageNum = 1, @@ -407,7 +407,7 @@ class EMGroupManager { /// /// **Throws** A description of the exception. See {@link EMError}. /// - Future getGroupAnnouncementFromServer(String groupId) async { + Future fetchAnnouncementFromServer(String groupId) async { Map req = {'groupId': groupId}; Map result = await _channel.invokeMethod( ChatMethodKeys.getGroupAnnouncementFromServer, req); @@ -697,7 +697,7 @@ class EMGroupManager { /// /// **Throws** A description of the exception. See {@link EMError}. /// - Future changeOwner( + Future changeOwner( String groupId, String newOwner, ) async { @@ -706,7 +706,6 @@ class EMGroupManager { await _channel.invokeMethod(ChatMethodKeys.updateGroupOwner, req); try { EMError.hasErrorFromResult(result); - return EMGroup.fromJson(result[ChatMethodKeys.updateGroupOwner]); } on EMError catch (e) { throw e; } @@ -725,7 +724,7 @@ class EMGroupManager { /// /// **Throws** A description of the exception. See {@link EMError}. /// - Future addAdmin( + Future addAdmin( String groupId, String memberId, ) async { @@ -733,7 +732,6 @@ class EMGroupManager { Map result = await _channel.invokeMethod(ChatMethodKeys.addAdmin, req); try { EMError.hasErrorFromResult(result); - return EMGroup.fromJson(result[ChatMethodKeys.addAdmin]); } on EMError catch (e) { throw e; } @@ -752,7 +750,7 @@ class EMGroupManager { /// /// **Throws** A description of the exception. See {@link EMError}. /// - Future removeAdmin( + Future removeAdmin( String groupId, String adminId, ) async { @@ -760,7 +758,6 @@ class EMGroupManager { Map result = await _channel.invokeMethod(ChatMethodKeys.removeAdmin, req); try { EMError.hasErrorFromResult(result); - return EMGroup.fromJson(result[ChatMethodKeys.removeAdmin]); } on EMError catch (e) { throw e; } @@ -777,11 +774,9 @@ class EMGroupManager { /// /// Param [duration] The mute duration in milliseconds. /// - /// **Return** The updated group instance. - /// /// **Throws** A description of the exception. See {@link EMError}. /// - Future muteMembers( + Future muteMembers( String groupId, List members, { int duration = -1, @@ -790,7 +785,6 @@ class EMGroupManager { Map result = await _channel.invokeMethod(ChatMethodKeys.muteMembers, req); try { EMError.hasErrorFromResult(result); - return EMGroup.fromJson(result[ChatMethodKeys.muteMembers]); } on EMError catch (e) { throw e; } @@ -998,7 +992,7 @@ class EMGroupManager { /// /// **Throws** A description of the exception. See {@link EMError}. /// - Future updateGroupAnnouncement( + Future updateGroupAnnouncement( String groupId, String announcement, ) async { @@ -1007,7 +1001,6 @@ class EMGroupManager { ChatMethodKeys.updateGroupAnnouncement, req); try { EMError.hasErrorFromResult(result); - return EMGroup.fromJson(result[ChatMethodKeys.updateGroupAnnouncement]); } on EMError catch (e) { throw e; } @@ -1044,7 +1037,7 @@ class EMGroupManager { /// For a group that requires no authentication,users can join it freely without obtaining permissions from the group owner. /// For a group that requires authentication, users need to wait for the group owner to agree before joining the group. For details, see {@link EMGroupStyle}. /// - ///Param [groupId] The group ID. + /// Param [groupId] The group ID. /// /// **Throws** A description of the exception. See {@link EMError}. /// @@ -1219,6 +1212,279 @@ class EMGroupManager { } } + /// + /// Gets the group information from the server. + /// + /// This method does not get member information. If member information is required, call {@link #fetchMemberListFromServer(String, int?, String?)}. + /// + /// Param [groupId] The group ID. + /// + /// **Return** The group instance. + /// + /// **Throws** A description of the exception. See {@link EMError}. + /// + @Deprecated("Switch to using fetchGroupInfoFromServer instead.") + Future getGroupSpecificationFromServer(String groupId) async { + Map req = {'groupId': groupId}; + Map result = await _channel.invokeMethod( + ChatMethodKeys.getGroupSpecificationFromServer, req); + try { + EMError.hasErrorFromResult(result); + return EMGroup.fromJson( + result[ChatMethodKeys.getGroupSpecificationFromServer]); + } on EMError catch (e) { + throw e; + } + } + + /// + /// Gets all groups of the current user from the server. + /// + /// This method returns a group list which does not contain member information. If you want to update information of a group to include its member information, call {@link #fetchGroupInfoFromServer(String groupId)}. + /// + /// **Return** The list of groups that the current user joins. + /// + /// **Throws** A description of the exception. See {@link EMError}. + /// + @Deprecated("Switch to using fetchJoinedGroupsFromServer instead.") + Future> getJoinedGroupsFromServer({ + int pageSize = 200, + int pageNum = 1, + }) async { + Map req = {'pageSize': pageSize, 'pageNum': pageNum}; + Map result = await _channel.invokeMethod( + ChatMethodKeys.getJoinedGroupsFromServer, req); + EMError.hasErrorFromResult(result); + List list = []; + result[ChatMethodKeys.getJoinedGroupsFromServer] + ?.forEach((element) => list.add(EMGroup.fromJson(element))); + return list; + } + + /// + /// Gets public groups from the server with pagination. + /// + /// Param [pageSize] The number of public groups per page. + /// + /// Param [cursor] The cursor position from which to start to get data next time. Sets the parameter as null for the first time. + /// + /// **Return** The result of {@link EMCursorResult}, including the cursor for getting data next time and the group list. + /// If `EMCursorResult.cursor` is an empty string (""), all data is fetched. + /// + /// **Throws** A description of the exception. See {@link EMError}. + /// + @Deprecated("Switch to using fetchPublicGroupsFromServer instead.") + Future> getPublicGroupsFromServer({ + int pageSize = 200, + String? cursor, + }) async { + Map req = {'pageSize': pageSize}; + req.setValueWithOutNull("cursor", cursor); + Map result = await _channel.invokeMethod( + ChatMethodKeys.getPublicGroupsFromServer, req); + try { + EMError.hasErrorFromResult(result); + return EMCursorResult.fromJson( + result[ChatMethodKeys.getPublicGroupsFromServer], + dataItemCallback: (value) { + return EMGroup.fromJson(value); + }); + } on EMError catch (e) { + throw e; + } + } + + /// + /// Gets the group block list from server with pagination. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// Param [pageSize] The number of groups per page. + /// + /// Param [pageNum] The page number, starting from 1. + /// + /// **Return** The group block list. + /// + /// **Throws** A description of the exception. See {@link EMError}. + /// + @Deprecated("Switch to using fetchBlockListFromServer instead.") + Future?> getBlockListFromServer( + String groupId, { + int pageSize = 200, + int pageNum = 1, + }) async { + Map req = {'groupId': groupId, 'pageNum': pageNum, 'pageSize': pageSize}; + Map result = await _channel.invokeMethod( + ChatMethodKeys.getGroupBlockListFromServer, req); + try { + EMError.hasErrorFromResult(result); + return result[ChatMethodKeys.getGroupBlockListFromServer]?.cast(); + } on EMError catch (e) { + throw e; + } + } + + /// + /// Gets the group announcement from the server. + /// + /// Group members can call this method. + /// + /// Param [groupId] The group ID. + /// + /// **Return** The group announcement. + /// + /// **Throws** A description of the exception. See {@link EMError}. + /// + @Deprecated("Switch to using fetchAnnouncementFromServer instead.") + Future getGroupAnnouncementFromServer(String groupId) async { + Map req = {'groupId': groupId}; + Map result = await _channel.invokeMethod( + ChatMethodKeys.getGroupAnnouncementFromServer, req); + try { + EMError.hasErrorFromResult(result); + return result[ChatMethodKeys.getGroupAnnouncementFromServer]; + } on EMError catch (e) { + throw e; + } + } + + /// + /// Gets the shared files of the group from the server. + /// + /// Param [groupId] The group ID. + /// + /// Param [pageSize] The number of shared files per page. + /// + /// Param [pageNum] The page number, starting from 1. + /// + /// **Return** The shared files. + /// + /// **Throws** A description of the exception. See {@link EMError}. + /// + @Deprecated("Switch to using fetchGroupFileListFromServer instead.") + Future?> getGroupFileListFromServer( + String groupId, { + int pageSize = 200, + int pageNum = 1, + }) async { + Map req = {'groupId': groupId, 'pageNum': pageNum, 'pageSize': pageSize}; + Map result = await _channel.invokeMethod( + ChatMethodKeys.getGroupFileListFromServer, req); + try { + EMError.hasErrorFromResult(result); + List list = []; + result[ChatMethodKeys.getGroupFileListFromServer]?.forEach((element) { + list.add(EMGroupSharedFile.fromJson(element)); + }); + return list; + } on EMError catch (e) { + throw e; + } + } + + /// + /// Gets the member list of the group with pagination. + /// + /// For example: + /// ```dart + /// EMCursorResult result = await EMClient.getInstance.groupManager.fetchMemberListFromServer(groupId); // search 1 + /// result = await EMClient.getInstance.groupManager.fetchMemberListFromServer(groupId, cursor: result.cursor); // search 2 + /// ``` + /// + /// Param [groupId] The group ID. + /// + /// Param [pageSize] The number of group members per page. + /// + /// Param [cursor] The cursor position from which to start to get data next time. Sets the parameter as null for the first time. + /// + /// **Return** The result of {@link EMCursorResult}, including the cursor for getting data next time and the group member list. + /// If `EMCursorResult.cursor` is an empty string (""), all data is fetched. + /// + /// **Throws** A description of the exception. See {@link EMError}. + /// + @Deprecated("Switch to using fetchMemberListFromServer instead.") + Future> getGroupMemberListFromServer( + String groupId, { + int pageSize = 200, + String? cursor, + }) async { + Map req = { + 'groupId': groupId, + 'pageSize': pageSize, + }; + req.setValueWithOutNull("cursor", cursor); + Map result = await _channel.invokeMethod( + ChatMethodKeys.getGroupMemberListFromServer, + req, + ); + try { + EMError.hasErrorFromResult(result); + return EMCursorResult.fromJson( + result[ChatMethodKeys.getGroupMemberListFromServer], + dataItemCallback: (value) => value); + } on EMError catch (e) { + throw e; + } + } + + /// + /// Gets the mute list of the group from the server. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// Param [pageSize] The number of muted members per page. + /// + /// Param [pageNum] The page number, starting from 1. + /// + /// **Return** The group mute list. + /// + /// **Throws** A description of the exception. See {@link EMError}. + /// + @Deprecated("Switch to using fetchMuteListFromServer instead.") + Future?> getMuteListFromServer( + String groupId, { + int pageSize = 200, + int pageNum = 1, + }) async { + Map req = {'groupId': groupId, 'pageNum': pageNum, 'pageSize': pageSize}; + Map result = await _channel.invokeMethod( + ChatMethodKeys.getGroupMuteListFromServer, req); + try { + EMError.hasErrorFromResult(result); + return result[ChatMethodKeys.getGroupMuteListFromServer]?.cast(); + } on EMError catch (e) { + throw e; + } + } + + /// + /// Gets the allow list of the group from the server. + /// + /// Only the group owner or admin can call this method. + /// + /// Param [groupId] The group ID. + /// + /// **Return** The allow list of the group. + /// + /// **Throws** A description of the exception. See {@link EMError}. + /// + @Deprecated("Switch to using fetchWhiteListFromServer instead.") + Future?> getWhiteListFromServer(String groupId) async { + Map req = {'groupId': groupId}; + Map result = await _channel.invokeMethod( + ChatMethodKeys.getGroupWhiteListFromServer, req); + try { + EMError.hasErrorFromResult(result); + return result[ChatMethodKeys.getGroupWhiteListFromServer]?.cast(); + } on EMError catch (e) { + throw e; + } + } + Future _onGroupChanged(Map? map) async { for (EMGroupEventListener listener in _groupChangeListeners) { var type = map!['type']; diff --git a/lib/src/em_push_manager.dart b/lib/src/em_push_manager.dart index 69b9d399..a211a845 100644 --- a/lib/src/em_push_manager.dart +++ b/lib/src/em_push_manager.dart @@ -36,7 +36,7 @@ class EMPushManager { } /// Gets the push configurations from the server. - Future getPushConfigsFromServer() async { + Future fetchPushConfigsFromServer() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getImPushConfigFromServer); try { @@ -110,6 +110,31 @@ class EMPushManager { } } + /// + /// Sets whether to turn on or turn off the push notification for the the specified users. + /// + /// [userIds] The list of users to be set. + /// + /// [enablePush] enable push notification. + /// `true`: Turns on the notification; + /// `false`: Turns off the notification; + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future updatePushServiceFroUsers({ + required List userIds, + required bool enablePush, + }) async { + Map req = {'noPush': !enablePush, 'user_ids': userIds}; + Map result = + await _channel.invokeMethod(ChatMethodKeys.updateUserPushService, req); + try { + EMError.hasErrorFromResult(result); + } on EMError catch (e) { + throw e; + } + } + /// /// Gets the list of groups which have blocked the push notification. /// @@ -117,7 +142,7 @@ class EMPushManager { /// /// **Throws** A description of the issue that caused this exception. See {@link EMError} /// - Future?> getNoPushGroupsFromCache() async { + Future> getNoPushGroupsFromCache() async { Map result = await _channel.invokeMethod(ChatMethodKeys.getNoPushGroups); List list = []; if (result.containsKey(ChatMethodKeys.getNoPushGroups)) { @@ -126,6 +151,22 @@ class EMPushManager { return list; } + /// + /// Gets the list of users which have blocked the push notification. + /// + /// **return** The list of user that blocked the push notification. + /// + /// **Throws** A description of the issue that caused this exception. See {@link EMError} + /// + Future> getNoPushUsersFromCache() async { + Map result = await _channel.invokeMethod(ChatMethodKeys.getNoPushUsers); + List list = []; + if (result.containsKey(ChatMethodKeys.getNoPushUsers)) { + list = result[ChatMethodKeys.getNoPushUsers]?.cast(); + } + return list; + } + /// /// Updates the push display nickname of the current user. /// @@ -251,4 +292,18 @@ class EMPushManager { throw e; } } + + /// Gets the push configurations from the server. + @Deprecated('use - fetchPushConfigsFromServer method instead.') + Future getPushConfigsFromServer() async { + Map result = + await _channel.invokeMethod(ChatMethodKeys.getImPushConfigFromServer); + try { + EMError.hasErrorFromResult(result); + return EMPushConfigs.fromJson( + result[ChatMethodKeys.getImPushConfigFromServer]); + } on EMError catch (e) { + throw e; + } + } } diff --git a/lib/src/internal/chat_method_keys.dart b/lib/src/internal/chat_method_keys.dart index e847cd83..c04f30ec 100644 --- a/lib/src/internal/chat_method_keys.dart +++ b/lib/src/internal/chat_method_keys.dart @@ -213,22 +213,19 @@ class ChatMethodKeys { /// EMPushManager static const String getImPushConfig = "getImPushConfig"; static const String getImPushConfigFromServer = "getImPushConfigFromServer"; - static const String updatePushNickname = "updatePushNickname"; - static const String updateHMSPushToken = "updateHMSPushToken"; - static const String updateFCMPushToken = "updateFCMPushToken"; - static const String updateAPNsPushToken = "updateAPNsPushToken"; static const String enableOfflinePush = "enableOfflinePush"; static const String disableOfflinePush = "disableOfflinePush"; - static const String getNoPushGroups = "getNoPushGroups"; - - /// ImPushConfig - static const String imPushNoDisturb = "imPushNoDisturb"; static const String updateImPushStyle = "updateImPushStyle"; + static const String updatePushNickname = "updatePushNickname"; + static const String updateGroupPushService = "updateGroupPushService"; - static const String getNoDisturbGroups = "getNoDisturbGroups"; - static const String setNoDisturbUsers = "setNoDisturbUsers"; - static const String getNoDisturbUsersFromServer = - "getNoDisturbUsersFromServer"; + static const String getNoPushGroups = "getNoPushGroups"; + static const String updateUserPushService = "updateUserPushService"; + static const String getNoPushUsers = "getNoPushUsers"; + + static const String updateHMSPushToken = "updateHMSPushToken"; + static const String updateFCMPushToken = "updateFCMPushToken"; + static const String updateAPNsPushToken = "updateAPNsPushToken"; /// EMUserInfoManager methods static const String updateOwnUserInfo = "updateOwnUserInfo"; diff --git a/lib/src/models/em_cursor_result.dart b/lib/src/models/em_cursor_result.dart index e85aa49f..d9a50c8f 100644 --- a/lib/src/models/em_cursor_result.dart +++ b/lib/src/models/em_cursor_result.dart @@ -6,7 +6,7 @@ typedef CursorResultCallback = Object Function(dynamic obj); /// /// ```dart /// String? cursor; -/// EMCursorResult result = await EMClient.getInstance.groupManager.getPublicGroupsFromServer(pageSize: 10, cursor: cursor); +/// EMCursorResult result = await EMClient.getInstance.groupManager.fetchPublicGroupsFromServer(pageSize: 10, cursor: cursor); /// List? group = result.data; /// cursor = result.cursor; /// ``` diff --git a/lib/src/models/em_group.dart b/lib/src/models/em_group.dart index 430006ba..3f25d019 100644 --- a/lib/src/models/em_group.dart +++ b/lib/src/models/em_group.dart @@ -36,7 +36,7 @@ class EMGroup { /// Gets the group name. /// /// **Note** - /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupSpecificationFromServer(String groupId)} before calling this method. + /// To get the correct value, ensure that you call {@link EMGroupManager#fetchGroupInfoFromServer(String groupId)} before calling this method. /// String? get name => _name; @@ -44,7 +44,7 @@ class EMGroup { /// Gets the group description. /// /// **Note** - /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupSpecificationFromServer(String groupId)} before calling this method. + /// To get the correct value, ensure that you call {@link EMGroupManager#fetchGroupInfoFromServer(String groupId)} before calling this method. /// String? get description => _description; @@ -52,7 +52,7 @@ class EMGroup { /// Gets the user ID of the group owner. /// /// **Note** - /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupSpecificationFromServer(String groupId)} before calling this method. + /// To get the correct value, ensure that you call {@link EMGroupManager#fetchGroupInfoFromServer(String groupId)} before calling this method. /// String? get owner => _owner; @@ -63,7 +63,7 @@ class EMGroup { /// Gets the member count of the group. /// /// **Note** - /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupSpecificationFromServer(String groupId)} before calling this method. + /// To get the correct value, ensure that you call {@link EMGroupManager#fetchGroupInfoFromServer(String groupId)} before calling this method. /// int? get memberCount => _memberCount; @@ -71,7 +71,7 @@ class EMGroup { /// Gets the member list of the group. /// /// **Note** - /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupMemberListFromServer(String, int?, String?)} before calling this method. + /// To get the correct value, ensure that you call {@link EMGroupManager#fetchMemberListFromServer(String, int?, String?)} before calling this method. /// List? get memberList => _memberList; @@ -79,7 +79,7 @@ class EMGroup { /// Gets the admin list of the group. /// /// **Note** - /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupSpecificationFromServer(String)} before calling this method. + /// To get the correct value, ensure that you call {@link EMGroupManager#fetchGroupInfoFromServer(String)} before calling this method. /// List? get adminList => _adminList; @@ -89,7 +89,7 @@ class EMGroup { /// If no block list is found from the server, the return may be empty. /// /// **Note** - /// To get the correct value, ensure that you call {@link EMGroupManager#getBlockListFromServer(String, int?, int?)} before calling this method. + /// To get the correct value, ensure that you call {@link EMGroupManager#fetchBlockListFromServer(String, int?, int?)} before calling this method. /// List? get blockList => _blockList; @@ -97,7 +97,7 @@ class EMGroup { /// Gets the mute list of the group. /// /// **Note** - /// To get the correct value, ensure that you call {@link EMGroupManager#getMuteListFromServer(String, int?, int?)} before calling this method. + /// To get the correct value, ensure that you call {@link EMGroupManager#fetchMuteListFromServer(String, int?, int?)} before calling this method. /// List? get muteList => _muteList; @@ -108,7 +108,7 @@ class EMGroup { /// Gets whether the group message is blocked. /// /// **Note** - /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupSpecificationFromServer(String)} before calling this method. + /// To get the correct value, ensure that you call {@link EMGroupManager#fetchGroupInfoFromServer(String)} before calling this method. /// bool? get messageBlocked => _messageBlocked; @@ -116,7 +116,7 @@ class EMGroup { /// Gets Whether all members are muted. /// /// **Note** - /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupSpecificationFromServer(String)} before calling this method. + /// To get the correct value, ensure that you call {@link EMGroupManager#fetchGroupInfoFromServer(String)} before calling this method. /// bool? get isAllMemberMuted => _isAllMemberMuted; @@ -128,7 +128,7 @@ class EMGroup { /// Gets the current user's role in group. /// /// **Note** - /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupSpecificationFromServer(String)} before calling this method. + /// To get the correct value, ensure that you call {@link EMGroupManager#fetchGroupInfoFromServer(String)} before calling this method. /// EMGroupPermissionType? get permissionType => _permissionType; @@ -136,7 +136,7 @@ class EMGroup { /// Gets the maximum number of group members allowed in a group. The parameter is set when the group is created. /// /// **Note** - /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupSpecificationFromServer(String)} before calling this method. + /// To get the correct value, ensure that you call {@link EMGroupManager#fetchGroupInfoFromServer(String)} before calling this method. /// int? get maxUserCount => _options?.maxCount; @@ -170,7 +170,7 @@ class EMGroup { /// Checks whether a group member is allowed to invite other users to join the group. /// /// **Note** - /// To get the correct value, ensure that you call {@link EMGroupManager#getGroupSpecificationFromServer(String)} before calling this method. + /// To get the correct value, ensure that you call {@link EMGroupManager#fetchGroupInfoFromServer(String)} before calling this method. /// /// **Return** /// - `true`: Yes; diff --git a/lib/src/models/em_group_shared_file.dart b/lib/src/models/em_group_shared_file.dart index 73e816a5..d86d3e37 100644 --- a/lib/src/models/em_group_shared_file.dart +++ b/lib/src/models/em_group_shared_file.dart @@ -3,10 +3,10 @@ import '../tools/em_extension.dart'; /// /// The EMGroupSharedFile class, which manages the chat group shared files. /// -/// To get the information of the chat group shared file, call {@link EMGroupManager#getGroupFileListFromServer(String, int?, int?)}. +/// To get the information of the chat group shared file, call {@link EMGroupManager#fetchGroupFileListFromServer(String, int?, int?)}. /// /// ```dart -/// List? list = await EMClient.getInstance.groupManager.getGroupFileListFromServer(groupId); +/// List? list = await EMClient.getInstance.groupManager.fetchGroupFileListFromServer(groupId); /// ``` class EMGroupSharedFile { EMGroupSharedFile._private(); diff --git a/lib/src/models/em_push_configs.dart b/lib/src/models/em_push_configs.dart index ecb93533..1561e166 100644 --- a/lib/src/models/em_push_configs.dart +++ b/lib/src/models/em_push_configs.dart @@ -50,7 +50,6 @@ class EMPushConfigs { int? _noDisturbEndHour; // ignore: unused_field List? _noDisturbGroups = []; - @Deprecated("Switch to using DisplayStyle instead") /// @nodoc factory EMPushConfigs.fromJson(Map map) { @@ -84,11 +83,10 @@ extension EMPushConfigsExtension on EMPushConfigs { 'startTime': startTime, 'endTime': endTime }; - Map result = - await _channel.invokeMethod(ChatMethodKeys.imPushNoDisturb, req); + Map result = await _channel.invokeMethod("imPushNoDisturb", req); try { EMError.hasErrorFromResult(result); - bool success = result.boolValue(ChatMethodKeys.imPushNoDisturb); + bool success = result.boolValue("imPushNoDisturb"); if (success) { _noDisturb = isNoDisturb; _noDisturbStartHour = startTime; @@ -128,11 +126,10 @@ extension EMPushConfigsExtension on EMPushConfigs { @Deprecated("Switch to using EMPushManager#getNoPushGroups instead") Future?> noDisturbGroupsFromServer() async { - Map result = await _channel.invokeMethod(ChatMethodKeys.getNoDisturbGroups); + Map result = await _channel.invokeMethod("getNoDisturbGroups"); try { EMError.hasErrorFromResult(result); - _noDisturbGroups = - result[ChatMethodKeys.getNoDisturbGroups]?.cast(); + _noDisturbGroups = result["getNoDisturbGroups"]?.cast(); return _noDisturbGroups; } on EMError catch (e) { throw e; From 9a4deee0c1e2b46bdf0a58cd0a1d0db4bb4c9aa8 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Thu, 14 Apr 2022 12:32:28 +0800 Subject: [PATCH 55/56] add api referance. --- lib/src/models/em_push_configs.dart | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/src/models/em_push_configs.dart b/lib/src/models/em_push_configs.dart index 1561e166..8aaca7ef 100644 --- a/lib/src/models/em_push_configs.dart +++ b/lib/src/models/em_push_configs.dart @@ -6,7 +6,7 @@ import 'em_chat_enums.dart'; import 'em_error.dart'; import '../em_push_manager.dart'; -/// The push configuration information class. +/// The push configuration class. class EMPushConfigs { EMPushConfigs._private({ this.displayStyle = DisplayStyle.Simple, @@ -16,27 +16,25 @@ class EMPushConfigs { }); /// - /// Gets the offline push display type. - /// The offline push display type. + /// The display type of push notifications. /// final DisplayStyle displayStyle; /// - /// Gets whether to enable offline push without disturbing. + /// Whether to enable the do-not-disturb mode for push notifications. + /// - `true`: Yes. + /// - `false`: No. /// Sets it by {@link EMPushManager#disableOfflinePush(int, int)}. - /// Whether to enable offline push without disturbing. /// final bool noDisturb; /// - /// Gets the start hour of the offline push without disturbing. - /// The start hour of the offline push without disturbing. + /// The start hour of the do-not-disturb mode for push notifications. /// final int noDisturbStartHour; /// - /// Gets the end hour of the offline push without disturbing. - /// The end hour of the offline push without disturbing. + /// The end hour of the do-not-disturb mode for push notifications. /// final int noDisturbEndHour; From 6c95aeee496b53172e9a1ee9095fce323deffcf1 Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Thu, 14 Apr 2022 14:07:43 +0800 Subject: [PATCH 56/56] update change log. --- CHANGELOG.md | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 558640a2..b9f21e47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,23 @@ ## NEXT +## 3.9.0 + +- 增加单人推送免打扰接口; + +- 增加api referance; + +- 增加renewToken api; + +- 修改消息callback方式; + +- iOS移除自动绑定deviceToken,如需使用,需要在iOS端单独增加; + +- android移除多余权限; + +- 修改已知bug; + ## 3.8.9 + - 增加单聊消息免打扰; - 去除不必要的信息收集; - 修复安卓某些场景下数据库损坏导致崩溃; @@ -14,17 +31,15 @@ - 默认使用https; - 优化登录速度; - ## 3.8.3+9 -- 将设置推送相关操作从EMPushConfigs中移到EMPushManager中; +- 将设置推送相关操作从EMPushConfigs中移到EMPushManager中; ## 3.8.3+8 - 修复ios使用token登录失败; - 修改Login方法和Logout方法返回值; - ## 3.8.3+6 - 修改EMImPushConfig为EMPushConfigs;