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:
parent
bb76c6a138
commit
e29c6b4842
@ -700,7 +700,7 @@ function Reminder ({ n }) {
|
||||
return (
|
||||
<>
|
||||
<NoteHeader color='info'>
|
||||
you asked to be reminded of this {n.item.title ? 'post' : 'comment'}
|
||||
you requested this reminder
|
||||
</NoteHeader>
|
||||
<NoteItem item={n.item} />
|
||||
</>
|
||||
|
@ -448,15 +448,11 @@ export async function notifyStreakLost (userId, streak) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function notifyReminder ({ userId, item, itemId }) {
|
||||
try {
|
||||
await sendUserNotification(userId, {
|
||||
title: 'this is your requested reminder',
|
||||
body: `you asked to be reminded of this ${item ? item.title ? 'post' : 'comment' : 'item'}`,
|
||||
tag: `REMIND-ITEM-${item?.id ?? itemId}`,
|
||||
item: item ?? { id: itemId }
|
||||
})
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
export async function notifyReminder ({ userId, item }) {
|
||||
await sendUserNotification(userId, {
|
||||
title: 'you requested this reminder',
|
||||
body: item.title ?? item.text,
|
||||
tag: `REMIND-ITEM-${item.id}`,
|
||||
item
|
||||
})
|
||||
}
|
||||
|
@ -1,18 +1,10 @@
|
||||
import { notifyReminder } from '@/lib/webPush'
|
||||
|
||||
export async function remindUser ({ data: { itemId, userId }, models }) {
|
||||
let item
|
||||
try {
|
||||
item = await models.item.findUnique({ where: { id: itemId } })
|
||||
const item = await models.item.findUnique({ where: { id: itemId } })
|
||||
await notifyReminder({ userId, item })
|
||||
} catch (err) {
|
||||
console.error('failed to lookup item by id', 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)
|
||||
console.error('failed to send reminder:', err)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user