diff --git a/CHANGELOG.md b/CHANGELOG.md index c1f38be..00b07a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 1.0.8 + +1.Upgrade sdk to 1.4.4.
+2.New and changed conversation return changed data and no longer return all data.
+3.New conversation paging method. + ## 1.0.7 Upgrade sdk to 1.3.4
diff --git a/android/build.gradle b/android/build.gradle index 0772a13..5b46479 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -51,5 +51,5 @@ android { } } dependencies { - implementation 'io.openim:client-sdk:1.3.4@aar' + implementation 'io.openim:client-sdk:1.4.4@aar' } \ No newline at end of file diff --git a/android/src/main/java/io/openim/flutter_openim_sdk/listener/BaseListener.java b/android/src/main/java/io/openim/flutter_openim_sdk/listener/BaseListener.java index 41810a4..10f4328 100644 --- a/android/src/main/java/io/openim/flutter_openim_sdk/listener/BaseListener.java +++ b/android/src/main/java/io/openim/flutter_openim_sdk/listener/BaseListener.java @@ -16,13 +16,13 @@ public class BaseListener implements Base { @Override public void onError(long l, String s) { - Log.e("F-OpenIMSD(callback)", s); +// Log.e("F-OpenIMSD(callback)", s); CommonUtil.runMainThreadReturnError(result, l, s, null); } @Override public void onSuccess(String s) { - Log.i("F-OpenIMSDK(callback)", s); +// Log.i("F-OpenIMSDK(callback)", s); CommonUtil.runMainThreadReturn(result, s); } } diff --git a/android/src/main/java/io/openim/flutter_openim_sdk/manager/ConversationManager.java b/android/src/main/java/io/openim/flutter_openim_sdk/manager/ConversationManager.java index 343b53e..cb0ab11 100644 --- a/android/src/main/java/io/openim/flutter_openim_sdk/manager/ConversationManager.java +++ b/android/src/main/java/io/openim/flutter_openim_sdk/manager/ConversationManager.java @@ -17,6 +17,12 @@ public class ConversationManager extends BaseManager { Open_im_sdk.getAllConversationList(new BaseListener(result)); } + public void getConversationListSplit(MethodCall methodCall, MethodChannel.Result result) { + Open_im_sdk.getConversationListSplit(new BaseListener(result), + int2long(methodCall, "offset"), + int2long(methodCall, "count")); + } + public void getOneConversation(MethodCall methodCall, MethodChannel.Result result) { Open_im_sdk.getOneConversation( value(methodCall, "sourceID"), diff --git a/ios/Classes/Module/ConversationManager.swift b/ios/Classes/Module/ConversationManager.swift index d686603..c0fa39d 100644 --- a/ios/Classes/Module/ConversationManager.swift +++ b/ios/Classes/Module/ConversationManager.swift @@ -15,6 +15,7 @@ public class ConversationManager: BaseServiceManager { self["setConversationListener"] = setConversationListener self["getAllConversationList"] = getAllConversationList + self["getConversationListSplit"] = getConversationListSplit self["getOneConversation"] = getOneConversation self["getMultipleConversation"] = getMultipleConversation self["deleteConversation"] = deleteConversation @@ -36,7 +37,11 @@ public class ConversationManager: BaseServiceManager { func getAllConversationList(methodCall: FlutterMethodCall, result: @escaping FlutterResult){ Open_im_sdkGetAllConversationList(BaseCallback(result: result)) } - + + func getConversationListSplit(methodCall: FlutterMethodCall, result: @escaping FlutterResult){ + Open_im_sdkGetConversationListSplit(BaseCallback(result: result), methodCall[int: "offset"], methodCall[int: "count"]) + } + func getOneConversation(methodCall: FlutterMethodCall, result: @escaping FlutterResult){ Open_im_sdkGetOneConversation(methodCall[string: "sourceID"], methodCall[int: "sessionType"], BaseCallback(result: result)) } @@ -75,7 +80,7 @@ public class ConversationManager: BaseServiceManager { } func setConversationRecvMessageOpt(methodCall: FlutterMethodCall, result: @escaping FlutterResult){ - Open_im_sdkSetConversationRecvMessageOpt(BaseCallback(result: result), methodCall[jsonString: "conversationIDList"], Int(methodCall[int64: "status"])) + Open_im_sdkSetConversationRecvMessageOpt(BaseCallback(result: result), methodCall[jsonString: "conversationIDList"], methodCall[int: "status"]) } func getConversationRecvMessageOpt(methodCall: FlutterMethodCall, result: @escaping FlutterResult){ diff --git a/ios/Framework/OpenIMCore.framework/Headers/Open_im_sdk.objc.h b/ios/Framework/OpenIMCore.framework/Headers/Open_im_sdk.objc.h index ea436a1..de38b93 100644 --- a/ios/Framework/OpenIMCore.framework/Headers/Open_im_sdk.objc.h +++ b/ios/Framework/OpenIMCore.framework/Headers/Open_im_sdk.objc.h @@ -941,6 +941,7 @@ - (void)getBlackList:(id _Nullable)callback; // skipped method UserRelated.GetCh with unsupported parameter or return types +- (void)getConversationListSplit:(id _Nullable)callback offset:(long)offset count:(long)count; - (void)getConversationRecvMessageOpt:(id _Nullable)callback conversationIDList:(NSString* _Nullable)conversationIDList; - (void)getFriendApplicationList:(id _Nullable)callback; - (void)getFriendList:(id _Nullable)callback; @@ -1157,8 +1158,6 @@ FOUNDATION_EXPORT NSString* _Nonnull const Open_im_sdkCmdReLogin; FOUNDATION_EXPORT NSString* _Nonnull const Open_im_sdkCmdRefuseFriend; FOUNDATION_EXPORT NSString* _Nonnull const Open_im_sdkCmdUnInit; FOUNDATION_EXPORT NSString* _Nonnull const Open_im_sdkCmdUpdateConversation; -FOUNDATION_EXPORT const int64_t Open_im_sdkConAndUnreadChange; -FOUNDATION_EXPORT const int64_t Open_im_sdkConChange; FOUNDATION_EXPORT const int64_t Open_im_sdkCreateGroupTip; FOUNDATION_EXPORT const int64_t Open_im_sdkCustom; FOUNDATION_EXPORT NSString* _Nonnull const Open_im_sdkDeFaultSuccessMsg; @@ -1207,9 +1206,13 @@ FOUNDATION_EXPORT const int64_t Open_im_sdkMsgStatusSendSuccess; * MsgStatus */ FOUNDATION_EXPORT const int64_t Open_im_sdkMsgStatusSending; +FOUNDATION_EXPORT const int64_t Open_im_sdkNewCon; +FOUNDATION_EXPORT const int64_t Open_im_sdkNewConChange; +FOUNDATION_EXPORT const int64_t Open_im_sdkNotPinned; FOUNDATION_EXPORT const int64_t Open_im_sdkNotRead; FOUNDATION_EXPORT const int64_t Open_im_sdkNotReceiveMessage; FOUNDATION_EXPORT const int64_t Open_im_sdkPicture; +FOUNDATION_EXPORT const int64_t Open_im_sdkPinned; FOUNDATION_EXPORT const int64_t Open_im_sdkQuitGroupTip; FOUNDATION_EXPORT const int64_t Open_im_sdkQuote; /** @@ -1536,6 +1539,8 @@ FOUNDATION_EXPORT void Open_im_sdkGetBlackList(id _Nullable cal FOUNDATION_EXPORT NSString* _Nonnull Open_im_sdkGetConversationIDBySessionType(NSString* _Nullable sourceID, long sessionType); +FOUNDATION_EXPORT void Open_im_sdkGetConversationListSplit(id _Nullable callback, long offset, long count); + FOUNDATION_EXPORT void Open_im_sdkGetConversationRecvMessageOpt(id _Nullable callback, NSString* _Nullable conversationIDList); /** @@ -1686,6 +1691,8 @@ FOUNDATION_EXPORT void Open_im_sdkSetGroupInfo(NSString* _Nullable jsonGroupInfo FOUNDATION_EXPORT void Open_im_sdkSetGroupListener(id _Nullable callback); +FOUNDATION_EXPORT void Open_im_sdkSetHearbeatInterval(int32_t interval); + /** * 1 no print */ diff --git a/ios/Framework/OpenIMCore.framework/OpenIMCore b/ios/Framework/OpenIMCore.framework/OpenIMCore index 07bed32..34398ef 100644 Binary files a/ios/Framework/OpenIMCore.framework/OpenIMCore and b/ios/Framework/OpenIMCore.framework/OpenIMCore differ diff --git a/lib/src/manager/im_conversation_manager.dart b/lib/src/manager/im_conversation_manager.dart index feda350..f736742 100644 --- a/lib/src/manager/im_conversation_manager.dart +++ b/lib/src/manager/im_conversation_manager.dart @@ -8,6 +8,7 @@ import 'package:flutter_openim_sdk/flutter_openim_sdk.dart'; class ConversationManager { MethodChannel _channel; late ConversationListener conversationListener; + var count = 0; ConversationManager(this._channel); @@ -22,6 +23,20 @@ class ConversationManager { .invokeMethod('getAllConversationList', _buildParam({})) .then((value) => _toList(value)); + /// Paging to get conversation + Future> getConversationListSplit({ + int offset = 0, + int count = 20, + }) => + _channel + .invokeMethod( + 'getConversationListSplit', + _buildParam({ + 'offset': offset, + 'count': count, + })) + .then((value) => _toList(value)); + /// Get a single conversation info /// [sourceID] if it is a single chat, Its value is userID. if it is a group chat, Its value is groupID /// [sessionType] if it is a single chat, it value is 1. if it is a group chat, it value is 2 @@ -91,21 +106,18 @@ class ConversationManager { .then((value) => _printValue(value)); /// Mark single chat messages as read - Future markSingleMessageHasRead({required String userID}) { - return _channel.invokeMethod( - 'markSingleMessageHasRead', _buildParam({'userID': userID})); - } + Future markSingleMessageHasRead({required String userID}) => + _channel.invokeMethod( + 'markSingleMessageHasRead', _buildParam({'userID': userID})); /// Mark group chat messages as read - Future markGroupMessageHasRead({required String groupID}) { - return _channel.invokeMethod( - 'markGroupMessageHasRead', _buildParam({'groupID': groupID})); - } + Future markGroupMessageHasRead({required String groupID}) => + _channel.invokeMethod( + 'markGroupMessageHasRead', _buildParam({'groupID': groupID})); /// Get the total number of unread messages - Future getTotalUnreadMsgCount() { - return _channel.invokeMethod('getTotalUnreadMsgCount', _buildParam({})); - } + Future getTotalUnreadMsgCount() => + _channel.invokeMethod('getTotalUnreadMsgCount', _buildParam({})); /// Query conversation id /// [sourceID] : if it is a single chat, Its value is userID. if it is a group chat, Its value is groupID @@ -113,42 +125,64 @@ class ConversationManager { Future getConversationID({ required String sourceID, required int sessionType, - }) { - return _channel.invokeMethod( - 'getConversationIDBySessionType', - _buildParam({ - "sourceID": sourceID, - "sessionType": sessionType, - })); - } + }) => + _channel.invokeMethod( + 'getConversationIDBySessionType', + _buildParam({ + "sourceID": sourceID, + "sessionType": sessionType, + })); /// Message Do Not Disturb /// [ status ] 1: Do not receive messages, 2: Do not notify when messages are received; 0: Normal Future setConversationRecvMessageOpt({ required List conversationIDList, required int status, - }) { - return _channel.invokeMethod( - 'setConversationRecvMessageOpt', - _buildParam({ - "conversationIDList": conversationIDList, - "status": status, - })); - } + }) => + _channel.invokeMethod( + 'setConversationRecvMessageOpt', + _buildParam({ + "conversationIDList": conversationIDList, + "status": status, + })); /// Message Do Not Disturb /// [{"conversationId":"single_13922222222","result":0}] Future> getConversationRecvMessageOpt({ required List conversationIDList, - }) { - return _channel - .invokeMethod( - 'getConversationRecvMessageOpt', - _buildParam({ - "conversationIDList": conversationIDList, - })) - .then((value) => _formatJson(value)); - } + }) => + _channel + .invokeMethod( + 'getConversationRecvMessageOpt', + _buildParam({ + "conversationIDList": conversationIDList, + })) + .then((value) => _formatJson(value)); + + /// Custom sort for conversation list + List simpleSort(List list) => list + ..sort((a, b) { + if ((a.isPinned == 1 && b.isPinned == 1) || + (a.isPinned != 1 && b.isPinned != 1)) { + int aCompare = a.draftTimestamp! > a.latestMsgSendTime! + ? a.draftTimestamp! + : a.latestMsgSendTime!; + int bCompare = b.draftTimestamp! > b.latestMsgSendTime! + ? b.draftTimestamp! + : b.latestMsgSendTime!; + if (aCompare > bCompare) { + return -1; + } else if (aCompare < bCompare) { + return 1; + } else { + return 0; + } + } else if (a.isPinned == 1 && b.isPinned != 1) { + return -1; + } else { + return 1; + } + }); static Map _buildParam(Map param) { param["ManagerName"] = "conversationManager"; @@ -164,9 +198,7 @@ class ConversationManager { static ConversationInfo _toObj(String value) => ConversationInfo.fromJson(_formatJson(value)); - static dynamic _formatJson(value) { - return jsonDecode(_printValue(value)); - } + static dynamic _formatJson(value) => jsonDecode(_printValue(value)); static String _printValue(value) { return value; diff --git a/lib/src/manager/im_friendship_manager.dart b/lib/src/manager/im_friendship_manager.dart index 517d1d2..7438896 100644 --- a/lib/src/manager/im_friendship_manager.dart +++ b/lib/src/manager/im_friendship_manager.dart @@ -16,92 +16,70 @@ class FriendshipManager { } /// Get friend info by user id - Future> getFriendsInfo({required List uidList}) { - return _channel - .invokeMethod('getFriendsInfo', _buildParam({"uidList": uidList})) - .then((value) => _toList(value)); - } + Future> getFriendsInfo({required List uidList}) => + _channel + .invokeMethod('getFriendsInfo', _buildParam({"uidList": uidList})) + .then((value) => _toList(value)); /// Send an friend application - Future addFriend({required String uid, required String reason}) { - return _channel.invokeMethod( - 'addFriend', _buildParam({"uid": uid, "reqMessage": reason})); - } + Future addFriend({required String uid, required String reason}) => + _channel.invokeMethod( + 'addFriend', _buildParam({"uid": uid, "reqMessage": reason})); /// Get all friend application, sent to you by others - Future> getFriendApplicationList() { - return _channel - .invokeMethod('getFriendApplicationList', _buildParam({})) - .then((value) => _toList(value)); - } + Future> getFriendApplicationList() => _channel + .invokeMethod('getFriendApplicationList', _buildParam({})) + .then((value) => _toList(value)); /// Find all friends including those who have been added to the blacklist - Future> getFriendList() { - return _channel - .invokeMethod('getFriendList', _buildParam({})) - .then((value) => _toList(value)); - } + Future> getFriendList() => _channel + .invokeMethod('getFriendList', _buildParam({})) + .then((value) => _toList(value)); /// Find all friends including those who have been added to the blacklist - Future> getFriendListMap() { - return _channel - .invokeMethod('getFriendList', _buildParam({})) - .then((value) => _toListMap(value)); - } + Future> getFriendListMap() => _channel + .invokeMethod('getFriendList', _buildParam({})) + .then((value) => _toListMap(value)); /// Modify friend information, only [comment] can be modified Future setFriendInfo( - {required String uid, required String comment}) { - return _channel.invokeMethod( - 'setFriendInfo', - _buildParam({ - 'uid': uid, - 'comment': comment, - })); - } + {required String uid, required String comment}) => + _channel.invokeMethod( + 'setFriendInfo', + _buildParam({ + 'uid': uid, + 'comment': comment, + })); /// Add friends to blacklist - Future addToBlackList({required String uid}) { - return _channel.invokeMethod('addToBlackList', _buildParam({"uid": uid})); - } + Future addToBlackList({required String uid}) => + _channel.invokeMethod('addToBlackList', _buildParam({"uid": uid})); /// Find all blacklist - Future> getBlackList() { - return _channel - .invokeMethod('getBlackList', _buildParam({})) - .then((value) => _toList(value)); - } + Future> getBlackList() => _channel + .invokeMethod('getBlackList', _buildParam({})) + .then((value) => _toList(value)); /// Remove from blacklist - Future deleteFromBlackList({required String uid}) { - return _channel.invokeMethod( - 'deleteFromBlackList', _buildParam({"uid": uid})); - } + Future deleteFromBlackList({required String uid}) => + _channel.invokeMethod('deleteFromBlackList', _buildParam({"uid": uid})); /// Determine if there is a friendship by userId - Future> checkFriend(List uidList) { - return _channel - .invokeMethod('checkFriend', _buildParam({'uidList': uidList})) - .then((value) => _toList(value)); - } + Future> checkFriend(List uidList) => _channel + .invokeMethod('checkFriend', _buildParam({'uidList': uidList})) + .then((value) => _toList(value)); /// Dissolve friendship from friend list - Future deleteFromFriendList({required String uid}) { - return _channel.invokeMethod( - 'deleteFromFriendList', _buildParam({"uid": uid})); - } + Future deleteFromFriendList({required String uid}) => + _channel.invokeMethod('deleteFromFriendList', _buildParam({"uid": uid})); /// Accept application of be friend - Future acceptFriendApplication({required String uid}) { - return _channel.invokeMethod( - 'acceptFriendApplication', _buildParam({"uid": uid})); - } + Future acceptFriendApplication({required String uid}) => _channel + .invokeMethod('acceptFriendApplication', _buildParam({"uid": uid})); /// Refuse application of be friend - Future refuseFriendApplication({required String uid}) { - return _channel.invokeMethod( - 'refuseFriendApplication', _buildParam({"uid": uid})); - } + Future refuseFriendApplication({required String uid}) => _channel + .invokeMethod('refuseFriendApplication', _buildParam({"uid": uid})); /// // Future forceSyncFriendApplication() { @@ -136,9 +114,7 @@ class FriendshipManager { // static UserInfo _toObj(String value) => UserInfo.fromJson(_formatJson(value)); - static dynamic _formatJson(value) { - return jsonDecode(_printValue(value)); - } + static dynamic _formatJson(value) => jsonDecode(_printValue(value)); static String _printValue(value) { return value; diff --git a/lib/src/manager/im_group_manager.dart b/lib/src/manager/im_group_manager.dart index cddb5e5..97b2102 100644 --- a/lib/src/manager/im_group_manager.dart +++ b/lib/src/manager/im_group_manager.dart @@ -21,55 +21,52 @@ class GroupManager { required String groupId, required List uidList, String? reason, - }) { - return _channel - .invokeMethod( - 'inviteUserToGroup', - _buildParam({ - 'gid': groupId, - 'reason': reason, - 'uidList': uidList, - })) - .then((value) => (_formatJson(value) as List) - .map((e) => GroupInviteResult.fromJson(e)) - .toList()); - } + }) => + _channel + .invokeMethod( + 'inviteUserToGroup', + _buildParam({ + 'gid': groupId, + 'reason': reason, + 'uidList': uidList, + })) + .then((value) => (_formatJson(value) as List) + .map((e) => GroupInviteResult.fromJson(e)) + .toList()); /// Remove member from group Future> kickGroupMember({ required String groupId, required List uidList, String? reason, - }) { - return _channel - .invokeMethod( - 'kickGroupMember', - _buildParam({ - 'gid': groupId, - 'reason': reason, - 'uidList': uidList, - })) - .then((value) => (_formatJson(value) as List) - .map((e) => GroupInviteResult.fromJson(e)) - .toList()); - } + }) => + _channel + .invokeMethod( + 'kickGroupMember', + _buildParam({ + 'gid': groupId, + 'reason': reason, + 'uidList': uidList, + })) + .then((value) => (_formatJson(value) as List) + .map((e) => GroupInviteResult.fromJson(e)) + .toList()); /// Get group member's info Future> getGroupMembersInfo({ required String groupId, required List uidList, - }) { - return _channel - .invokeMethod( - 'getGroupMembersInfo', - _buildParam({ - 'gid': groupId, - 'uidList': uidList, - })) - .then((value) => (_formatJson(value) as List) - .map((e) => GroupMembersInfo.fromJson(e)) - .toList()); - } + }) => + _channel + .invokeMethod( + 'getGroupMembersInfo', + _buildParam({ + 'gid': groupId, + 'uidList': uidList, + })) + .then((value) => (_formatJson(value) as List) + .map((e) => GroupMembersInfo.fromJson(e)) + .toList()); /// Get the list of group members /// [filter] 0: all user, 1: group owner, 2: administrator @@ -78,55 +75,48 @@ class GroupManager { required String groupId, int filter = 0, int next = 0, - }) { - return _channel - .invokeMethod( - 'getGroupMemberList', - _buildParam({ - 'gid': groupId, - 'filter': filter, - 'next': next, - })) - .then((value) => GroupMembersList.fromJson(_formatJson(value))); - } + }) => + _channel + .invokeMethod( + 'getGroupMemberList', + _buildParam({ + 'gid': groupId, + 'filter': filter, + 'next': next, + })) + .then((value) => GroupMembersList.fromJson(_formatJson(value))); /// Get the list of group members Future getGroupMemberListMap({ required String groupId, int filter = 0, int next = 0, - }) { - return _channel - .invokeMethod( - 'getGroupMemberList', - _buildParam({ - 'gid': groupId, - 'filter': filter, - 'next': next, - })) - .then((value) => _formatJson(value)); - } + }) => + _channel + .invokeMethod( + 'getGroupMemberList', + _buildParam({ + 'gid': groupId, + 'filter': filter, + 'next': next, + })) + .then((value) => _formatJson(value)); /// Find all groups you have joined - Future> getJoinedGroupList() { - return _channel.invokeMethod('getJoinedGroupList', _buildParam({})).then( - (value) => (_formatJson(value) as List) - .map((e) => GroupInfo.fromJson(e)) - .toList()); - } + Future> getJoinedGroupList() => _channel + .invokeMethod('getJoinedGroupList', _buildParam({})) + .then((value) => (_formatJson(value) as List) + .map((e) => GroupInfo.fromJson(e)) + .toList()); /// Find all groups you have joined - Future> getJoinedGroupListMap() { - return _channel - .invokeMethod('getJoinedGroupList', _buildParam({})) - .then((value) => _formatJson(value)); - } + Future> getJoinedGroupListMap() => _channel + .invokeMethod('getJoinedGroupList', _buildParam({})) + .then((value) => _formatJson(value)); /// Check if you are a member of the group - Future isJoinedGroup({required String gid}) { - return getJoinedGroupList() - .then((list) => list.where((e) => e.groupID == gid).length > 0); - } + Future isJoinedGroup({required String gid}) => getJoinedGroupList() + .then((list) => list.where((e) => e.groupID == gid).length > 0); /// Create a group Future createGroup({ @@ -135,20 +125,18 @@ class GroupManager { String? introduction, String? faceUrl, required List list, - }) { - return _channel.invokeMethod( - 'createGroup', - _buildParam({ - 'gInfo': { - "groupName": groupName, - "notification": notification, - "introduction": introduction, - "faceUrl": faceUrl, - }, - 'memberList': list.map((e) => e.toJson()).toList() - })); - /*.then((value) => _formatJson(value)['groupID'])*/ - } + }) => + _channel.invokeMethod( + 'createGroup', + _buildParam({ + 'gInfo': { + "groupName": groupName, + "notification": notification, + "introduction": introduction, + "faceUrl": faceUrl, + }, + 'memberList': list.map((e) => e.toJson()).toList() + })); /// Edit group information Future setGroupInfo({ @@ -157,101 +145,92 @@ class GroupManager { String? notification, String? introduction, String? faceUrl, - }) { - return _channel.invokeMethod( - 'setGroupInfo', - _buildParam({ - 'gInfo': { - "groupID": groupID, - "groupName": groupName, - "notification": notification, - "introduction": introduction, - "faceUrl": faceUrl, - }, - })); - } + }) => + _channel.invokeMethod( + 'setGroupInfo', + _buildParam({ + 'gInfo': { + "groupID": groupID, + "groupName": groupName, + "notification": notification, + "introduction": introduction, + "faceUrl": faceUrl, + }, + })); /// Find group information by group id Future> getGroupsInfo({ required List gidList, - }) { - return _channel - .invokeMethod('getGroupsInfo', _buildParam({'gidList': gidList})) - .then((value) { - List list = _formatJson(value); - return list.map((e) => GroupInfo.fromJson(e)).toList(); - }); - } + }) => + _channel + .invokeMethod('getGroupsInfo', _buildParam({'gidList': gidList})) + .then((value) { + List list = _formatJson(value); + return list.map((e) => GroupInfo.fromJson(e)).toList(); + }); /// Apply to join the group Future joinGroup({ required String gid, String? reason, - }) { - return _channel.invokeMethod( - 'joinGroup', - _buildParam({ - 'gid': gid, - 'reason': reason, - })); - } + }) => + _channel.invokeMethod( + 'joinGroup', + _buildParam({ + 'gid': gid, + 'reason': reason, + })); /// Leave group Future quitGroup({ required String gid, - }) { - return _channel.invokeMethod( - 'quitGroup', - _buildParam({ - 'gid': gid, - })); - } + }) => + _channel.invokeMethod( + 'quitGroup', + _buildParam({ + 'gid': gid, + })); /// Give group permissions to others Future transferGroupOwner({ required String gid, required String uid, - }) { - return _channel.invokeMethod( - 'transferGroupOwner', - _buildParam({ - 'gid': gid, - 'uid': uid, - })); - } + }) => + _channel.invokeMethod( + 'transferGroupOwner', + _buildParam({ + 'gid': gid, + 'uid': uid, + })); /// Get the list of applications - Future getGroupApplicationList() { - return _channel - .invokeMethod('getGroupApplicationList', _buildParam({})) - .then((value) => GroupApplicationList.fromJson(_formatJson(value))); - } + Future getGroupApplicationList() => _channel + .invokeMethod('getGroupApplicationList', _buildParam({})) + .then((value) => GroupApplicationList.fromJson(_formatJson(value))); /// Accept group application Future acceptGroupApplication({ required GroupApplicationInfo info, required String reason, - }) { - return _channel.invokeMethod( - 'acceptGroupApplication', - _buildParam({ - 'application': info.toJson(), - 'reason': reason, - })); - } + }) => + _channel.invokeMethod( + 'acceptGroupApplication', + _buildParam({ + 'application': info.toJson(), + 'reason': reason, + })); /// Refuse group application Future refuseGroupApplication({ required GroupApplicationInfo info, required String reason, - }) { - return _channel.invokeMethod( - 'refuseGroupApplication', - _buildParam({ - 'application': info.toJson(), - 'reason': reason, - })); - } + }) => + _channel.invokeMethod( + 'refuseGroupApplication', + _buildParam({ + 'application': info.toJson(), + 'reason': reason, + })); /// // Future forceSyncApplyGroupRequest() { @@ -278,9 +257,7 @@ class GroupManager { return param; } - static dynamic _formatJson(value) { - return jsonDecode(_printValue(value)); - } + static dynamic _formatJson(value) => jsonDecode(_printValue(value)); static String _printValue(value) { return value; diff --git a/lib/src/manager/im_manager.dart b/lib/src/manager/im_manager.dart index b2c3e76..9861671 100644 --- a/lib/src/manager/im_manager.dart +++ b/lib/src/manager/im_manager.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'dart:developer'; import 'package:flutter/services.dart'; import 'package:flutter_openim_sdk/flutter_openim_sdk.dart'; @@ -31,7 +32,7 @@ class IMManager { void _addNativeCallback(MethodChannel _channel) { _channel.setMethodCallHandler((call) { try { - print('call:$call'); + log('Flutter : $call'); if (call.method == ListenerType.initSDKListener) { String type = call.arguments['type']; dynamic data = call.arguments['data']; @@ -187,7 +188,6 @@ class IMManager { } else if (call.method == ListenerType.conversationListener) { String type = call.arguments['type']; dynamic data = call.arguments['data']; - print('type:$type data:$data'); switch (type) { case 'onSyncServerStart': conversationManager.conversationListener.syncServerStart(); @@ -325,63 +325,50 @@ class IMManager { } /// - Future getLoginStatus() { - return _channel.invokeMethod('getLoginStatus', _buildParam({})); - } + Future getLoginStatus() => + _channel.invokeMethod('getLoginStatus', _buildParam({})); /// Current user id - Future getLoginUid() { - return Future.value(uid); - // return _channel.invokeMethod('getLoginUid', _buildParam({})); - } + Future getLoginUid() => Future.value(uid); /// Current user info - Future getLoginUserInfo() { - return Future.value(uInfo); - } + Future getLoginUserInfo() => Future.value(uInfo); /// Modify current user info Future setSelfInfo( - {required String uid, - String? name, - String? icon, - int? gender, - String? mobile, - String? birth, - String? email, - String? ex}) { - return _channel.invokeMethod( - 'setSelfInfo', - _buildParam({ - 'uid': uid, - 'name': name, - 'icon': icon, - 'gender': gender, - 'mobile': mobile, - 'birth': birth, - 'email': email, - 'ex': ex, - })); - // .then((value) => UserInfo.fromJson(value)); - } + {required String uid, + String? name, + String? icon, + int? gender, + String? mobile, + String? birth, + String? email, + String? ex}) => + _channel.invokeMethod( + 'setSelfInfo', + _buildParam({ + 'uid': uid, + 'name': name, + 'icon': icon, + 'gender': gender, + 'mobile': mobile, + 'birth': birth, + 'email': email, + 'ex': ex, + })); /// Query user information - Future> getUsersInfo(List uidList) { - return _channel - .invokeMethod('getUsersInfo', _buildParam({'uidList': uidList})) - .then((value) => _toList(value)); - } + Future> getUsersInfo(List uidList) => _channel + .invokeMethod('getUsersInfo', _buildParam({'uidList': uidList})) + .then((value) => _toList(value)); /// - void enabledSDKLog({required bool enabled}) { - _channel.invokeMethod( - 'setSdkLog', _buildParam({'sdkLog': enabled ? 0 : 1})); - } + Future enabledSDKLog({required bool enabled}) => _channel.invokeMethod( + 'setSdkLog', _buildParam({'sdkLog': enabled ? 0 : 1})); /// - Future forceSyncLoginUerInfo(List uidList) { - return _channel.invokeMethod('forceSyncLoginUerInfo', _buildParam({})); - } + Future forceSyncLoginUerInfo(List uidList) => + _channel.invokeMethod('forceSyncLoginUerInfo', _buildParam({})); /// // Future forceReConn() { @@ -396,9 +383,7 @@ class IMManager { static List _toList(String value) => (_formatJson(value) as List).map((e) => UserInfo.fromJson(e)).toList(); - static dynamic _formatJson(value) { - return jsonDecode(_printValue(value)); - } + static dynamic _formatJson(value) => jsonDecode(_printValue(value)); static String _printValue(value) { return value; diff --git a/lib/src/manager/im_message_manager.dart b/lib/src/manager/im_message_manager.dart index 2643a96..4d703dc 100644 --- a/lib/src/manager/im_message_manager.dart +++ b/lib/src/manager/im_message_manager.dart @@ -43,16 +43,15 @@ class MessageManager { String? userID, String? groupID, bool onlineUserOnly = false, - }) { - return _channel.invokeMethod( - 'sendMessage', - _buildParam({ - 'message': message.toJson(), - 'receiver': userID ?? '', - 'groupID': groupID ?? '', - 'onlineUserOnly': onlineUserOnly, - })) /*.then((value) => _toObj(value))*/; - } + }) => + _channel.invokeMethod( + 'sendMessage', + _buildParam({ + 'message': message.toJson(), + 'receiver': userID ?? '', + 'groupID': groupID ?? '', + 'onlineUserOnly': onlineUserOnly, + })) /*.then((value) => _toObj(value))*/; /// Find all history message Future> getHistoryMessageList({ @@ -60,157 +59,139 @@ class MessageManager { String? groupID, Message? startMsg, int? count, - }) { - return _channel - .invokeMethod( - 'getHistoryMessageList', - _buildParam({ - 'userID': userID ?? '', - 'startMsg': startMsg?.toJson() /*?? {}*/, - 'groupID': groupID ?? '', - 'count': count ?? 10, - })) - .then((value) => _toList(value)); - } + }) => + _channel + .invokeMethod( + 'getHistoryMessageList', + _buildParam({ + 'userID': userID ?? '', + 'startMsg': startMsg?.toJson() /*?? {}*/, + 'groupID': groupID ?? '', + 'count': count ?? 10, + })) + .then((value) => _toList(value)); /// Revoke the sent information - Future revokeMessage({required Message message}) { - return _channel.invokeMethod( - 'revokeMessage', _buildParam(message.toJson())); - } + Future revokeMessage({required Message message}) => + _channel.invokeMethod('revokeMessage', _buildParam(message.toJson())); /// Delete message - Future deleteMessageFromLocalStorage({required Message message}) { - return _channel.invokeMethod( - 'deleteMessageFromLocalStorage', _buildParam(message.toJson())); - } + Future deleteMessageFromLocalStorage({required Message message}) => + _channel.invokeMethod( + 'deleteMessageFromLocalStorage', _buildParam(message.toJson())); /// @deprecated - Future deleteMessages({required List msgList}) { - return _channel.invokeMethod('deleteMessages', - _buildParam({"msgList": msgList.map((e) => e.toJson()).toList()})); - } + Future deleteMessages({required List msgList}) => + _channel.invokeMethod('deleteMessages', + _buildParam({"msgList": msgList.map((e) => e.toJson()).toList()})); /// Future insertSingleMessageToLocalStorage({ String? receiver, String? sender, Message? message, - }) { - return _channel.invokeMethod( - 'insertSingleMessageToLocalStorage', - _buildParam({ - "userID": receiver, - "message": message?.toJson(), - "sender": sender, - })); - } + }) => + _channel.invokeMethod( + 'insertSingleMessageToLocalStorage', + _buildParam({ + "userID": receiver, + "message": message?.toJson(), + "sender": sender, + })); /// Query the message according to the message id - Future findMessages({required List messageIDList}) { - return _channel.invokeMethod( - 'findMessages', - _buildParam({ - "messageIDList": messageIDList, - })); - } + Future findMessages({required List messageIDList}) => + _channel.invokeMethod( + 'findMessages', + _buildParam({ + "messageIDList": messageIDList, + })); /// Mark c2c message as read Future markC2CMessageAsRead({ required String userID, required List messageIDList, - }) { - return _channel.invokeMethod( - 'markC2CMessageAsRead', - _buildParam({ - "messageIDList": messageIDList, - "userID": userID, - })); - } + }) => + _channel.invokeMethod( + 'markC2CMessageAsRead', + _buildParam({ + "messageIDList": messageIDList, + "userID": userID, + })); /// Typing Future typingStatusUpdate({ required String userID, bool typing = false, - }) { - return _channel.invokeMethod( - 'typingStatusUpdate', - _buildParam({ - "typing": typing ? 'yes' : 'no', - "userID": userID, - })); - } + }) => + _channel.invokeMethod( + 'typingStatusUpdate', + _buildParam({ + "typing": typing ? 'yes' : 'no', + "userID": userID, + })); /// Create text message - Future createTextMessage({required String text}) { - return _channel - .invokeMethod('createTextMessage', _buildParam({'text': text})) - .then((value) => _toObj(value)); - } + Future createTextMessage({required String text}) => _channel + .invokeMethod('createTextMessage', _buildParam({'text': text})) + .then((value) => _toObj(value)); /// Create @ message Future createTextAtMessage({ required String text, required List atUidList, - }) { - return _channel - .invokeMethod( - 'createTextAtMessage', - _buildParam({ - 'text': text, - 'atUserList': atUidList, - }), - ) - .then((value) => _toObj(value)); - } + }) => + _channel + .invokeMethod( + 'createTextAtMessage', + _buildParam({ + 'text': text, + 'atUserList': atUidList, + }), + ) + .then((value) => _toObj(value)); /// Create picture message - Future createImageMessage({required String imagePath}) { - return _channel - .invokeMethod( - 'createImageMessage', - _buildParam({'imagePath': imagePath}), - ) - .then((value) => _toObj(value)); - } + Future createImageMessage({required String imagePath}) => _channel + .invokeMethod( + 'createImageMessage', + _buildParam({'imagePath': imagePath}), + ) + .then((value) => _toObj(value)); /// Create picture message - Future createImageMessageFromFullPath({required String imagePath}) { - return _channel - .invokeMethod( - 'createImageMessageFromFullPath', - _buildParam({'imagePath': imagePath}), - ) - .then((value) => _toObj(value)); - } - + Future createImageMessageFromFullPath({required String imagePath}) => + _channel + .invokeMethod( + 'createImageMessageFromFullPath', + _buildParam({'imagePath': imagePath}), + ) + .then((value) => _toObj(value)); /// Create sound message Future createSoundMessage({ required String soundPath, required int duration, - }) { - return _channel - .invokeMethod( - 'createSoundMessage', - _buildParam({'soundPath': soundPath, "duration": duration}), - ) - .then((value) => _toObj(value)); - } + }) => + _channel + .invokeMethod( + 'createSoundMessage', + _buildParam({'soundPath': soundPath, "duration": duration}), + ) + .then((value) => _toObj(value)); /// Create sound message Future createSoundMessageFromFullPath({ required String soundPath, required int duration, - }) { - return _channel - .invokeMethod( - 'createSoundMessageFromFullPath', - _buildParam({'soundPath': soundPath, "duration": duration}), - ) - .then((value) => _toObj(value)); - } + }) => + _channel + .invokeMethod( + 'createSoundMessageFromFullPath', + _buildParam({'soundPath': soundPath, "duration": duration}), + ) + .then((value) => _toObj(value)); /// Create video message Future createVideoMessage({ @@ -218,18 +199,17 @@ class MessageManager { required String videoType, required int duration, required String snapshotPath, - }) { - return _channel - .invokeMethod( - 'createVideoMessage', - _buildParam({ - 'videoPath': videoPath, - 'videoType': videoType, - 'duration': duration, - 'snapshotPath': snapshotPath, - })) - .then((value) => _toObj(value)); - } + }) => + _channel + .invokeMethod( + 'createVideoMessage', + _buildParam({ + 'videoPath': videoPath, + 'videoType': videoType, + 'duration': duration, + 'snapshotPath': snapshotPath, + })) + .then((value) => _toObj(value)); /// Create video message Future createVideoMessageFromFullPath({ @@ -237,18 +217,17 @@ class MessageManager { required String videoType, required int duration, required String snapshotPath, - }) { - return _channel - .invokeMethod( - 'createVideoMessageFromFullPath', - _buildParam({ - 'videoPath': videoPath, - 'videoType': videoType, - 'duration': duration, - 'snapshotPath': snapshotPath, - })) - .then((value) => _toObj(value)); - } + }) => + _channel + .invokeMethod( + 'createVideoMessageFromFullPath', + _buildParam({ + 'videoPath': videoPath, + 'videoType': videoType, + 'duration': duration, + 'snapshotPath': snapshotPath, + })) + .then((value) => _toObj(value)); /// Create file message Future createFileMessage({ @@ -269,33 +248,31 @@ class MessageManager { Future createFileMessageFromFullPath({ required String filePath, required String fileName, - }) { - return _channel - .invokeMethod( - 'createFileMessageFromFullPath', - _buildParam({ - 'filePath': filePath, - 'fileName': fileName, - })) - .then((value) => _toObj(value)); - } + }) => + _channel + .invokeMethod( + 'createFileMessageFromFullPath', + _buildParam({ + 'filePath': filePath, + 'fileName': fileName, + })) + .then((value) => _toObj(value)); /// Create merger message Future createMergerMessage({ required List messageList, required String title, required List summaryList, - }) { - return _channel - .invokeMethod( - 'createMergerMessage', - _buildParam({ - 'messageList': messageList.map((e) => e.toJson()).toList(), - 'title': title, - 'summaryList': summaryList, - })) - .then((value) => _toObj(value)); - } + }) => + _channel + .invokeMethod( + 'createMergerMessage', + _buildParam({ + 'messageList': messageList.map((e) => e.toJson()).toList(), + 'title': title, + 'summaryList': summaryList, + })) + .then((value) => _toObj(value)); /// Create forward message Future createForwardMessage({required Message message}) { @@ -313,79 +290,71 @@ class MessageManager { required double latitude, required double longitude, required String description, - }) { - return _channel - .invokeMethod( - 'createLocationMessage', - _buildParam({ - 'latitude': latitude, - 'longitude': longitude, - 'description': description, - })) - .then((value) => _toObj(value)); - } + }) => + _channel + .invokeMethod( + 'createLocationMessage', + _buildParam({ + 'latitude': latitude, + 'longitude': longitude, + 'description': description, + })) + .then((value) => _toObj(value)); /// Create custom message Future createCustomMessage({ required String data, required String extension, required String description, - }) { - return _channel - .invokeMethod( - 'createCustomMessage', - _buildParam({ - 'data': data, - 'extension': extension, - 'description': description, - })) - .then((value) => _toObj(value)); - } + }) => + _channel + .invokeMethod( + 'createCustomMessage', + _buildParam({ + 'data': data, + 'extension': extension, + 'description': description, + })) + .then((value) => _toObj(value)); /// Create quote message Future createQuoteMessage({ required String text, required Message quoteMsg, - }) { - return _channel - .invokeMethod( - 'createQuoteMessage', - _buildParam({ - 'quoteText': text, - 'quoteMessage': quoteMsg.toJson(), - })) - .then((value) => _toObj(value)); - } + }) => + _channel + .invokeMethod( + 'createQuoteMessage', + _buildParam({ + 'quoteText': text, + 'quoteMessage': quoteMsg.toJson(), + })) + .then((value) => _toObj(value)); /// Create card message Future createCardMessage({ required Map data, - }) { - return _channel - .invokeMethod( - 'createCardMessage', - _buildParam({ - 'cardMessage': data, - })) - .then((value) => _toObj(value)); - } + }) => + _channel + .invokeMethod( + 'createCardMessage', + _buildParam({ + 'cardMessage': data, + })) + .then((value) => _toObj(value)); /// - Future clearC2CHistoryMessage({required String uid}) { - return _channel.invokeMethod( - 'clearC2CHistoryMessage', _buildParam({"userID": uid})); - } + Future clearC2CHistoryMessage({required String uid}) => _channel + .invokeMethod('clearC2CHistoryMessage', _buildParam({"userID": uid})); /// - Future clearGroupHistoryMessage({required String gid}) { - return _channel.invokeMethod( - 'clearGroupHistoryMessage', _buildParam({"groupID": gid})); - } + Future clearGroupHistoryMessage({required String gid}) => _channel + .invokeMethod('clearGroupHistoryMessage', _buildParam({"groupID": gid})); /// - void forceSyncMsg() { - _channel.invokeMethod('forceSyncMsg', _buildParam({})); - } + // void forceSyncMsg() { + // _channel.invokeMethod('forceSyncMsg', _buildParam({})); + // } static Map _buildParam(Map param) { param["ManagerName"] = "messageManager"; @@ -397,9 +366,7 @@ class MessageManager { static Message _toObj(String value) => Message.fromJson(_formatJson(value)); - static dynamic _formatJson(value) { - return jsonDecode(_printValue(value)); - } + static dynamic _formatJson(value) => jsonDecode(_printValue(value)); static String _printValue(value) { return value; diff --git a/lib/src/models/conversation_info.dart b/lib/src/models/conversation_info.dart index a443130..0a08373 100644 --- a/lib/src/models/conversation_info.dart +++ b/lib/src/models/conversation_info.dart @@ -87,4 +87,14 @@ class ConversationInfo { bool get isGroupChat => conversationType == ConversationType.group_chat; bool get isTop => isPinned == 1; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is ConversationInfo && + runtimeType == other.runtimeType && + conversationID == other.conversationID; + + @override + int get hashCode => conversationID.hashCode; } diff --git a/lib/src/models/message.dart b/lib/src/models/message.dart index 0328aad..4001e2a 100644 --- a/lib/src/models/message.dart +++ b/lib/src/models/message.dart @@ -153,17 +153,14 @@ class Message { } @override - bool operator ==(Object other) { - if (other is Message) { - return other._id == _id; - } - return false; - } + bool operator ==(Object other) => + identical(this, other) || + other is Message && + runtimeType == other.runtimeType && + clientMsgID == other.clientMsgID; @override - int get hashCode => super.hashCode; - - String? get _id => clientMsgID; + int get hashCode => clientMsgID.hashCode; } class PictureElem { diff --git a/pubspec.yaml b/pubspec.yaml index 4281b65..5971f57 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_openim_sdk description: An instant messaging plug-in that supports Android and IOS. And the server is also all open source. -version: 1.0.7 +version: 1.0.8 homepage: https://www.rentsoft.cn repository: https://github.com/OpenIMSDK/Open-IM-SDK-Flutter