mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 03:48:12 +03:00
Fix query on poll events for encrypted rooms
This commit is contained in:
parent
a3077dfaa7
commit
4cfd6d29fc
1 changed files with 19 additions and 15 deletions
|
@ -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>> {
|
||||||
|
val eventsLiveData = monarchy.findAllMappedWithChanges(
|
||||||
{ realm ->
|
{ realm ->
|
||||||
val pollTypes = EventType.POLL_START.values.toTypedArray()
|
val pollTypes = (EventType.POLL_START.values + EventType.ENCRYPTED).toTypedArray()
|
||||||
realm.where<TimelineEventEntity>()
|
realm.where<TimelineEventEntity>()
|
||||||
.equalTo(TimelineEventEntityFields.ROOM_ID, roomId)
|
.equalTo(TimelineEventEntityFields.ROOM_ID, roomId)
|
||||||
.`in`(TimelineEventEntityFields.ROOT.TYPE, pollTypes)
|
.`in`(TimelineEventEntityFields.ROOT.TYPE, pollTypes)
|
||||||
.greaterThan(TimelineEventEntityFields.ROOT.ORIGIN_SERVER_TS, oldestTimestamp)
|
.greaterThan(TimelineEventEntityFields.ROOT.ORIGIN_SERVER_TS, timestampMs)
|
||||||
},
|
},
|
||||||
{ result ->
|
{ result ->
|
||||||
timelineEventMapper.map(result, buildReadReceipts = false)
|
timelineEventMapper.map(result, buildReadReceipts = false)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return Transformations.map(eventsLiveData) { events ->
|
||||||
|
events.filter { it.root.getClearType() in EventType.POLL_START.values }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue