From 4fef487562d66bdd8b00cb1e207e5e9b3f47b531 Mon Sep 17 00:00:00 2001 From: Brett <> Date: Tue, 17 Oct 2023 17:01:56 +0800 Subject: [PATCH] fix: Fixed some issues. --- lib/src/manager/im_friendship_manager.dart | 54 +++--- lib/src/manager/im_user_manager.dart | 16 +- lib/src/models/search_info.dart | 12 +- lib/src/models/user_info.dart | 193 ++------------------- 4 files changed, 51 insertions(+), 224 deletions(-) diff --git a/lib/src/manager/im_friendship_manager.dart b/lib/src/manager/im_friendship_manager.dart index d3c99f7..ccc8280 100644 --- a/lib/src/manager/im_friendship_manager.dart +++ b/lib/src/manager/im_friendship_manager.dart @@ -15,7 +15,7 @@ class FriendshipManager { /// Query Friend Information /// [userIDList] List of user IDs - Future> getFriendsInfo({ + Future> getFriendsInfo({ required List userIDList, String? operationID, }) => @@ -26,7 +26,7 @@ class FriendshipManager { "userIDList": userIDList, "operationID": Utils.checkOperationID(operationID), })) - .then((value) => Utils.toList(value, (v) => UserInfo.fromJson(v))); + .then((value) => Utils.toList(value, (v) => FriendInfo.fromJson(v))); /// Send a Friend Request, the other party needs to accept the request to become friends. /// [userID] User ID to be invited @@ -45,37 +45,31 @@ class FriendshipManager { })); /// Get Friend Requests Sent to Me - Future> getFriendApplicationListAsRecipient( - {String? operationID}) => - _channel - .invokeMethod( - 'getFriendApplicationListAsRecipient', - _buildParam({ - "operationID": Utils.checkOperationID(operationID), - })) - .then((value) => - Utils.toList(value, (v) => FriendApplicationInfo.fromJson(v))); + Future> getFriendApplicationListAsRecipient({String? operationID}) => _channel + .invokeMethod( + 'getFriendApplicationListAsRecipient', + _buildParam({ + "operationID": Utils.checkOperationID(operationID), + })) + .then((value) => Utils.toList(value, (v) => FriendApplicationInfo.fromJson(v))); /// Get Friend Requests Sent by Me - Future> getFriendApplicationListAsApplicant( - {String? operationID}) => - _channel - .invokeMethod( - 'getFriendApplicationListAsApplicant', - _buildParam({ - "operationID": Utils.checkOperationID(operationID), - })) - .then((value) => - Utils.toList(value, (v) => FriendApplicationInfo.fromJson(v))); + Future> getFriendApplicationListAsApplicant({String? operationID}) => _channel + .invokeMethod( + 'getFriendApplicationListAsApplicant', + _buildParam({ + "operationID": Utils.checkOperationID(operationID), + })) + .then((value) => Utils.toList(value, (v) => FriendApplicationInfo.fromJson(v))); /// Get Friend List, including friends who have been put into the blacklist - Future> getFriendList({String? operationID}) => _channel + Future> getFriendList({String? operationID}) => _channel .invokeMethod( 'getFriendList', _buildParam({ "operationID": Utils.checkOperationID(operationID), })) - .then((value) => Utils.toList(value, (v) => UserInfo.fromJson(v))); + .then((value) => Utils.toList(value, (v) => FriendInfo.fromJson(v))); /// Get Friend List, including friends who have been put into the blacklist (returns a map) Future> getFriendListMap({String? operationID}) => _channel @@ -116,13 +110,13 @@ class FriendshipManager { })); /// Get Blacklist - Future> getBlacklist({String? operationID}) => _channel + Future> getBlacklist({String? operationID}) => _channel .invokeMethod( 'getBlacklist', _buildParam({ "operationID": Utils.checkOperationID(operationID), })) - .then((value) => Utils.toList(value, (v) => UserInfo.fromJson(v))); + .then((value) => Utils.toList(value, (v) => BlacklistInfo.fromJson(v))); /// Remove from Blacklist /// [userID] User ID @@ -150,8 +144,7 @@ class FriendshipManager { 'userIDList': userIDList, "operationID": Utils.checkOperationID(operationID), })) - .then((value) => - Utils.toList(value, (v) => FriendshipInfo.fromJson(v))); + .then((value) => Utils.toList(value, (v) => FriendshipInfo.fromJson(v))); /// Delete Friend /// [userID] User ID @@ -203,7 +196,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, @@ -222,8 +215,7 @@ class FriendshipManager { }, 'operationID': Utils.checkOperationID(operationID), })) - .then((value) => - Utils.toList(value, (map) => SearchFriendInfo.fromJson(map))); + .then((value) => Utils.toList(value, (map) => SearchFriendsInfo.fromJson(map))); static Map _buildParam(Map param) { param["ManagerName"] = "friendshipManager"; diff --git a/lib/src/manager/im_user_manager.dart b/lib/src/manager/im_user_manager.dart index 5e528e8..79d873d 100644 --- a/lib/src/manager/im_user_manager.dart +++ b/lib/src/manager/im_user_manager.dart @@ -43,11 +43,7 @@ class UserManager { /// Modify the profile of the currently logged-in user /// [nickname] Nickname /// [faceURL] Profile picture - /// [gender] Gender /// [appManagerLevel] - /// [phoneNumber] Phone number - /// [birth] Date of birth - /// [email] Email /// [ex] Additional fields Future setSelfInfo({ String? nickname, @@ -78,8 +74,7 @@ class UserManager { 'userIDs': userIDs, 'operationID': Utils.checkOperationID(operationID), })) - .then((value) => - Utils.toList(value, (map) => UserStatusInfo.fromJson(map))); + .then((value) => Utils.toList(value, (map) => UserStatusInfo.fromJson(map))); } Future> unsubscribeUsersStatus( @@ -93,8 +88,7 @@ class UserManager { 'userIDs': userIDs, 'operationID': Utils.checkOperationID(operationID), })) - .then((value) => - Utils.toList(value, (map) => UserStatusInfo.fromJson(map))); + .then((value) => Utils.toList(value, (map) => UserStatusInfo.fromJson(map))); } Future> getSubscribeUsersStatus({ @@ -106,8 +100,7 @@ class UserManager { _buildParam({ 'operationID': Utils.checkOperationID(operationID), })) - .then((value) => - Utils.toList(value, (map) => UserStatusInfo.fromJson(map))); + .then((value) => Utils.toList(value, (map) => UserStatusInfo.fromJson(map))); } Future> getUserStatus( @@ -121,8 +114,7 @@ class UserManager { 'userIDs': userIDs, 'operationID': Utils.checkOperationID(operationID), })) - .then((value) => - Utils.toList(value, (map) => UserStatusInfo.fromJson(map))); + .then((value) => Utils.toList(value, (map) => UserStatusInfo.fromJson(map))); } Future> getUsersInfoStranger( diff --git a/lib/src/models/search_info.dart b/lib/src/models/search_info.dart index 7e5ed84..0748239 100644 --- a/lib/src/models/search_info.dart +++ b/lib/src/models/search_info.dart @@ -31,12 +31,10 @@ class SearchResult { final data = Map(); data['totalCount'] = this.totalCount; if (this.searchResultItems != null) { - data['searchResultItems'] = - this.searchResultItems!.map((v) => v.toJson()).toList(); + data['searchResultItems'] = this.searchResultItems!.map((v) => v.toJson()).toList(); } if (this.findResultItems != null) { - data['findResultItems'] = - this.findResultItems!.map((v) => v.toJson()).toList(); + data['findResultItems'] = this.findResultItems!.map((v) => v.toJson()).toList(); } return data; } @@ -115,11 +113,11 @@ class SearchParams { } } -class SearchFriendInfo extends FriendInfo { +class SearchFriendsInfo extends FriendInfo { late int relationship; - SearchFriendInfo({required this.relationship}) : super(); + SearchFriendsInfo({required this.relationship}) : super(); - SearchFriendInfo.fromJson(Map json) : super.fromJson(json) { + SearchFriendsInfo.fromJson(Map json) : super.fromJson(json) { relationship = json['relationship']; } diff --git a/lib/src/models/user_info.dart b/lib/src/models/user_info.dart index 9aeaad5..6caa115 100644 --- a/lib/src/models/user_info.dart +++ b/lib/src/models/user_info.dart @@ -8,18 +8,6 @@ class UserInfo { /// Profile picture String? faceURL; - /// Gender - int? gender; - - /// Phone number - String? phoneNumber; - - /// Date of birth - int? birth; - - /// Email - String? email; - /// Additional information String? ex; @@ -35,150 +23,43 @@ class UserInfo { /// 2: Accept online messages but not offline messages int? globalRecvMsgOpt; - /// Allow adding as a friend: - /// 1: Allowed - /// 2: Not allowed - int? allowAddFriend; - - /// New message ringtone: - /// 1: Allowed - /// 2: Not allowed - int? allowBeep; - - /// New message vibration: - /// 1: Allowed - /// 2: Not allowed - int? allowVibration; - - /// Prohibited from logging in - int? forbidden; - - /// User's public information - PublicUserInfo? publicInfo; - - /// Information visible only to friends - FriendInfo? friendInfo; - - /// Blacklist information - BlacklistInfo? blackInfo; - - /// Whether there is a friendship relationship - bool? isFriendship; - - /// Whether the user is in the blacklist - bool? isBlacklist; + int? appMangerLevel; UserInfo({ - this.publicInfo, - this.friendInfo, - this.blackInfo, - this.isFriendship, - this.isBlacklist, - // this.userID, this.nickname, this.faceURL, - this.phoneNumber, - this.birth, - this.gender, - this.email, + this.appMangerLevel, this.ex, this.createTime, this.remark, this.globalRecvMsgOpt, - this.allowAddFriend, - this.allowBeep, - this.allowVibration, - this.forbidden, }); UserInfo.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; - - isFriendship = friendInfo != null; - isBlacklist = blackInfo != null; - - userID = json['userID'] ?? _userID; - nickname = json['nickname'] ?? _nickname; - faceURL = json['faceURL'] ?? _faceUrl; - gender = json['gender'] ?? _gender; - phoneNumber = json['phoneNumber'] ?? _phoneNumber; - birth = json['birth'] ?? _birth; - email = json['email'] ?? _email; - remark = json['remark'] ?? _remark; - ex = json['ex'] ?? _ex; + userID = json['userID'] ?? userID; + nickname = json['nickname'] ?? nickname; + faceURL = json['faceURL'] ?? faceURL; + remark = json['remark'] ?? remark; + ex = json['ex'] ?? ex; createTime = json['createTime']; globalRecvMsgOpt = json['globalRecvMsgOpt']; - allowAddFriend = json['allowAddFriend']; - allowBeep = json['allowBeep']; - allowVibration = json['allowVibration']; - forbidden = json['forbidden']; + appMangerLevel = json['appMangerLevel']; } Map toJson() { final data = Map(); - data['publicInfo'] = this.publicInfo?.toJson(); - data['friendInfo'] = this.friendInfo?.toJson(); - data['blackInfo'] = this.blackInfo?.toJson(); - // - data['isFriendship'] = this.isFriendship; - data['isBlacklist'] = this.isBlacklist; + data['appMangerLevel'] = this.appMangerLevel; data['userID'] = this.userID; data['nickname'] = this.nickname; data['faceURL'] = this.faceURL; - data['gender'] = this.gender; - data['phoneNumber'] = this.phoneNumber; - data['birth'] = this.birth; - data['email'] = this.email; data['ex'] = this.ex; data['createTime'] = this.createTime; data['remark'] = this.remark; data['globalRecvMsgOpt'] = this.globalRecvMsgOpt; - data['allowAddFriend'] = this.allowAddFriend; - data['allowBeep'] = this.allowBeep; - data['allowVibration'] = this.allowVibration; - data['forbidden'] = this.forbidden; return data; } - bool get isMale => gender == 1; - - String get _userID => isFriendship! - ? friendInfo!.userID! - : (isBlacklist! ? blackInfo!.userID! : publicInfo!.userID!); - - String? get _nickname => isFriendship! - ? friendInfo?.nickname - : (isBlacklist! ? blackInfo?.nickname : publicInfo?.nickname); - - String? get _faceUrl => isFriendship! - ? friendInfo?.faceURL - : (isBlacklist! ? blackInfo?.faceURL : publicInfo?.faceURL); - - int? get _gender => isFriendship! - ? friendInfo?.gender - : (isBlacklist! ? blackInfo?.gender : publicInfo?.gender); - - String? get _ex => isFriendship! - ? friendInfo?.ex - : (isBlacklist! ? blackInfo?.ex : publicInfo?.ex); - - String? get _phoneNumber => friendInfo?.phoneNumber; - - int? get _birth => friendInfo?.birth; - - String? get _email => friendInfo?.email; - - String? get _remark => friendInfo?.remark; - String getShowName() => _isNull(remark) ?? _isNull(nickname) ?? userID!; static String? _isNull(String? value) { @@ -187,11 +68,7 @@ class UserInfo { } @override - bool operator ==(Object other) => - identical(this, other) || - other is UserInfo && - runtimeType == other.runtimeType && - userID == other.userID; + bool operator ==(Object other) => identical(this, other) || other is UserInfo && runtimeType == other.runtimeType && userID == other.userID; @override int get hashCode => userID.hashCode; @@ -208,15 +85,9 @@ class FullUserInfo { 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; + 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() { @@ -239,9 +110,6 @@ class PublicUserInfo { /// Profile picture String? faceURL; - /// Gender - int? gender; - /// App Manager Level: /// 1: AppOrdinaryUsers /// 2: AppAdmin @@ -254,7 +122,6 @@ class PublicUserInfo { this.userID, this.nickname, this.faceURL, - this.gender, this.appManagerLevel, this.ex, }); @@ -263,7 +130,6 @@ class PublicUserInfo { userID = json['userID']; nickname = json['nickname']; faceURL = json['faceURL']; - gender = json['gender']; appManagerLevel = json['appManagerLevel']; ex = json['ex']; } @@ -273,7 +139,6 @@ class PublicUserInfo { data['userID'] = this.userID; data['nickname'] = this.nickname; data['faceURL'] = this.faceURL; - data['gender'] = this.gender; data['appMangerLevel'] = this.appManagerLevel; data['ex'] = this.ex; return data; @@ -293,17 +158,8 @@ class FriendInfo { /// Profile picture String? faceURL; - /// Gender - int? gender; - - /// Phone number - String? phoneNumber; - - /// Date of birth - int? birth; - - /// Email - String? email; + /// friend User ID + String? friendUserID; /// Remark String? remark; @@ -325,10 +181,7 @@ class FriendInfo { this.userID, this.nickname, this.faceURL, - this.gender, - this.phoneNumber, - this.birth, - this.email, + this.friendUserID, this.remark, this.ex, this.createTime, @@ -345,10 +198,7 @@ class FriendInfo { operatorUserID = json['operatorUserID']; nickname = json['nickname']; faceURL = json['faceURL']; - gender = json['gender']; - phoneNumber = json['phoneNumber']; - birth = json['birth']; - email = json['email']; + friendUserID = json['friendUserID']; ex = json['ex']; } @@ -362,10 +212,7 @@ class FriendInfo { data['operatorUserID'] = this.operatorUserID; data['nickname'] = this.nickname; data['faceURL'] = this.faceURL; - data['gender'] = this.gender; - data['phoneNumber'] = this.phoneNumber; - data['birth'] = this.birth; - data['email'] = this.email; + data['friendUserID'] = this.friendUserID; data['ex'] = this.ex; return data; } @@ -591,9 +438,7 @@ class UserStatusInfo { UserStatusInfo.fromJson(Map json) { userID = json['userID']; status = json['status']; - platformIDs = json["platformIDs"] == null - ? [] - : List.from(json["platformIDs"].map((x) => x)); + platformIDs = json["platformIDs"] == null ? [] : List.from(json["platformIDs"].map((x) => x)); } Map toJson() {