我正在尝试检查2个用户是否正在彼此聊天。该代码曾经可以工作,但是当我添加功能时,它不再起作用。
这是代码:
firebaseFirestore.collection(getString(R.string.app_name)).document("App Collections")
.collection("Users").document(contactID).collection("Chats With").document(userID).addSnapshotListener(new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) {
boolean chatOpened = documentSnapshot.getBoolean("chat opened");
if (!chatOpened) {
firebaseFirestore.collection(getString(R.string.app_name)).document("App Collections")
.collection("Users").document(contactID).collection("Chats With").document(userID)
.update("chat opened", false);
} else if (chatOpened) {
firebaseFirestore.collection(getString(R.string.app_name)).document("App Collections")
.collection("Users").document(contactID).collection("Chats With").document(userID)
.update("chat opened", true);
}
}
});
如果当前用户(userID)已经打开了聊天并且聊天用户(contactID)也已经打开了聊天,那么两个都同时打开了聊天,contactID文档中的“聊天已打开”字段应该保持真实。这是怎么回事,它变为false。
如何检查2个用户是否同时打开聊天?