mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-06 06:26:07 +03: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
4 changed files with 26 additions and 21 deletions
matrix-sdk-android/src/main/java/im/vector/matrix/android/internal
database
session
|
@ -6,8 +6,9 @@ import io.realm.RealmResults
|
||||||
import io.realm.annotations.LinkingObjects
|
import io.realm.annotations.LinkingObjects
|
||||||
|
|
||||||
internal open class ChunkEntity(var prevToken: String? = null,
|
internal open class ChunkEntity(var prevToken: String? = null,
|
||||||
var nextToken: String? = null,
|
var nextToken: String? = null,
|
||||||
var events: RealmList<EventEntity> = RealmList()
|
var isLast: Boolean = false,
|
||||||
|
var events: RealmList<EventEntity> = RealmList()
|
||||||
) : RealmObject() {
|
) : RealmObject() {
|
||||||
|
|
||||||
@LinkingObjects("chunks")
|
@LinkingObjects("chunks")
|
||||||
|
|
|
@ -38,10 +38,8 @@ internal fun ChunkEntity.Companion.findWithNextToken(realm: Realm, roomId: Strin
|
||||||
|
|
||||||
internal fun ChunkEntity.Companion.findLastLiveChunkFromRoom(realm: Realm, roomId: String): ChunkEntity? {
|
internal fun ChunkEntity.Companion.findLastLiveChunkFromRoom(realm: Realm, roomId: String): ChunkEntity? {
|
||||||
return where(realm, roomId)
|
return where(realm, roomId)
|
||||||
.and()
|
.equalTo(ChunkEntityFields.IS_LAST, true)
|
||||||
.isNull(ChunkEntityFields.NEXT_TOKEN)
|
.findFirst()
|
||||||
.findAll()
|
|
||||||
.last(null)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun ChunkEntity.Companion.findAllIncludingEvents(realm: Realm, eventIds: List<String>): RealmResults<ChunkEntity> {
|
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.events.model.EnrichedEvent
|
||||||
import im.vector.matrix.android.api.session.room.TimelineHolder
|
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.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.model.EventEntityFields
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
import im.vector.matrix.android.internal.database.query.where
|
||||||
import im.vector.matrix.android.internal.session.events.interceptor.MessageEventInterceptor
|
import im.vector.matrix.android.internal.session.events.interceptor.MessageEventInterceptor
|
||||||
|
@ -17,8 +18,8 @@ import io.realm.Sort
|
||||||
private const val PAGE_SIZE = 30
|
private const val PAGE_SIZE = 30
|
||||||
|
|
||||||
internal class DefaultTimelineHolder(private val roomId: String,
|
internal class DefaultTimelineHolder(private val roomId: String,
|
||||||
private val monarchy: Monarchy,
|
private val monarchy: Monarchy,
|
||||||
private val boundaryCallback: TimelineBoundaryCallback
|
private val boundaryCallback: TimelineBoundaryCallback
|
||||||
) : TimelineHolder {
|
) : TimelineHolder {
|
||||||
|
|
||||||
private val eventInterceptors = ArrayList<EnrichedEventInterceptor>()
|
private val eventInterceptors = ArrayList<EnrichedEventInterceptor>()
|
||||||
|
@ -30,12 +31,9 @@ internal class DefaultTimelineHolder(private val roomId: String,
|
||||||
|
|
||||||
override fun liveTimeline(): LiveData<PagedList<EnrichedEvent>> {
|
override fun liveTimeline(): LiveData<PagedList<EnrichedEvent>> {
|
||||||
val realmDataSourceFactory = monarchy.createDataSourceFactory { realm ->
|
val realmDataSourceFactory = monarchy.createDataSourceFactory { realm ->
|
||||||
ChunkEntity.where(realm, roomId)
|
EventEntity.where(realm, roomId = roomId)
|
||||||
.findAll()
|
.equalTo("${EventEntityFields.CHUNK}.${ChunkEntityFields.IS_LAST}", true)
|
||||||
.last(null)
|
.sort(EventEntityFields.ORIGIN_SERVER_TS, Sort.DESCENDING)
|
||||||
?.let {
|
|
||||||
it.events.where().sort(EventEntityFields.ORIGIN_SERVER_TS, Sort.DESCENDING)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
val domainSourceFactory = realmDataSourceFactory
|
val domainSourceFactory = realmDataSourceFactory
|
||||||
.map { it.asDomain() }
|
.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.findAllIncludingEvents
|
||||||
import im.vector.matrix.android.internal.database.query.findLastLiveChunkFromRoom
|
import im.vector.matrix.android.internal.database.query.findLastLiveChunkFromRoom
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
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.Realm
|
||||||
import io.realm.kotlin.createObject
|
import io.realm.kotlin.createObject
|
||||||
|
|
||||||
|
@ -38,9 +42,9 @@ internal class RoomSyncHandler(private val monarchy: Monarchy,
|
||||||
|
|
||||||
private fun handleRoomSync(realm: Realm, handlingStrategy: HandlingStrategy) {
|
private fun handleRoomSync(realm: Realm, handlingStrategy: HandlingStrategy) {
|
||||||
val rooms = when (handlingStrategy) {
|
val rooms = when (handlingStrategy) {
|
||||||
is HandlingStrategy.JOINED -> handlingStrategy.data.map { handleJoinedRoom(realm, it.key, it.value) }
|
is HandlingStrategy.JOINED -> handlingStrategy.data.map { handleJoinedRoom(realm, it.key, it.value) }
|
||||||
is HandlingStrategy.INVITED -> handlingStrategy.data.map { handleInvitedRoom(realm, it.key, it.value) }
|
is HandlingStrategy.INVITED -> handlingStrategy.data.map { handleInvitedRoom(realm, it.key, it.value) }
|
||||||
is HandlingStrategy.LEFT -> handlingStrategy.data.map { handleLeftRoom(it.key, it.value) }
|
is HandlingStrategy.LEFT -> handlingStrategy.data.map { handleLeftRoom(it.key, it.value) }
|
||||||
}
|
}
|
||||||
realm.insertOrUpdate(rooms)
|
realm.insertOrUpdate(rooms)
|
||||||
}
|
}
|
||||||
|
@ -50,7 +54,7 @@ internal class RoomSyncHandler(private val monarchy: Monarchy,
|
||||||
roomSync: RoomSync): RoomEntity {
|
roomSync: RoomSync): RoomEntity {
|
||||||
|
|
||||||
val roomEntity = RoomEntity.where(realm, roomId).findFirst()
|
val roomEntity = RoomEntity.where(realm, roomId).findFirst()
|
||||||
?: RoomEntity(roomId)
|
?: RoomEntity(roomId)
|
||||||
|
|
||||||
if (roomEntity.membership == MyMembership.INVITED) {
|
if (roomEntity.membership == MyMembership.INVITED) {
|
||||||
roomEntity.chunks.deleteAllFromRealm()
|
roomEntity.chunks.deleteAllFromRealm()
|
||||||
|
@ -111,7 +115,7 @@ internal class RoomSyncHandler(private val monarchy: Monarchy,
|
||||||
roomSummary: RoomSyncSummary) {
|
roomSummary: RoomSyncSummary) {
|
||||||
|
|
||||||
val roomSummaryEntity = RoomSummaryEntity.where(realm, roomId).findFirst()
|
val roomSummaryEntity = RoomSummaryEntity.where(realm, roomId).findFirst()
|
||||||
?: RoomSummaryEntity(roomId)
|
?: RoomSummaryEntity(roomId)
|
||||||
|
|
||||||
if (roomSummary.heroes.isNotEmpty()) {
|
if (roomSummary.heroes.isNotEmpty()) {
|
||||||
roomSummaryEntity.heroes.clear()
|
roomSummaryEntity.heroes.clear()
|
||||||
|
@ -132,13 +136,17 @@ internal class RoomSyncHandler(private val monarchy: Monarchy,
|
||||||
prevToken: String? = null,
|
prevToken: String? = null,
|
||||||
nextToken: String? = null,
|
nextToken: String? = null,
|
||||||
isLimited: Boolean = true): ChunkEntity {
|
isLimited: Boolean = true): ChunkEntity {
|
||||||
|
|
||||||
|
val lastChunk = ChunkEntity.findLastLiveChunkFromRoom(realm, roomId)
|
||||||
val chunkEntity = if (!isLimited) {
|
val chunkEntity = if (!isLimited) {
|
||||||
ChunkEntity.findLastLiveChunkFromRoom(realm, roomId)
|
lastChunk
|
||||||
} else {
|
} else {
|
||||||
val eventIds = eventList.filter { it.eventId != null }.map { it.eventId!! }
|
val eventIds = eventList.filter { it.eventId != null }.map { it.eventId!! }
|
||||||
ChunkEntity.findAllIncludingEvents(realm, eventIds).firstOrNull()
|
ChunkEntity.findAllIncludingEvents(realm, eventIds).firstOrNull()
|
||||||
} ?: realm.createObject<ChunkEntity>().apply { this.prevToken = prevToken }
|
} ?: realm.createObject<ChunkEntity>().apply { this.prevToken = prevToken }
|
||||||
|
|
||||||
|
lastChunk?.isLast = false
|
||||||
|
chunkEntity.isLast = true
|
||||||
chunkEntity.nextToken = nextToken
|
chunkEntity.nextToken = nextToken
|
||||||
eventList.addManagedToChunk(chunkEntity)
|
eventList.addManagedToChunk(chunkEntity)
|
||||||
return chunkEntity
|
return chunkEntity
|
||||||
|
|
Loading…
Add table
Reference in a new issue