mirror of
https://github.com/element-hq/element-android
synced 2024-09-06 17:05:20 +00:00
Add a param "isLast" in chunk as we want live results in timeline... not sure it's the right way to do it.
This commit is contained in:
parent
2c6b155794
commit
d46ce8245d
|
@ -7,6 +7,7 @@ import io.realm.annotations.LinkingObjects
|
|||
|
||||
internal open class ChunkEntity(var prevToken: String? = null,
|
||||
var nextToken: String? = null,
|
||||
var isLast: Boolean = false,
|
||||
var events: RealmList<EventEntity> = RealmList()
|
||||
) : RealmObject() {
|
||||
|
||||
|
|
|
@ -38,10 +38,8 @@ internal fun ChunkEntity.Companion.findWithNextToken(realm: Realm, roomId: Strin
|
|||
|
||||
internal fun ChunkEntity.Companion.findLastLiveChunkFromRoom(realm: Realm, roomId: String): ChunkEntity? {
|
||||
return where(realm, roomId)
|
||||
.and()
|
||||
.isNull(ChunkEntityFields.NEXT_TOKEN)
|
||||
.findAll()
|
||||
.last(null)
|
||||
.equalTo(ChunkEntityFields.IS_LAST, true)
|
||||
.findFirst()
|
||||
}
|
||||
|
||||
internal fun ChunkEntity.Companion.findAllIncludingEvents(realm: Realm, eventIds: List<String>): RealmResults<ChunkEntity> {
|
||||
|
|
|
@ -8,7 +8,8 @@ import im.vector.matrix.android.api.session.events.interceptor.EnrichedEventInte
|
|||
import im.vector.matrix.android.api.session.events.model.EnrichedEvent
|
||||
import im.vector.matrix.android.api.session.room.TimelineHolder
|
||||
import im.vector.matrix.android.internal.database.mapper.asDomain
|
||||
import im.vector.matrix.android.internal.database.model.ChunkEntity
|
||||
import im.vector.matrix.android.internal.database.model.ChunkEntityFields
|
||||
import im.vector.matrix.android.internal.database.model.EventEntity
|
||||
import im.vector.matrix.android.internal.database.model.EventEntityFields
|
||||
import im.vector.matrix.android.internal.database.query.where
|
||||
import im.vector.matrix.android.internal.session.events.interceptor.MessageEventInterceptor
|
||||
|
@ -30,12 +31,9 @@ internal class DefaultTimelineHolder(private val roomId: String,
|
|||
|
||||
override fun liveTimeline(): LiveData<PagedList<EnrichedEvent>> {
|
||||
val realmDataSourceFactory = monarchy.createDataSourceFactory { realm ->
|
||||
ChunkEntity.where(realm, roomId)
|
||||
.findAll()
|
||||
.last(null)
|
||||
?.let {
|
||||
it.events.where().sort(EventEntityFields.ORIGIN_SERVER_TS, Sort.DESCENDING)
|
||||
}
|
||||
EventEntity.where(realm, roomId = roomId)
|
||||
.equalTo("${EventEntityFields.CHUNK}.${ChunkEntityFields.IS_LAST}", true)
|
||||
.sort(EventEntityFields.ORIGIN_SERVER_TS, Sort.DESCENDING)
|
||||
}
|
||||
val domainSourceFactory = realmDataSourceFactory
|
||||
.map { it.asDomain() }
|
||||
|
|
|
@ -11,7 +11,11 @@ import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
|
|||
import im.vector.matrix.android.internal.database.query.findAllIncludingEvents
|
||||
import im.vector.matrix.android.internal.database.query.findLastLiveChunkFromRoom
|
||||
import im.vector.matrix.android.internal.database.query.where
|
||||
import im.vector.matrix.android.internal.session.sync.model.*
|
||||
import im.vector.matrix.android.internal.session.sync.model.InvitedRoomSync
|
||||
import im.vector.matrix.android.internal.session.sync.model.RoomSync
|
||||
import im.vector.matrix.android.internal.session.sync.model.RoomSyncEphemeral
|
||||
import im.vector.matrix.android.internal.session.sync.model.RoomSyncSummary
|
||||
import im.vector.matrix.android.internal.session.sync.model.RoomsSyncResponse
|
||||
import io.realm.Realm
|
||||
import io.realm.kotlin.createObject
|
||||
|
||||
|
@ -132,13 +136,17 @@ internal class RoomSyncHandler(private val monarchy: Monarchy,
|
|||
prevToken: String? = null,
|
||||
nextToken: String? = null,
|
||||
isLimited: Boolean = true): ChunkEntity {
|
||||
|
||||
val lastChunk = ChunkEntity.findLastLiveChunkFromRoom(realm, roomId)
|
||||
val chunkEntity = if (!isLimited) {
|
||||
ChunkEntity.findLastLiveChunkFromRoom(realm, roomId)
|
||||
lastChunk
|
||||
} else {
|
||||
val eventIds = eventList.filter { it.eventId != null }.map { it.eventId!! }
|
||||
ChunkEntity.findAllIncludingEvents(realm, eventIds).firstOrNull()
|
||||
} ?: realm.createObject<ChunkEntity>().apply { this.prevToken = prevToken }
|
||||
|
||||
lastChunk?.isLast = false
|
||||
chunkEntity.isLast = true
|
||||
chunkEntity.nextToken = nextToken
|
||||
eventList.addManagedToChunk(chunkEntity)
|
||||
return chunkEntity
|
||||
|
|
Loading…
Reference in a new issue