From 629fe4dddd1f15ddde17e2ba6fa881abfd0131c9 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Mon, 3 Feb 2025 23:48:53 -0800 Subject: [PATCH] add cancelNotificationIfExists implementation --- src/services/NotificationService.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/services/NotificationService.ts b/src/services/NotificationService.ts index 1b49710..a59d31e 100644 --- a/src/services/NotificationService.ts +++ b/src/services/NotificationService.ts @@ -198,7 +198,18 @@ export class NotificationService { * @param stopId Stop ID of the ETA object. */ public async cancelNotificationIfExists({ deviceId, shuttleId, stopId }: ScheduledNotificationData) { + const tupleKey = new TupleKey(shuttleId, stopId); + if ( + this.deviceIdsToDeliverTo[tupleKey.toString()] === undefined + || !this.deviceIdsToDeliverTo[tupleKey.toString()].includes(deviceId) + ) { + return; + } + const index = this.deviceIdsToDeliverTo[tupleKey.toString()].findIndex(id => id === deviceId); + if (index !== -1) { + this.deviceIdsToDeliverTo[tupleKey.toString()].splice(index, 1); + } } /**