Replace getOrCreate() by get() in worker

This commit is contained in:
Maxime NATUREL 2022-05-25 10:59:08 +02:00
parent b05fc763ae
commit b081429725
2 changed files with 11 additions and 3 deletions

View File

@ -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()
}

View File

@ -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
}
}