Hello, I'm creating an Android chat app using Firebase. Firstly, Sorry for my bad English writing skill. I have some problems and impossibilities with Firebase Realtime database structure.
Scenario, in may chat app , there are 2 available chat options; single(1 to 1 ) chat and group chat. As documentations, I don't want users to fetch unnecessary data. So I structured my database like this.
chat:{
$UID1:{
$RoomID1 : 122113455, // $UID1 last talk timestamp
$RoomID2 : 122113288, //$UID1 last talk timestamp
...
},
$UID2:{
$RoomID1 : 121808790, //$UID2 last talk timestamp
...
},
...
},
chat_info:{
$RoomID1:{
last_talk: 1223345343, //Timestamp
created_at: 1211424452,
},
$RoomID2:{...},
...
},
members:{
$RoomID1:{
$UID1 : true,
$UID2 : true,
...
},
...
}
As above JSON tree, a user can have many chat_rooms and a chat room can have many user. I want to retrieve all chat room of a user order by "chat_info/$RoomID/last_talk" where "last_talk" always change whenever new message is added. So if I add "last_talk" to "chat/$UID/", I have to change each user node every time new message is added in group chat. I search on google and there is no answer for cost and time effective approach. I think I need a new type of filter to this type of query. If this approach already exist or another database structure is suitable, kindly advice me . Thank you for your support.