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 (
|
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} />
|
||||||
</>
|
</>
|
||||||
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user