In my project I have a chat feature to allow users to speak in private message. For now it's only one-to-one, but it could be improved later to allow group discussion.
Currently I'm struggling with custom rules. Indeed, for my projet I need users to have theirs own list of discussion. For example, user A and B talk through private message, but user C, D or whatever shouldn't be able to read the discussion.
Here is how the Database json look like :
{
"room-messages": {
"-KWgoXt567vzgxZ-1gii": {
"-KWgoXt567vzgxZ-1gii": {
"name": "Friendly Chat",
"sent": 1479294463723,
"text": "Nice ! You have created a new chat",
"uid": "user_A_id"
},
"-KWh5_W12qsXFaJhyOvx": {
"name": "Lucien Guimaraes",
"sent": 1479294463728,
"text": "A text message",
"uid": "user_B_id"
}
},
"-KWgoXt567vzgxZ-1git": {
"-KWgoXt567vzgxZ-1git": {
"name": "Friendly Chat",
"sent": 1479294463723,
"text": "Nice ! You have created a new chat (2)",
"uid": "user_A_id"
},
"-KWh5_W12qsXFaJhyOvz": {
"name": "Lucien Guimaraes",
"sent": 1479294463729,
"text": "Test",
"uid": "user_C_id"
}
}
},
"room-metadata": {
"-KWgoXt567vzgxZ-1gii": {
"users": {
"user_A_id": "Lucien Guimaraes",
"user_B_id": "Geralt of Rivia"
}
},
"-KWgoXt567vzgxZ-1git": {
"users": {
"user_A_id": "Lucien Guimaraes",
"user_C_id": " Gordon Freeman"
}
}
}
}
For your information "user_A_id" or "user_B_id" should be the id provided by Firebase Authentication. In this example I want user A to get all rooms (because he's in both available room). User B should have only the first room and user B only the last room.
Here are my rules :
I have been able to allow write access for Rooms almost perfectly (the only remaining issue is user who can't delete a message, I don't know why). But for Read I have a huge issue : I can't set a custom rule because the value "$roomId" is unknown inside "room-messages". It's only possible to do this as a child of "$roomId".
Is there any solution for what I want implemented ?
Thanks !
#AskFirebase