fix: Fixed some issues.

main
Brett 2 years ago
parent dc61665f13
commit 4fef487562
  1. 54
      lib/src/manager/im_friendship_manager.dart
  2. 16
      lib/src/manager/im_user_manager.dart
  3. 12
      lib/src/models/search_info.dart
  4. 193
      lib/src/models/user_info.dart

@ -15,7 +15,7 @@ class FriendshipManager {
/// Query Friend Information /// Query Friend Information
/// [userIDList] List of user IDs /// [userIDList] List of user IDs
Future<List<UserInfo>> getFriendsInfo({ Future<List<FriendInfo>> getFriendsInfo({
required List<String> userIDList, required List<String> userIDList,
String? operationID, String? operationID,
}) => }) =>
@ -26,7 +26,7 @@ class FriendshipManager {
"userIDList": userIDList, "userIDList": userIDList,
"operationID": Utils.checkOperationID(operationID), "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. /// Send a Friend Request, the other party needs to accept the request to become friends.
/// [userID] User ID to be invited /// [userID] User ID to be invited
@ -45,37 +45,31 @@ class FriendshipManager {
})); }));
/// Get Friend Requests Sent to Me /// Get Friend Requests Sent to Me
Future<List<FriendApplicationInfo>> getFriendApplicationListAsRecipient( Future<List<FriendApplicationInfo>> getFriendApplicationListAsRecipient({String? operationID}) => _channel
{String? operationID}) => .invokeMethod(
_channel 'getFriendApplicationListAsRecipient',
.invokeMethod( _buildParam({
'getFriendApplicationListAsRecipient', "operationID": Utils.checkOperationID(operationID),
_buildParam({ }))
"operationID": Utils.checkOperationID(operationID), .then((value) => Utils.toList(value, (v) => FriendApplicationInfo.fromJson(v)));
}))
.then((value) =>
Utils.toList(value, (v) => FriendApplicationInfo.fromJson(v)));
/// Get Friend Requests Sent by Me /// Get Friend Requests Sent by Me
Future<List<FriendApplicationInfo>> getFriendApplicationListAsApplicant( Future<List<FriendApplicationInfo>> getFriendApplicationListAsApplicant({String? operationID}) => _channel
{String? operationID}) => .invokeMethod(
_channel 'getFriendApplicationListAsApplicant',
.invokeMethod( _buildParam({
'getFriendApplicationListAsApplicant', "operationID": Utils.checkOperationID(operationID),
_buildParam({ }))
"operationID": Utils.checkOperationID(operationID), .then((value) => Utils.toList(value, (v) => FriendApplicationInfo.fromJson(v)));
}))
.then((value) =>
Utils.toList(value, (v) => FriendApplicationInfo.fromJson(v)));
/// Get Friend List, including friends who have been put into the blacklist /// Get Friend List, including friends who have been put into the blacklist
Future<List<UserInfo>> getFriendList({String? operationID}) => _channel Future<List<FriendInfo>> getFriendList({String? operationID}) => _channel
.invokeMethod( .invokeMethod(
'getFriendList', 'getFriendList',
_buildParam({ _buildParam({
"operationID": Utils.checkOperationID(operationID), "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) /// Get Friend List, including friends who have been put into the blacklist (returns a map)
Future<List<dynamic>> getFriendListMap({String? operationID}) => _channel Future<List<dynamic>> getFriendListMap({String? operationID}) => _channel
@ -116,13 +110,13 @@ class FriendshipManager {
})); }));
/// Get Blacklist /// Get Blacklist
Future<List<UserInfo>> getBlacklist({String? operationID}) => _channel Future<List<BlacklistInfo>> getBlacklist({String? operationID}) => _channel
.invokeMethod( .invokeMethod(
'getBlacklist', 'getBlacklist',
_buildParam({ _buildParam({
"operationID": Utils.checkOperationID(operationID), "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 /// Remove from Blacklist
/// [userID] User ID /// [userID] User ID
@ -150,8 +144,7 @@ class FriendshipManager {
'userIDList': userIDList, 'userIDList': userIDList,
"operationID": Utils.checkOperationID(operationID), "operationID": Utils.checkOperationID(operationID),
})) }))
.then((value) => .then((value) => Utils.toList(value, (v) => FriendshipInfo.fromJson(v)));
Utils.toList(value, (v) => FriendshipInfo.fromJson(v)));
/// Delete Friend /// Delete Friend
/// [userID] User ID /// [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 /// [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 /// [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 /// [isSearchRemark] Whether to search by remark name with keywords, defaults to false if empty
Future<List<SearchFriendInfo>> searchFriends({ Future<List<SearchFriendsInfo>> searchFriends({
List<String> keywordList = const [], List<String> keywordList = const [],
bool isSearchUserID = false, bool isSearchUserID = false,
bool isSearchNickname = false, bool isSearchNickname = false,
@ -222,8 +215,7 @@ class FriendshipManager {
}, },
'operationID': Utils.checkOperationID(operationID), 'operationID': Utils.checkOperationID(operationID),
})) }))
.then((value) => .then((value) => Utils.toList(value, (map) => SearchFriendsInfo.fromJson(map)));
Utils.toList(value, (map) => SearchFriendInfo.fromJson(map)));
static Map _buildParam(Map param) { static Map _buildParam(Map param) {
param["ManagerName"] = "friendshipManager"; param["ManagerName"] = "friendshipManager";

@ -43,11 +43,7 @@ class UserManager {
/// Modify the profile of the currently logged-in user /// Modify the profile of the currently logged-in user
/// [nickname] Nickname /// [nickname] Nickname
/// [faceURL] Profile picture /// [faceURL] Profile picture
/// [gender] Gender
/// [appManagerLevel] /// [appManagerLevel]
/// [phoneNumber] Phone number
/// [birth] Date of birth
/// [email] Email
/// [ex] Additional fields /// [ex] Additional fields
Future<String?> setSelfInfo({ Future<String?> setSelfInfo({
String? nickname, String? nickname,
@ -78,8 +74,7 @@ class UserManager {
'userIDs': userIDs, 'userIDs': userIDs,
'operationID': Utils.checkOperationID(operationID), 'operationID': Utils.checkOperationID(operationID),
})) }))
.then((value) => .then((value) => Utils.toList(value, (map) => UserStatusInfo.fromJson(map)));
Utils.toList(value, (map) => UserStatusInfo.fromJson(map)));
} }
Future<List<UserStatusInfo>> unsubscribeUsersStatus( Future<List<UserStatusInfo>> unsubscribeUsersStatus(
@ -93,8 +88,7 @@ class UserManager {
'userIDs': userIDs, 'userIDs': userIDs,
'operationID': Utils.checkOperationID(operationID), 'operationID': Utils.checkOperationID(operationID),
})) }))
.then((value) => .then((value) => Utils.toList(value, (map) => UserStatusInfo.fromJson(map)));
Utils.toList(value, (map) => UserStatusInfo.fromJson(map)));
} }
Future<List<UserStatusInfo>> getSubscribeUsersStatus({ Future<List<UserStatusInfo>> getSubscribeUsersStatus({
@ -106,8 +100,7 @@ class UserManager {
_buildParam({ _buildParam({
'operationID': Utils.checkOperationID(operationID), 'operationID': Utils.checkOperationID(operationID),
})) }))
.then((value) => .then((value) => Utils.toList(value, (map) => UserStatusInfo.fromJson(map)));
Utils.toList(value, (map) => UserStatusInfo.fromJson(map)));
} }
Future<List<UserStatusInfo>> getUserStatus( Future<List<UserStatusInfo>> getUserStatus(
@ -121,8 +114,7 @@ class UserManager {
'userIDs': userIDs, 'userIDs': userIDs,
'operationID': Utils.checkOperationID(operationID), 'operationID': Utils.checkOperationID(operationID),
})) }))
.then((value) => .then((value) => Utils.toList(value, (map) => UserStatusInfo.fromJson(map)));
Utils.toList(value, (map) => UserStatusInfo.fromJson(map)));
} }
Future<List<UserInfo>> getUsersInfoStranger( Future<List<UserInfo>> getUsersInfoStranger(

@ -31,12 +31,10 @@ class SearchResult {
final data = Map<String, dynamic>(); final data = Map<String, dynamic>();
data['totalCount'] = this.totalCount; data['totalCount'] = this.totalCount;
if (this.searchResultItems != null) { if (this.searchResultItems != null) {
data['searchResultItems'] = data['searchResultItems'] = this.searchResultItems!.map((v) => v.toJson()).toList();
this.searchResultItems!.map((v) => v.toJson()).toList();
} }
if (this.findResultItems != null) { if (this.findResultItems != null) {
data['findResultItems'] = data['findResultItems'] = this.findResultItems!.map((v) => v.toJson()).toList();
this.findResultItems!.map((v) => v.toJson()).toList();
} }
return data; return data;
} }
@ -115,11 +113,11 @@ class SearchParams {
} }
} }
class SearchFriendInfo extends FriendInfo { class SearchFriendsInfo extends FriendInfo {
late int relationship; late int relationship;
SearchFriendInfo({required this.relationship}) : super(); SearchFriendsInfo({required this.relationship}) : super();
SearchFriendInfo.fromJson(Map<String, dynamic> json) : super.fromJson(json) { SearchFriendsInfo.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
relationship = json['relationship']; relationship = json['relationship'];
} }

@ -8,18 +8,6 @@ class UserInfo {
/// Profile picture /// Profile picture
String? faceURL; String? faceURL;
/// Gender
int? gender;
/// Phone number
String? phoneNumber;
/// Date of birth
int? birth;
/// Email
String? email;
/// Additional information /// Additional information
String? ex; String? ex;
@ -35,150 +23,43 @@ class UserInfo {
/// 2: Accept online messages but not offline messages /// 2: Accept online messages but not offline messages
int? globalRecvMsgOpt; int? globalRecvMsgOpt;
/// Allow adding as a friend: int? appMangerLevel;
/// 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;
UserInfo({ UserInfo({
this.publicInfo,
this.friendInfo,
this.blackInfo,
this.isFriendship,
this.isBlacklist,
//
this.userID, this.userID,
this.nickname, this.nickname,
this.faceURL, this.faceURL,
this.phoneNumber, this.appMangerLevel,
this.birth,
this.gender,
this.email,
this.ex, this.ex,
this.createTime, this.createTime,
this.remark, this.remark,
this.globalRecvMsgOpt, this.globalRecvMsgOpt,
this.allowAddFriend,
this.allowBeep,
this.allowVibration,
this.forbidden,
}); });
UserInfo.fromJson(Map<String, dynamic> json) { UserInfo.fromJson(Map<String, dynamic> json) {
publicInfo = json['publicInfo'] != null userID = json['userID'] ?? userID;
? PublicUserInfo.fromJson(json['publicInfo']) nickname = json['nickname'] ?? nickname;
: null; faceURL = json['faceURL'] ?? faceURL;
friendInfo = json['friendInfo'] != null remark = json['remark'] ?? remark;
? FriendInfo.fromJson(json['friendInfo']) ex = json['ex'] ?? ex;
: 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;
createTime = json['createTime']; createTime = json['createTime'];
globalRecvMsgOpt = json['globalRecvMsgOpt']; globalRecvMsgOpt = json['globalRecvMsgOpt'];
allowAddFriend = json['allowAddFriend']; appMangerLevel = json['appMangerLevel'];
allowBeep = json['allowBeep'];
allowVibration = json['allowVibration'];
forbidden = json['forbidden'];
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = Map<String, dynamic>(); final data = Map<String, dynamic>();
data['publicInfo'] = this.publicInfo?.toJson(); data['appMangerLevel'] = this.appMangerLevel;
data['friendInfo'] = this.friendInfo?.toJson();
data['blackInfo'] = this.blackInfo?.toJson();
//
data['isFriendship'] = this.isFriendship;
data['isBlacklist'] = this.isBlacklist;
data['userID'] = this.userID; data['userID'] = this.userID;
data['nickname'] = this.nickname; data['nickname'] = this.nickname;
data['faceURL'] = this.faceURL; 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['ex'] = this.ex;
data['createTime'] = this.createTime; data['createTime'] = this.createTime;
data['remark'] = this.remark; data['remark'] = this.remark;
data['globalRecvMsgOpt'] = this.globalRecvMsgOpt; data['globalRecvMsgOpt'] = this.globalRecvMsgOpt;
data['allowAddFriend'] = this.allowAddFriend;
data['allowBeep'] = this.allowBeep;
data['allowVibration'] = this.allowVibration;
data['forbidden'] = this.forbidden;
return data; 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!; String getShowName() => _isNull(remark) ?? _isNull(nickname) ?? userID!;
static String? _isNull(String? value) { static String? _isNull(String? value) {
@ -187,11 +68,7 @@ class UserInfo {
} }
@override @override
bool operator ==(Object other) => bool operator ==(Object other) => identical(this, other) || other is UserInfo && runtimeType == other.runtimeType && userID == other.userID;
identical(this, other) ||
other is UserInfo &&
runtimeType == other.runtimeType &&
userID == other.userID;
@override @override
int get hashCode => userID.hashCode; int get hashCode => userID.hashCode;
@ -208,15 +85,9 @@ class FullUserInfo {
BlacklistInfo? blackInfo; BlacklistInfo? blackInfo;
FullUserInfo.fromJson(Map<String, dynamic> json) { FullUserInfo.fromJson(Map<String, dynamic> json) {
publicInfo = json['publicInfo'] != null publicInfo = json['publicInfo'] != null ? PublicUserInfo.fromJson(json['publicInfo']) : null;
? PublicUserInfo.fromJson(json['publicInfo']) friendInfo = json['friendInfo'] != null ? FriendInfo.fromJson(json['friendInfo']) : null;
: null; blackInfo = json['blackInfo'] != null ? BlacklistInfo.fromJson(json['blackInfo']) : null;
friendInfo = json['friendInfo'] != null
? FriendInfo.fromJson(json['friendInfo'])
: null;
blackInfo = json['blackInfo'] != null
? BlacklistInfo.fromJson(json['blackInfo'])
: null;
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
@ -239,9 +110,6 @@ class PublicUserInfo {
/// Profile picture /// Profile picture
String? faceURL; String? faceURL;
/// Gender
int? gender;
/// App Manager Level: /// App Manager Level:
/// 1: AppOrdinaryUsers /// 1: AppOrdinaryUsers
/// 2: AppAdmin /// 2: AppAdmin
@ -254,7 +122,6 @@ class PublicUserInfo {
this.userID, this.userID,
this.nickname, this.nickname,
this.faceURL, this.faceURL,
this.gender,
this.appManagerLevel, this.appManagerLevel,
this.ex, this.ex,
}); });
@ -263,7 +130,6 @@ class PublicUserInfo {
userID = json['userID']; userID = json['userID'];
nickname = json['nickname']; nickname = json['nickname'];
faceURL = json['faceURL']; faceURL = json['faceURL'];
gender = json['gender'];
appManagerLevel = json['appManagerLevel']; appManagerLevel = json['appManagerLevel'];
ex = json['ex']; ex = json['ex'];
} }
@ -273,7 +139,6 @@ class PublicUserInfo {
data['userID'] = this.userID; data['userID'] = this.userID;
data['nickname'] = this.nickname; data['nickname'] = this.nickname;
data['faceURL'] = this.faceURL; data['faceURL'] = this.faceURL;
data['gender'] = this.gender;
data['appMangerLevel'] = this.appManagerLevel; data['appMangerLevel'] = this.appManagerLevel;
data['ex'] = this.ex; data['ex'] = this.ex;
return data; return data;
@ -293,17 +158,8 @@ class FriendInfo {
/// Profile picture /// Profile picture
String? faceURL; String? faceURL;
/// Gender /// friend User ID
int? gender; String? friendUserID;
/// Phone number
String? phoneNumber;
/// Date of birth
int? birth;
/// Email
String? email;
/// Remark /// Remark
String? remark; String? remark;
@ -325,10 +181,7 @@ class FriendInfo {
this.userID, this.userID,
this.nickname, this.nickname,
this.faceURL, this.faceURL,
this.gender, this.friendUserID,
this.phoneNumber,
this.birth,
this.email,
this.remark, this.remark,
this.ex, this.ex,
this.createTime, this.createTime,
@ -345,10 +198,7 @@ class FriendInfo {
operatorUserID = json['operatorUserID']; operatorUserID = json['operatorUserID'];
nickname = json['nickname']; nickname = json['nickname'];
faceURL = json['faceURL']; faceURL = json['faceURL'];
gender = json['gender']; friendUserID = json['friendUserID'];
phoneNumber = json['phoneNumber'];
birth = json['birth'];
email = json['email'];
ex = json['ex']; ex = json['ex'];
} }
@ -362,10 +212,7 @@ class FriendInfo {
data['operatorUserID'] = this.operatorUserID; data['operatorUserID'] = this.operatorUserID;
data['nickname'] = this.nickname; data['nickname'] = this.nickname;
data['faceURL'] = this.faceURL; data['faceURL'] = this.faceURL;
data['gender'] = this.gender; data['friendUserID'] = this.friendUserID;
data['phoneNumber'] = this.phoneNumber;
data['birth'] = this.birth;
data['email'] = this.email;
data['ex'] = this.ex; data['ex'] = this.ex;
return data; return data;
} }
@ -591,9 +438,7 @@ class UserStatusInfo {
UserStatusInfo.fromJson(Map<String, dynamic> json) { UserStatusInfo.fromJson(Map<String, dynamic> json) {
userID = json['userID']; userID = json['userID'];
status = json['status']; status = json['status'];
platformIDs = json["platformIDs"] == null platformIDs = json["platformIDs"] == null ? [] : List<int>.from(json["platformIDs"].map((x) => x));
? []
: List<int>.from(json["platformIDs"].map((x) => x));
} }
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {

Loading…
Cancel
Save