mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-25 18:02:04 +00:00
Remove outdated push subscription (#7080)
This commit is contained in:
parent
4501a1cc04
commit
3da16bf670
@ -607,6 +607,8 @@ export async function createPushNotification (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const errorMessages = ['expired', 'Unregistered', 'No such subscription']
|
||||||
|
|
||||||
async function sendPushToSubscription (
|
async function sendPushToSubscription (
|
||||||
control: TriggerControl,
|
control: TriggerControl,
|
||||||
targetUser: Ref<Account>,
|
targetUser: Ref<Account>,
|
||||||
@ -617,9 +619,11 @@ async function sendPushToSubscription (
|
|||||||
await webpush.sendNotification(subscription, JSON.stringify(data))
|
await webpush.sendNotification(subscription, JSON.stringify(data))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
control.ctx.info('Cannot send push notification to', { user: targetUser, err })
|
control.ctx.info('Cannot send push notification to', { user: targetUser, err })
|
||||||
if (err instanceof WebPushError && err.body.includes('expired')) {
|
if (err instanceof WebPushError) {
|
||||||
const tx = control.txFactory.createTxRemoveDoc(subscription._class, subscription.space, subscription._id)
|
if (errorMessages.some((p) => (err as WebPushError).body.includes(p))) {
|
||||||
await control.apply(control.ctx, [tx])
|
const tx = control.txFactory.createTxRemoveDoc(subscription._class, subscription.space, subscription._id)
|
||||||
|
await control.apply(control.ctx, [tx])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user