manifold/functions/src/on-follow-user.ts
Ian Philips 37c7f909a3
Notification detail, grouping, and settings control [wip] (#403)
* Revert "Revert "Notifications ux fixes - wip (#383)""

This reverts commit 699b03eb42.

* Group & provide more control over notification display

* UI/UX improvements

* Remove unused text key

* Refactor

* Refactor

* Show answer resolution in notification

* Disable eslint on single linefor exhaustive deps

* Handle arbritrary notifications

* Refactor

* Remove unused vars

* Add follow user

* Various UX improvements, add follow notif

* Various small ui changes

* Show notification settings breakdown

* Improve notification status lines
2022-06-06 10:52:11 -06:00

29 lines
774 B
TypeScript

import * as functions from 'firebase-functions'
import { getUser } from './utils'
import { createNotification } from './create-notification'
export const onFollowUser = functions.firestore
.document('users/{userId}/follows/{followedUserId}')
.onCreate(async (change, context) => {
const { userId } = context.params as {
userId: string
}
const { eventId } = context
const follow = change.data() as { userId: string; timestamp: number }
const followingUser = await getUser(userId)
if (!followingUser) throw new Error('Could not find following user')
await createNotification(
followingUser.id,
'follow',
'created',
followingUser,
eventId,
undefined,
undefined,
follow.userId
)
})