Keep live event/pagination listeners.

This commit is contained in:
David Langley 2022-03-28 17:23:05 +01:00
parent 4fe8650387
commit b4885629af
7 changed files with 43 additions and 6 deletions

1
changelog.d/5639.sdk Normal file
View file

@ -0,0 +1 @@
Include original event in decryption live decryption listeners.

View file

@ -17,10 +17,15 @@
package org.matrix.android.sdk.api.session
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.util.JsonDict
interface LiveEventListener {
fun onEventDecrypted(event: Event)
fun onLiveEvent(roomId: String, event: Event)
fun onPaginatedEvent(roomId: String, event: Event)
fun onEventDecrypted(event: Event, clearEvent: JsonDict)
fun onEventDecryptionError(event: Event, throwable: Throwable)

View file

@ -113,7 +113,7 @@ internal class MXMegolmDecryption(private val userId: String,
forwardingCurve25519KeyChain = olmDecryptionResult.forwardingCurve25519KeyChain
.orEmpty()
).also {
liveEventManager.get().dispatchLiveEventDecrypted(event)
liveEventManager.get().dispatchLiveEventDecrypted(event, it)
}
} else {
throw MXCryptoError.Base(MXCryptoError.ErrorType.MISSING_FIELDS, MXCryptoError.MISSING_FIELDS_REASON)

View file

@ -23,6 +23,7 @@ import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.session.LiveEventListener
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.internal.crypto.MXEventDecryptionResult
import timber.log.Timber
import javax.inject.Inject
@ -41,12 +42,36 @@ internal class StreamEventsManager @Inject constructor() {
listeners.remove(listener)
}
fun dispatchLiveEventDecrypted(event: Event) {
fun dispatchLiveEventReceived(event: Event, roomId: String, initialSync: Boolean) {
Timber.v("## dispatchLiveEventReceived ${event.eventId}")
coroutineScope.launch {
if (!initialSync) {
listeners.forEach {
tryOrNull {
it.onLiveEvent(roomId, event)
}
}
}
}
}
fun dispatchPaginatedEventReceived(event: Event, roomId: String) {
Timber.v("## dispatchPaginatedEventReceived ${event.eventId}")
coroutineScope.launch {
listeners.forEach {
tryOrNull {
it.onPaginatedEvent(roomId, event)
}
}
}
}
fun dispatchLiveEventDecrypted(event: Event, result: MXEventDecryptionResult) {
Timber.v("## dispatchLiveEventDecrypted ${event.eventId}")
coroutineScope.launch {
listeners.forEach {
tryOrNull {
it.onEventDecrypted(event)
it.onEventDecrypted(event, result.clearEvent)
}
}
}

View file

@ -186,7 +186,7 @@ internal class TokenChunkEventPersistor @Inject constructor(
}
roomMemberContentsByUser[event.stateKey] = contentToUse.toModel<RoomMemberContent>()
}
liveEventManager.get().dispatchPaginatedEventReceived(event, roomId)
currentChunk.addTimelineEvent(
roomId = roomId,
eventEntity = eventEntity,

View file

@ -382,6 +382,7 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle
}
eventIds.add(event.eventId)
liveEventService.get().dispatchLiveEventReceived(event, roomId, insertType == EventInsertType.INITIAL_SYNC)
val isInitialSync = insertType == EventInsertType.INITIAL_SYNC

View file

@ -20,6 +20,7 @@ import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.session.LiveEventListener
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.util.JsonDict
import org.matrix.android.sdk.internal.crypto.model.event.EncryptedEventContent
import timber.log.Timber
import java.util.Timer
@ -68,7 +69,7 @@ class UISIDetector : LiveEventListener {
private val timeoutMillis = 30_000L
private val enabled: Boolean get() = callback?.enabled.orFalse()
override fun onEventDecrypted(event: Event) {
override fun onEventDecrypted(event: Event, clearEvent: JsonDict) {
val eventId = event.eventId
val roomId = event.roomId
if (!enabled || eventId == null || roomId == null) return
@ -108,6 +109,10 @@ class UISIDetector : LiveEventListener {
timer.schedule(timeoutTask, timeoutMillis)
}
override fun onLiveEvent(roomId: String, event: Event) { }
override fun onPaginatedEvent(roomId: String, event: Event) { }
private fun trackerId(eventId: String, roomId: String): String = "$roomId-$eventId"
private fun triggerUISI(source: E2EMessageDetected) {