Skip to content

Instantly share code, notes, and snippets.

@Viveckh
Last active August 29, 2019 12:04
Show Gist options
  • Save Viveckh/4d2690ecb5cea2af4b3e7325cc31bb07 to your computer and use it in GitHub Desktop.
Save Viveckh/4d2690ecb5cea2af4b3e7325cc31bb07 to your computer and use it in GitHub Desktop.
Dating App - Firebase Realtime Database Schema - Chat
"chats": {
"$chat_id": {
// only members can read the node
".read": "root.child('chats/' + $chat_id + '/members').hasChild(auth.uid)",
// If members not added yet, then any authenticated user can write. If members added already, then only members can write
".write": "(!root.child('chats/' + $chat_id).hasChild('members') && auth != null )|| root.child('chats/' + $chat_id + '/members').hasChild(auth.uid)",
// Creating a new chat room requires to have member node
".validate": "!data.exists() && newData.hasChildren(['members'])",
"members": {
".validate": "!data.exists()",
"$member_uid": {
".validate": "root.child('users/' + $member_uid).exists()"
}
},
"last_message": { ".validate": "newData.isString()" },
"last_message_timestamp": { ".validate": "newData.val() <= now" }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment