Keep track of related events to a poll which had failed to be decrypted

This commit is contained in:
Maxime NATUREL 2022-12-21 14:10:13 +01:00 committed by Maxime NATUREL
parent bd7b1f9496
commit ae2639aeb0
8 changed files with 28 additions and 18 deletions

View file

@ -23,5 +23,7 @@ data class PollResponseAggregatedSummary(
val nbOptions: Int = 0,
// The list of the eventIDs used to build the summary (might be out of sync if chunked received from message chunk)
val sourceEvents: List<String>,
val localEchos: List<String>
val localEchos: List<String>,
// list of related event ids which are encrypted due to decryption failure
val encryptedRelatedEventIds: List<String>,
)

View file

@ -40,9 +40,6 @@ internal class EventInsertLiveObserver @Inject constructor(
private val lock = Mutex()
// TODO should we create a dedicated UnableToDecryptEntity or EncryptedEventEntity?
// and process them into a dedicated observer?
// Create also a new LiveProcessor interface for the new entity?
override val query = Monarchy.Query {
it.where(EventInsertEntity::class.java).equalTo(EventInsertEntityFields.CAN_BE_PROCESSED, true)
}

View file

@ -30,7 +30,8 @@ internal object PollResponseAggregatedSummaryEntityMapper {
closedTime = entity.closedTime,
localEchos = entity.sourceLocalEchoEvents.toList(),
sourceEvents = entity.sourceEvents.toList(),
nbOptions = entity.nbOptions
nbOptions = entity.nbOptions,
encryptedRelatedEventIds = entity.encryptedRelatedEventIds.toList(),
)
}
@ -40,7 +41,8 @@ internal object PollResponseAggregatedSummaryEntityMapper {
nbOptions = model.nbOptions,
closedTime = model.closedTime,
sourceEvents = RealmList<String>().apply { addAll(model.sourceEvents) },
sourceLocalEchoEvents = RealmList<String>().apply { addAll(model.localEchos) }
sourceLocalEchoEvents = RealmList<String>().apply { addAll(model.localEchos) },
encryptedRelatedEventIds = RealmList<String>().apply { addAll(model.encryptedRelatedEventIds) },
)
}
}

View file

@ -33,9 +33,10 @@ internal open class PollResponseAggregatedSummaryEntity(
// The list of the eventIDs used to build the summary (might be out of sync if chunked received from message chunk)
var sourceEvents: RealmList<String> = RealmList(),
var sourceLocalEchoEvents: RealmList<String> = RealmList()
var sourceLocalEchoEvents: RealmList<String> = RealmList(),
// list of related event ids which are encrypted due to decryption failure
var encryptedRelatedEventIds: RealmList<String> = RealmList(),
) : RealmObject() {
// TODO add a list of related eventIds which could not be decrypted
companion object
}

View file

@ -72,7 +72,8 @@ import org.matrix.android.sdk.internal.database.model.threads.ThreadSummaryEntit
SpaceParentSummaryEntity::class,
UserPresenceEntity::class,
ThreadSummaryEntity::class,
ThreadListPageEntity::class
ThreadListPageEntity::class,
UnableToDecryptEventEntity::class,
]
)
internal class SessionRealmModule

View file

@ -75,7 +75,7 @@ internal class EncryptedEventRelationsAggregationProcessor @Inject constructor(
RelationType.REFERENCE -> {
// can we / should we do we something for UTD reference??
Timber.w("## UTD reference in room $roomId related to ${encryptedEventContent.relatesTo.eventId}")
encryptedReferenceAggregationProcessor.handle(realm, event, roomId, isLocalEcho, encryptedEventContent.relatesTo.eventId)
encryptedReferenceAggregationProcessor.handle(realm, event, isLocalEcho, encryptedEventContent.relatesTo.eventId)
}
RelationType.ANNOTATION -> {
// can we / should we do we something for UTD annotation??

View file

@ -18,6 +18,8 @@ package org.matrix.android.sdk.internal.session.room.aggregation.utd
import io.realm.Realm
import org.matrix.android.sdk.api.session.events.model.Event
import org.matrix.android.sdk.internal.database.model.PollResponseAggregatedSummaryEntity
import org.matrix.android.sdk.internal.database.model.PollResponseAggregatedSummaryEntityFields
import javax.inject.Inject
class EncryptedReferenceAggregationProcessor @Inject constructor() {
@ -26,23 +28,28 @@ class EncryptedReferenceAggregationProcessor @Inject constructor() {
fun handle(
realm: Realm,
event: Event,
roomId: String,
isLocalEcho: Boolean,
relatedEventId: String?
) {
if(isLocalEcho || relatedEventId.isNullOrEmpty()) return
if (isLocalEcho || relatedEventId.isNullOrEmpty()) return
handlePollReference(realm = realm, event = event, roomId = roomId, relatedEventId = relatedEventId)
handlePollReference(realm = realm, event = event, relatedEventId = relatedEventId)
}
// TODO how to check this is working?
private fun handlePollReference(
realm: Realm,
event: Event,
roomId: String,
relatedEventId: String
) {
// TODO check if relatedEventId is referencing any existing poll event in DB
// TODO if related to a poll, then add the event id into the list of encryptedRelatedEvents in the summary
event.eventId?.let { eventId ->
val existingRelatedPoll = getPollSummaryWithEventId(realm, relatedEventId)
existingRelatedPoll?.encryptedRelatedEventIds?.add(eventId)
}
}
private fun getPollSummaryWithEventId(realm: Realm, eventId: String): PollResponseAggregatedSummaryEntity? {
return realm.where(PollResponseAggregatedSummaryEntity::class.java)
.containsValue(PollResponseAggregatedSummaryEntityFields.SOURCE_EVENTS.`$`, eventId)
.findFirst()
}
}

View file

@ -35,7 +35,7 @@ class PollItemViewStateFactory @Inject constructor(
pollContent: MessagePollContent,
informationData: MessageInformationData,
): PollViewState {
// TODO check for decryption failure error in informationData
// TODO add new field in ViewState to reflect decryption error of related events
val pollCreationInfo = pollContent.getBestPollCreationInfo()
val question = pollCreationInfo?.question?.getBestQuestion().orEmpty()