Last active
August 29, 2019 12:04
-
-
Save Viveckh/4d2690ecb5cea2af4b3e7325cc31bb07 to your computer and use it in GitHub Desktop.
Dating App - Firebase Realtime Database Schema - Chat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
"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