aboutsummaryrefslogtreecommitdiffstats
path: root/lib/notifications.js
blob: 18d5b503213afc064f9579e3ac4cdf2247378d0b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const webpush = require("web-push");

if (config.vapid) {
  webpush.setVapidDetails(
    config.vapid.url,
    
"p">.privateKey ); } notify = (user, payload) => { let { subscriptions } = user; if (subscriptions) { subscriptions.map(async (subscription, i) => { try { await webpush.sendNotification(subscription, payload); } catch (e) { if (e.body && (e.body.includes('expired') || e.body.includes('No such'))) { user.subscriptions.splice(i, 1); await user.save(); } else { l.error("problem sending notification", e); } } }); } };