mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-18 07:11:58 +03:00
Merge pull request #8744 from element-hq/feature/bma/usedDecryptedEvent
[Crypto] Improve Event.getClearContent() and fix assignement issue.
This commit is contained in:
commit
1277f6fdd9
4 changed files with 16 additions and 9 deletions
1
changelog.d/8744.bugfix
Normal file
1
changelog.d/8744.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
Improve `Event.getClearContent()` and fix assignment issue that may help to decrypt last Event in the room list.
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<RoomKeyContent>() ?: 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<ForwardedRoomKeyContent>() ?: 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)
|
||||
|
|
|
@ -89,7 +89,7 @@ class ValidDecryptedEventTest {
|
|||
).toContent()
|
||||
)
|
||||
|
||||
val unValidatedContent = mixedEvent.getClearContent().toModel<MessageTextContent>()
|
||||
val unValidatedContent = mixedEvent.content.toModel<MessageTextContent>()
|
||||
unValidatedContent?.body shouldBe "some message"
|
||||
|
||||
mixedEvent.toValidDecryptedEvent()?.clearContent?.toModel<MessageTextContent>() shouldBe null
|
||||
|
|
Loading…
Reference in a new issue