Compare commits
No commits in common. "1cc35a57c949afc30144a36b0e64fff94b8436cf" and "dc586e3991e53ed589dd992deec76f16c5f79c73" have entirely different histories.
1cc35a57c9
...
dc586e3991
2 changed files with 21 additions and 19 deletions
|
@ -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")
|
||||||
|
|
||||||
let devicesList
|
const devices = []
|
||||||
if (reason === "relative") {
|
if (reason === "relative") {
|
||||||
logger.debug({ alertingUserId }, "Querying device record for user")
|
logger.debug({ alertingUserId }, "Querying device record for user")
|
||||||
devicesList = await sql`
|
const devicesList = await sql`
|
||||||
SELECT
|
SELECT
|
||||||
"id",
|
"id",
|
||||||
"fcm_token" as "fcmToken",
|
"fcm_token" as "fcmToken",
|
||||||
|
@ -148,21 +148,33 @@ 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")
|
||||||
devicesList = await sql`
|
const [device] = 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
|
||||||
"user_id" = ${alertingUserId}
|
"id" = ${deviceId}
|
||||||
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 }))
|
}
|
||||||
|
|
||||||
|
let sentOnce = false
|
||||||
|
await async.allLimit(devices, MAX_PARALLEL_PUSHES, async (device) => {
|
||||||
|
const { id: deviceId, fcmToken } = device
|
||||||
|
const notificationAlertLevel = device.notificationAlertLevel || "green"
|
||||||
|
logger.debug(
|
||||||
|
{ deviceId, notificationAlertLevel },
|
||||||
|
"Found device record"
|
||||||
|
)
|
||||||
|
|
||||||
logger.debug({ alertId }, "Querying alert record")
|
logger.debug({ alertId }, "Querying alert record")
|
||||||
const [{ userId: alertUserId, level, code }] = await sql`
|
const [{ userId: alertUserId, level, code }] = await sql`
|
||||||
|
@ -176,16 +188,6 @@ module.exports = async function () {
|
||||||
"alert"."id" = ${alertId}
|
"alert"."id" = ${alertId}
|
||||||
`
|
`
|
||||||
|
|
||||||
let sentOnce = false
|
|
||||||
|
|
||||||
await async.allLimit(devices, MAX_PARALLEL_PUSHES, async (device) => {
|
|
||||||
const { id: deviceId, fcmToken } = device
|
|
||||||
const notificationAlertLevel = device.notificationAlertLevel || "green"
|
|
||||||
logger.debug(
|
|
||||||
{ deviceId, notificationAlertLevel },
|
|
||||||
"Found device record"
|
|
||||||
)
|
|
||||||
|
|
||||||
if (alertUserId === alertingUserId) {
|
if (alertUserId === alertingUserId) {
|
||||||
logger.info(
|
logger.info(
|
||||||
{ alertUserId, alertingUserId },
|
{ alertUserId, alertingUserId },
|
||||||
|
|
|
@ -29,7 +29,7 @@ module.exports = async function () {
|
||||||
"id" = ${alertId}
|
"id" = ${alertId}
|
||||||
`
|
`
|
||||||
|
|
||||||
if (!alert) {
|
if (alert) {
|
||||||
// alert removed
|
// alert removed
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue