add code to update device ids object on successful delivery

This commit is contained in:
2025-02-03 21:50:59 -08:00
parent e96316aa1e
commit 8bc71d25fe

View File

@@ -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);