我正在使用 firebase 创建一个聊天应用程序。我的聊天数据库结构是这样的。
chat:{
$UID1:{
$RoomID1 : 122113455,
// user last talk timestamp
$RoomID2 : 122113288,
},
$UID2:{...},
...
},
chat_info:{
$RoomID1:{
last_talk: 1223345343, //Timestamp
created_at: 1211424452,
},
$RoomID2:{...},
...
}
现在我想检索order by$RoomID下的所有聊天室()。我怎样才能做到这一点?我可以用 Kotlin 和 Java 编写代码,所以两个答案都很好。$UID1last_talk
编辑:这是我尝试过的没有 orderBy() 的代码
rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference chat = rootRef.child("chat").child(myUID);
DatabaseReference chat_info = rootRef.chipd("chat_info");
chat.addValueEventListener(new ChildEventListener(){
@Override
private void onChildAdded(DataSnapshot snapshot,String s){
chatliveData.setValue(snapshot.getKey());
}
});
//Here I retrieve Chat_Info one by one
chat_infoliveData = Transformations.switchMap(chatliveData, room_id->{
ChatInfo.getInstance().getChatInfo(room_id);
});