diff --git a/functions/src/on-create-comment-on-group.ts b/functions/src/on-create-comment-on-group.ts index fbadf227..7217e602 100644 --- a/functions/src/on-create-comment-on-group.ts +++ b/functions/src/on-create-comment-on-group.ts @@ -13,24 +13,25 @@ export const onCreateCommentOnGroup = functions.firestore const { groupId } = context.params as { groupId: string } + const comment = change.data() as Comment const creatorSnapshot = await firestore .collection('users') .doc(comment.userId) .get() 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 .collection('groups') .doc(groupId) .get() if (!groupSnapshot.exists) throw new Error('Could not find group') + const group = groupSnapshot.data() as Group - // update group's most recent activity await firestore.collection('groups').doc(groupId).update({ mostRecentActivityTime: comment.createdTime, }) + await Promise.all( group.memberIds.map(async (memberId) => { return await createNotification(