diff --git a/changelog.d/8744.bugfix b/changelog.d/8744.bugfix new file mode 100644 index 0000000000..3ce7637059 --- /dev/null +++ b/changelog.d/8744.bugfix @@ -0,0 +1 @@ +Improve `Event.getClearContent()` and fix assignment issue that may help to decrypt last Event in the room list. diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/Event.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/Event.kt index bad8b3766d..196b419598 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/Event.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/Event.kt @@ -219,10 +219,16 @@ data class Event( } /** - * @return the event content + * @return the event content. + * If the content is encrypted, it will return the decrypted content, or null if the content is not + * decrypted. */ fun getClearContent(): Content? { - return getDecryptedContent() ?: content + return if (isEncrypted()) { + getDecryptedContent() + } else { + content + } } /** diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/RustCryptoService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/RustCryptoService.kt index d743631264..c0407ca4e8 100755 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/RustCryptoService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/RustCryptoService.kt @@ -627,7 +627,7 @@ internal class RustCryptoService @Inject constructor( } private fun notifyRoomKeyReceived( - roomId: String, + roomId: String?, sessionId: String, ) { megolmSessionImportManager.dispatchNewSession(roomId, sessionId) @@ -664,9 +664,9 @@ internal class RustCryptoService @Inject constructor( when (event.type) { EventType.ROOM_KEY -> { val content = event.getClearContent().toModel() ?: return@forEach - content.sessionKey - val roomId = content.sessionId ?: return@forEach - val sessionId = content.sessionId + + val roomId = content.roomId + val sessionId = content.sessionId ?: return@forEach notifyRoomKeyReceived(roomId, sessionId) matrixConfiguration.cryptoAnalyticsPlugin?.onRoomKeyImported(sessionId, EventType.ROOM_KEY) @@ -674,8 +674,8 @@ internal class RustCryptoService @Inject constructor( EventType.FORWARDED_ROOM_KEY -> { val content = event.getClearContent().toModel() ?: return@forEach - val roomId = content.sessionId ?: return@forEach - val sessionId = content.sessionId + val roomId = content.roomId + val sessionId = content.sessionId ?: return@forEach notifyRoomKeyReceived(roomId, sessionId) matrixConfiguration.cryptoAnalyticsPlugin?.onRoomKeyImported(sessionId, EventType.FORWARDED_ROOM_KEY) diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/event/ValidDecryptedEventTest.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/event/ValidDecryptedEventTest.kt index 5fda242b90..534d7ba6ad 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/event/ValidDecryptedEventTest.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/session/event/ValidDecryptedEventTest.kt @@ -89,7 +89,7 @@ class ValidDecryptedEventTest { ).toContent() ) - val unValidatedContent = mixedEvent.getClearContent().toModel() + val unValidatedContent = mixedEvent.content.toModel() unValidatedContent?.body shouldBe "some message" mixedEvent.toValidDecryptedEvent()?.clearContent?.toModel() shouldBe null