timy-messenger/firebase/functions/channel-flagChannelUnread.js
Franz Heinfling 64d39ac266 Initial commit.
Co-authored-by: Miguel Beltran <m@beltran.work>
2019-10-01 17:26:36 +02:00

24 lines
715 B
JavaScript

const { db } = require('./admin');
/**
* Sets `hasUpdates` flag for user in channel to false.
* This is used to allow the channels listener on client-side
* to update its list accordingly.
*/
const flagChannelUnread = async (groupdId, channelId, userId) => {
try {
await db
.collection("/groups/")
.doc(groupdId)
.collection("/channels/")
.doc(channelId)
.collection("/users/").doc(userId).update({
hasUpdates: true
});
console.log("Updated has updates for user: " + userId);
} catch (error) {
console.error("Error writing document: ", error);
}
}
module.exports = flagChannelUnread;