Firebase onCreate Reference to child - Javascript -
i have created , deployed cloud function sending push notifications on data write.
now trying little more complex. have implemented chat application used send one-to-one messages between users , every 2 users have separate conversation node
messages | |-conversation1 | |-messagenode1 | | |-message:abc | | |-sender:xhgdjsgghsdgj | | |-receiver: 73gfdsfghsdgfgfsd | | | |+-messagenode2 | |+-messagenode3 | |+-conversation2 |+-conversation3
so if message arrives in of these conversations, push message should generated receiver not sender (i implement logic self).
the main problem facing conversations have unique keys messages can implement trigger new message arrive in conversation , key conversation.
current code -> if new node added settings2
exports.sendpush = functions.database.ref('/settings2').onwrite(event => { return loadusers().then(users => { let tokens = []; (let user of users) { tokens.push(user.token); } let payload = { notification: { title: 'firebase notification', body: 'this message', sound: 'default', badge: '1' } }; return admin.messaging().sendtodevice(tokens, payload); }); });
Comments
Post a Comment