Add nym in reply notification ()

Co-authored-by: ekzyis <ek@stacker.news>
This commit is contained in:
ekzyis 2023-07-07 15:45:44 +02:00 committed by GitHub
parent 422b2ce8b6
commit 5e4dedad28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -895,13 +895,15 @@ export default {
createComment: async (parent, data, { me, models }) => { createComment: async (parent, data, { me, models }) => {
await ssValidate(commentSchema, data) await ssValidate(commentSchema, data)
const item = await createItem(parent, data, { me, models }) const item = await createItem(parent, data, { me, models })
// fetch user to get up-to-date name
const user = await models.user.findUnique({ where: { id: me.id } })
const parents = await models.$queryRaw( const parents = await models.$queryRaw(
'SELECT DISTINCT p."userId" FROM "Item" i JOIN "Item" p ON p.path @> i.path WHERE i.id = $1 and p."userId" <> $2', 'SELECT DISTINCT p."userId" FROM "Item" i JOIN "Item" p ON p.path @> i.path WHERE i.id = $1 and p."userId" <> $2',
Number(item.parentId), Number(me.id)) Number(item.parentId), Number(me.id))
Promise.allSettled( Promise.allSettled(
parents.map(({ userId }) => sendUserNotification(userId, { parents.map(({ userId }) => sendUserNotification(userId, {
title: 'you have a new reply', title: `@${user.name} replied to you`,
body: data.text, body: data.text,
item, item,
tag: 'REPLY' tag: 'REPLY'