我正在使用 Firestore 数据库创建一个聊天模块。以下是我的监听器代码,用于监听新消息:
mDb.collection("Users_Collection").document(mAuth.getUid()).collection("Recipients")
.document(psychichObj.getUid()).collection("Messages").orderBy("time").limit(30)
.addSnapshotListener(MetadataChanges.INCLUDE, new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
if (e==null){
for (DocumentChange dc:queryDocumentSnapshots.getDocumentChanges()){
switch (dc.getType()){
case ADDED:
Log.d("chatevents", "onEvent:Added ");
messgaesDataClass msg = dc.getDocument().toObject(messgaesDataClass.class);
messages.add(msg);
chatAdapter.notifyDataSetChanged();
messagesRecycler.smoothScrollToPosition(messages.size());
break;
case REMOVED:
Log.d("chatevents", "onEvent:Removed ");
case MODIFIED:
Log.d("chatevents", "onEvent:Modiefied ");
}
}
}
}
});
当我发送消息时,我想知道如何侦听本地缓存中的 msg 对象或其元数据处于挂起状态且尚未发送到服务器?
千巷猫影
相关分类