Fix query on poll events for encrypted rooms

This commit is contained in:
Maxime NATUREL 2023-01-20 15:29:39 +01:00
parent a3077dfaa7
commit 4cfd6d29fc

View file

@ -25,15 +25,12 @@ import dagger.assisted.AssistedInject
import io.realm.kotlin.where import io.realm.kotlin.where
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.room.model.PollResponseAggregatedSummary
import org.matrix.android.sdk.api.session.room.poll.LoadedPollsStatus import org.matrix.android.sdk.api.session.room.poll.LoadedPollsStatus
import org.matrix.android.sdk.api.session.room.poll.PollHistoryService import org.matrix.android.sdk.api.session.room.poll.PollHistoryService
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
import org.matrix.android.sdk.internal.database.mapper.PollResponseAggregatedSummaryEntityMapper
import org.matrix.android.sdk.internal.database.mapper.TimelineEventMapper import org.matrix.android.sdk.internal.database.mapper.TimelineEventMapper
import org.matrix.android.sdk.internal.database.model.PollHistoryStatusEntity import org.matrix.android.sdk.internal.database.model.PollHistoryStatusEntity
import org.matrix.android.sdk.internal.database.model.PollHistoryStatusEntityFields import org.matrix.android.sdk.internal.database.model.PollHistoryStatusEntityFields
import org.matrix.android.sdk.internal.database.model.PollResponseAggregatedSummaryEntity
import org.matrix.android.sdk.internal.database.model.TimelineEventEntity import org.matrix.android.sdk.internal.database.model.TimelineEventEntity
import org.matrix.android.sdk.internal.database.model.TimelineEventEntityFields import org.matrix.android.sdk.internal.database.model.TimelineEventEntityFields
import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.di.SessionDatabase
@ -90,19 +87,26 @@ internal class DefaultPollHistoryService @AssistedInject constructor(
return Transformations.switchMap(pollHistoryStatusLiveData) { results -> return Transformations.switchMap(pollHistoryStatusLiveData) { results ->
val oldestTimestamp = results.firstOrNull()?.oldestTimestampReachedMs ?: clock.epochMillis() val oldestTimestamp = results.firstOrNull()?.oldestTimestampReachedMs ?: clock.epochMillis()
Timber.d("oldestTimestamp=$oldestTimestamp") Timber.d("oldestTimestamp=$oldestTimestamp")
getPollStartEventsAfter(oldestTimestamp)
}
}
monarchy.findAllMappedWithChanges( private fun getPollStartEventsAfter(timestampMs: Long): LiveData<List<TimelineEvent>> {
{ realm -> val eventsLiveData = monarchy.findAllMappedWithChanges(
val pollTypes = EventType.POLL_START.values.toTypedArray() { realm ->
realm.where<TimelineEventEntity>() val pollTypes = (EventType.POLL_START.values + EventType.ENCRYPTED).toTypedArray()
.equalTo(TimelineEventEntityFields.ROOM_ID, roomId) realm.where<TimelineEventEntity>()
.`in`(TimelineEventEntityFields.ROOT.TYPE, pollTypes) .equalTo(TimelineEventEntityFields.ROOM_ID, roomId)
.greaterThan(TimelineEventEntityFields.ROOT.ORIGIN_SERVER_TS, oldestTimestamp) .`in`(TimelineEventEntityFields.ROOT.TYPE, pollTypes)
}, .greaterThan(TimelineEventEntityFields.ROOT.ORIGIN_SERVER_TS, timestampMs)
{ result -> },
timelineEventMapper.map(result, buildReadReceipts = false) { result ->
} timelineEventMapper.map(result, buildReadReceipts = false)
) }
)
return Transformations.map(eventsLiveData) { events ->
events.filter { it.root.getClearType() in EventType.POLL_START.values }
} }
} }