Compare commits

...

3 commits

Author SHA1 Message Date
1cc35a57c9
fix: multi device lost notifications
All checks were successful
/ build (map[dockerfile:./services/api/Dockerfile name:api]) (push) Successful in 1m1s
/ build (map[dockerfile:./services/files/Dockerfile name:files]) (push) Successful in 1m32s
/ build (map[dockerfile:./services/web/Dockerfile name:web]) (push) Successful in 2m20s
/ build (map[dockerfile:./services/app/Dockerfile name:app]) (push) Successful in 1m35s
/ build (map[dockerfile:./services/tasks/Dockerfile name:tasks]) (push) Successful in 2m11s
/ build (map[dockerfile:./services/hasura/Dockerfile name:hasura]) (push) Successful in 2m15s
/ build (map[dockerfile:./services/watchers/Dockerfile name:watchers]) (push) Successful in 2m17s
/ deploy (push) Successful in 12s
2025-08-24 12:55:50 +02:00
e4da0f59b3
fix: opti 2025-08-24 11:53:15 +02:00
d6bd2308a1
fix: typo 2025-08-24 11:18:25 +02:00
2 changed files with 19 additions and 21 deletions

View file

@ -134,10 +134,10 @@ module.exports = async function () {
const { reason, alertId, userId: alertingUserId } = alertingRow const { reason, alertId, userId: alertingUserId } = alertingRow
logger.debug({ reason, alertId, alertingUserId }, "Found alerting record") logger.debug({ reason, alertId, alertingUserId }, "Found alerting record")
const devices = [] let devicesList
if (reason === "relative") { if (reason === "relative") {
logger.debug({ alertingUserId }, "Querying device record for user") logger.debug({ alertingUserId }, "Querying device record for user")
const devicesList = await sql` devicesList = await sql`
SELECT SELECT
"id", "id",
"fcm_token" as "fcmToken", "fcm_token" as "fcmToken",
@ -148,26 +148,36 @@ module.exports = async function () {
"user_id" = ${alertingUserId} "user_id" = ${alertingUserId}
AND "fcm_token" IS NOT NULL AND "fcm_token" IS NOT NULL
` `
devices.push(...devicesList.map((device) => ({ ...device })))
} else { } else {
const { deviceId } = alertingRow const { deviceId } = alertingRow
logger.debug({ deviceId }, "Querying device record") logger.debug({ deviceId }, "Querying device record")
const [device] = await sql` devicesList = await sql`
SELECT SELECT
"fcm_token" as "fcmToken", "fcm_token" as "fcmToken",
"notification_alert_level" as "notificationAlertLevel" "notification_alert_level" as "notificationAlertLevel"
FROM FROM
"device" "device"
WHERE WHERE
"id" = ${deviceId} "user_id" = ${alertingUserId}
AND "fcm_token" IS NOT NULL AND "fcm_token" IS NOT NULL
` `
if (device) {
devices.push({ id: deviceId, ...device })
}
} }
const devices = devicesList.map((device) => ({ ...device }))
logger.debug({ alertId }, "Querying alert record")
const [{ userId: alertUserId, level, code }] = await sql`
SELECT
"alert"."level" as "level",
"alert"."user_id" as "userId",
"alert"."code" as "code"
FROM
"alert"
WHERE
"alert"."id" = ${alertId}
`
let sentOnce = false let sentOnce = false
await async.allLimit(devices, MAX_PARALLEL_PUSHES, async (device) => { await async.allLimit(devices, MAX_PARALLEL_PUSHES, async (device) => {
const { id: deviceId, fcmToken } = device const { id: deviceId, fcmToken } = device
const notificationAlertLevel = device.notificationAlertLevel || "green" const notificationAlertLevel = device.notificationAlertLevel || "green"
@ -176,18 +186,6 @@ module.exports = async function () {
"Found device record" "Found device record"
) )
logger.debug({ alertId }, "Querying alert record")
const [{ userId: alertUserId, level, code }] = await sql`
SELECT
"alert"."level" as "level",
"alert"."user_id" as "userId",
"alert"."code" as "code"
FROM
"alert"
WHERE
"alert"."id" = ${alertId}
`
if (alertUserId === alertingUserId) { if (alertUserId === alertingUserId) {
logger.info( logger.info(
{ alertUserId, alertingUserId }, { alertUserId, alertingUserId },

View file

@ -29,7 +29,7 @@ module.exports = async function () {
"id" = ${alertId} "id" = ${alertId}
` `
if (alert) { if (!alert) {
// alert removed // alert removed
return return
} }