mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
add seconds threshold for notification
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import { GetterRepository } from "../repositories/GetterRepository";
|
import { GetterRepository } from "../repositories/GetterRepository";
|
||||||
import * as crypto from "node:crypto";
|
|
||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import { TupleKey } from "../types/TupleKey";
|
import { TupleKey } from "../types/TupleKey";
|
||||||
@@ -140,11 +139,7 @@ export class NotificationService {
|
|||||||
|
|
||||||
const indicesToRemove = new Set();
|
const indicesToRemove = new Set();
|
||||||
await Promise.all(this.deviceIdsToDeliverTo[tuple.toString()].map(async (deviceId, index) => {
|
await Promise.all(this.deviceIdsToDeliverTo[tuple.toString()].map(async (deviceId, index) => {
|
||||||
const deliveredSuccessfully = await this.sendEtaNotificationImmediately({
|
const deliveredSuccessfully = await this.sendEtaNotificationImmediatelyIfSecondsRemainingBelowThreshold(deviceId, eta);
|
||||||
deviceId,
|
|
||||||
shuttleId: eta.shuttleId,
|
|
||||||
stopId: eta.stopId,
|
|
||||||
});
|
|
||||||
if (deliveredSuccessfully) {
|
if (deliveredSuccessfully) {
|
||||||
indicesToRemove.add(index);
|
indicesToRemove.add(index);
|
||||||
}
|
}
|
||||||
@@ -153,6 +148,19 @@ export class NotificationService {
|
|||||||
this.deviceIdsToDeliverTo[tuple.toString()] = this.deviceIdsToDeliverTo[tuple.toString()].filter((_, index) => !indicesToRemove.has(index));
|
this.deviceIdsToDeliverTo[tuple.toString()] = this.deviceIdsToDeliverTo[tuple.toString()].filter((_, index) => !indicesToRemove.has(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async sendEtaNotificationImmediatelyIfSecondsRemainingBelowThreshold(deviceId: string, eta: IEta) {
|
||||||
|
const secondsThresholdForNotificationToFire = 300;
|
||||||
|
if (eta.secondsRemaining > secondsThresholdForNotificationToFire) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return await this.sendEtaNotificationImmediately({
|
||||||
|
deviceId,
|
||||||
|
shuttleId: eta.shuttleId,
|
||||||
|
stopId: eta.stopId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queue a notification to be sent.
|
* Queue a notification to be sent.
|
||||||
* @param deviceId The device ID to send the notification to.
|
* @param deviceId The device ID to send the notification to.
|
||||||
|
|||||||
Reference in New Issue
Block a user