From 17be24eab7ea88ce2f7da7f2474eb41de2a31740 Mon Sep 17 00:00:00 2001 From: Prasanth Ullattil Date: Tue, 22 Oct 2019 10:57:19 +0200 Subject: [PATCH] Remove duplicate entries in the notification token list. The application id coming from the app is generated using the identifierForVendor iOS API. This can change for the same device depending on varios factors (see the documentation) So we will use the token from FCM to cleanup any duplicate entries. --- .../prime/storage/documentstore/DocumentDataStore.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/document-data-store/src/main/kotlin/org/ostelco/prime/storage/documentstore/DocumentDataStore.kt b/document-data-store/src/main/kotlin/org/ostelco/prime/storage/documentstore/DocumentDataStore.kt index ff754e309..413244f4f 100644 --- a/document-data-store/src/main/kotlin/org/ostelco/prime/storage/documentstore/DocumentDataStore.kt +++ b/document-data-store/src/main/kotlin/org/ostelco/prime/storage/documentstore/DocumentDataStore.kt @@ -36,6 +36,12 @@ object DocumentDataStoreSingleton : DocumentStore { .getOrElse { emptyList() } override fun addNotificationToken(customerId: String, token: ApplicationToken): Boolean { + // Remove any other entries with the same token. + getNotificationTokens(customerId).forEach { + if (it.tokenType == token.tokenType && it.token == token.token && it.applicationID != token.applicationID) { + removeNotificationToken(customerId, it.applicationID) + } + } return notificationTokenStore.put( token, token.applicationID,