diff --git a/lib/flutter_openim_sdk.dart b/lib/flutter_openim_sdk.dart index dcbbc68..b1e4f69 100644 --- a/lib/flutter_openim_sdk.dart +++ b/lib/flutter_openim_sdk.dart @@ -29,6 +29,7 @@ export 'src/manager/im_message_manager.dart'; export 'src/manager/im_user_manager.dart'; export 'src/models/conversation_info.dart'; export 'src/models/group_info.dart'; +export 'src/models/init_config.dart'; export 'src/models/message.dart'; export 'src/models/notification_info.dart'; export 'src/models/search_info.dart'; diff --git a/lib/src/enum/message_type.dart b/lib/src/enum/message_type.dart index 390c64c..54327f9 100644 --- a/lib/src/enum/message_type.dart +++ b/lib/src/enum/message_type.dart @@ -30,9 +30,6 @@ class MessageType { /// Custom static const custom = 110; - /// Has Read Receipt - static const hasReadReceipt = 112; - /// Typing static const typing = 113; diff --git a/lib/src/manager/im_friendship_manager.dart b/lib/src/manager/im_friendship_manager.dart index e54a8f5..d3c99f7 100644 --- a/lib/src/manager/im_friendship_manager.dart +++ b/lib/src/manager/im_friendship_manager.dart @@ -203,7 +203,7 @@ class FriendshipManager { /// [isSearchUserID] Whether to search for friend IDs with keywords (note: cannot be false at the same time), defaults to false if empty /// [isSearchNickname] Whether to search by nickname with keywords, defaults to false if empty /// [isSearchRemark] Whether to search by remark name with keywords, defaults to false if empty - Future> searchFriends({ + Future> searchFriends({ List keywordList = const [], bool isSearchUserID = false, bool isSearchNickname = false, @@ -223,7 +223,7 @@ class FriendshipManager { 'operationID': Utils.checkOperationID(operationID), })) .then((value) => - Utils.toList(value, (map) => FriendInfo.fromJson(map))); + Utils.toList(value, (map) => SearchFriendInfo.fromJson(map))); static Map _buildParam(Map param) { param["ManagerName"] = "friendshipManager"; diff --git a/lib/src/manager/im_group_manager.dart b/lib/src/manager/im_group_manager.dart index d503c2a..713154c 100644 --- a/lib/src/manager/im_group_manager.dart +++ b/lib/src/manager/im_group_manager.dart @@ -33,7 +33,8 @@ class GroupManager { 'reason': reason, "operationID": Utils.checkOperationID(operationID), })) - .then((value) => Utils.toList(value, (map) => GroupInviteResult.fromJson(map))); + .then((value) => + Utils.toList(value, (map) => GroupInviteResult.fromJson(map))); /// Remove group members /// [groupID] Group ID @@ -54,7 +55,8 @@ class GroupManager { 'reason': reason, "operationID": Utils.checkOperationID(operationID), })) - .then((value) => Utils.toList(value, (map) => GroupInviteResult.fromJson(map))); + .then((value) => + Utils.toList(value, (map) => GroupInviteResult.fromJson(map))); /// Query group member information /// [groupID] Group ID @@ -72,7 +74,8 @@ class GroupManager { 'userIDList': userIDList, "operationID": Utils.checkOperationID(operationID), })) - .then((value) => Utils.toList(value, (map) => GroupMembersInfo.fromJson(map))); + .then((value) => + Utils.toList(value, (map) => GroupMembersInfo.fromJson(map))); /// Paginate and retrieve the group member list /// [groupID] Group ID @@ -96,7 +99,8 @@ class GroupManager { 'count': count, 'operationID': Utils.checkOperationID(operationID), })) - .then((value) => Utils.toList(value, (map) => GroupMembersInfo.fromJson(map))); + .then((value) => + Utils.toList(value, (map) => GroupMembersInfo.fromJson(map))); /// Paginate and retrieve the group member list as a map /// [groupID] Group ID @@ -177,7 +181,8 @@ class GroupManager { 'ownerUserID': ownerUserID, 'operationID': Utils.checkOperationID(operationID), })) - .then((value) => Utils.toObj(value, (map) => GroupInfo.fromJson(map))); + .then( + (value) => Utils.toObj(value, (map) => GroupInfo.fromJson(map))); /// Edit group information Future setGroupInfo({ @@ -221,7 +226,8 @@ class GroupManager { 'groupIDList': groupIDList, 'operationID': Utils.checkOperationID(operationID), })) - .then((value) => Utils.toList(value, (map) => GroupInfo.fromJson(map))); + .then( + (value) => Utils.toList(value, (map) => GroupInfo.fromJson(map))); /// Apply to join a group, requiring approval from an administrator or the group. /// [joinSource] 2: Invited, 3: Searched, 4: Using a QR code @@ -269,22 +275,28 @@ class GroupManager { })); /// Handle group membership applications received as a group owner or administrator - Future> getGroupApplicationListAsRecipient({String? operationID}) => _channel - .invokeMethod( - 'getGroupApplicationListAsRecipient', - _buildParam({ - 'operationID': Utils.checkOperationID(operationID), - })) - .then((value) => Utils.toList(value, (map) => GroupApplicationInfo.fromJson(map))); + Future> getGroupApplicationListAsRecipient( + {String? operationID}) => + _channel + .invokeMethod( + 'getGroupApplicationListAsRecipient', + _buildParam({ + 'operationID': Utils.checkOperationID(operationID), + })) + .then((value) => + Utils.toList(value, (map) => GroupApplicationInfo.fromJson(map))); /// Get the list of group membership applications sent by the user - Future> getGroupApplicationListAsApplicant({String? operationID}) => _channel - .invokeMethod( - 'getGroupApplicationListAsApplicant', - _buildParam({ - 'operationID': Utils.checkOperationID(operationID), - })) - .then((value) => Utils.toList(value, (map) => GroupApplicationInfo.fromJson(map))); + Future> getGroupApplicationListAsApplicant( + {String? operationID}) => + _channel + .invokeMethod( + 'getGroupApplicationListAsApplicant', + _buildParam({ + 'operationID': Utils.checkOperationID(operationID), + })) + .then((value) => + Utils.toList(value, (map) => GroupApplicationInfo.fromJson(map))); /// Accept a group membership application as an administrator or group owner /// Note: Membership applications require approval from administrators or the group. @@ -410,7 +422,8 @@ class GroupManager { }, 'operationID': Utils.checkOperationID(operationID), })) - .then((value) => Utils.toList(value, (map) => GroupInfo.fromJson(map))); + .then( + (value) => Utils.toList(value, (map) => GroupInfo.fromJson(map))); /// Set group member role /// [groupID] Group ID @@ -453,7 +466,8 @@ class GroupManager { 'excludeUserIDList': excludeUserIDList, 'operationID': Utils.checkOperationID(operationID), })) - .then((value) => Utils.toList(value, (map) => GroupMembersInfo.fromJson(map))); + .then((value) => + Utils.toList(value, (map) => GroupMembersInfo.fromJson(map))); /// Set group verification for joining /// [groupID] Group ID @@ -516,7 +530,8 @@ class GroupManager { 'groupID': groupID, 'operationID': Utils.checkOperationID(operationID), })) - .then((value) => Utils.toList(value, (map) => GroupMembersInfo.fromJson(map))); + .then((value) => + Utils.toList(value, (map) => GroupMembersInfo.fromJson(map))); /// Search for group members /// [groupID] Group ID @@ -548,7 +563,8 @@ class GroupManager { }, 'operationID': Utils.checkOperationID(operationID), })) - .then((value) => Utils.toList(value, (map) => GroupMembersInfo.fromJson(map))); + .then((value) => + Utils.toList(value, (map) => GroupMembersInfo.fromJson(map))); /// Query a group /// [groupID] Group ID diff --git a/lib/src/manager/im_manager.dart b/lib/src/manager/im_manager.dart index 19b7a4e..1a613e7 100644 --- a/lib/src/manager/im_manager.dart +++ b/lib/src/manager/im_manager.dart @@ -362,6 +362,26 @@ class IMManager { }); } + Future init( + InitConfig config, + OnConnectListener listener, { + String? operationID, + }) { + this._connectListener = listener; + if (config.logFilePath == null) { + config.logFilePath = config.dataDir; + } + return _channel.invokeMethod( + 'initSDK', + _buildParam( + { + ...config.toMap(), + "operationID": Utils.checkOperationID(operationID), + }, + ), + ); + } + /// Initialize the SDK /// [platform] Platform ID [IMPlatform] /// [apiAddr] SDK API address diff --git a/lib/src/manager/im_user_manager.dart b/lib/src/manager/im_user_manager.dart index 924b465..5e528e8 100644 --- a/lib/src/manager/im_user_manager.dart +++ b/lib/src/manager/im_user_manager.dart @@ -52,11 +52,7 @@ class UserManager { Future setSelfInfo({ String? nickname, String? faceURL, - int? gender, int? appManagerLevel, - String? phoneNumber, - int? birth, - String? email, String? ex, String? operationID, }) => @@ -66,11 +62,7 @@ class UserManager { // 'userID': userID, 'nickname': nickname, 'faceURL': faceURL, - 'gender': gender, 'appManagerLevel': appManagerLevel, - 'phoneNumber': phoneNumber, - 'birth': birth, - 'email': email, 'ex': ex, 'operationID': Utils.checkOperationID(operationID), })); diff --git a/lib/src/models/init_config.dart b/lib/src/models/init_config.dart new file mode 100644 index 0000000..a49ee18 --- /dev/null +++ b/lib/src/models/init_config.dart @@ -0,0 +1,47 @@ +class InitConfig { + int platformID; + String apiAddr; + String wsAddr; + String dataDir; + String objectStorage; + int logLevel; + bool isLogStandardOutput; + String? logFilePath; + + InitConfig({ + required this.platformID, + required this.apiAddr, + required this.wsAddr, + required this.dataDir, + required this.objectStorage, + this.logLevel = 6, + this.isLogStandardOutput = true, + this.logFilePath, + }); + + factory InitConfig.fromJson(Map json) { + return InitConfig( + platformID: json['platformID'], + apiAddr: json['apiAddr'], + wsAddr: json['wsAddr'], + dataDir: json['dataDir'], + objectStorage: json['objectStorage'], + logLevel: json['logLevel'], + isLogStandardOutput: json['isLogStandardOutput'], + logFilePath: json['logFilePath'], + ); + } + + Map toMap() { + return { + 'platformID': platformID, + 'apiAddr': apiAddr, + 'wsAddr': wsAddr, + 'dataDir': dataDir, + 'objectStorage': objectStorage, + 'logLevel': logLevel, + 'isLogStandardOutput': isLogStandardOutput, + 'logFilePath': logFilePath, + }; + } +} diff --git a/lib/src/models/search_info.dart b/lib/src/models/search_info.dart index acb2091..7e5ed84 100644 --- a/lib/src/models/search_info.dart +++ b/lib/src/models/search_info.dart @@ -114,3 +114,18 @@ class SearchParams { return data; } } + +class SearchFriendInfo extends FriendInfo { + late int relationship; + SearchFriendInfo({required this.relationship}) : super(); + + SearchFriendInfo.fromJson(Map json) : super.fromJson(json) { + relationship = json['relationship']; + } + + Map toJson() { + final data = super.toJson(); + data['relationship'] = this.relationship; + return data ?? {}; + } +} diff --git a/lib/src/models/user_info.dart b/lib/src/models/user_info.dart index 5c0d1fb..9aeaad5 100644 --- a/lib/src/models/user_info.dart +++ b/lib/src/models/user_info.dart @@ -197,6 +197,38 @@ class UserInfo { int get hashCode => userID.hashCode; } +class FullUserInfo { + /// User's public information + PublicUserInfo? publicInfo; + + /// Information visible only to friends + FriendInfo? friendInfo; + + /// Blacklist information + BlacklistInfo? blackInfo; + + FullUserInfo.fromJson(Map json) { + publicInfo = json['publicInfo'] != null + ? PublicUserInfo.fromJson(json['publicInfo']) + : null; + friendInfo = json['friendInfo'] != null + ? FriendInfo.fromJson(json['friendInfo']) + : null; + blackInfo = json['blackInfo'] != null + ? BlacklistInfo.fromJson(json['blackInfo']) + : null; + } + + Map toJson() { + final data = Map(); + data['publicInfo'] = this.publicInfo?.toJson(); + data['friendInfo'] = this.friendInfo?.toJson(); + data['blackInfo'] = this.blackInfo?.toJson(); + + return data; + } +} + class PublicUserInfo { /// User ID String? userID; @@ -249,6 +281,9 @@ class PublicUserInfo { } class FriendInfo { + /// owner User ID + String? ownerUserID; + /// User ID String? userID; @@ -286,6 +321,7 @@ class FriendInfo { String? operatorUserID; FriendInfo({ + this.ownerUserID, this.userID, this.nickname, this.faceURL, @@ -301,7 +337,7 @@ class FriendInfo { }); FriendInfo.fromJson(Map json) { - // ownerUserID = json['ownerUserID']; + ownerUserID = json['ownerUserID']; userID = json['userID']; remark = json['remark']; createTime = json['createTime']; @@ -318,7 +354,7 @@ class FriendInfo { Map toJson() { final data = Map(); - // data['ownerUserID'] = this.ownerUserID; + data['ownerUserID'] = this.ownerUserID; data['userID'] = this.userID; data['remark'] = this.remark; data['createTime'] = this.createTime; @@ -349,6 +385,12 @@ class BlacklistInfo { /// Nickname String? nickname; + /// owner User ID + String? ownerUserID; + + /// block User ID + String? blockUserID; + /// Profile picture String? faceURL; @@ -368,6 +410,8 @@ class BlacklistInfo { String? ex; BlacklistInfo({ + this.ownerUserID, + this.blockUserID, this.userID, this.nickname, this.faceURL, @@ -379,6 +423,8 @@ class BlacklistInfo { }); BlacklistInfo.fromJson(Map json) { + ownerUserID = json['ownerUserID']; + blockUserID = json['blockUserID']; userID = json['userID']; nickname = json['nickname']; faceURL = json['faceURL']; @@ -391,6 +437,8 @@ class BlacklistInfo { Map toJson() { final data = Map(); + data['ownerUserID'] = this.ownerUserID; + data['blockUserID'] = this.blockUserID; data['userID'] = this.userID; data['nickname'] = this.nickname; data['faceURL'] = this.faceURL; @@ -435,9 +483,6 @@ class FriendApplicationInfo { /// Initiator user profile picture String? fromFaceURL; - /// Initiator user gender - int? fromGender; - /// Recipient user ID String? toUserID; @@ -447,9 +492,6 @@ class FriendApplicationInfo { /// Recipient user profile picture String? toFaceURL; - /// Recipient user gender - int? toGender; - /// Handling result int? handleResult; @@ -475,11 +517,9 @@ class FriendApplicationInfo { {this.fromUserID, this.fromNickname, this.fromFaceURL, - this.fromGender, this.toUserID, this.toNickname, this.toFaceURL, - this.toGender, this.handleResult, this.reqMsg, this.createTime, @@ -492,11 +532,9 @@ class FriendApplicationInfo { fromUserID = json['fromUserID']; fromNickname = json['fromNickname']; fromFaceURL = json['fromFaceURL']; - fromGender = json['fromGender']; toUserID = json['toUserID']; toNickname = json['toNickname']; toFaceURL = json['toFaceURL']; - toGender = json['toGender']; handleResult = json['handleResult']; reqMsg = json['reqMsg']; createTime = json['createTime']; @@ -511,11 +549,9 @@ class FriendApplicationInfo { data['fromUserID'] = this.fromUserID; data['fromNickname'] = this.fromNickname; data['fromFaceURL'] = this.fromFaceURL; - data['fromGender'] = this.fromGender; data['toUserID'] = this.toUserID; data['toNickname'] = this.toNickname; data['toFaceURL'] = this.toFaceURL; - data['toGender'] = this.toGender; data['handleResult'] = this.handleResult; data['reqMsg'] = this.reqMsg; data['createTime'] = this.createTime;