From e7f447c18539a7f5d7bafd9c21874c039461f904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=C2=A0Koby=C5=82ko?= Date: Sat, 2 Sep 2023 22:15:41 +0200 Subject: [PATCH] Allow domain to be matched only once --- .../services/data/ServicesRepositoryImpl.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/services/src/main/java/com/twofasapp/services/data/ServicesRepositoryImpl.kt b/services/src/main/java/com/twofasapp/services/data/ServicesRepositoryImpl.kt index cf478ba3..433d2620 100644 --- a/services/src/main/java/com/twofasapp/services/data/ServicesRepositoryImpl.kt +++ b/services/src/main/java/com/twofasapp/services/data/ServicesRepositoryImpl.kt @@ -80,6 +80,18 @@ internal class ServicesRepositoryImpl( return } + // Remove duplicates + val matchingServices = localData.selectAll().filter { it.assignedDomains.contains(domain.lowercase()) } + + matchingServices.forEach { matched -> + localData.updateServiceSuspend( + matched.copy( + assignedDomains = matched.assignedDomains.minus(domain.lowercase()), + updatedAt = timeProvider.systemCurrentTime(), + ) + ) + } + localData.updateServiceSuspend( service.copy( assignedDomains = service.assignedDomains.plus(domain.lowercase()),