Ensure the event is decrypted before applying push rules

This commit is contained in:
Florian Renaud 2023-03-01 11:49:43 +01:00
parent ccf971afc4
commit 75559fb21a
3 changed files with 6 additions and 5 deletions

View File

@ -45,10 +45,7 @@ class EventMatchCondition(
if (decryptedRawJson != null) {
rawJson
.toMutableMap()
.apply {
set("type", decryptedRawJson["type"])
set("content", decryptedRawJson["content"])
}
.apply { putAll(decryptedRawJson) }
} else {
rawJson
}

View File

@ -94,6 +94,7 @@ internal class EventDecryptor @Inject constructor(
* @param timeline the id of the timeline where the event is decrypted. It is used to prevent replay attack.
*/
suspend fun decryptEventAndSaveResult(event: Event, timeline: String) {
if (event.type == EventType.ENCRYPTED && event.mxDecryptionResult != null) return
tryOrNull(message = "Unable to decrypt the event") {
decryptEvent(event, timeline)
}

View File

@ -21,6 +21,7 @@ import org.matrix.android.sdk.api.session.events.model.isInvitation
import org.matrix.android.sdk.api.session.pushrules.PushEvents
import org.matrix.android.sdk.api.session.pushrules.rest.PushRule
import org.matrix.android.sdk.api.session.sync.model.RoomsSyncResponse
import org.matrix.android.sdk.internal.crypto.EventDecryptor
import org.matrix.android.sdk.internal.di.UserId
import org.matrix.android.sdk.internal.task.Task
import timber.log.Timber
@ -36,7 +37,8 @@ internal interface ProcessEventForPushTask : Task<ProcessEventForPushTask.Params
internal class DefaultProcessEventForPushTask @Inject constructor(
private val defaultPushRuleService: DefaultPushRuleService,
private val pushRuleFinder: PushRuleFinder,
@UserId private val userId: String
@UserId private val userId: String,
private val eventDecryptor: EventDecryptor,
) : ProcessEventForPushTask {
override suspend fun execute(params: ProcessEventForPushTask.Params) {
@ -73,6 +75,7 @@ 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