在我的聊天应用程序中,我意识到了一切,并且效果很好,但是 我想向用户显示他们在另一个片段中有消息,我该怎么做?
这是我要向正在显示对话的用户显示的方法,但是当我添加另一个对话时,它将覆盖先前的对话。 我真的很遗憾这个错误的解释,希望任何人都能理解我...
private void readFriends()
{
chatRef = FirebaseFirestore.getInstance().collection("Chats");
chatRef.whereArrayContains("participants", firebaseUser.getUid())
.addSnapshotListener(new EventListener<QuerySnapshot>()
{
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e)
{
mChats.clear();
for (QueryDocumentSnapshot documentSnapshot : queryDocumentSnapshots)
{
ArrayList<String> arrList = new ArrayList<String>();
arrList = (ArrayList<String>) documentSnapshot.get("participants");
for(int i=0;i<arrList.size();i++)
receiverId = arrList.get(1);
List<String> list = new ArrayList<>();
list.add(receiverId);
System.out.println("first element in list"+ receiverId);
userRef.document(receiverId)
.addSnapshotListener(new EventListener<DocumentSnapshot>()
{
@Override
public void onEvent(@Nullable DocumentSnapshot documentSnapshot, @Nullable FirebaseFirestoreException e)
{
mUsers.clear();
if (documentSnapshot != null)
{
User user = documentSnapshot.toObject(User.class);
assert user != null;
if(user.getId().equals(receiverId))
mUsers.add(user);
}
chatsAdapter.notifyDataSetChanged();
}
}) ;
}
}
});
}