File tree Expand file tree Collapse file tree
main/java/org/matrix/android/sdk
test/java/org/matrix/android/sdk/internal/session/event Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ Improve `Event.getClearContent()` and fix assignment issue that may help to decrypt last Event in the room list.
Original file line number Diff line number Diff line change @@ -219,10 +219,16 @@ data class Event(
219219 }
220220
221221 /* *
222- * @return the event content
222+ * @return the event content.
223+ * If the content is encrypted, it will return the decrypted content, or null if the content is not
224+ * decrypted.
223225 */
224226 fun getClearContent (): Content ? {
225- return getDecryptedContent() ? : content
227+ return if (isEncrypted()) {
228+ getDecryptedContent()
229+ } else {
230+ content
231+ }
226232 }
227233
228234 /* *
Original file line number Diff line number Diff line change @@ -627,7 +627,7 @@ internal class RustCryptoService @Inject constructor(
627627 }
628628
629629 private fun notifyRoomKeyReceived (
630- roomId : String ,
630+ roomId : String? ,
631631 sessionId : String ,
632632 ) {
633633 megolmSessionImportManager.dispatchNewSession(roomId, sessionId)
@@ -664,18 +664,18 @@ internal class RustCryptoService @Inject constructor(
664664 when (event.type) {
665665 EventType .ROOM_KEY -> {
666666 val content = event.getClearContent().toModel<RoomKeyContent >() ? : return @forEach
667- content.sessionKey
668- val roomId = content.sessionId ? : return @forEach
669- val sessionId = content.sessionId
667+
668+ val roomId = content.roomId
669+ val sessionId = content.sessionId ? : return @forEach
670670
671671 notifyRoomKeyReceived(roomId, sessionId)
672672 matrixConfiguration.cryptoAnalyticsPlugin?.onRoomKeyImported(sessionId, EventType .ROOM_KEY )
673673 }
674674 EventType .FORWARDED_ROOM_KEY -> {
675675 val content = event.getClearContent().toModel<ForwardedRoomKeyContent >() ? : return @forEach
676676
677- val roomId = content.sessionId ? : return @forEach
678- val sessionId = content.sessionId
677+ val roomId = content.roomId
678+ val sessionId = content.sessionId ? : return @forEach
679679
680680 notifyRoomKeyReceived(roomId, sessionId)
681681 matrixConfiguration.cryptoAnalyticsPlugin?.onRoomKeyImported(sessionId, EventType .FORWARDED_ROOM_KEY )
Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ class ValidDecryptedEventTest {
8989 ).toContent()
9090 )
9191
92- val unValidatedContent = mixedEvent.getClearContent() .toModel<MessageTextContent >()
92+ val unValidatedContent = mixedEvent.content .toModel<MessageTextContent >()
9393 unValidatedContent?.body shouldBe " some message"
9494
9595 mixedEvent.toValidDecryptedEvent()?.clearContent?.toModel<MessageTextContent >() shouldBe null
You can’t perform that action at this time.
0 commit comments