Skip to content

Commit ddc83fd

Browse files
guangyaoguangyao
authored andcommitted
fix 非好友名片不显示的问题
1 parent 1978af8 commit ddc83fd

File tree

2 files changed

+30
-43
lines changed

2 files changed

+30
-43
lines changed

ios/RNNeteaseIm/RNNeteaseIm/ContactViewController.m

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,32 @@ -(void)getAllContactFriends{
116116
}
117117
//获取本地用户资料
118118
-(void)getUserInFo:(NSString *)userId Success:(Success )success{
119-
NIMUser *user = [[NIMSDK sharedSDK].userManager userInfo:userId];
119+
NIMUser *user = [[NIMSDK sharedSDK].userManager userInfo:userId];
120+
if (!user.userInfo) {
121+
[[NIMSDK sharedSDK].userManager fetchUserInfos:@[userId] completion:^(NSArray *users, NSError *error) {
122+
//从服务器获取用户信息,会自动缓存到本地
123+
}];
124+
}
125+
NSMutableDictionary *userDict = [self setupUserDict:user andUserId:userId];
126+
success(userDict);
127+
128+
}
129+
130+
//获取服务器用户资料
131+
-(void)fetchUserInfos:(NSString *)userId Success:(Success )success error:(Error )err{
132+
[[NIMSDK sharedSDK].userManager fetchUserInfos:@[userId] completion:^(NSArray *users, NSError *error) {
133+
if (users.count) {
134+
for (NIMUser *user in users) {
135+
NSMutableDictionary *userDict = [self setupUserDict:user andUserId:userId];
136+
success(userDict);
137+
}
138+
}else{
139+
err(@"该用户不存在,请检查你输入的帐号是否正确");
140+
}
141+
}];
142+
}
143+
//设置用户信息
144+
- (NSMutableDictionary *)setupUserDict:(NIMUser *)user andUserId:(NSString *)userId{
120145
BOOL isMe = [userId isEqualToString:[NIMSDK sharedSDK].loginManager.currentAccount];
121146
BOOL isMyFriend = [[NIMSDK sharedSDK].userManager isMyFriend:userId];
122147
BOOL isInBlackList = [[NIMSDK sharedSDK].userManager isUserInBlackList:userId];
@@ -132,59 +157,21 @@ -(void)getUserInFo:(NSString *)userId Success:(Success )success{
132157
[dic setObject:[NSString stringWithFormat:@"%@",user.userInfo.birth] forKey:@"birthday"];
133158
[dic setObject:[NSString stringWithFormat:@"%@",user.userInfo.mobile] forKey:@"mobile"];
134159
[dic setObject:[NSString stringWithFormat:@"%@",user.userInfo.ext] forKey:@"extension"];
160+
[dic setObject:@"" forKey:@"extensionMap"];
135161
[dic setObject:[NSString stringWithFormat:@"%d",isMe] forKey:@"isMe"];
136162
[dic setObject:[NSString stringWithFormat:@"%d",isMyFriend] forKey:@"isMyFriend"];
137163
[dic setObject:[NSString stringWithFormat:@"%d",isInBlackList] forKey:@"isInBlackList"];
138164
[dic setObject:[NSString stringWithFormat:@"%d",needNotify] forKey:@"mute"];
139-
[dic setObject:@"" forKey:@"extensionMap"];
140165
NSArray *keys = [dic allKeys];
141166
for (NSString *tem in keys) {
142167
if ([[dic objectForKey:tem] isEqualToString:@"(null)"]) {
143168
[dic setObject:@"" forKey:tem];
144169
}
145170
}
146-
success(dic);
171+
return dic;
147172
}
148173

149-
//获取服务器用户资料
150-
-(void)fetchUserInfos:(NSString *)userId Success:(Success )success error:(Error )err{
151-
[[NIMSDK sharedSDK].userManager fetchUserInfos:@[userId] completion:^(NSArray *users, NSError *error) {
152-
if (users.count) {
153-
BOOL isMe = [userId isEqualToString:[NIMSDK sharedSDK].loginManager.currentAccount];
154-
BOOL isMyFriend = [[NIMSDK sharedSDK].userManager isMyFriend:userId];
155-
BOOL isInBlackList = [[NIMSDK sharedSDK].userManager isUserInBlackList:userId];
156-
BOOL needNotify = [[NIMSDK sharedSDK].userManager notifyForNewMsg:userId];
157-
for (NIMUser *user in users) {
158-
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
159-
[dic setObject:[NSString stringWithFormat:@"%@", user.userId] forKey:@"contactId"];
160-
[dic setObject:[NSString stringWithFormat:@"%@", user.alias] forKey:@"alias"];
161-
[dic setObject:[NSString stringWithFormat:@"%@",user.userInfo.nickName] forKey:@"name"];
162-
[dic setObject:[NSString stringWithFormat:@"%@",user.userInfo.avatarUrl] forKey:@"avatar"];
163-
[dic setObject:[NSString stringWithFormat:@"%@",user.userInfo.sign] forKey:@"signature"];
164-
[dic setObject:[NSString stringWithFormat:@"%ld", user.userInfo.gender ] forKey:@"gender"];
165-
[dic setObject:[NSString stringWithFormat:@"%@",user.userInfo.email] forKey:@"email"];
166-
[dic setObject:[NSString stringWithFormat:@"%@",user.userInfo.birth] forKey:@"birthday"];
167-
[dic setObject:[NSString stringWithFormat:@"%@",user.userInfo.mobile] forKey:@"mobile"];
168-
[dic setObject:[NSString stringWithFormat:@"%@",user.userInfo.ext] forKey:@"extension"];
169-
[dic setObject:@"" forKey:@"extensionMap"];
170-
[dic setObject:[NSString stringWithFormat:@"%d",isMe] forKey:@"isMe"];
171-
[dic setObject:[NSString stringWithFormat:@"%d",isMyFriend] forKey:@"isMyFriend"];
172-
[dic setObject:[NSString stringWithFormat:@"%d",isInBlackList] forKey:@"isInBlackList"];
173-
[dic setObject:[NSString stringWithFormat:@"%d",needNotify] forKey:@"needNotify"];
174-
NSArray *keys = [dic allKeys];
175-
for (NSString *tem in keys) {
176-
if ([[dic objectForKey:tem] isEqualToString:@"(null)"]) {
177-
[dic setObject:@"" forKey:tem];
178-
}
179-
}
180-
success(dic);
181-
}
182-
}else{
183-
err(@"该用户不存在,请检查你输入的帐号是否正确");
184-
}
185-
}];
186174

187-
}
188175
//修改好友备注
189176
-(void)upDateUserInfo:(NSString *)contactId alias:(NSString *)alias Success:(Success )success error:(Error )err{
190177
_user = [[NIMSDK sharedSDK].userManager userInfo:contactId];

ios/RNNeteaseIm/RNNeteaseIm/TeamViewController.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ -(void)getTeamMemberList:(NSString *)teamId Succ:(Success)succ Err:(Errors)err{
321321
[memb setObject:[NSString stringWithFormat:@"%d",isMe] forKey:@"isMe"];
322322
[memb setObject:[NSString stringWithFormat:@"%d",isMyFriend] forKey:@"isMyFriend"];
323323
[memb setObject:[NSString stringWithFormat:@"%d",isInBlackList] forKey:@"isInBlackList"];
324-
[memb setObject:[NSString stringWithFormat:@"%d",needNotify] forKey:@"needNotify"];
324+
[memb setObject:[NSString stringWithFormat:@"%d",needNotify] forKey:@"mute"];
325325
[memb setObject:@"" forKey:@"extensionMap"];
326326
NSArray *keys = [memb allKeys];
327327
for (NSString *tem in keys) {
@@ -366,7 +366,7 @@ - (void)fetchTeamMemberInfo:(NSString *)teamId contactId:(NSString *)contactId S
366366
[memb setObject:[NSString stringWithFormat:@"%d",isMe] forKey:@"isMe"];
367367
[memb setObject:[NSString stringWithFormat:@"%d",isMyFriend] forKey:@"isMyFriend"];
368368
[memb setObject:[NSString stringWithFormat:@"%d",isInBlackList] forKey:@"isInBlackList"];
369-
[memb setObject:[NSString stringWithFormat:@"%d",needNotify] forKey:@"needNotify"];
369+
[memb setObject:[NSString stringWithFormat:@"%d",needNotify] forKey:@"mute"];
370370
[memb setObject:@"" forKey:@"extensionMap"];
371371
NSArray *keys = [memb allKeys];
372372
for (NSString *tem in keys) {

0 commit comments

Comments
 (0)