This commit is contained in:
Ian Philips 2022-07-05 17:12:57 -06:00
parent 4c9842291d
commit e1847da9c7

View File

@ -13,24 +13,25 @@ export const onCreateCommentOnGroup = functions.firestore
const { groupId } = context.params as { const { groupId } = context.params as {
groupId: string groupId: string
} }
const comment = change.data() as Comment const comment = change.data() as Comment
const creatorSnapshot = await firestore const creatorSnapshot = await firestore
.collection('users') .collection('users')
.doc(comment.userId) .doc(comment.userId)
.get() .get()
if (!creatorSnapshot.exists) throw new Error('Could not find user') if (!creatorSnapshot.exists) throw new Error('Could not find user')
// find members of group
// send them a notification with a custom isSeenOnHref set to the group's /group/slug
const groupSnapshot = await firestore const groupSnapshot = await firestore
.collection('groups') .collection('groups')
.doc(groupId) .doc(groupId)
.get() .get()
if (!groupSnapshot.exists) throw new Error('Could not find group') if (!groupSnapshot.exists) throw new Error('Could not find group')
const group = groupSnapshot.data() as Group const group = groupSnapshot.data() as Group
// update group's most recent activity
await firestore.collection('groups').doc(groupId).update({ await firestore.collection('groups').doc(groupId).update({
mostRecentActivityTime: comment.createdTime, mostRecentActivityTime: comment.createdTime,
}) })
await Promise.all( await Promise.all(
group.memberIds.map(async (memberId) => { group.memberIds.map(async (memberId) => {
return await createNotification( return await createNotification(