我有一种方法可以通过其uid
获取用户列表:
public void getNeededUsers(List<String> uidList, UsersListCallback usersListCallback) {
CollectionReference users = db.collection(Consts.USERS_DB);
for (String uid: uidList) {
users.whereEqualTo(Consts.UID, uid).get()
.addOnCompleteListener(task -> {
List<FsUser> fsUserList = new ArrayList<>();
for (DocumentSnapshot snapshot : task.getResult().getDocuments()) {
fsUserList.add(snapshot.toObject(FsUser.class));
}
usersListCallback.getUsers(fsUserList);
});
}
}
但是,似乎这种方法无法正常工作。当我尝试用另一种方法遍历用户列表时,我从回调中逐个接收用户,而不是全部获取,因此它们在我的列表中重复。
这是另一种方法的代码:
public void createUserChats(UserChatListCallback userChatListCallback) {
final List<UserChat> userChatList = new ArrayList<>();
getChatAndUidList((chatList, uidList) -> {
getRtUsersAndMessages(uidList, (rtUserList, messageList) -> {
getNeededUsers(uidList, userList -> {
if (!userList.isEmpty()) {
for (int i = 0; i < userList.size(); i++) {
String name = userList.get(i).getName();
String image = userList.get(i).getImage();
String userId = userList.get(i).getUid();
long timeStamp = chatList.get(i).getTimeStamp();
boolean seen = chatList.get(i).getSeen();
String online = rtUserList.get(i).getOnline();
String message = messageList.get(i).getMessage();
long messageTimestamp = messageList.get(i).getTime();
userChatList.add(new UserChat(name, image, timeStamp, seen, userId, online,
message, messageTimestamp));
}
}
userChatListCallback.getUserChatList(userChatList);
});
});
});
}
答案 0 :(得分:1)
要获取用户列表,请使用以下代码:
event.target.value