Skip to content

Commit ba3ffcf

Browse files
committed
Add push notification if infected
1 parent 0d09996 commit ba3ffcf

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

api/paidAction/zap.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HOURS_OF_IMMUNITY, PAID_ACTION_PAYMENT_METHODS, USER_ID } from '@/lib/constants'
22
import { msatsToSats, satsToMsats } from '@/lib/format'
33
import { datePivot } from '@/lib/time'
4-
import { notifyZapped } from '@/lib/webPush'
4+
import { notifyZapped, notifyInfected } from '@/lib/webPush'
55
import { getInvoiceableWallets } from '@/wallets/server'
66
import { Prisma } from '@prisma/client'
77

@@ -252,11 +252,15 @@ async function maybeInfectUser (itemAct, { tx }) {
252252
return
253253
}
254254

255-
await tx.$queryRaw`
255+
const count = await tx.$executeRaw`
256256
INSERT INTO "Infection" ("itemActId", "infecteeId", "infectorId")
257257
VALUES (${id}::INTEGER, ${toId}::INTEGER, ${fromId}::INTEGER)
258258
ON CONFLICT ("infecteeId") DO NOTHING`
259259
await tx.user.update({ where: { id: toId }, data: { infected: true } })
260+
261+
if (count > 0) {
262+
notifyInfected(toId).catch(console.error)
263+
}
260264
}
261265

262266
export async function nonCriticalSideEffects ({ invoice, actIds }, { models }) {

lib/webPush.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,3 +464,14 @@ export async function notifyReminder ({ userId, item }) {
464464
itemId: item.id
465465
})
466466
}
467+
468+
export async function notifyInfected (userId) {
469+
try {
470+
await sendUserNotification(userId, {
471+
title: 'you have been bitten by a zombie',
472+
body: 'You\'re feeling cold and clammy and you have a sudden desire to zap everyone ...'
473+
})
474+
} catch (err) {
475+
log('error sending infected notification:', err)
476+
}
477+
}

0 commit comments

Comments
 (0)