From db84c679b47e215831c79a145a26c9d62728af28 Mon Sep 17 00:00:00 2001
From: Valere <valeref@matrix.org>
Date: Fri, 4 Mar 2022 19:19:18 +0100
Subject: [PATCH] Code review cleaning

---
 .../matrix/android/sdk/internal/crypto/MXOlmDevice.kt |  2 --
 .../android/sdk/internal/crypto/OlmSessionStore.kt    | 11 +++--------
 .../crypto/algorithms/megolm/MXMegolmEncryption.kt    |  5 ++---
 .../sdk/internal/crypto/store/IMXCryptoStore.kt       |  4 ++--
 4 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/MXOlmDevice.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/MXOlmDevice.kt
index 79f2dc6ad3..501fb42db2 100755
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/MXOlmDevice.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/MXOlmDevice.kt
@@ -280,7 +280,6 @@ internal class MXOlmDevice @Inject constructor(
             olmSessionWrapper.onMessageReceived()
 
             olmSessionStore.storeSession(olmSessionWrapper, theirIdentityKey)
-//            store.storeSession(olmSessionWrapper, theirIdentityKey)
 
             val sessionIdentifier = olmSession.sessionIdentifier()
 
@@ -866,7 +865,6 @@ internal class MXOlmDevice @Inject constructor(
         // sanity check
         return if (theirDeviceIdentityKey.isEmpty() || sessionId.isEmpty()) null else {
             olmSessionStore.getDeviceSession(sessionId, theirDeviceIdentityKey)
-//            store.getDeviceSession(sessionId, theirDeviceIdentityKey)
         }
     }
 
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/OlmSessionStore.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/OlmSessionStore.kt
index 8f8bb62c85..f4fbca6a0f 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/OlmSessionStore.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/OlmSessionStore.kt
@@ -51,18 +51,13 @@ internal class OlmSessionStore @Inject constructor(private val store: IMXCryptoS
     }
 
     /**
-     * Get all the Olm Sessions we are sharing with the given user
-     * device.
+     * Get all the Olm Sessions we are sharing with the given device.
      *
      * @param deviceKey the public key of the other device.
      * @return A set of sessionId, or empty if device is not known
      */
     @Synchronized
     fun getDeviceSessionIds(deviceKey: String): List<String> {
-        return internalGetAllSessions(deviceKey)
-    }
-
-    private fun internalGetAllSessions(deviceKey: String): MutableList<String> {
         // we need to get the persisted ids first
         val persistedKnownSessions = store.getDeviceSessionIds(deviceKey)
                 .orEmpty()
@@ -79,12 +74,12 @@ internal class OlmSessionStore @Inject constructor(private val store: IMXCryptoS
     }
 
     /**
-     * Retrieve an end-to-end session between the logged-in user and another
+     * Retrieve an end-to-end session between our own device and another
      * device.
      *
      * @param sessionId the session Id.
      * @param deviceKey the public key of the other device.
-     * @return The Base64 end-to-end session, or null if not found
+     * @return the session wrapper if found
      */
     @Synchronized
     fun getDeviceSession(sessionId: String, deviceKey: String): OlmSessionWrapper? {
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt
index 85a6f5a7ef..cf9733dc2d 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/algorithms/megolm/MXMegolmEncryption.kt
@@ -471,9 +471,8 @@ internal class MXMegolmEncryption(
         }
         val olmSessionResult = usersDeviceMap?.getObject(userId, deviceId)
         if (olmSessionResult?.sessionId == null) {
-            return false.also {
-                Timber.tag(loggerTag.value).w("reshareKey: no session with this device, probably because there were no one-time keys")
-            }
+            Timber.tag(loggerTag.value).w("reshareKey: no session with this device, probably because there were no one-time keys")
+            return false
         }
         Timber.tag(loggerTag.value).i(" reshareKey: $groupSessionId:$chainIndex with device $userId:$deviceId using session ${olmSessionResult.sessionId}")
 
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/IMXCryptoStore.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/IMXCryptoStore.kt
index c28a1985b4..e662ff74e7 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/IMXCryptoStore.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/IMXCryptoStore.kt
@@ -261,7 +261,7 @@ internal interface IMXCryptoStore {
     fun storeSession(olmSessionWrapper: OlmSessionWrapper, deviceKey: String)
 
     /**
-     * Retrieve the end-to-end session ids between the logged-in user and another
+     * Retrieve all end-to-end session ids between our own device and another
      * device.
      *
      * @param deviceKey the public key of the other device.
@@ -270,7 +270,7 @@ internal interface IMXCryptoStore {
     fun getDeviceSessionIds(deviceKey: String): List<String>?
 
     /**
-     * Retrieve an end-to-end session between the logged-in user and another
+     * Retrieve an end-to-end session between our own device and another
      * device.
      *
      * @param sessionId the session Id.