Refactor reminder push notifications (#2026)

* Refactor reminder push notifications

items should always exist and if not, we can just immediately fail imo

* Use same text for reminders in /notifications
This commit is contained in:
ekzyis 2025-03-26 10:59:27 -05:00 committed by GitHub
parent bb76c6a138
commit e29c6b4842
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 24 deletions

View File

@ -700,7 +700,7 @@ function Reminder ({ n }) {
return ( return (
<> <>
<NoteHeader color='info'> <NoteHeader color='info'>
you asked to be reminded of this {n.item.title ? 'post' : 'comment'} you requested this reminder
</NoteHeader> </NoteHeader>
<NoteItem item={n.item} /> <NoteItem item={n.item} />
</> </>

View File

@ -448,15 +448,11 @@ export async function notifyStreakLost (userId, streak) {
} }
} }
export async function notifyReminder ({ userId, item, itemId }) { export async function notifyReminder ({ userId, item }) {
try { await sendUserNotification(userId, {
await sendUserNotification(userId, { title: 'you requested this reminder',
title: 'this is your requested reminder', body: item.title ?? item.text,
body: `you asked to be reminded of this ${item ? item.title ? 'post' : 'comment' : 'item'}`, tag: `REMIND-ITEM-${item.id}`,
tag: `REMIND-ITEM-${item?.id ?? itemId}`, item
item: item ?? { id: itemId } })
})
} catch (err) {
console.error(err)
}
} }

View File

@ -1,18 +1,10 @@
import { notifyReminder } from '@/lib/webPush' import { notifyReminder } from '@/lib/webPush'
export async function remindUser ({ data: { itemId, userId }, models }) { export async function remindUser ({ data: { itemId, userId }, models }) {
let item
try { try {
item = await models.item.findUnique({ where: { id: itemId } }) const item = await models.item.findUnique({ where: { id: itemId } })
await notifyReminder({ userId, item })
} catch (err) { } catch (err) {
console.error('failed to lookup item by id', err) console.error('failed to send reminder:', err)
}
try {
if (item) {
await notifyReminder({ userId, item, itemId })
} else {
await notifyReminder({ userId, itemId })
}
} catch (err) {
console.error('failed to send push notification for reminder', err)
} }
} }