Update decryption result on the events from the sync response

As the decryption is done on a copy of the event (containing the roomId), we have to update the initial event with the decryption result
This commit is contained in:
Florian Renaud 2023-03-02 14:40:31 +01:00
parent 245ca13049
commit 084bd44348
2 changed files with 6 additions and 3 deletions

View File

@ -45,14 +45,14 @@ internal class DefaultProcessEventForPushTask @Inject constructor(
val newJoinEvents = params.syncResponse.join
.mapNotNull { (key, value) ->
value.timeline?.events?.mapNotNull {
it.takeIf { !it.isInvitation() }?.copy(roomId = key)
it.takeIf { !it.isInvitation() }?.copyAll(roomId = key)
}
}
.flatten()
val inviteEvents = params.syncResponse.invite
.mapNotNull { (key, value) ->
value.inviteState?.events?.map { it.copy(roomId = key) }
value.inviteState?.events?.map { it.copyAll(roomId = key) }
}
.flatten()
@ -75,7 +75,6 @@ internal class DefaultProcessEventForPushTask @Inject constructor(
" to check for push rules with ${params.rules.size} rules"
)
val matchedEvents = allEvents.mapNotNull { event ->
eventDecryptor.decryptEventAndSaveResult(event, "")
pushRuleFinder.fulfilledBingRule(event, params.rules)?.let {
Timber.v("[PushRules] Rule $it match for event ${event.eventId}")
event to it

View File

@ -437,6 +437,10 @@ internal class RoomSyncHandler @Inject constructor(
if (event.isEncrypted() && !isInitialSync) {
try {
decryptIfNeeded(event, roomId)
// share the decryption result with the rawEvent because the decryption is done on a copy containing the roomId, see previous comment
rawEvent.mxDecryptionResult = event.mxDecryptionResult
rawEvent.mCryptoError = event.mCryptoError
rawEvent.mCryptoErrorReason = event.mCryptoErrorReason
} catch (e: InterruptedException) {
Timber.i("Decryption got interrupted")
}