From 377a228f88ba16b9fb0202f4b78667420170a675 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 22 Oct 2019 17:31:07 +0200 Subject: [PATCH] Improve code --- .../session/room/timeline/TimelineEventDecryptor.kt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TimelineEventDecryptor.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TimelineEventDecryptor.kt index 62ae5f621b..967dd66397 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TimelineEventDecryptor.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TimelineEventDecryptor.kt @@ -39,8 +39,8 @@ internal class TimelineEventDecryptor( override fun onNewSession(roomId: String?, senderKey: String, sessionId: String) { synchronized(unknownSessionsFailure) { unknownSessionsFailure[sessionId] + ?.toList() .orEmpty() - .toList() .also { unknownSessionsFailure[sessionId]?.clear() } @@ -55,7 +55,7 @@ internal class TimelineEventDecryptor( // Set of eventIds which are currently decrypting private val existingRequests = mutableSetOf() // sessionId -> list of eventIds - private val unknownSessionsFailure = mutableMapOf>() + private val unknownSessionsFailure = mutableMapOf>() fun start() { executor = Executors.newSingleThreadExecutor() @@ -84,11 +84,10 @@ internal class TimelineEventDecryptor( } } synchronized(existingRequests) { - if (eventId in existingRequests) { + if (!existingRequests.add(eventId)) { Timber.d("Skip Decryption request for event $eventId, already requested") return } - existingRequests.add(eventId) } executor?.execute { Realm.getInstance(realmConfiguration).use { realm -> @@ -120,7 +119,7 @@ internal class TimelineEventDecryptor( event.content?.toModel()?.let { content -> content.sessionId?.let { sessionId -> synchronized(unknownSessionsFailure) { - val list = unknownSessionsFailure.getOrPut(sessionId) { ArrayList() } + val list = unknownSessionsFailure.getOrPut(sessionId) { mutableSetOf() } list.add(eventId) } }