From feb738d55a386b9cbbc7b2c226457ad4620b1a94 Mon Sep 17 00:00:00 2001 From: Angus Date: Tue, 23 Jun 2020 22:00:22 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20=20=E8=A7=A3=E5=86=B3JMConversationI?= =?UTF-8?q?nfo=20toJson=E4=B8=8EfromJson=20=E4=B8=ADtarget=E4=B8=8Eextras?= =?UTF-8?q?=E4=B8=8D=E5=8C=B9=E9=85=8D=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/jmessage_flutter.dart | 2323 +++++++++++++++++++------------------ 1 file changed, 1199 insertions(+), 1124 deletions(-) diff --git a/lib/jmessage_flutter.dart b/lib/jmessage_flutter.dart index 74aea7d..9140311 100644 --- a/lib/jmessage_flutter.dart +++ b/lib/jmessage_flutter.dart @@ -1,21 +1,21 @@ import 'dart:async'; +import 'dart:convert'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:platform/platform.dart'; - final String flutterLog = "| JMessage | Flutter | "; -T getEnumFromString(Iterable values,String str) { - return values.firstWhere((f) => f.toString().split('.').last == str - , orElse: () => null); +T getEnumFromString(Iterable values, String str) { + return values.firstWhere((f) => f.toString().split('.').last == str, + orElse: () => null); } String getStringFromEnum(T) { if (T == null) { return null; } - + return T.toString().split('.').last; } @@ -25,7 +25,7 @@ class JMNotificationSettingsIOS { final bool alert; final bool badge; - const JMNotificationSettingsIOS ({ + const JMNotificationSettingsIOS({ this.sound = true, this.alert = true, this.badge = true, @@ -43,58 +43,79 @@ typedef JMCallback = void Function(dynamic a, dynamic b); // message 和 retractedMessage 可能是 JMTextMessage | JMVoiceMessage | JMImageMessage | JMFileMessage | JMEventMessage | JMCustomMessage; typedef JMMessageEventListener = void Function(dynamic message); -typedef JMSyncOfflineMessageListener = void Function(JMConversationInfo conversation, List messageArray); -typedef JMSyncRoamingMessageListener = void Function(JMConversationInfo conversation); -typedef JMLoginStateChangedListener = void Function(JMLoginStateChangedType type); +typedef JMSyncOfflineMessageListener = void Function( + JMConversationInfo conversation, List messageArray); +typedef JMSyncRoamingMessageListener = void Function( + JMConversationInfo conversation); +typedef JMLoginStateChangedListener = void Function( + JMLoginStateChangedType type); typedef JMContactNotifyListener = void Function(JMContactNotifyEvent event); typedef JMMessageRetractListener = void Function(dynamic retractedMessage); -typedef JMReceiveTransCommandListener = void Function(JMReceiveTransCommandEvent event); -typedef JMReceiveChatRoomMessageListener = void Function(List messageList); -typedef JMReceiveApplyJoinGroupApprovalListener = void Function(JMReceiveApplyJoinGroupApprovalEvent event); -typedef JMReceiveGroupAdminRejectListener = void Function(JMReceiveGroupAdminRejectEvent event); -typedef JMReceiveGroupAdminApprovalListener = void Function(JMReceiveGroupAdminApprovalEvent event); -typedef JMMessageReceiptStatusChangeListener = void Function(JMConversationInfo conversation, ListserverMessageIdList); +typedef JMReceiveTransCommandListener = void Function( + JMReceiveTransCommandEvent event); +typedef JMReceiveChatRoomMessageListener = void Function( + List messageList); +typedef JMReceiveApplyJoinGroupApprovalListener = void Function( + JMReceiveApplyJoinGroupApprovalEvent event); +typedef JMReceiveGroupAdminRejectListener = void Function( + JMReceiveGroupAdminRejectEvent event); +typedef JMReceiveGroupAdminApprovalListener = void Function( + JMReceiveGroupAdminApprovalEvent event); +typedef JMMessageReceiptStatusChangeListener = void Function( + JMConversationInfo conversation, List serverMessageIdList); class JMEventHandlers { + static final JMEventHandlers _instance = new JMEventHandlers._internal(); - static final JMEventHandlers _instance = new JMEventHandlers._internal(); - JMEventHandlers._internal(); - factory JMEventHandlers() => _instance; - - /// 收到:消息 - List receiveMessage = []; - /// 收到:离线消息 - List syncOfflineMessage = []; - /// 收到:漫游消息 - List syncRoamingMessage = []; - /// 收到:聊天室消息 - List receiveChatRoomMessage = []; - /// 收到:登录状态发生变更 - List loginStateChanged = []; - /// 收到:好友事件 - List contactNotify = []; - /// 收到:触发通知栏点击事件 - List clickMessageNotification = []; - /// 收到:透传命令 - List receiveTransCommand = []; - /// 收到:申请入群请求 - List receiveApplyJoinGroupApproval = []; - /// 收到:管理员拒绝事件 - List receiveGroupAdminReject = []; - /// 收到:管理员审核事件 - List receiveGroupAdminApproval = []; - /// 收到:消息已读回执事件 - List receiveReceiptStatusChangeEvents = []; - /// 收到:消息撤回事件 - List retractMessage = []; -} + JMEventHandlers._internal(); -class JmessageFlutter { + factory JMEventHandlers() => _instance; + + /// 收到:消息 + List receiveMessage = []; + + /// 收到:离线消息 + List syncOfflineMessage = []; + + /// 收到:漫游消息 + List syncRoamingMessage = []; + + /// 收到:聊天室消息 + List receiveChatRoomMessage = []; + + /// 收到:登录状态发生变更 + List loginStateChanged = []; + + /// 收到:好友事件 + List contactNotify = []; + + /// 收到:触发通知栏点击事件 + List clickMessageNotification = []; + + /// 收到:透传命令 + List receiveTransCommand = []; + + /// 收到:申请入群请求 + List receiveApplyJoinGroupApproval = + []; + /// 收到:管理员拒绝事件 + List receiveGroupAdminReject = []; + /// 收到:管理员审核事件 + List receiveGroupAdminApproval = []; + + /// 收到:消息已读回执事件 + List receiveReceiptStatusChangeEvents = + []; + + /// 收到:消息撤回事件 + List retractMessage = []; +} + +class JmessageFlutter { static final JmessageFlutter _instance = new JmessageFlutter.private( - const MethodChannel('jmessage_flutter'), - const LocalPlatform()); + const MethodChannel('jmessage_flutter'), const LocalPlatform()); factory JmessageFlutter() => _instance; @@ -103,211 +124,268 @@ class JmessageFlutter { final JMEventHandlers _eventHanders = new JMEventHandlers(); @visibleForTesting - JmessageFlutter.private(MethodChannel channel, Platform platform) - : _channel = channel, - _platform = platform; + JmessageFlutter.private(MethodChannel channel, Platform platform) + : _channel = channel, + _platform = platform; - // Events - addReceiveMessageListener(JMMessageEventListener callback) { - _eventHanders.receiveMessage.add(callback); - } - removeReceiveMessageListener(JMMessageEventListener callback) { - _eventHanders.receiveMessage.removeWhere((cb) => cb == callback); - } - addClickMessageNotificationListener(JMMessageEventListener callback) { - _eventHanders.clickMessageNotification.add(callback); - } - removeClickMessageNotificationListener(JMMessageEventListener callback) { - _eventHanders.clickMessageNotification.removeWhere((cb) => cb == callback); - } - addSyncOfflineMessageListener(JMSyncOfflineMessageListener callback) { - _eventHanders.syncOfflineMessage.add(callback); - } - removeSyncOfflineMessageListener(JMSyncOfflineMessageListener callback) { - _eventHanders.syncOfflineMessage.removeWhere((cb) => cb == callback); - } - addSyncRoamingMessageListener(JMSyncRoamingMessageListener callback) { - _eventHanders.syncRoamingMessage.add(callback); - } - removeSyncRoamingMessageListener(JMSyncRoamingMessageListener callback) { - _eventHanders.syncRoamingMessage.removeWhere((cb) => cb == callback); - } - addLoginStateChangedListener(JMLoginStateChangedListener callback) { - _eventHanders.loginStateChanged.add(callback); - } - removeLoginStateChangedListener(JMLoginStateChangedListener callback) { - _eventHanders.loginStateChanged.removeWhere((cb) => cb == callback); - } - addContactNotifyListener(JMContactNotifyListener callback) { - _eventHanders.contactNotify.add(callback); - } - removeContactNotifyListener(JMContactNotifyListener callback) { - _eventHanders.contactNotify.removeWhere((cb) => cb == callback); - } - addMessageRetractListener(JMMessageRetractListener callback) { - _eventHanders.retractMessage.add(callback); - } - removeMessageRetractListener(JMMessageRetractListener callback) { - _eventHanders.retractMessage.removeWhere((cb) => cb == callback); - } - addReceiveTransCommandListener(JMReceiveTransCommandListener callback) { - _eventHanders.receiveTransCommand.add(callback); - } - removeReceiveTransCommandListener(JMReceiveTransCommandListener callback) { - _eventHanders.receiveTransCommand.removeWhere((cb) => cb == callback); - } - addReceiveChatRoomMessageListener(JMReceiveChatRoomMessageListener callback) { - _eventHanders.receiveChatRoomMessage.add(callback); - } - removeReceiveChatRoomMessageListener(JMReceiveChatRoomMessageListener callback) { - _eventHanders.receiveChatRoomMessage.removeWhere((cb) => cb == callback); - } - addReceiveApplyJoinGroupApprovalListener(JMReceiveApplyJoinGroupApprovalListener callback) { - _eventHanders.receiveApplyJoinGroupApproval.add(callback); - } - removeReceiveApplyJoinGroupApprovalListener(JMReceiveApplyJoinGroupApprovalListener callback) { - _eventHanders.receiveApplyJoinGroupApproval.removeWhere((cb) => cb == callback); - } - addReceiveGroupAdminRejectListener(JMReceiveGroupAdminRejectListener callback) { - _eventHanders.receiveGroupAdminReject.add(callback); - } - removeReceiveGroupAdminRejectListener(JMReceiveGroupAdminRejectListener callback) { - _eventHanders.receiveGroupAdminReject.removeWhere((cb) => cb == callback); - } - addReceiveGroupAdminApprovalListener(JMReceiveGroupAdminApprovalListener callback) { - _eventHanders.receiveGroupAdminApproval.add(callback); - } - removeReceiveGroupAdminApprovalListener(JMReceiveGroupAdminApprovalListener callback) { - _eventHanders.receiveGroupAdminApproval.removeWhere((cb) => cb == callback); - } - addReceiveMessageReceiptStatusChangelistener(JMMessageReceiptStatusChangeListener callback) { - _eventHanders.receiveReceiptStatusChangeEvents.add(callback); - } - removeMessageReceiptStatusChangelistener(JMMessageReceiptStatusChangeListener callback) { - _eventHanders.receiveReceiptStatusChangeEvents.removeWhere((cb) => cb == callback); - } + // Events + addReceiveMessageListener(JMMessageEventListener callback) { + _eventHanders.receiveMessage.add(callback); + } - Future get platformVersion async { - final String version = await _channel.invokeMethod('getPlatformVersion'); - return version; - } - - Future _handleMethod(MethodCall call) async { - print("handleMethod method = ${call.method}"); - switch (call.method) { - case 'onReceiveMessage': - for (JMMessageEventListener cb in _eventHanders.receiveMessage) { - cb(JMNormalMessage.generateMessageFromJson(call.arguments.cast())); - } - break; - case 'onRetractMessage': - for (JMMessageRetractListener cb in _eventHanders.retractMessage) { - cb(JMNormalMessage.generateMessageFromJson(call.arguments.cast()['retractedMessage'])); - } - break; - case 'onLoginStateChanged': - for (JMLoginStateChangedListener cb in _eventHanders.loginStateChanged) { - String type = call.arguments.cast()['type']; - JMLoginStateChangedType loginState = getEnumFromString(JMLoginStateChangedType.values, type); - cb(loginState); - } - break; - case 'onSyncOfflineMessage': - for (JMSyncOfflineMessageListener cb in _eventHanders.syncOfflineMessage) { - Map param = call.arguments.cast(); - List msgDicArray = param['messageArray']; -// List msgs = msgDicArray.map((json) => JMNormalMessage.generateMessageFromJson(json)).toList(); + removeReceiveMessageListener(JMMessageEventListener callback) { + _eventHanders.receiveMessage.removeWhere((cb) => cb == callback); + } - List msgs = []; - for (Map json in msgDicArray) { - print("offline message: ${json.toString()}"); - JMNormalMessage normsg = JMNormalMessage.generateMessageFromJson(json); - msgs.add(normsg); - } + addClickMessageNotificationListener(JMMessageEventListener callback) { + _eventHanders.clickMessageNotification.add(callback); + } - cb(JMConversationInfo.fromJson(param['conversation']), msgs); - } - break; - case 'onSyncRoamingMessage': - for (JMSyncRoamingMessageListener cb in _eventHanders.syncRoamingMessage) { - Map json = call.arguments.cast(); - cb(JMConversationInfo.fromJson(json)); - } - break; - case 'onContactNotify': - for (JMContactNotifyListener cb in _eventHanders.contactNotify) { - Map json = call.arguments.cast(); - cb(JMContactNotifyEvent.fromJson(json)); - } - break; - case 'onClickMessageNotification': - for (JMMessageEventListener cb in _eventHanders.clickMessageNotification) { - // TODO: only work in android - Map json = call.arguments.cast(); - cb(JMNormalMessage.generateMessageFromJson(json)); - } - break; - case 'onReceiveTransCommand': - for (JMReceiveTransCommandListener cb in _eventHanders.receiveTransCommand) { - Map json = call.arguments.cast(); - JMReceiveTransCommandEvent ev = JMReceiveTransCommandEvent.fromJson(json); - cb(ev); - } - break; - case 'onReceiveChatRoomMessage': - for (JMReceiveChatRoomMessageListener cb in _eventHanders.receiveChatRoomMessage) { - List msgJsons = call.arguments.cast(); - List msgs = msgJsons.map((json) => JMNormalMessage.generateMessageFromJson(json)).toList(); - cb(msgs); - } - break; - case 'onReceiveApplyJoinGroupApproval': - for (JMReceiveApplyJoinGroupApprovalListener cb in _eventHanders.receiveApplyJoinGroupApproval) { - Map json = call.arguments.cast(); - JMReceiveApplyJoinGroupApprovalEvent e = JMReceiveApplyJoinGroupApprovalEvent.fromJson(json); - cb(e); - } - break; - case 'onReceiveGroupAdminReject': - for (JMReceiveGroupAdminRejectListener cb in _eventHanders.receiveGroupAdminReject) { - Map json = call.arguments.cast(); - cb(JMReceiveGroupAdminRejectEvent.fromJson(json)); - } - break; - case 'onReceiveGroupAdminApproval': - for (JMReceiveGroupAdminApprovalListener cb in _eventHanders.receiveGroupAdminApproval) { - Map json = call.arguments.cast(); - cb(JMReceiveGroupAdminApprovalEvent.fromJson(json)); - } - break; - case 'onReceiveMessageReceiptStatusChange': - for (JMMessageReceiptStatusChangeListener cb in _eventHanders.receiveReceiptStatusChangeEvents) { - Map param = call.arguments.cast(); - List serverMessageIdList = param['serverMessageIdList']; - JMConversationInfo conversationInfo = JMConversationInfo.fromJson(param['conversation']); - cb(conversationInfo, serverMessageIdList); + removeClickMessageNotificationListener(JMMessageEventListener callback) { + _eventHanders.clickMessageNotification.removeWhere((cb) => cb == callback); + } + + addSyncOfflineMessageListener(JMSyncOfflineMessageListener callback) { + _eventHanders.syncOfflineMessage.add(callback); + } + + removeSyncOfflineMessageListener(JMSyncOfflineMessageListener callback) { + _eventHanders.syncOfflineMessage.removeWhere((cb) => cb == callback); + } + + addSyncRoamingMessageListener(JMSyncRoamingMessageListener callback) { + _eventHanders.syncRoamingMessage.add(callback); + } + + removeSyncRoamingMessageListener(JMSyncRoamingMessageListener callback) { + _eventHanders.syncRoamingMessage.removeWhere((cb) => cb == callback); + } + + addLoginStateChangedListener(JMLoginStateChangedListener callback) { + _eventHanders.loginStateChanged.add(callback); + } + + removeLoginStateChangedListener(JMLoginStateChangedListener callback) { + _eventHanders.loginStateChanged.removeWhere((cb) => cb == callback); + } + + addContactNotifyListener(JMContactNotifyListener callback) { + _eventHanders.contactNotify.add(callback); + } + + removeContactNotifyListener(JMContactNotifyListener callback) { + _eventHanders.contactNotify.removeWhere((cb) => cb == callback); + } + + addMessageRetractListener(JMMessageRetractListener callback) { + _eventHanders.retractMessage.add(callback); + } + + removeMessageRetractListener(JMMessageRetractListener callback) { + _eventHanders.retractMessage.removeWhere((cb) => cb == callback); + } + + addReceiveTransCommandListener(JMReceiveTransCommandListener callback) { + _eventHanders.receiveTransCommand.add(callback); + } + + removeReceiveTransCommandListener(JMReceiveTransCommandListener callback) { + _eventHanders.receiveTransCommand.removeWhere((cb) => cb == callback); + } + + addReceiveChatRoomMessageListener(JMReceiveChatRoomMessageListener callback) { + _eventHanders.receiveChatRoomMessage.add(callback); + } + + removeReceiveChatRoomMessageListener( + JMReceiveChatRoomMessageListener callback) { + _eventHanders.receiveChatRoomMessage.removeWhere((cb) => cb == callback); + } + + addReceiveApplyJoinGroupApprovalListener( + JMReceiveApplyJoinGroupApprovalListener callback) { + _eventHanders.receiveApplyJoinGroupApproval.add(callback); + } + + removeReceiveApplyJoinGroupApprovalListener( + JMReceiveApplyJoinGroupApprovalListener callback) { + _eventHanders.receiveApplyJoinGroupApproval + .removeWhere((cb) => cb == callback); + } + + addReceiveGroupAdminRejectListener( + JMReceiveGroupAdminRejectListener callback) { + _eventHanders.receiveGroupAdminReject.add(callback); + } + + removeReceiveGroupAdminRejectListener( + JMReceiveGroupAdminRejectListener callback) { + _eventHanders.receiveGroupAdminReject.removeWhere((cb) => cb == callback); + } + + addReceiveGroupAdminApprovalListener( + JMReceiveGroupAdminApprovalListener callback) { + _eventHanders.receiveGroupAdminApproval.add(callback); + } + + removeReceiveGroupAdminApprovalListener( + JMReceiveGroupAdminApprovalListener callback) { + _eventHanders.receiveGroupAdminApproval.removeWhere((cb) => cb == callback); + } + + addReceiveMessageReceiptStatusChangelistener( + JMMessageReceiptStatusChangeListener callback) { + _eventHanders.receiveReceiptStatusChangeEvents.add(callback); + } + + removeMessageReceiptStatusChangelistener( + JMMessageReceiptStatusChangeListener callback) { + _eventHanders.receiveReceiptStatusChangeEvents + .removeWhere((cb) => cb == callback); + } + + Future get platformVersion async { + final String version = await _channel.invokeMethod('getPlatformVersion'); + return version; + } + + Future _handleMethod(MethodCall call) async { + print("handleMethod method = ${call.method}"); + switch (call.method) { + case 'onReceiveMessage': + for (JMMessageEventListener cb in _eventHanders.receiveMessage) { + cb(JMNormalMessage.generateMessageFromJson( + call.arguments.cast())); + } + break; + case 'onRetractMessage': + for (JMMessageRetractListener cb in _eventHanders.retractMessage) { + cb(JMNormalMessage.generateMessageFromJson( + call.arguments.cast()['retractedMessage'])); + } + break; + case 'onLoginStateChanged': + for (JMLoginStateChangedListener cb + in _eventHanders.loginStateChanged) { + String type = call.arguments.cast()['type']; + JMLoginStateChangedType loginState = + getEnumFromString(JMLoginStateChangedType.values, type); + cb(loginState); + } + break; + case 'onSyncOfflineMessage': + for (JMSyncOfflineMessageListener cb + in _eventHanders.syncOfflineMessage) { + Map param = call.arguments.cast(); + List msgDicArray = param['messageArray']; +// List msgs = msgDicArray.map((json) => JMNormalMessage.generateMessageFromJson(json)).toList(); + + List msgs = []; + for (Map json in msgDicArray) { + print("offline message: ${json.toString()}"); + JMNormalMessage normsg = + JMNormalMessage.generateMessageFromJson(json); + msgs.add(normsg); } - break; - default: - throw new UnsupportedError("Unrecognized Event"); - } - return; + + cb(JMConversationInfo.fromJson(param['conversation']), msgs); + } + break; + case 'onSyncRoamingMessage': + for (JMSyncRoamingMessageListener cb + in _eventHanders.syncRoamingMessage) { + Map json = call.arguments.cast(); + cb(JMConversationInfo.fromJson(json)); + } + break; + case 'onContactNotify': + for (JMContactNotifyListener cb in _eventHanders.contactNotify) { + Map json = call.arguments.cast(); + cb(JMContactNotifyEvent.fromJson(json)); + } + break; + case 'onClickMessageNotification': + for (JMMessageEventListener cb + in _eventHanders.clickMessageNotification) { + // TODO: only work in android + Map json = call.arguments.cast(); + cb(JMNormalMessage.generateMessageFromJson(json)); + } + break; + case 'onReceiveTransCommand': + for (JMReceiveTransCommandListener cb + in _eventHanders.receiveTransCommand) { + Map json = call.arguments.cast(); + JMReceiveTransCommandEvent ev = + JMReceiveTransCommandEvent.fromJson(json); + cb(ev); + } + break; + case 'onReceiveChatRoomMessage': + for (JMReceiveChatRoomMessageListener cb + in _eventHanders.receiveChatRoomMessage) { + List msgJsons = call.arguments.cast(); + List msgs = msgJsons + .map((json) => JMNormalMessage.generateMessageFromJson(json)) + .toList(); + cb(msgs); + } + break; + case 'onReceiveApplyJoinGroupApproval': + for (JMReceiveApplyJoinGroupApprovalListener cb + in _eventHanders.receiveApplyJoinGroupApproval) { + Map json = call.arguments.cast(); + JMReceiveApplyJoinGroupApprovalEvent e = + JMReceiveApplyJoinGroupApprovalEvent.fromJson(json); + cb(e); + } + break; + case 'onReceiveGroupAdminReject': + for (JMReceiveGroupAdminRejectListener cb + in _eventHanders.receiveGroupAdminReject) { + Map json = call.arguments.cast(); + cb(JMReceiveGroupAdminRejectEvent.fromJson(json)); + } + break; + case 'onReceiveGroupAdminApproval': + for (JMReceiveGroupAdminApprovalListener cb + in _eventHanders.receiveGroupAdminApproval) { + Map json = call.arguments.cast(); + cb(JMReceiveGroupAdminApprovalEvent.fromJson(json)); + } + break; + case 'onReceiveMessageReceiptStatusChange': + for (JMMessageReceiptStatusChangeListener cb + in _eventHanders.receiveReceiptStatusChangeEvents) { + Map param = call.arguments.cast(); + List serverMessageIdList = param['serverMessageIdList']; + JMConversationInfo conversationInfo = + JMConversationInfo.fromJson(param['conversation']); + cb(conversationInfo, serverMessageIdList); + } + break; + default: + throw new UnsupportedError("Unrecognized Event"); } + return; + } void init({ - @required bool isOpenMessageRoaming, - @required String appkey, - String channel, - bool isProduction = false, - }) { + @required bool isOpenMessageRoaming, + @required String appkey, + String channel, + bool isProduction = false, + }) { _channel.setMethodCallHandler(_handleMethod); - _channel.invokeMethod('setup', { - 'isOpenMessageRoaming': isOpenMessageRoaming, - 'appkey': appkey, - 'channel': channel, - 'isProduction': isProduction - }..removeWhere((key, value) => value == null)); + _channel.invokeMethod( + 'setup', + { + 'isOpenMessageRoaming': isOpenMessageRoaming, + 'appkey': appkey, + 'channel': channel, + 'isProduction': isProduction + }..removeWhere((key, value) => value == null)); } void setDebugMode({bool enable = false}) { @@ -317,8 +395,9 @@ class JmessageFlutter { /// /// 申请推送权限,注意这个方法只会向用户弹出一次推送权限请求(如果用户不同意,之后只能用户到设置页面里面勾选相应权限),需要开发者选择合适的时机调用。 /// - void applyPushAuthority([JMNotificationSettingsIOS iosSettings = const JMNotificationSettingsIOS()]) { - + void applyPushAuthority( + [JMNotificationSettingsIOS iosSettings = + const JMNotificationSettingsIOS()]) { if (!_platform.isIOS) { return; } @@ -331,27 +410,19 @@ class JmessageFlutter { /// /// @param {Int} badge /// - Future setBadge({ - @required int badge - }) async { - await _channel.invokeMethod('setBadge', { - 'badge': badge - }); + Future setBadge({@required int badge}) async { + await _channel.invokeMethod('setBadge', {'badge': badge}); return; } - Future userRegister({ - @required String username, - @required String password, - String nickname - }) async { - print("Action - userRegister: username=$username,pw=$password"); - await _channel.invokeMethod('userRegister', { - 'username': username, - 'password': password, - 'nickname': nickname - }); - } + Future userRegister( + {@required String username, + @required String password, + String nickname}) async { + print("Action - userRegister: username=$username,pw=$password"); + await _channel.invokeMethod('userRegister', + {'username': username, 'password': password, 'nickname': nickname}); + } /* * 登录 @@ -361,19 +432,16 @@ class JmessageFlutter { @required String username, @required String password, }) async { - if (username == null || - password == null) { - throw("username or password was passed null"); + if (username == null || password == null) { + throw ("username or password was passed null"); } print("Action - login: username=$username,pw=$password"); - Map userJson = await _channel.invokeMethod('login', { - 'username': username, - 'password': password - }); + Map userJson = await _channel + .invokeMethod('login', {'username': username, 'password': password}); if (userJson == null) { return null; - }else{ + } else { return JMUserInfo.fromJson(userJson); } } @@ -382,116 +450,109 @@ class JmessageFlutter { await _channel.invokeMethod('logout'); } - - Future getMyInfo() async { Map userJson = await _channel.invokeMethod('getMyInfo'); if (userJson == null) { return null; - }else{ + } else { return JMUserInfo.fromJson(userJson); } - } - Future getUserInfo({ - @required String username, - String appKey - }) async { - Map userJson = await _channel.invokeMethod('getUserInfo', { - 'username': username, - 'appKey': appKey - }..removeWhere((key, value) => value == null)); + Future getUserInfo( + {@required String username, String appKey}) async { + Map userJson = await _channel.invokeMethod( + 'getUserInfo', + {'username': username, 'appKey': appKey} + ..removeWhere((key, value) => value == null)); return JMUserInfo.fromJson(userJson); } - Future updateMyPassword({ - @required String oldPwd, - @required String newPwd - }) async { - await _channel.invokeMethod('updateMyPassword', { - 'oldPwd': oldPwd, - 'newPwd': newPwd - }); + Future updateMyPassword( + {@required String oldPwd, @required String newPwd}) async { + await _channel + .invokeMethod('updateMyPassword', {'oldPwd': oldPwd, 'newPwd': newPwd}); return; } - Future updateMyAvatar({ - @required String imgPath - }) async { - await _channel.invokeMethod('updateMyAvatar', { - 'imgPath': imgPath - }); + Future updateMyAvatar({@required String imgPath}) async { + await _channel.invokeMethod('updateMyAvatar', {'imgPath': imgPath}); return; } - Future updateMyInfo({ - int birthday, - String nickname, - String signature, - String region, - String address, - JMGender gender, - Map extras - }) async { - await _channel.invokeMethod('updateMyInfo', { - 'birthday': birthday, - 'nickname':nickname, - 'signature':signature, - 'region':region, - 'address':address, - 'gender': getStringFromEnum(gender), - 'extras': extras, - }..removeWhere((key,value) => value == null)); + Future updateMyInfo( + {int birthday, + String nickname, + String signature, + String region, + String address, + JMGender gender, + Map extras}) async { + await _channel.invokeMethod( + 'updateMyInfo', + { + 'birthday': birthday, + 'nickname': nickname, + 'signature': signature, + 'region': region, + 'address': address, + 'gender': getStringFromEnum(gender), + 'extras': extras, + }..removeWhere((key, value) => value == null)); return; } - Future updateGroupAvatar({ - @required String id, - @required String imgPath - }) async { - await _channel.invokeMethod('updateGroupAvatar', { - 'id': id, - 'imgPath': imgPath, - }..removeWhere((key,value) => value == null)); + Future updateGroupAvatar( + {@required String id, @required String imgPath}) async { + await _channel.invokeMethod( + 'updateGroupAvatar', + { + 'id': id, + 'imgPath': imgPath, + }..removeWhere((key, value) => value == null)); return; } Future downloadThumbGroupAvatar({ @required String id, }) async { - Map res = await _channel.invokeMethod('downloadThumbGroupAvatar', { - 'id': id, - }..removeWhere((key,value) => value == null)); + Map res = await _channel.invokeMethod( + 'downloadThumbGroupAvatar', + { + 'id': id, + }..removeWhere((key, value) => value == null)); return res; } Future downloadOriginalGroupAvatar({ @required String id, }) async { - Map res = await _channel.invokeMethod('downloadOriginalGroupAvatar', { - 'id': id, - }..removeWhere((key,value) => value == null)); - return { - 'id': res['id'], - 'filePath': res['filePath'] - }; + Map res = await _channel.invokeMethod( + 'downloadOriginalGroupAvatar', + { + 'id': id, + }..removeWhere((key, value) => value == null)); + return {'id': res['id'], 'filePath': res['filePath']}; } - Future setConversationExtras({ - dynamic type,/// (JMSingle | JMGroup | JMChatRoom) - Map extras - }) async { + Future setConversationExtras( + {dynamic type, + + /// (JMSingle | JMGroup | JMChatRoom) + Map extras}) async { var param = type.toJson(); param['extras'] = extras; - Map resMap = await _channel.invokeMethod('setConversationExtras', param..removeWhere((key,value) => value == null)); + Map resMap = await _channel.invokeMethod('setConversationExtras', + param..removeWhere((key, value) => value == null)); var res = JMConversationInfo.fromJson(resMap); return res; // {id: string; filePath: string} } Future createMessage({ @required JMMessageType type, // 消息类型 - @required dynamic targetType, /// (JMSingle | JMGroup | JMChatRoom) + @required dynamic targetType, + + /// (JMSingle | JMGroup | JMChatRoom) String text, String path, String fileName, @@ -503,52 +564,57 @@ class JmessageFlutter { Map extras, }) async { Map param = targetType.toJson(); - + if (extras != null) { param..addAll({'extras': extras}); } - param..addAll({ - 'messageType': getStringFromEnum(type), - 'text': text, - 'path': path, - 'fileName':fileName, - 'customObject': customObject, - 'latitude': latitude, - 'longitude': longitude, - 'scale': scale, - 'address': address, + param + ..addAll({ + 'messageType': getStringFromEnum(type), + 'text': text, + 'path': path, + 'fileName': fileName, + 'customObject': customObject, + 'latitude': latitude, + 'longitude': longitude, + 'scale': scale, + 'address': address, }); - Map resMap = await _channel.invokeMethod('createMessage', - param..removeWhere((key,value) => value == null)); + Map resMap = await _channel.invokeMethod( + 'createMessage', param..removeWhere((key, value) => value == null)); var res = JMNormalMessage.generateMessageFromJson(resMap); - return res; + return res; } /// message 可能是 JMTextMessage | JMVoiceMessage | JMImageMessage | JMFileMessage | JMCustomMessage; /// NOTE: 不要传接收到的消息进去,只能传通过 createMessage 创建的消息。 - Future sendMessage({ - @required JMNormalMessage message, - JMMessageSendOptions sendOption - }) async { + Future sendMessage( + {@required JMNormalMessage message, + JMMessageSendOptions sendOption}) async { Map param = message.target.targetType.toJson(); Map optionMap = {}; if (sendOption != null) { - optionMap = {'messageSendingOptions': sendOption.toJson()..removeWhere((key,value) => value == null)}; + optionMap = { + 'messageSendingOptions': sendOption.toJson() + ..removeWhere((key, value) => value == null) + }; } param..addAll(optionMap)..addAll({'id': message.id}); - Map resMap = await _channel.invokeMethod('sendDraftMessage', - param..removeWhere((key,value) => value == null)); + Map resMap = await _channel.invokeMethod( + 'sendDraftMessage', param..removeWhere((key, value) => value == null)); var res = JMNormalMessage.generateMessageFromJson(resMap); - return res; + return res; } Future sendTextMessage({ - @required dynamic type, /// (JMSingle | JMGroup | JMChatRoom) + @required dynamic type, + + /// (JMSingle | JMGroup | JMChatRoom) @required String text, JMMessageSendOptions sendOption, Map extras, @@ -556,32 +622,40 @@ class JmessageFlutter { Map param = type.toJson(); Map optionMap = {}; if (sendOption != null) { - optionMap = {'messageSendingOptions': sendOption.toJson()..removeWhere((key,value) => value == null)}; + optionMap = { + 'messageSendingOptions': sendOption.toJson() + ..removeWhere((key, value) => value == null) + }; } - + if (extras != null) { param..addAll({'extras': extras}); } param..addAll(optionMap)..addAll({'text': text}); - Map resMap = await _channel.invokeMethod('sendTextMessage', - param..removeWhere((key,value) => value == null)); + Map resMap = await _channel.invokeMethod( + 'sendTextMessage', param..removeWhere((key, value) => value == null)); var res = JMNormalMessage.generateMessageFromJson(resMap); - return res; + return res; } Future sendImageMessage({ - @required dynamic type, /// (JMSingle | JMGroup | JMChatRoom) + @required dynamic type, + + /// (JMSingle | JMGroup | JMChatRoom) @required String path, JMMessageSendOptions sendOption, Map extras, }) async { Map param = type.toJson(); - + Map optionMap = {}; if (sendOption != null) { - optionMap = {'messageSendingOptions': sendOption.toJson()..removeWhere((key,value) => value == null)}; + optionMap = { + 'messageSendingOptions': sendOption.toJson() + ..removeWhere((key, value) => value == null) + }; } if (extras != null) { @@ -590,14 +664,16 @@ class JmessageFlutter { param..addAll(optionMap)..addAll({'path': path}); - Map resMap = await _channel.invokeMethod('sendImageMessage', - param..removeWhere((key,value) => value == null)); + Map resMap = await _channel.invokeMethod( + 'sendImageMessage', param..removeWhere((key, value) => value == null)); var res = JMNormalMessage.generateMessageFromJson(resMap); - return res; + return res; } Future sendVoiceMessage({ - @required dynamic type, /// (JMSingle | JMGroup | JMChatRoom) + @required dynamic type, + + /// (JMSingle | JMGroup | JMChatRoom) @required String path, JMMessageSendOptions sendOption, Map extras, @@ -606,7 +682,10 @@ class JmessageFlutter { Map optionMap = {}; if (sendOption != null) { - optionMap = {'messageSendingOptions': sendOption.toJson()..removeWhere((key,value) => value == null)}; + optionMap = { + 'messageSendingOptions': sendOption.toJson() + ..removeWhere((key, value) => value == null) + }; } if (extras != null) { @@ -615,23 +694,28 @@ class JmessageFlutter { param..addAll(optionMap)..addAll({'path': path}); - Map resMap = await _channel.invokeMethod('sendVoiceMessage', - param..removeWhere((key,value) => value == null)); + Map resMap = await _channel.invokeMethod( + 'sendVoiceMessage', param..removeWhere((key, value) => value == null)); var res = JMNormalMessage.generateMessageFromJson(resMap); - return res; + return res; } Future sendCustomMessage({ - @required dynamic type, /// (JMSingle | JMGroup | JMChatRoom) + @required dynamic type, + + /// (JMSingle | JMGroup | JMChatRoom) @required Map customObject, JMMessageSendOptions sendOption, Map extras, }) async { Map param = type.toJson(); - + Map optionMap = {}; if (sendOption != null) { - optionMap = {'messageSendingOptions': sendOption.toJson()..removeWhere((key,value) => value == null)}; + optionMap = { + 'messageSendingOptions': sendOption.toJson() + ..removeWhere((key, value) => value == null) + }; } if (extras != null) { @@ -640,14 +724,16 @@ class JmessageFlutter { param..addAll(optionMap)..addAll({'customObject': customObject}); - Map resMap = await _channel.invokeMethod('sendCustomMessage', - param..removeWhere((key,value) => value == null)); + Map resMap = await _channel.invokeMethod( + 'sendCustomMessage', param..removeWhere((key, value) => value == null)); var res = JMNormalMessage.generateMessageFromJson(resMap); - return res; + return res; } Future sendLocationMessage({ - @required dynamic type, /// (JMSingle | JMGroup | JMChatRoom) + @required dynamic type, + + /// (JMSingle | JMGroup | JMChatRoom) @required double latitude, @required double longitude, @required int scale, @@ -656,32 +742,38 @@ class JmessageFlutter { Map extras, }) async { Map param = type.toJson(); - + Map optionMap = {}; if (sendOption != null) { - optionMap = {'messageSendingOptions': sendOption.toJson()..removeWhere((key,value) => value == null)}; + optionMap = { + 'messageSendingOptions': sendOption.toJson() + ..removeWhere((key, value) => value == null) + }; } if (extras != null) { param..addAll({'extras': extras}); } - - param..addAll(optionMap) + + param + ..addAll(optionMap) ..addAll({ - 'latitude': latitude, - 'longitude': longitude, - 'scale': scale, - 'address': address, + 'latitude': latitude, + 'longitude': longitude, + 'scale': scale, + 'address': address, }); - Map resMap = await _channel.invokeMethod('sendLocationMessage', - param..removeWhere((key,value) => value == null)); + Map resMap = await _channel.invokeMethod('sendLocationMessage', + param..removeWhere((key, value) => value == null)); var res = JMNormalMessage.generateMessageFromJson(resMap); - return res; + return res; } Future sendFileMessage({ - @required dynamic type, /// (JMSingle | JMGroup | JMChatRoom) + @required dynamic type, + + /// (JMSingle | JMGroup | JMChatRoom) @required String path, JMMessageSendOptions sendOption, Map extras, @@ -689,22 +781,24 @@ class JmessageFlutter { Map param = type.toJson(); Map optionMap = {}; if (sendOption != null) { - optionMap = {'messageSendingOptions': sendOption.toJson()..removeWhere((key,value) => value == null)}; + optionMap = { + 'messageSendingOptions': sendOption.toJson() + ..removeWhere((key, value) => value == null) + }; } if (extras != null) { param..addAll({'extras': extras}); } - + param..addAll(optionMap)..addAll({'path': path}); - Map resMap = await _channel.invokeMethod('sendFileMessage', - param..removeWhere((key,value) => value == null)); + Map resMap = await _channel.invokeMethod( + 'sendFileMessage', param..removeWhere((key, value) => value == null)); var res = JMNormalMessage.generateMessageFromJson(resMap); - return res; + return res; } - /** * 消息撤回 * @@ -713,7 +807,9 @@ class JmessageFlutter { * * */ Future retractMessage({ - @required dynamic target, /// (JMSingle | JMGroup ) + @required dynamic target, + + /// (JMSingle | JMGroup ) @required String serverMessageId, }) async { Map param = target.toJson(); @@ -722,9 +818,9 @@ class JmessageFlutter { print("retractMessage: ${param.toString()}"); - await _channel.invokeMethod('retractMessage', - param..removeWhere((key,value) => value == null)); - + await _channel.invokeMethod( + 'retractMessage', param..removeWhere((key, value) => value == null)); + return; } @@ -737,29 +833,26 @@ class JmessageFlutter { * @param isDescend 是否倒叙 * * */ - Future getHistoryMessages({ - @required dynamic type, /// (JMSingle | JMGroup) - @required int from, - @required int limit, - bool isDescend = false - }) async { + Future getHistoryMessages( + {@required dynamic type, + + /// (JMSingle | JMGroup) + @required int from, + @required int limit, + bool isDescend = false}) async { Map param = type.toJson(); - - param..addAll({ - 'from': from, - 'limit': limit, - 'isDescend': isDescend - }); - List resArr = await _channel.invokeMethod('getHistoryMessages', - param..removeWhere((key,value) => value == null)); + param..addAll({'from': from, 'limit': limit, 'isDescend': isDescend}); + + List resArr = await _channel.invokeMethod('getHistoryMessages', + param..removeWhere((key, value) => value == null)); List res = []; for (Map messageMap in resArr) { dynamic d = JMNormalMessage.generateMessageFromJson(messageMap); if (d != null) { res.add(d); - }else{ + } else { print("get history msg, get a message is null"); } } @@ -771,41 +864,47 @@ class JmessageFlutter { /// @param target 聊天对象, JMSingle | JMGroup /// @param serverMessageId 服务器返回的 serverMessageId,非本地数据库中的消息id, Future getMessageByServerMessageId({ - @required dynamic type, /// (JMSingle | JMGroup | JMChatRoom) + @required dynamic type, + + /// (JMSingle | JMGroup | JMChatRoom) @required String serverMessageId, }) async { Map param = type.toJson(); - param..addAll({ - 'serverMessageId': serverMessageId, - }); + param + ..addAll({ + 'serverMessageId': serverMessageId, + }); Map msgMap = await _channel.invokeMethod('getMessageByServerMessageId', - param..removeWhere((key,value) => value == null)); + param..removeWhere((key, value) => value == null)); return JMNormalMessage.generateMessageFromJson(msgMap); } /** * 获取本地单条消息 - * - * @param target 聊天对象, JMSingle | JMGroup - * @param messageId 本地数据库中的消息id,非 serverMessageId - * - * */ + * + * @param target 聊天对象, JMSingle | JMGroup + * @param messageId 本地数据库中的消息id,非 serverMessageId + * + * */ Future getMessageById({ - @required dynamic type, /// (JMSingle | JMGroup | JMChatRoom) + @required dynamic type, + + /// (JMSingle | JMGroup | JMChatRoom) @required String messageId, }) async { Map param = type.toJson(); - - param..addAll({ + + param + ..addAll({ 'messageId': messageId, }); - Map msgMap = await _channel.invokeMethod('getMessageById', - param..removeWhere((key,value) => value == null)); - + Map msgMap = await _channel.invokeMethod( + 'getMessageById', param..removeWhere((key, value) => value == null)); + return JMNormalMessage.generateMessageFromJson(msgMap); } @@ -817,18 +916,21 @@ class JmessageFlutter { * * */ Future deleteMessageById({ - @required dynamic type, /// (JMSingle | JMGroup | JMChatRoom) + @required dynamic type, + + /// (JMSingle | JMGroup | JMChatRoom) @required String messageId, }) async { Map param = type.toJson(); - - param..addAll({ + + param + ..addAll({ 'messageId': messageId, }); - await _channel.invokeMethod('deleteMessageById', - param..removeWhere((key,value) => value == null)); - + await _channel.invokeMethod( + 'deleteMessageById', param..removeWhere((key, value) => value == null)); + return; } @@ -837,14 +939,14 @@ class JmessageFlutter { @required String reason, String appKey, }) async { - - await _channel.invokeMethod('sendInvitationRequest', - { - 'username': username, - 'reason': reason, - 'appKey': appKey, - }..removeWhere((key,value) => value == null)); - + await _channel.invokeMethod( + 'sendInvitationRequest', + { + 'username': username, + 'reason': reason, + 'appKey': appKey, + }..removeWhere((key, value) => value == null)); + return; } @@ -852,13 +954,13 @@ class JmessageFlutter { @required String username, String appKey, }) async { - - await _channel.invokeMethod('acceptInvitation', - { - 'username': username, - 'appKey': appKey, - }..removeWhere((key,value) => value == null)); - + await _channel.invokeMethod( + 'acceptInvitation', + { + 'username': username, + 'appKey': appKey, + }..removeWhere((key, value) => value == null)); + return; } @@ -867,13 +969,14 @@ class JmessageFlutter { @required String reason, String appKey, }) async { - await _channel.invokeMethod('declineInvitation', - { - 'username': username, - 'reason': reason, - 'appKey': appKey, - }..removeWhere((key,value) => value == null)); - + await _channel.invokeMethod( + 'declineInvitation', + { + 'username': username, + 'reason': reason, + 'appKey': appKey, + }..removeWhere((key, value) => value == null)); + return; } @@ -881,12 +984,13 @@ class JmessageFlutter { @required String username, String appKey, }) async { - await _channel.invokeMethod('removeFromFriendList', - { - 'username': username, - 'appKey': appKey, - }..removeWhere((key,value) => value == null)); - + await _channel.invokeMethod( + 'removeFromFriendList', + { + 'username': username, + 'appKey': appKey, + }..removeWhere((key, value) => value == null)); + return; } @@ -895,13 +999,14 @@ class JmessageFlutter { @required String noteName, String appKey, }) async { - await _channel.invokeMethod('updateFriendNoteName', - { - 'username': username, - 'noteName': noteName, - 'appKey': appKey, - }..removeWhere((key,value) => value == null)); - + await _channel.invokeMethod( + 'updateFriendNoteName', + { + 'username': username, + 'noteName': noteName, + 'appKey': appKey, + }..removeWhere((key, value) => value == null)); + return; } @@ -910,20 +1015,22 @@ class JmessageFlutter { @required String noteText, String appKey, }) async { - await _channel.invokeMethod('updateFriendNoteText', - { - 'username': username, - 'noteText': noteText, - 'appKey': appKey, - }..removeWhere((key,value) => value == null)); - + await _channel.invokeMethod( + 'updateFriendNoteText', + { + 'username': username, + 'noteText': noteText, + 'appKey': appKey, + }..removeWhere((key, value) => value == null)); + return; } Future> getFriends() async { List userJsons = await _channel.invokeMethod('getFriends'); - List users = userJsons.map((userMap) => JMUserInfo.fromJson(userMap)).toList(); + List users = + userJsons.map((userMap) => JMUserInfo.fromJson(userMap)).toList(); return users; } @@ -932,14 +1039,11 @@ class JmessageFlutter { String name, String desc, }) async { - - String groupId = await _channel.invokeMethod('createGroup', - { - 'groupType': getStringFromEnum(groupType), - 'name': name, - 'desc': desc - }..removeWhere((key,value) => value == null)); - + String groupId = await _channel.invokeMethod( + 'createGroup', + {'groupType': getStringFromEnum(groupType), 'name': name, 'desc': desc} + ..removeWhere((key, value) => value == null)); + return groupId; } @@ -949,113 +1053,97 @@ class JmessageFlutter { return res; } - Future getGroupInfo({ @required String id}) async { - - Map groupJson = await _channel.invokeMethod('getGroupInfo', - { - 'id': id - }..removeWhere((key,value) => value == null)); - + Future getGroupInfo({@required String id}) async { + Map groupJson = await _channel.invokeMethod( + 'getGroupInfo', {'id': id}..removeWhere((key, value) => value == null)); + return JMGroupInfo.fromJson(groupJson); } - Future updateGroupInfo({ - @required String id, - String newName, - String newDesc, - }) async { - - await _channel.invokeMethod('updateGroupInfo', - { - 'id': id, - 'newName': newName, - 'newDesc': newDesc - }..removeWhere((key,value) => value == null)); - + Future updateGroupInfo({ + @required String id, + String newName, + String newDesc, + }) async { + await _channel.invokeMethod( + 'updateGroupInfo', + {'id': id, 'newName': newName, 'newDesc': newDesc} + ..removeWhere((key, value) => value == null)); + return; } - Future addGroupMembers({ - @required String id, - @required List usernameArray, - String appKey, - }) async { - - await _channel.invokeMethod('addGroupMembers', - { - 'id': id, - 'usernameArray': usernameArray, - 'appKey': appKey, - }..removeWhere((key,value) => value == null)); - + Future addGroupMembers({ + @required String id, + @required List usernameArray, + String appKey, + }) async { + await _channel.invokeMethod( + 'addGroupMembers', + { + 'id': id, + 'usernameArray': usernameArray, + 'appKey': appKey, + }..removeWhere((key, value) => value == null)); + return; } - Future removeGroupMembers({ - @required String id, - @required List usernames, - String appKey, - }) async { - - await _channel.invokeMethod('removeGroupMembers', - { - 'id': id, - 'usernameArray': usernames, - 'appKey': appKey, - }..removeWhere((key,value) => value == null)); - + Future removeGroupMembers({ + @required String id, + @required List usernames, + String appKey, + }) async { + await _channel.invokeMethod( + 'removeGroupMembers', + { + 'id': id, + 'usernameArray': usernames, + 'appKey': appKey, + }..removeWhere((key, value) => value == null)); + return; } - Future exitGroup({ @required String id}) async { - - await _channel.invokeMethod('exitGroup', - { - 'id': id - }..removeWhere((key,value) => value == null)); - + Future exitGroup({@required String id}) async { + await _channel.invokeMethod( + 'exitGroup', {'id': id}..removeWhere((key, value) => value == null)); + return; } - Future> getGroupMembers({ @required String id}) async { + Future> getGroupMembers({@required String id}) async { + List membersJsons = await _channel.invokeMethod('getGroupMembers', + {'id': id}..removeWhere((key, value) => value == null)); - List membersJsons = await _channel.invokeMethod('getGroupMembers', - { 'id': id }..removeWhere((key,value) => value == null)); - - List res = membersJsons.map((memberJson) => JMGroupMemberInfo.fromJson(memberJson)).toList(); + List res = membersJsons + .map((memberJson) => JMGroupMemberInfo.fromJson(memberJson)) + .toList(); return res; } - Future addUsersToBlacklist({ - @required List usernameArray, - String appKey - }) async { - - await _channel.invokeMethod('addUsersToBlacklist', - { - 'usernameArray': usernameArray, - 'appKey': appKey - }..removeWhere((key,value) => value == null)); + Future addUsersToBlacklist( + {@required List usernameArray, String appKey}) async { + await _channel.invokeMethod( + 'addUsersToBlacklist', + {'usernameArray': usernameArray, 'appKey': appKey} + ..removeWhere((key, value) => value == null)); return; } - Future removeUsersFromBlacklist({ - @required List usernameArray, - String appKey - }) async { - - await _channel.invokeMethod('removeUsersFromBlacklist', - { - 'usernameArray': usernameArray, - 'appKey': appKey - }..removeWhere((key,value) => value == null)); + Future removeUsersFromBlacklist( + {@required List usernameArray, String appKey}) async { + await _channel.invokeMethod( + 'removeUsersFromBlacklist', + {'usernameArray': usernameArray, 'appKey': appKey} + ..removeWhere((key, value) => value == null)); return; } Future> getBlacklist() async { - List userJsons = await _channel.invokeMethod('getBlacklist'); - List res = userJsons.map((json) => JMUserInfo.fromJson(json)).toList(); + List res = + userJsons.map((json) => JMUserInfo.fromJson(json)).toList(); return res; } @@ -1065,30 +1153,29 @@ class JmessageFlutter { }) async { var param = target.toJson(); param['isNoDisturb'] = isNoDisturb; - await _channel.invokeMethod('setNoDisturb', - param..removeWhere((key,value) => value == null)); + await _channel.invokeMethod( + 'setNoDisturb', param..removeWhere((key, value) => value == null)); return; } Future getNoDisturbList() async { - Map resJson = await _channel.invokeMethod('getNoDisturbList'); List userJsons = resJson['userInfoArray']; List groupJsons = resJson['groupInfoArray']; - - List users = userJsons.map((json) => JMUserInfo.fromJson(json)).toList(); - List groups = groupJsons.map((json) => JMGroupInfo.fromJson(json)).toList(); - return { - 'userInfos': users, - 'groupInfos': groups - }; + List users = + userJsons.map((json) => JMUserInfo.fromJson(json)).toList(); + List groups = + groupJsons.map((json) => JMGroupInfo.fromJson(json)).toList(); + + return {'userInfos': users, 'groupInfos': groups}; } - Future setNoDisturbGlobal({ @required bool isNoDisturb}) async { - await _channel.invokeMethod('setNoDisturbGlobal', { - 'isNoDisturb': isNoDisturb - }..removeWhere((key, value) => value == null)); + Future setNoDisturbGlobal({@required bool isNoDisturb}) async { + await _channel.invokeMethod( + 'setNoDisturbGlobal', + {'isNoDisturb': isNoDisturb} + ..removeWhere((key, value) => value == null)); return; } @@ -1097,29 +1184,29 @@ class JmessageFlutter { return resJson['isNoDisturb']; } - Future blockGroupMessage({ + Future blockGroupMessage({ @required String id, @required bool isBlock, }) async { - await _channel.invokeMethod('blockGroupMessage',{ - 'id': id, - 'isBlock': isBlock - }..removeWhere((key, value) => value == null)); + await _channel.invokeMethod( + 'blockGroupMessage', + {'id': id, 'isBlock': isBlock} + ..removeWhere((key, value) => value == null)); return; } - Future isGroupBlocked({ + Future isGroupBlocked({ @required String id, }) async { - Map resJson = await _channel.invokeMethod('isGroupBlocked',{ - 'id': id - }..removeWhere((key, value) => value == null)); + Map resJson = await _channel.invokeMethod('isGroupBlocked', + {'id': id}..removeWhere((key, value) => value == null)); return resJson['isBlocked']; } Future> getBlockedGroupList() async { List resJson = await _channel.invokeMethod('getBlockedGroupList'); - List res = resJson.map((json) => JMGroupInfo.fromJson(json)).toList(); + List res = + resJson.map((json) => JMGroupInfo.fromJson(json)).toList(); return res; } @@ -1127,11 +1214,13 @@ class JmessageFlutter { @required String username, String appKey, }) async { - Map resJson = await _channel.invokeMethod('downloadThumbUserAvatar', { - 'username': username, - 'appKey': appKey, - }..removeWhere((key, value) => value == null)); - + Map resJson = await _channel.invokeMethod( + 'downloadThumbUserAvatar', + { + 'username': username, + 'appKey': appKey, + }..removeWhere((key, value) => value == null)); + return { 'username': resJson['username'], 'appKey': resJson['appKey'], @@ -1143,11 +1232,13 @@ class JmessageFlutter { @required String username, String appKey, }) async { - Map resJson = await _channel.invokeMethod('downloadOriginalUserAvatar', { - 'username': username, - 'appKey': appKey, - }..removeWhere((key, value) => value == null)); - + Map resJson = await _channel.invokeMethod( + 'downloadOriginalUserAvatar', + { + 'username': username, + 'appKey': appKey, + }..removeWhere((key, value) => value == null)); + return { 'username': resJson['username'], 'appKey': resJson['appKey'], @@ -1168,12 +1259,10 @@ class JmessageFlutter { }) async { Map param = target.toJson(); param['messageId'] = messageId; - Map resJson = await _channel.invokeMethod('downloadThumbImage', param..removeWhere((key, value) => value == null)); - - return { - 'messageId': resJson['messageId'], - 'filePath': resJson['filePath'] - }; + Map resJson = await _channel.invokeMethod('downloadThumbImage', + param..removeWhere((key, value) => value == null)); + + return {'messageId': resJson['messageId'], 'filePath': resJson['filePath']}; } /** @@ -1189,12 +1278,10 @@ class JmessageFlutter { }) async { Map param = target.toJson(); param['messageId'] = messageId; - Map resJson = await _channel.invokeMethod('downloadOriginalImage', param..removeWhere((key, value) => value == null)); - - return { - 'messageId': resJson['messageId'], - 'filePath': resJson['filePath'] - }; + Map resJson = await _channel.invokeMethod('downloadOriginalImage', + param..removeWhere((key, value) => value == null)); + + return {'messageId': resJson['messageId'], 'filePath': resJson['filePath']}; } /** @@ -1210,12 +1297,10 @@ class JmessageFlutter { }) async { Map param = target.toJson(); param['messageId'] = messageId; - Map resJson = await _channel.invokeMethod('downloadVoiceFile', param..removeWhere((key, value) => value == null)); - - return { - 'messageId': resJson['messageId'], - 'filePath': resJson['filePath'] - }; + Map resJson = await _channel.invokeMethod( + 'downloadVoiceFile', param..removeWhere((key, value) => value == null)); + + return {'messageId': resJson['messageId'], 'filePath': resJson['filePath']}; } /** @@ -1231,21 +1316,19 @@ class JmessageFlutter { }) async { Map param = target.toJson(); param['messageId'] = messageId; - Map resJson = await _channel.invokeMethod('downloadFile', param..removeWhere((key, value) => value == null)); - - return { - 'messageId': resJson['messageId'], - 'filePath': resJson['filePath'] - }; + Map resJson = await _channel.invokeMethod( + 'downloadFile', param..removeWhere((key, value) => value == null)); + + return {'messageId': resJson['messageId'], 'filePath': resJson['filePath']}; } Future createConversation({ @required dynamic target, //(JMSingle | JMGroup | JMChatRoom) }) async { Map param = target.toJson(); - Map resJson = await _channel.invokeMethod('createConversation', - param..removeWhere((key, value) => value == null)); - + Map resJson = await _channel.invokeMethod('createConversation', + param..removeWhere((key, value) => value == null)); + return JMConversationInfo.fromJson(resJson); } @@ -1253,9 +1336,9 @@ class JmessageFlutter { @required dynamic target, //(JMSingle | JMGroup | JMChatRoom) }) async { Map param = target.toJson(); - await _channel.invokeMethod('deleteConversation', - param..removeWhere((key, value) => value == null)); - + await _channel.invokeMethod('deleteConversation', + param..removeWhere((key, value) => value == null)); + return; } @@ -1264,10 +1347,10 @@ class JmessageFlutter { }) async { if (_platform.isAndroid) { Map param = target.toJson(); - await _channel.invokeMethod('enterConversation', - param..removeWhere((key, value) => value == null)); + await _channel.invokeMethod('enterConversation', + param..removeWhere((key, value) => value == null)); } - + return; } @@ -1276,38 +1359,38 @@ class JmessageFlutter { }) async { if (_platform.isAndroid) { Map param = target.toJson(); - await _channel.invokeMethod('exitConversation', - param..removeWhere((key, value) => value == null)); + await _channel.invokeMethod('exitConversation', + param..removeWhere((key, value) => value == null)); } - + return; } Future getConversation({ @required dynamic target, //(JMSingle | JMGroup | JMChatRoom) }) async { - Map param = target.toJson(); - Map resJson = await _channel.invokeMethod('getConversation', - param..removeWhere((key, value) => value == null)); - + Map resJson = await _channel.invokeMethod( + 'getConversation', param..removeWhere((key, value) => value == null)); + return JMConversationInfo.fromJson(resJson); } Future> getConversations() async { List conversionJsons = await _channel.invokeMethod('getConversations'); - List conversations = conversionJsons.map((json) => JMConversationInfo.fromJson(json)).toList(); + List conversations = conversionJsons + .map((json) => JMConversationInfo.fromJson(json)) + .toList(); return conversations; } Future resetUnreadMessageCount({ @required dynamic target, //(JMSingle | JMGroup | JMChatRoom) }) async { - Map param = target.toJson(); - await _channel.invokeMethod('resetUnreadMessageCount', - param..removeWhere((key, value) => value == null)); - + await _channel.invokeMethod('resetUnreadMessageCount', + param..removeWhere((key, value) => value == null)); + return; } @@ -1316,13 +1399,14 @@ class JmessageFlutter { @required String username, String appKey, }) async { - await _channel.invokeMethod('transferGroupOwner', - { - 'groupId': groupId, - 'username': username, - 'appKey': appKey, - }..removeWhere((key, value) => value == null)); - + await _channel.invokeMethod( + 'transferGroupOwner', + { + 'groupId': groupId, + 'username': username, + 'appKey': appKey, + }..removeWhere((key, value) => value == null)); + return; } @@ -1332,14 +1416,15 @@ class JmessageFlutter { @required String username, String appKey, }) async { - await _channel.invokeMethod('setGroupMemberSilence', - { - 'groupId': groupId, - 'username': username, - 'isSilence': isSilence, - 'appKey': appKey, - }..removeWhere((key, value) => value == null)); - + await _channel.invokeMethod( + 'setGroupMemberSilence', + { + 'groupId': groupId, + 'username': username, + 'isSilence': isSilence, + 'appKey': appKey, + }..removeWhere((key, value) => value == null)); + return; } @@ -1348,23 +1433,26 @@ class JmessageFlutter { @required String username, String appKey, }) async { - Map resJson = await _channel.invokeMethod('isSilenceMember', - { - 'groupId': groupId, - 'username': username, - 'appKey': appKey, - }..removeWhere((key, value) => value == null)); + Map resJson = await _channel.invokeMethod( + 'isSilenceMember', + { + 'groupId': groupId, + 'username': username, + 'appKey': appKey, + }..removeWhere((key, value) => value == null)); return resJson['isSilence']; } Future> groupSilenceMembers({ @required String groupId, }) async { - List memberJsons = await _channel.invokeMethod('groupSilenceMembers', - { - 'groupId': groupId, - }..removeWhere((key, value) => value == null)); - List members = memberJsons.map((json) => JMUserInfo.fromJson(json)).toList(); + List memberJsons = await _channel.invokeMethod( + 'groupSilenceMembers', + { + 'groupId': groupId, + }..removeWhere((key, value) => value == null)); + List members = + memberJsons.map((json) => JMUserInfo.fromJson(json)).toList(); return members; } @@ -1374,49 +1462,51 @@ class JmessageFlutter { @required String username, String appKey, }) async { - await _channel.invokeMethod('setGroupNickname', - { - 'groupId': groupId, - 'nickName': nickName, - 'username': username, - 'appKey': appKey, - }..removeWhere((key, value) => value == null)); - + await _channel.invokeMethod( + 'setGroupNickname', + { + 'groupId': groupId, + 'nickName': nickName, + 'username': username, + 'appKey': appKey, + }..removeWhere((key, value) => value == null)); + return; } Future enterChatRoom({ @required String roomId, }) async { - - Map resJson = await _channel.invokeMethod('enterChatRoom', - { 'roomId': roomId }..removeWhere((key, value) => value == null)); - + Map resJson = await _channel.invokeMethod('enterChatRoom', + {'roomId': roomId}..removeWhere((key, value) => value == null)); + return JMConversationInfo.fromJson(resJson); } Future exitChatRoom({ @required String roomId, }) async { - - await _channel.invokeMethod('exitChatRoom', - { 'roomId': roomId }..removeWhere((key, value) => value == null)); - + await _channel.invokeMethod('exitChatRoom', + {'roomId': roomId}..removeWhere((key, value) => value == null)); + return; } Future getChatRoomConversation({ @required String roomId, }) async { - Map resJson = await _channel.invokeMethod('getChatRoomConversation', - { 'roomId': roomId }..removeWhere((key, value) => value == null)); - + Map resJson = await _channel.invokeMethod('getChatRoomConversation', + {'roomId': roomId}..removeWhere((key, value) => value == null)); + return JMConversationInfo.fromJson(resJson); } Future> getChatRoomConversationList() async { - List conversationJsons = await _channel.invokeMethod('getChatRoomConversationList'); - List conversations = conversationJsons.map((json) => JMConversationInfo.fromJson(json)).toList(); + List conversationJsons = + await _channel.invokeMethod('getChatRoomConversationList'); + List conversations = conversationJsons + .map((json) => JMConversationInfo.fromJson(json)) + .toList(); return conversations; } @@ -1430,11 +1520,10 @@ class JmessageFlutter { @required List usernames, String appKey, }) async { - await _channel.invokeMethod('addGroupAdmins',{ - 'groupId': groupId, - 'usernames': usernames, - 'appKey': appKey - }..removeWhere((key, value) => value == null)); + await _channel.invokeMethod( + 'addGroupAdmins', + {'groupId': groupId, 'usernames': usernames, 'appKey': appKey} + ..removeWhere((key, value) => value == null)); return; } @@ -1443,11 +1532,10 @@ class JmessageFlutter { @required List usernames, String appKey, }) async { - await _channel.invokeMethod('removeGroupAdmins',{ - 'groupId': groupId, - 'usernames': usernames, - 'appKey': appKey - }..removeWhere((key, value) => value == null)); + await _channel.invokeMethod( + 'removeGroupAdmins', + {'groupId': groupId, 'usernames': usernames, 'appKey': appKey} + ..removeWhere((key, value) => value == null)); return; } @@ -1455,11 +1543,10 @@ class JmessageFlutter { @required String groupId, @required JMGroupType type, }) async { - - await _channel.invokeMethod('changeGroupType',{ - 'groupId': groupId, - 'type': getStringFromEnum(type) - }..removeWhere((key, value) => value == null)); + await _channel.invokeMethod( + 'changeGroupType', + {'groupId': groupId, 'type': getStringFromEnum(type)} + ..removeWhere((key, value) => value == null)); return; } @@ -1468,13 +1555,12 @@ class JmessageFlutter { @required num start, @required num count, }) async { - - List groupJsons = await _channel.invokeMethod('getPublicGroupInfos',{ - 'appKey': appKey, - 'start': start, - 'count': count - }..removeWhere((key, value) => value == null)); - List groups = groupJsons.map((json) => JMGroupInfo.fromJson(json)).toList(); + List groupJsons = await _channel.invokeMethod( + 'getPublicGroupInfos', + {'appKey': appKey, 'start': start, 'count': count} + ..removeWhere((key, value) => value == null)); + List groups = + groupJsons.map((json) => JMGroupInfo.fromJson(json)).toList(); return groups; } @@ -1482,12 +1568,11 @@ class JmessageFlutter { @required String groupId, String reason, }) async { - - await _channel.invokeMethod('applyJoinGroup',{ - 'groupId': groupId, - 'reason': reason - }..removeWhere((key, value) => value == null)); - + await _channel.invokeMethod( + 'applyJoinGroup', + {'groupId': groupId, 'reason': reason} + ..removeWhere((key, value) => value == null)); + return; } @@ -1497,25 +1582,27 @@ class JmessageFlutter { @required bool isRespondInviter, String reason, }) async { - - await _channel.invokeMethod('processApplyJoinGroup',{ - 'events': events, - 'isAgree': isAgree == 0 ? false : true, - 'isRespondInviter': isRespondInviter == 0 ? false : true, - 'reason': reason - }..removeWhere((key, value) => value == null)); - + await _channel.invokeMethod( + 'processApplyJoinGroup', + { + 'events': events, + 'isAgree': isAgree == 0 ? false : true, + 'isRespondInviter': isRespondInviter == 0 ? false : true, + 'reason': reason + }..removeWhere((key, value) => value == null)); + return; } Future dissolveGroup({ - @required String groupId, + @required String groupId, }) async { - - await _channel.invokeMethod('dissolveGroup',{ - 'groupId': groupId, - }..removeWhere((key, value) => value == null)); - + await _channel.invokeMethod( + 'dissolveGroup', + { + 'groupId': groupId, + }..removeWhere((key, value) => value == null)); + return; } @@ -1524,16 +1611,16 @@ class JmessageFlutter { @required String message, @required dynamic target, //(JMSingle | JMGroup) }) async { - if (target is JMChatRoom) { - print("does not support chatroom message trans."); - return; - } + if (target is JMChatRoom) { + print("does not support chatroom message trans."); + return; + } - Map param = target.toJson(); - param["message"] = message; - param.removeWhere((key, value) => value == null); + Map param = target.toJson(); + param["message"] = message; + param.removeWhere((key, value) => value == null); - await _channel.invokeMethod('sendMessageTransCommand',param); + await _channel.invokeMethod('sendMessageTransCommand', param); } /// 设备间透传命令 @@ -1541,13 +1628,12 @@ class JmessageFlutter { @required String message, @required JMPlatformType platform, }) async { - Map param = Map(); param["message"] = message; param["type"] = getStringFromEnum(platform); param.removeWhere((key, value) => value == null); - await _channel.invokeMethod('sendCrossDeviceTransCommand',param); + await _channel.invokeMethod('sendCrossDeviceTransCommand', param); } /* @@ -1558,7 +1644,9 @@ class JmessageFlutter { * * */ Future getMessageUnreceiptCount({ - @required dynamic target, /// (JMSingle | JMGroup) + @required dynamic target, + + /// (JMSingle | JMGroup) @required String msgId, }) async { print(flutterLog + "getMessageUnreceiptCount" + " msgid = $msgId"); @@ -1570,7 +1658,8 @@ class JmessageFlutter { Map param = target.toJson(); param["id"] = msgId; - int count = await _channel.invokeMethod('getMessageUnreceiptCount', param..removeWhere((key,value) => value == null)); + int count = await _channel.invokeMethod('getMessageUnreceiptCount', + param..removeWhere((key, value) => value == null)); return count; } @@ -1585,30 +1674,35 @@ class JmessageFlutter { * */ void getMessageReceiptDetails({ - @required dynamic target, /// (JMSingle | JMGroup) + @required dynamic target, + + /// (JMSingle | JMGroup) @required String msgId, @required JMCallback callback, }) async { print(flutterLog + "getMessageUnreceiptCount" + " msgid = $msgId"); if (msgId == null || msgId.length == 0 || target == null) { - callback(null,null); - return ; + callback(null, null); + return; } Map param = target.toJson(); param["id"] = msgId; - Map resultMap = await _channel.invokeMethod('getMessageReceiptDetails', param..removeWhere((key,value) => value == null)); + Map resultMap = await _channel.invokeMethod('getMessageReceiptDetails', + param..removeWhere((key, value) => value == null)); if (resultMap != null) { - List receiptJosnList = resultMap["receiptList"]; - List unreceiptJosnList = resultMap["unreceiptList"]; - - List receiptUserList = receiptJosnList.map((json) => JMUserInfo.fromJson(json)).toList(); - List unreceiptUserList = unreceiptJosnList.map((json) => JMUserInfo.fromJson(json)).toList(); - callback(receiptUserList,unreceiptUserList); - }else{ - callback(null,null); + List receiptJosnList = resultMap["receiptList"]; + List unreceiptJosnList = resultMap["unreceiptList"]; + + List receiptUserList = + receiptJosnList.map((json) => JMUserInfo.fromJson(json)).toList(); + List unreceiptUserList = + unreceiptJosnList.map((json) => JMUserInfo.fromJson(json)).toList(); + callback(receiptUserList, unreceiptUserList); + } else { + callback(null, null); } } @@ -1620,7 +1714,9 @@ class JmessageFlutter { * @return true/false 设置成功返回 true,设置失败返回 false * */ Future setMessageHaveRead({ - @required dynamic target, /// (JMSingle | JMGroup) + @required dynamic target, + + /// (JMSingle | JMGroup) @required String msgId, }) async { print(flutterLog + "setMessageHaveRead" + " msgid = $msgId"); @@ -1631,7 +1727,8 @@ class JmessageFlutter { Map param = target.toJson(); param["id"] = msgId; - bool isSuccess = await _channel.invokeMethod('setMessageHaveRead', param..removeWhere((key,value) => value == null)); + bool isSuccess = await _channel.invokeMethod('setMessageHaveRead', + param..removeWhere((key, value) => value == null)); return isSuccess; } @@ -1645,7 +1742,9 @@ class JmessageFlutter { * @return * */ Future getMessageHaveReadStatus({ - @required dynamic target, /// (JMSingle | JMGroup) + @required dynamic target, + + /// (JMSingle | JMGroup) @required String msgId, }) async { print(flutterLog + "getMessageHaveReadStatus" + " msgid = $msgId"); @@ -1656,30 +1755,22 @@ class JmessageFlutter { Map param = target.toJson(); param["id"] = msgId; - bool isSuccess = await _channel.invokeMethod('getMessageHaveReadStatus', param..removeWhere((key,value) => value == null)); + bool isSuccess = await _channel.invokeMethod('getMessageHaveReadStatus', + param..removeWhere((key, value) => value == null)); return isSuccess; } } -enum JMPlatformType { - android,ios,windows,web,all -} -enum JMConversationType { - single, group, chatRoom -} +enum JMPlatformType { android, ios, windows, web, all } +enum JMConversationType { single, group, chatRoom } -enum JMTargetType { - user, group -} +enum JMTargetType { user, group } // 'male' | 'female' | 'unknown'; -enum JMGender { - male, female, unknown -} +enum JMGender { male, female, unknown } class JMSingle { - final JMConversationType type = JMConversationType.single; String username; String appKey; @@ -1687,19 +1778,18 @@ class JMSingle { Map toJson() { return { "type": getStringFromEnum(JMConversationType.single), - "username": username, + "username": username, "appKey": appKey - }; + }; } JMSingle.fromJson(Map json) - : username = json['username'], - appKey = json['appKey']; -} -enum JMGroupType { - private, public + : username = json['username'], + appKey = json['appKey']; } +enum JMGroupType { private, public } + class JMGroup { final JMConversationType type = JMConversationType.group; String groupId; @@ -1715,8 +1805,7 @@ class JMGroup { }; } - JMGroup.fromJson(Map json) - : groupId = json['groupId']; + JMGroup.fromJson(Map json) : groupId = json['groupId']; } class JMChatRoom { @@ -1731,33 +1820,28 @@ class JMChatRoom { return { "type": getStringFromEnum(JMConversationType.chatRoom), "roomId": roomId - }; + }; } - JMChatRoom.fromJson(Map json) - : roomId = json['roomId']; + JMChatRoom.fromJson(Map json) : roomId = json['roomId']; } - // export type JMAllType = (JMSingle | JMGroup | JMChatRoom); - class JMMessageSendOptions { - /// 接收方是否针对此次消息发送展示通知栏通知。 /// @defaultvalue bool isShowNotification; - + /// 是否让后台在对方不在线时保存这条离线消息,等到对方上线后再推送给对方。 /// @defaultvalue bool isRetainOffline; - bool isCustomNotificationEnabled; - + /// 设置此条消息在接收方通知栏所展示通知的标题。 String notificationTitle; - + /// 设置此条消息在接收方通知栏所展示通知的内容。 String notificationText; @@ -1766,22 +1850,22 @@ class JMMessageSendOptions { Map toJson() { return { - 'isShowNotification': isShowNotification, - 'isRetainOffline': isRetainOffline, - 'isCustomNotificationEnabled': isCustomNotificationEnabled, - 'notificationTitle': notificationTitle, - 'notificationText': notificationText, - 'needReadReceipt':needReadReceipt, - }; + 'isShowNotification': isShowNotification, + 'isRetainOffline': isRetainOffline, + 'isCustomNotificationEnabled': isCustomNotificationEnabled, + 'notificationTitle': notificationTitle, + 'notificationText': notificationText, + 'needReadReceipt': needReadReceipt, + }; } JMMessageSendOptions.fromJson(Map json) - : isShowNotification = json['isShowNotification'], - isRetainOffline = json['isRetainOffline'], - isCustomNotificationEnabled = json['isCustomNotificationEnabled'], - notificationTitle = json['notificationTitle'], - notificationText = json['notificationText'], - needReadReceipt=json['needReadReceipt']; + : isShowNotification = json['isShowNotification'], + isRetainOffline = json['isRetainOffline'], + isCustomNotificationEnabled = json['isCustomNotificationEnabled'], + notificationTitle = json['notificationTitle'], + notificationText = json['notificationText'], + needReadReceipt = json['needReadReceipt']; } class JMMessageOptions { @@ -1802,83 +1886,81 @@ class JMError { Map toJson() { return { - 'code': code, - 'description': description, - }; + 'code': code, + 'description': description, + }; } JMError.fromJson(Map json) - : code = json['code'], - description = json['description']; + : code = json['code'], + description = json['description']; } class JMUserInfo { - JMTargetType type = JMTargetType.user; + JMTargetType userType = JMTargetType.user; - String username;// 用户名 - String appKey;// 用户所属应用的 appKey,可与 username 共同作为用户的唯一标识 - String nickname;// 昵称 + String username; // 用户名 + String appKey; // 用户所属应用的 appKey,可与 username 共同作为用户的唯一标识 + String nickname; // 昵称 JMGender gender; // 性别 - String avatarThumbPath;// 头像的缩略图地址 - String birthday;// 日期的毫秒数 - String region;// 地区 - String signature;// 个性签名 - String address;// 具体地址 - String noteName;// 备注名 - String noteText;// 备注信息 - bool isNoDisturb;// 是否免打扰 - bool isInBlackList;// 是否在黑名单中 - bool isFriend;// 是否为好友 - Map extras;// 自定义键值对 - - JMSingle get targetType => JMSingle.fromJson({ - 'username': username, - 'appKey': appKey - }); + String avatarThumbPath; // 头像的缩略图地址 + String birthday; // 日期的毫秒数 + String region; // 地区 + String signature; // 个性签名 + String address; // 具体地址 + String noteName; // 备注名 + String noteText; // 备注信息 + bool isNoDisturb; // 是否免打扰 + bool isInBlackList; // 是否在黑名单中 + bool isFriend; // 是否为好友 + Map extras; // 自定义键值对 + + JMSingle get targetType => + JMSingle.fromJson({'username': username, 'appKey': appKey}); bool operator ==(dynamic other) { return (other is JMUserInfo && other.username == username); } Map toJson() { - return { - 'type': getStringFromEnum(type), - 'gender': getStringFromEnum(gender), - 'username': username, - 'appKey': appKey, - 'nickname': nickname, - 'avatarThumbPath': avatarThumbPath, - 'birthday': birthday, - 'region': region, - 'signature': signature, - 'address': address, - 'noteName': noteName, - 'noteText': noteText, - 'isNoDisturb': isNoDisturb, - 'isInBlackList': isInBlackList, - 'isFriend': isFriend, - 'extras': extras - }; + 'type': getStringFromEnum(userType), + 'gender': getStringFromEnum(gender), + 'username': username, + 'appKey': appKey, + 'nickname': nickname, + 'avatarThumbPath': avatarThumbPath, + 'birthday': birthday, + 'region': region, + 'signature': signature, + 'address': address, + 'noteName': noteName, + 'noteText': noteText, + 'isNoDisturb': isNoDisturb, + 'isInBlackList': isInBlackList, + 'isFriend': isFriend, + 'extras': extras + }; } JMUserInfo.fromJson(Map json) - : username = json['username'], - appKey = json['appKey'], - nickname = json['nickname'], - avatarThumbPath = json['avatarThumbPath'], - birthday = json['birthday'], - region = json['region'], - signature = json['signature'], - address = json['address'], - noteName = json['noteName'], - noteText = json['noteText'], - isNoDisturb = json['isNoDisturb'], - isInBlackList = json['isInBlackList'], - isFriend = json['isFriend'], - gender = getEnumFromString(JMGender.values, json['gender']), - extras = json['extras']; + : username = json['username'], + appKey = json['appKey'], + nickname = json['nickname'], + avatarThumbPath = json['avatarThumbPath'], + birthday = json['birthday'], + region = json['region'], + signature = json['signature'], + address = json['address'], + noteName = json['noteName'], + noteText = json['noteText'], + isNoDisturb = json['isNoDisturb'], + isInBlackList = json['isInBlackList'], + isFriend = json['isFriend'], + gender = getEnumFromString(JMGender.values, json['gender']), + extras = json['extras']; } + enum JMMessageState { draft, // 创建的消息,还未发送 sending, // 正在发送中 @@ -1892,84 +1974,81 @@ enum JMMessageState { } class JMNormalMessage { - - String id;// 本地数据库中的消息 id + String id; // 本地数据库中的消息 id JMMessageState state; // 消息的状态 - String serverMessageId;// 对应服务器端的消息 id,只用于在服务端查询问题 - bool isSend;// 消息是否由当前用户发出。true:为当前用户发送;false:为对方用户发送。 - JMUserInfo from;// 消息发送者对象 - int createTime;// 发送消息时间 - Map extras;// 附带的键值对 - dynamic target; // JMUserInfo | JMGroupInfo + String serverMessageId; // 对应服务器端的消息 id,只用于在服务端查询问题 + bool isSend; // 消息是否由当前用户发出。true:为当前用户发送;false:为对方用户发送。 + JMUserInfo from; // 消息发送者对象 + int createTime; // 发送消息时间 + Map extras; // 附带的键值对 + dynamic target; // JMUserInfo | JMGroupInfo Map toJson() { return { - 'id': id, - 'serverMessageId': serverMessageId, - 'isSend': isSend, - 'from': from.toJson(), - 'createTime': createTime, - 'extras': extras, - 'target': target.toJson() - }; + 'id': id, + 'serverMessageId': serverMessageId, + 'isSend': isSend, + 'from': from.toJson(), + 'createTime': createTime, + 'extras': extras, + 'target': target.toJson() + }; } JMNormalMessage.fromJson(Map json) - : id = json['id'], - createTime = json['createTime'], - serverMessageId = json['serverMessageId'], - isSend = json['isSend'], - state = getEnumFromString(JMMessageState.values, json['state']), - from = JMUserInfo.fromJson(json['from']), - extras = json['extras'] { - switch (json['target']['type']) { - case 'user': - target = JMUserInfo.fromJson(json['target']); - break; - case 'group': - target = JMGroupInfo.fromJson(json['target']); - break; - } - } + : id = json['id'], + createTime = json['createTime'], + serverMessageId = json['serverMessageId'], + isSend = json['isSend'], + state = getEnumFromString(JMMessageState.values, json['state']), + from = JMUserInfo.fromJson(json['from']), + extras = json['extras'] { + switch (json['target']['type']) { + case 'user': + target = JMUserInfo.fromJson(json['target']); + break; + case 'group': + target = JMGroupInfo.fromJson(json['target']); + break; + } + } - static dynamic generateMessageFromJson(Map json) { - if (json == null) { - return null; - } + static dynamic generateMessageFromJson(Map json) { + if (json == null) { + return null; + } - JMMessageType type = getEnumFromString(JMMessageType.values, json['type']); - switch (type) { - case JMMessageType.text: - return JMTextMessage.fromJson(json); - break; - case JMMessageType.image: - return JMImageMessage.fromJson(json); - break; - case JMMessageType.voice: - return JMVoiceMessage.fromJson(json); - break; - case JMMessageType.location: - return JMLocationMessage.fromJson(json); - break; - case JMMessageType.file: - return JMFileMessage.fromJson(json); - break; - case JMMessageType.custom: - return JMCustomMessage.fromJson(json); - break; - case JMMessageType.event: - return JMEventMessage.fromJson(json); - break; - case JMMessageType.prompt: - return JMPromptMessage.fromJson(json); - break; - } - } + JMMessageType type = getEnumFromString(JMMessageType.values, json['type']); + switch (type) { + case JMMessageType.text: + return JMTextMessage.fromJson(json); + break; + case JMMessageType.image: + return JMImageMessage.fromJson(json); + break; + case JMMessageType.voice: + return JMVoiceMessage.fromJson(json); + break; + case JMMessageType.location: + return JMLocationMessage.fromJson(json); + break; + case JMMessageType.file: + return JMFileMessage.fromJson(json); + break; + case JMMessageType.custom: + return JMCustomMessage.fromJson(json); + break; + case JMMessageType.event: + return JMEventMessage.fromJson(json); + break; + case JMMessageType.prompt: + return JMPromptMessage.fromJson(json); + break; + } + } } -enum JMMessageType { - text, image, voice, file, custom, location, event,prompt -} +enum JMMessageType { text, image, voice, file, custom, location, event, prompt } class JMTextMessage extends JMNormalMessage { final JMMessageType type = JMMessageType.text; @@ -1983,8 +2062,8 @@ class JMTextMessage extends JMNormalMessage { } JMTextMessage.fromJson(Map json) - : text = json['text'], - super.fromJson(json); + : text = json['text'], + super.fromJson(json); } class JMVoiceMessage extends JMNormalMessage { @@ -1999,9 +2078,9 @@ class JMVoiceMessage extends JMNormalMessage { } JMVoiceMessage.fromJson(Map json) - : path = json['path'], - duration = json['duration'], - super.fromJson(json); + : path = json['path'], + duration = json['duration'], + super.fromJson(json); } class JMImageMessage extends JMNormalMessage { @@ -2014,8 +2093,8 @@ class JMImageMessage extends JMNormalMessage { } JMImageMessage.fromJson(Map json) - : thumbPath = json['thumbPath'], - super.fromJson(json); + : thumbPath = json['thumbPath'], + super.fromJson(json); } class JMFileMessage extends JMNormalMessage { @@ -2028,14 +2107,14 @@ class JMFileMessage extends JMNormalMessage { } JMFileMessage.fromJson(Map json) - : fileName = json['fileName'], - super.fromJson(json); + : fileName = json['fileName'], + super.fromJson(json); } class JMLocationMessage extends JMNormalMessage { - double longitude; // 经度 - double latitude; // 纬度 - int scale; // 地图缩放比例 + double longitude; // 经度 + double latitude; // 纬度 + int scale; // 地图缩放比例 String address; // 详细地址 Map toJson() { @@ -2049,16 +2128,16 @@ class JMLocationMessage extends JMNormalMessage { } JMLocationMessage.fromJson(Map json) - : longitude = json['longitude'], - latitude = json['latitude'], - scale = json['scale'], - address = json['address'], - super.fromJson(json); + : longitude = json['longitude'], + latitude = json['latitude'], + scale = json['scale'], + address = json['address'], + super.fromJson(json); } class JMCustomMessage extends JMNormalMessage { Map customObject; // 自定义键值对 - + Map toJson() { var json = super.toJson(); json['customObject'] = customObject; @@ -2066,11 +2145,10 @@ class JMCustomMessage extends JMNormalMessage { } JMCustomMessage.fromJson(Map json) - : customObject = json['customObject'], - super.fromJson(json); + : customObject = json['customObject'], + super.fromJson(json); } - class JMPromptMessage extends JMNormalMessage { String promptText; @@ -2081,13 +2159,11 @@ class JMPromptMessage extends JMNormalMessage { } JMPromptMessage.fromJson(Map json) - :promptText = json["promptText"], + : promptText = json["promptText"], super.fromJson(json); } -enum JMEventType { - group_member_added, group_member_removed, group_member_exit -} +enum JMEventType { group_member_added, group_member_removed, group_member_exit } class JMEventMessage extends JMNormalMessage { JMEventType eventType; // 事件类型 @@ -2098,17 +2174,14 @@ class JMEventMessage extends JMNormalMessage { json['eventType'] = getStringFromEnum(eventType); json['usernames'] = usernames; return json; - } JMEventMessage.fromJson(Map json) - : eventType = getEnumFromString(JMEventType.values, json['eventType']), - usernames = json['usernames'], - super.fromJson(json); + : eventType = getEnumFromString(JMEventType.values, json['eventType']), + usernames = json['usernames'], + super.fromJson(json); } - - enum JMLoginStateChangedType { user_logout, // 被踢、被迫退出 user_deleted, // 用户被删除 @@ -2118,7 +2191,10 @@ enum JMLoginStateChangedType { } enum JMContactNotifyType { - invite_received, invite_accepted, invite_declined, contact_deleted + invite_received, + invite_accepted, + invite_declined, + contact_deleted } class JMContactNotifyEvent { @@ -2137,10 +2213,10 @@ class JMContactNotifyEvent { } JMContactNotifyEvent.fromJson(Map json) - : type = getEnumFromString(JMContactNotifyType.values, json['type']), - reason = json['reason'], - fromUserName = json['fromUsername'], - fromUserAppKey = json['fromUserAppKey']; + : type = getEnumFromString(JMContactNotifyType.values, json['type']), + reason = json['reason'], + fromUserName = json['fromUsername'], + fromUserAppKey = json['fromUserAppKey']; } class JMReceiveTransCommandEvent { @@ -2159,16 +2235,17 @@ class JMReceiveTransCommandEvent { } JMReceiveTransCommandEvent.fromJson(Map json) - :receiverType = getEnumFromString(JMTargetType.values, json['receiverType']), + : receiverType = + getEnumFromString(JMTargetType.values, json['receiverType']), message = json['message'], sender = JMUserInfo.fromJson(json['sender']) { - switch (receiverType) { - case JMTargetType.user: - receiver = JMUserInfo.fromJson(json['receiver']); - break; - case JMTargetType.group: - receiver = JMGroupInfo.fromJson(json['receiver']); - break; + switch (receiverType) { + case JMTargetType.user: + receiver = JMUserInfo.fromJson(json['receiver']); + break; + case JMTargetType.group: + receiver = JMGroupInfo.fromJson(json['receiver']); + break; } } } @@ -2182,16 +2259,16 @@ class JMReceiveApplyJoinGroupApprovalEvent { String reason; JMReceiveApplyJoinGroupApprovalEvent.fromJson(Map json) - : eventId = json['eventId'], - groupId = json['groupId'], - isInitiativeApply = json['isInitiativeApply'], - sendApplyUser = JMUserInfo.fromJson(json['sendApplyUser']), - reason = json['reason'] { - List userJsons = json['joinGroupUsers']; - joinGroupUsers = userJsons.map( (userJson) { - return JMUserInfo.fromJson(userJson); - }).toList(); - } + : eventId = json['eventId'], + groupId = json['groupId'], + isInitiativeApply = json['isInitiativeApply'], + sendApplyUser = JMUserInfo.fromJson(json['sendApplyUser']), + reason = json['reason'] { + List userJsons = json['joinGroupUsers']; + joinGroupUsers = userJsons.map((userJson) { + return JMUserInfo.fromJson(userJson); + }).toList(); + } } class JMReceiveGroupAdminRejectEvent { @@ -2200,9 +2277,9 @@ class JMReceiveGroupAdminRejectEvent { String reason; JMReceiveGroupAdminRejectEvent.fromJson(Map json) - : groupId = json['groupId'], - groupManager = JMUserInfo.fromJson(json['groupManager']), - reason = json['reason']; + : groupId = json['groupId'], + groupManager = JMUserInfo.fromJson(json['groupManager']), + reason = json['reason']; } class JMReceiveGroupAdminApprovalEvent { @@ -2213,31 +2290,29 @@ class JMReceiveGroupAdminApprovalEvent { List users; JMReceiveGroupAdminApprovalEvent.fromJson(Map json) - : isAgree = json['isAgree'], - applyEventId = json['applyEventId'] , - groupId = json['groupId'], - groupAdmin = JMUserInfo.fromJson(json['groupAdmin']) { - List userJsons = json['users']; - users = userJsons.map( (userJson) { - return JMUserInfo.fromJson(userJson); - }).toList(); - } + : isAgree = json['isAgree'], + applyEventId = json['applyEventId'], + groupId = json['groupId'], + groupAdmin = JMUserInfo.fromJson(json['groupAdmin']) { + List userJsons = json['users']; + users = userJsons.map((userJson) { + return JMUserInfo.fromJson(userJson); + }).toList(); + } } class JMGroupInfo { - String id; // 群组 id + String id; // 群组 id String name; // 群组名称 String desc; // 群组描述 - int level; // 群组等级,默认等级 4 + int level; // 群组等级,默认等级 4 String owner; // 群主的 username String ownerAppKey; // 群主的 appKey int maxMemberCount; // 最大成员数 bool isNoDisturb; // 是否免打扰 bool isBlocked; // 是否屏蔽群消息 JMGroupType groupType; // 群类型 - JMGroup get targetType => JMGroup.fromJson({ - 'groupId': id - }); + JMGroup get targetType => JMGroup.fromJson({'groupId': id}); bool operator ==(dynamic other) { return (other is JMGroupInfo && other.id == id); @@ -2245,48 +2320,47 @@ class JMGroupInfo { Map toJson() { return { - 'id': id, - 'name': name, - 'desc': desc, - 'level': level, - 'owner': owner, - 'ownerAppKey': ownerAppKey, - 'maxMemberCount': maxMemberCount, - 'isNoDisturb': isNoDisturb, - 'isBlocked': isBlocked, - 'groupType': getStringFromEnum(groupType), - }; - + 'id': id, + 'name': name, + 'desc': desc, + 'level': level, + 'owner': owner, + 'ownerAppKey': ownerAppKey, + 'maxMemberCount': maxMemberCount, + 'isNoDisturb': isNoDisturb, + 'isBlocked': isBlocked, + 'groupType': getStringFromEnum(groupType), + }; } JMGroupInfo.fromJson(Map json) - : id = json['id'], - name = json['name'], - desc = json['desc'], - level = json['level'], - owner = json['owner'], - ownerAppKey = json['ownerAppKey'], - maxMemberCount = json['maxMemberCount'], - isNoDisturb = json['isNoDisturb'], - isBlocked = json['isBlocked'], - groupType = getEnumFromString(JMGroupType.values, json['groupType']); - - Future exitGroup({ @required String id}) async { + : id = json['id'], + name = json['name'], + desc = json['desc'], + level = json['level'], + owner = json['owner'], + ownerAppKey = json['ownerAppKey'], + maxMemberCount = json['maxMemberCount'], + isNoDisturb = json['isNoDisturb'], + isBlocked = json['isBlocked'], + groupType = getEnumFromString(JMGroupType.values, json['groupType']); + + Future exitGroup({@required String id}) async { await JmessageFlutter().exitGroup(id: id); return; } - Future updateGroupInfo({ - String newName, - String newDesc, - }) async { - await JmessageFlutter().updateGroupInfo( - id: id, - newDesc: newDesc, - newName: newName, - ); - return; - } + Future updateGroupInfo({ + String newName, + String newDesc, + }) async { + await JmessageFlutter().updateGroupInfo( + id: id, + newDesc: newDesc, + newName: newName, + ); + return; + } } enum JMGroupMemberType { @@ -2303,57 +2377,56 @@ class JMGroupMemberInfo { Map toJson() { return { - 'user': user.toJson(), - 'groupNickname': groupNickname, - 'memberType': getStringFromEnum(memberType), - 'joinGroupTime': joinGroupTime - }; + 'user': user.toJson(), + 'groupNickname': groupNickname, + 'memberType': getStringFromEnum(memberType), + 'joinGroupTime': joinGroupTime + }; } JMGroupMemberInfo.fromJson(Map json) - : user = JMUserInfo.fromJson(json['user']), - groupNickname = json['groupNickname'], - memberType = getEnumFromString(JMGroupMemberType.values, json['memberType']), - joinGroupTime = json['joinGroupTime']; + : user = JMUserInfo.fromJson(json['user']), + groupNickname = json['groupNickname'], + memberType = + getEnumFromString(JMGroupMemberType.values, json['memberType']), + joinGroupTime = json['joinGroupTime']; } class JMChatRoomInfo { - String roomId;// 聊天室 id - String name;// 聊天室名称 - String appKey;// 聊天室所属应用的 App Key - String description;// 聊天室描述信息 - int createTime;// 创建日期,单位:秒 - int maxMemberCount;// 最大成员数 - int memberCount;// 当前成员数 - - JMChatRoom get targetType => JMChatRoom.fromJson({ - 'roomId': roomId - }); - + String roomId; // 聊天室 id + String name; // 聊天室名称 + String appKey; // 聊天室所属应用的 App Key + String description; // 聊天室描述信息 + int createTime; // 创建日期,单位:秒 + int maxMemberCount; // 最大成员数 + int memberCount; // 当前成员数 + + JMChatRoom get targetType => JMChatRoom.fromJson({'roomId': roomId}); + bool operator ==(dynamic other) { return (other is JMChatRoomInfo && other.roomId == roomId); } Map toJson() { return { - 'roomId': roomId, - 'name': name, - 'appKey': appKey, - 'description': description, - 'createTime': createTime, - 'maxMemberCount': maxMemberCount, - 'memberCount': memberCount, - }; + 'roomId': roomId, + 'name': name, + 'appKey': appKey, + 'description': description, + 'createTime': createTime, + 'maxMemberCount': maxMemberCount, + 'memberCount': memberCount, + }; } JMChatRoomInfo.fromJson(Map json) - : roomId = json['roomId'], - name = json['name'], - appKey = json['appKey'], - description = json['description'], - createTime = json['createTime'], - maxMemberCount = json['maxMemberCount'], - memberCount = json['memberCount']; + : roomId = json['roomId'], + name = json['name'], + appKey = json['appKey'], + description = json['description'], + createTime = json['createTime'], + maxMemberCount = json['maxMemberCount'], + memberCount = json['memberCount']; } class JMConversationInfo { @@ -2369,29 +2442,31 @@ class JMConversationInfo { 'title': title, 'conversationType': getStringFromEnum(conversationType), 'unreadCount': unreadCount, - 'extras': extras.toString(), + 'extras': json.encode(extras), }; } - JMConversationInfo.fromJson(Map json) - : conversationType = getEnumFromString(JMConversationType.values, json['conversationType']), - title = json['title'], - unreadCount = json['unreadCount'], - extras = json['extras'] { - switch (conversationType) { - case JMConversationType.single: - target = JMUserInfo.fromJson(json['target']); - break; - case JMConversationType.group: - target = JMGroupInfo.fromJson(json['target']); - break; - case JMConversationType.chatRoom: - target = JMChatRoomInfo.fromJson(json['target']); - break; - } - - latestMessage = JMNormalMessage.generateMessageFromJson(json['latestMessage']); - } + JMConversationInfo.fromJson(Map map) + : conversationType = getEnumFromString( + JMConversationType.values, map['conversationType']), + title = map['title'], + unreadCount = map['unreadCount'], + extras = json.decode(map['extras']) { + switch (conversationType) { + case JMConversationType.single: + target = JMUserInfo.fromJson(map['target']); + break; + case JMConversationType.group: + target = JMGroupInfo.fromJson(map['target']); + break; + case JMConversationType.chatRoom: + target = JMChatRoomInfo.fromJson(map['target']); + break; + } + + latestMessage = + JMNormalMessage.generateMessageFromJson(map['latestMessage']); + } bool isMyMessage(dynamic message) { // TODO: @@ -2406,8 +2481,7 @@ class JMConversationInfo { extras: extras, ); } - - + // sendText Future sendTextMessage({ @required String text, @@ -2415,13 +2489,13 @@ class JMConversationInfo { Map extras, }) async { JMTextMessage msg = await JmessageFlutter().sendTextMessage( - type: target.targetType, - text: text, - sendOption: sendOption, - extras: extras - ); + type: target.targetType, + text: text, + sendOption: sendOption, + extras: extras); return msg; } + // sendImage Future sendImageMessage({ @required String path, @@ -2436,6 +2510,7 @@ class JMConversationInfo { ); return msg; } + // sendVoice Future sendVoiceMessage({ @required String path, @@ -2450,6 +2525,7 @@ class JMConversationInfo { ); return msg; } + // sendCustom Future sendCustomMessage({ @required Map customObject, @@ -2464,6 +2540,7 @@ class JMConversationInfo { ); return msg; } + // sendLocation Future sendLocationMessage({ @required double latitude, @@ -2484,9 +2561,12 @@ class JMConversationInfo { ); return msg; } + // sendFile Future sendFileMessage({ - @required dynamic type, /// (JMSingle | JMGroup | JMChatRoom) + @required dynamic type, + + /// (JMSingle | JMGroup | JMChatRoom) @required String path, JMMessageSendOptions sendOption, Map extras, @@ -2501,18 +2581,13 @@ class JMConversationInfo { } // getHistoryMessages - Future getHistoryMessages({ - @required int from, - @required int limit, - bool isDescend = false - }) async { + Future getHistoryMessages( + {@required int from, @required int limit, bool isDescend = false}) async { List msgs = await JmessageFlutter().getHistoryMessages( - type: target.targetType, - from: from, - limit: limit, - isDescend: isDescend - ); + type: target.targetType, + from: from, + limit: limit, + isDescend: isDescend); return msgs; } - -} \ No newline at end of file +} From 2efcb5c2a6b4b2a76aa4c67c9abd953e9548cf6b Mon Sep 17 00:00:00 2001 From: Angus Date: Wed, 24 Jun 2020 07:56:13 +0800 Subject: [PATCH 2/5] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3JMConversationInfo?= =?UTF-8?q?=20toJson=E4=B8=8EfromJson=E7=9A=84=E4=BA=92=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/jmessage_flutter.dart | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/jmessage_flutter.dart b/lib/jmessage_flutter.dart index 9140311..7bfa146 100644 --- a/lib/jmessage_flutter.dart +++ b/lib/jmessage_flutter.dart @@ -2442,7 +2442,8 @@ class JMConversationInfo { 'title': title, 'conversationType': getStringFromEnum(conversationType), 'unreadCount': unreadCount, - 'extras': json.encode(extras), + 'target': target, + 'extras': extras, }; } @@ -2451,16 +2452,28 @@ class JMConversationInfo { JMConversationType.values, map['conversationType']), title = map['title'], unreadCount = map['unreadCount'], - extras = json.decode(map['extras']) { + extras = map['extras'] { switch (conversationType) { case JMConversationType.single: - target = JMUserInfo.fromJson(map['target']); + if (map['target'].runtimeType == JMUserInfo) { + target = map['target']; + } else { + target = JMUserInfo.fromJson(map['target']); + } break; case JMConversationType.group: - target = JMGroupInfo.fromJson(map['target']); + if (map['target'].runtimeType == JMGroupInfo) { + target = map['target']; + } else { + target = JMGroupInfo.fromJson(map['target']); + } break; case JMConversationType.chatRoom: - target = JMChatRoomInfo.fromJson(map['target']); + if (map['target'].runtimeType == JMChatRoomInfo) { + target = map['target']; + } else { + target = JMChatRoomInfo.fromJson(map['target']); + } break; } From 1ede32fa495d8c20db0cdaca3291f6a924d5e327 Mon Sep 17 00:00:00 2001 From: Pepe Date: Sun, 4 Jul 2021 15:03:17 +0800 Subject: [PATCH 3/5] =?UTF-8?q?wip:=20=E8=A7=A3=E5=86=B3=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=92=8Cnull=20safe=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/jmessage_flutter.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jmessage_flutter.dart b/lib/jmessage_flutter.dart index 64f0a3e..6740fab 100644 --- a/lib/jmessage_flutter.dart +++ b/lib/jmessage_flutter.dart @@ -444,7 +444,7 @@ class JmessageFlutter { } print("Action - login: username=$username,pw=$password"); - Map userJson = await _channel + Map? userJson = await _channel .invokeMethod('login', {'username': username, 'password': password}); if (userJson == null) { return null; @@ -1977,7 +1977,7 @@ class JMUserInfo { Map toJson() { return { - 'type': getStringFromEnum(type), + 'type': getStringFromEnum(userType), 'gender': getStringFromEnum(gender), 'username': username, 'appKey': appKey, From 8d4ae7189a663ac790d5655511a25d76816eedd2 Mon Sep 17 00:00:00 2001 From: Pepe Date: Sat, 14 Aug 2021 21:12:09 +0800 Subject: [PATCH 4/5] =?UTF-8?q?wip:=E6=9B=B4=E6=96=B0=E4=BE=9D=E8=B5=96JPC?= =?UTF-8?q?ore=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/build.gradle | 2 +- example/.flutter-plugins-dependencies | 2 +- example/android/app/build.gradle | 6 +++--- example/ios/Flutter/flutter_export_environment.sh | 8 ++++---- lib/jmessage_flutter.dart | 1 - 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index f0f6041..9cb5a82 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -38,5 +38,5 @@ android { dependencies { implementation 'cn.jiguang.sdk:jmessage:2.9.2' - implementation 'cn.jiguang.sdk:jcore:2.8.2' + implementation 'cn.jiguang.sdk:jcore:2.9.2' } \ No newline at end of file diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies index bc25b71..2624f6c 100644 --- a/example/.flutter-plugins-dependencies +++ b/example/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"image_picker","path":"D:\\\\Workspace\\\\android\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.flutter-io.cn\\\\image_picker-0.7.5+2\\\\","dependencies":[]},{"name":"jmessage_flutter","path":"D:\\\\Workspace\\\\flutter\\\\jmessage-flutter-plugin\\\\","dependencies":[]},{"name":"modal_progress_hud_nsn","path":"D:\\\\Workspace\\\\android\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.flutter-io.cn\\\\modal_progress_hud_nsn-0.1.0-nullsafety-1\\\\","dependencies":[]},{"name":"video_thumbnail","path":"D:\\\\Workspace\\\\android\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.flutter-io.cn\\\\video_thumbnail-0.3.3\\\\","dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"D:\\\\Workspace\\\\android\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.flutter-io.cn\\\\flutter_plugin_android_lifecycle-2.0.1\\\\","dependencies":[]},{"name":"image_picker","path":"D:\\\\Workspace\\\\android\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.flutter-io.cn\\\\image_picker-0.7.5+2\\\\","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"jmessage_flutter","path":"D:\\\\Workspace\\\\flutter\\\\jmessage-flutter-plugin\\\\","dependencies":[]},{"name":"modal_progress_hud_nsn","path":"D:\\\\Workspace\\\\android\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.flutter-io.cn\\\\modal_progress_hud_nsn-0.1.0-nullsafety-1\\\\","dependencies":[]},{"name":"video_thumbnail","path":"D:\\\\Workspace\\\\android\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.flutter-io.cn\\\\video_thumbnail-0.3.3\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[{"name":"image_picker_for_web","path":"D:\\\\Workspace\\\\android\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.flutter-io.cn\\\\image_picker_for_web-2.0.0\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"image_picker","dependencies":["flutter_plugin_android_lifecycle","image_picker_for_web"]},{"name":"image_picker_for_web","dependencies":[]},{"name":"jmessage_flutter","dependencies":[]},{"name":"modal_progress_hud_nsn","dependencies":[]},{"name":"video_thumbnail","dependencies":[]}],"date_created":"2021-06-01 11:58:00.043626","version":"2.2.0"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"image_picker","path":"/Users/angus/.pub-cache/hosted/pub.flutter-io.cn/image_picker-0.7.5+4/","dependencies":[]},{"name":"jmessage_flutter","path":"/Users/angus/Projects/jmessage-flutter-plugin/","dependencies":[]},{"name":"modal_progress_hud_nsn","path":"/Users/angus/.pub-cache/hosted/pub.flutter-io.cn/modal_progress_hud_nsn-0.1.0-nullsafety-1/","dependencies":[]},{"name":"video_thumbnail","path":"/Users/angus/.pub-cache/hosted/pub.flutter-io.cn/video_thumbnail-0.3.3/","dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"/Users/angus/.pub-cache/hosted/pub.flutter-io.cn/flutter_plugin_android_lifecycle-2.0.2/","dependencies":[]},{"name":"image_picker","path":"/Users/angus/.pub-cache/hosted/pub.flutter-io.cn/image_picker-0.7.5+4/","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"jmessage_flutter","path":"/Users/angus/Projects/jmessage-flutter-plugin/","dependencies":[]},{"name":"modal_progress_hud_nsn","path":"/Users/angus/.pub-cache/hosted/pub.flutter-io.cn/modal_progress_hud_nsn-0.1.0-nullsafety-1/","dependencies":[]},{"name":"video_thumbnail","path":"/Users/angus/.pub-cache/hosted/pub.flutter-io.cn/video_thumbnail-0.3.3/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[{"name":"image_picker_for_web","path":"/Users/angus/.pub-cache/hosted/pub.flutter-io.cn/image_picker_for_web-2.1.2/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"image_picker","dependencies":["flutter_plugin_android_lifecycle","image_picker_for_web"]},{"name":"image_picker_for_web","dependencies":[]},{"name":"jmessage_flutter","dependencies":[]},{"name":"modal_progress_hud_nsn","dependencies":[]},{"name":"video_thumbnail","dependencies":[]}],"date_created":"2021-08-14 21:10:45.736445","version":"2.2.3"} \ No newline at end of file diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index ce62977..21ceeea 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -25,7 +25,7 @@ apply plugin: 'com.android.application' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 28 + compileSdkVersion 30 lintOptions { disable 'InvalidPackage' @@ -35,7 +35,7 @@ android { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.shikk.testJpush" minSdkVersion 17 - targetSdkVersion 28 + targetSdkVersion 30 versionCode flutterVersionCode.toInteger() versionName flutterVersionName testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -67,7 +67,7 @@ flutter { } dependencies { - testImplementation 'junit:junit:4.12' + testImplementation 'junit:junit:4.13.1' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' } diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh index 159b7cb..a24d748 100755 --- a/example/ios/Flutter/flutter_export_environment.sh +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -1,11 +1,11 @@ #!/bin/sh # This is a generated file; do not edit or check into version control. -export "FLUTTER_ROOT=D:\Workspace\android\flutter" -export "FLUTTER_APPLICATION_PATH=D:\Workspace\flutter\jmessage-flutter-plugin\example" +export "FLUTTER_ROOT=/Users/angus/flutter" +export "FLUTTER_APPLICATION_PATH=/Users/angus/Projects/jmessage-flutter-plugin/example" export "COCOAPODS_PARALLEL_CODE_SIGN=true" -export "FLUTTER_TARGET=lib\main.dart" +export "FLUTTER_TARGET=lib/main.dart" export "FLUTTER_BUILD_DIR=build" -export "SYMROOT=${SOURCE_ROOT}/../build\ios" +export "SYMROOT=${SOURCE_ROOT}/../build/ios" export "FLUTTER_BUILD_NAME=1.0.0" export "FLUTTER_BUILD_NUMBER=1" export "DART_OBFUSCATION=false" diff --git a/lib/jmessage_flutter.dart b/lib/jmessage_flutter.dart index a5b8c13..42ecbf9 100644 --- a/lib/jmessage_flutter.dart +++ b/lib/jmessage_flutter.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:convert'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; From d54d94eb9c83c36977166536869c6d76b799fda0 Mon Sep 17 00:00:00 2001 From: Pepe Date: Sun, 9 Nov 2025 12:16:03 +0800 Subject: [PATCH 5/5] Update description in pubspec.yaml Removed Chinese description from pubspec.yaml. --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 4f0e6c7..e22a6aa 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: jmessage_flutter -description: JIGUANG officially supported JMessage Flutter plugin (Android & iOS). 极光推送官方支持的 Flutter 插件(Android & iOS)(https://www.jiguang.cn). +description: JIGUANG officially supported JMessage Flutter plugin (Android & iOS) version: 2.2.1 homepage: https://www.jiguang.cn