mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
add code to update device ids object on successful delivery
This commit is contained in:
@@ -19,7 +19,9 @@ export class NotificationService {
|
||||
return this._lastRefreshedTimeMs;
|
||||
}
|
||||
|
||||
constructor(private repository: GetterRepository) {}
|
||||
constructor(private repository: GetterRepository) {
|
||||
this.etaSubscriberCallback = this.etaSubscriberCallback.bind(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* An object of device ID arrays to deliver notifications to.
|
||||
@@ -79,13 +81,19 @@ export class NotificationService {
|
||||
return;
|
||||
}
|
||||
|
||||
await Promise.all(this.deviceIdsToDeliverTo[tuple.toString()].map(async (deviceId) => {
|
||||
await this.sendEtaNotificationImmediately({
|
||||
const indicesToRemove = new Set();
|
||||
await Promise.all(this.deviceIdsToDeliverTo[tuple.toString()].map(async (deviceId, index) => {
|
||||
const deliveredSuccessfully = await this.sendEtaNotificationImmediately({
|
||||
deviceId,
|
||||
shuttleId: eta.shuttleId,
|
||||
stopId: eta.stopId,
|
||||
});
|
||||
if (deliveredSuccessfully) {
|
||||
indicesToRemove.add(index);
|
||||
}
|
||||
}));
|
||||
|
||||
this.deviceIdsToDeliverTo[tuple.toString()] = this.deviceIdsToDeliverTo[tuple.toString()].filter((_, index) => !indicesToRemove.has(index));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +110,6 @@ export class NotificationService {
|
||||
this.deviceIdsToDeliverTo[tuple.toString()].push(deviceId);
|
||||
}
|
||||
|
||||
// Refresh the subscriber with the updated array if needed
|
||||
this.repository.unsubscribeFromEtaUpdates(this.etaSubscriberCallback);
|
||||
this.repository.subscribeToEtaUpdates(this.etaSubscriberCallback);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user