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
/// [userIDList] List of user IDs
Future<List<UserInfo>> getFriendsInfo({
Future<List<FriendInfo>> getFriendsInfo({
required List<String> 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<List<FriendApplicationInfo>> getFriendApplicationListAsRecipient(
{String? operationID}) =>
_channel
.invokeMethod(
'getFriendApplicationListAsRecipient',
_buildParam({
"operationID": Utils.checkOperationID(operationID),
}))
.then((value) =>
Utils.toList(value, (v) => FriendApplicationInfo.fromJson(v)));
Future<List<FriendApplicationInfo>> 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<List<FriendApplicationInfo>> getFriendApplicationListAsApplicant(
{String? operationID}) =>
_channel
.invokeMethod(
'getFriendApplicationListAsApplicant',
_buildParam({
"operationID": Utils.checkOperationID(operationID),
}))
.then((value) =>
Utils.toList(value, (v) => FriendApplicationInfo.fromJson(v)));
Future<List<FriendApplicationInfo>> 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<List<UserInfo>> getFriendList({String? operationID}) => _channel
Future<List<FriendInfo>> 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<List<dynamic>> getFriendListMap({String? operationID}) => _channel
@ -116,13 +110,13 @@ class FriendshipManager {
}));
/// Get Blacklist
Future<List<UserInfo>> getBlacklist({String? operationID}) => _channel
Future<List<BlacklistInfo>> 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<List<SearchFriendInfo>> searchFriends({
Future<List<SearchFriendsInfo>> searchFriends({
List<String> 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";

@ -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<String?> 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<List<UserStatusInfo>> 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<List<UserStatusInfo>> 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<List<UserStatusInfo>> 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<List<UserInfo>> getUsersInfoStranger(

@ -31,12 +31,10 @@ class SearchResult {
final data = Map<String, dynamic>();
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<String, dynamic> json) : super.fromJson(json) {
SearchFriendsInfo.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
relationship = json['relationship'];
}

@ -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<String, dynamic> 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<String, dynamic> toJson() {
final data = Map<String, dynamic>();
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<String, dynamic> 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<String, dynamic> 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<String, dynamic> json) {
userID = json['userID'];
status = json['status'];
platformIDs = json["platformIDs"] == null
? []
: List<int>.from(json["platformIDs"].map((x) => x));
platformIDs = json["platformIDs"] == null ? [] : List<int>.from(json["platformIDs"].map((x) => x));
}
Map<String, dynamic> toJson() {

Loading…
Cancel
Save