From b081429725637a74d0daa6df2f48602b96a33882 Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Wed, 25 May 2022 10:59:08 +0200 Subject: [PATCH] Replace getOrCreate() by get() in worker --- .../LiveLocationShareAggregatedSummaryEntityQuery.kt | 8 ++++++++ .../livelocation/DeactivateLiveLocationShareWorker.kt | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/query/LiveLocationShareAggregatedSummaryEntityQuery.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/query/LiveLocationShareAggregatedSummaryEntityQuery.kt index 2e2e939fa2..816b5f4392 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/query/LiveLocationShareAggregatedSummaryEntityQuery.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/query/LiveLocationShareAggregatedSummaryEntityQuery.kt @@ -55,3 +55,11 @@ internal fun LiveLocationShareAggregatedSummaryEntity.Companion.getOrCreate( return LiveLocationShareAggregatedSummaryEntity.where(realm, roomId, eventId).findFirst() ?: LiveLocationShareAggregatedSummaryEntity.create(realm, roomId, eventId) } + +internal fun LiveLocationShareAggregatedSummaryEntity.Companion.get( + realm: Realm, + roomId: String, + eventId: String, +): LiveLocationShareAggregatedSummaryEntity? { + return LiveLocationShareAggregatedSummaryEntity.where(realm, roomId, eventId).findFirst() +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/aggregation/livelocation/DeactivateLiveLocationShareWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/aggregation/livelocation/DeactivateLiveLocationShareWorker.kt index 6461b90435..a437975668 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/aggregation/livelocation/DeactivateLiveLocationShareWorker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/aggregation/livelocation/DeactivateLiveLocationShareWorker.kt @@ -23,7 +23,7 @@ import io.realm.RealmConfiguration import org.matrix.android.sdk.internal.SessionManager import org.matrix.android.sdk.internal.database.awaitTransaction import org.matrix.android.sdk.internal.database.model.livelocation.LiveLocationShareAggregatedSummaryEntity -import org.matrix.android.sdk.internal.database.query.getOrCreate +import org.matrix.android.sdk.internal.database.query.get import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.session.SessionComponent import org.matrix.android.sdk.internal.worker.SessionSafeCoroutineWorker @@ -74,12 +74,12 @@ internal class DeactivateLiveLocationShareWorker(context: Context, params: Worke private suspend fun deactivateLiveLocationShare(params: Params) { awaitTransaction(realmConfiguration) { realm -> - val aggregatedSummary = LiveLocationShareAggregatedSummaryEntity.getOrCreate( + val aggregatedSummary = LiveLocationShareAggregatedSummaryEntity.get( realm = realm, roomId = params.roomId, eventId = params.eventId ) - aggregatedSummary.isActive = false + aggregatedSummary?.isActive = false } }