Skip to content

Commit

Permalink
添加异步获取批量用户信息的接口
Browse files Browse the repository at this point in the history
  • Loading branch information
heavyrian2012 committed Nov 9, 2024
1 parent 13d10fd commit f1b01b6
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ interface IRemoteClient {
oneway void getGroupInfoEx(in String groupId, in boolean refresh, in IGetGroupCallback callback);
UserInfo getUserInfo(in String userId, in String groupId, in boolean refresh);
List<UserInfo> getUserInfos(in List<String> userIds, in String groupId);
oneway void getUserInfosAsync(in List<String> userIds, in String groupId, in IGetUserInfoListCallback callback);
oneway void getUserInfoEx(in String userId, in String groupId, in boolean refresh, in IGetUserCallback callback);

oneway void uploadMedia(in String fileName, in byte[] data, int mediaType, in IUploadMediaCallback callback);
Expand Down
44 changes: 44 additions & 0 deletions client/src/main/java/cn/wildfirechat/client/ClientService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2001,6 +2001,50 @@ public List<UserInfo> getUserInfos(List<String> userIds, String groupId) throws
return userInfos;
}

@Override
public void getUserInfosAsync(List<String> userIds, String groupId, IGetUserInfoListCallback callback) throws RemoteException {
String[] userIdsArray = new String[userIds.size()];
ProtoLogic.getUserInfosEx(userIds.toArray(userIdsArray), groupId == null ? "" : groupId, new ProtoLogic.ISearchUserCallback() {
@Override
public void onSuccess(ProtoUserInfo[] protoUserInfos) {
UserInfo[] userInfos = new UserInfo[protoUserInfos.length];
for (int i = 0; i < userInfos.length; i++) {
UserInfo userInfo = convertProtoUserInfo(protoUserInfos[i]);
if (userInfo.name == null && userInfo.displayName == null) {
userInfo = new NullUserInfo(userInfo.uid);
}
userInfos[i] = userInfo;
}

try {
SafeIPCEntry<UserInfo> entry;
int startIndex = 0;
do {
entry = buildSafeIPCEntry(userInfos, startIndex);
callback.onSuccess(entry.entries, entry.entries.size() > 0 && entry.index > 0 && entry.index < userInfos.length - 1);
startIndex = entry.index + 1;
} while (entry.index > 0 && entry.index < userInfos.length - 1);
} catch (RemoteException e) {
e.printStackTrace();
try {
callback.onFailure(-1);
} catch (RemoteException ex) {
e.printStackTrace();
}
}
}

@Override
public void onFailure(int i) {
try {
callback.onFailure(i);
} catch (RemoteException e) {
e.printStackTrace();
}
}
});
}

@Override
public void getUserInfoEx(String userId, String groupId, boolean refresh, IGetUserCallback callback) throws RemoteException {
ProtoLogic.getUserInfoEx2(userId, groupId, refresh, new ProtoLogic.IGetUserInfoCallback() {
Expand Down
43 changes: 43 additions & 0 deletions client/src/main/java/cn/wildfirechat/remote/ChatManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5536,6 +5536,49 @@ public List<UserInfo> getUserInfos(List<String> userIds, String groupId) {
return null;
}

public void getUserInfosAsync(List<String> userIds, String groupId, GetUserInfoListCallback callback) {
if (userIds == null || userIds.isEmpty()) {
return;
}

// if (userSource != null) {
// List<UserInfo> userInfos = new ArrayList<>();
// for (String userId : userIds) {
// userInfos.add(userSource.getUser(userId));
// }
// return userInfos;
// }

if (!checkRemoteService()) {
callback.onFail(-1);
return;
}

try {
List<UserInfo> userInfos = new ArrayList<>();
mClient.getUserInfosAsync(userIds, groupId, new IGetUserInfoListCallback.Stub() {

@Override
public void onSuccess(List<UserInfo> infos, boolean hasMore) throws RemoteException {
userInfos.addAll(infos);
if (callback != null && !hasMore) {
mainHandler.post(() -> callback.onSuccess(userInfos));
}
}

@Override
public void onFailure(int errorCode) throws RemoteException {
if (callback != null) {
mainHandler.post(() -> callback.onFail(errorCode));
}
}
});
} catch (RemoteException e) {
e.printStackTrace();
callback.onFail(-1);
}
}

public void getUserInfo(String userId, boolean refresh, GetUserInfoCallback callback) {
getUserInfo(userId, null, refresh, callback);
}
Expand Down
Binary file modified mars-core-release/mars-core-release.aar
Binary file not shown.

0 comments on commit f1b01b6

Please sign in to comment.