Fix some issues with sync (bad thread, bad use of last() )

This commit is contained in:
ganfra 2018-10-19 17:18:24 +02:00
parent ecbc64082f
commit 6e3992e70e
9 changed files with 11 additions and 11 deletions

Binary file not shown.

View File

@ -34,7 +34,7 @@ class RoomListFragment : RiotFragment(), RoomController.Callback {
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
epoxyRecyclerView.setController(roomController) epoxyRecyclerView.setController(roomController)
currentSession.rooms().observe(this, Observer<List<Room>> { renderRooms(it) }) currentSession.liveRooms().observe(this, Observer<List<Room>> { renderRooms(it) })
} }


private fun renderRooms(rooms: List<Room>?) { private fun renderRooms(rooms: List<Room>?) {

View File

@ -8,6 +8,6 @@ interface RoomService {


fun getAllRooms(): List<Room> fun getAllRooms(): List<Room>


fun rooms(): LiveData<List<Room>> fun liveRooms(): LiveData<List<Room>>


} }

View File

@ -34,7 +34,7 @@ fun ChunkEntity.Companion.findLastFromRoom(realm: Realm, roomId: String): ChunkE
.and() .and()
.isNull("nextToken") .isNull("nextToken")
.findAll() .findAll()
.last() .last(null)
} }


fun ChunkEntity.Companion.findAllIncludingEvents(realm: Realm, eventIds: List<String>): RealmResults<ChunkEntity> { fun ChunkEntity.Companion.findAllIncludingEvents(realm: Realm, eventIds: List<String>): RealmResults<ChunkEntity> {

View File

@ -23,5 +23,5 @@ fun RealmResults<EventEntity>.getLast(type: String? = null): EventEntity? {
if (type != null) { if (type != null) {
query = query.equalTo("type", type) query = query.equalTo("type", type)
} }
return query.findAll().sort("age").last() return query.findAll().sort("age").last(null)
} }

View File

@ -66,8 +66,8 @@ class DefaultSession(private val sessionParams: SessionParams) : Session, KoinCo
return roomService.getAllRooms() return roomService.getAllRooms()
} }


override fun rooms(): LiveData<List<Room>> { override fun liveRooms(): LiveData<List<Room>> {
return roomService.rooms() return roomService.liveRooms()
} }


// Private methods ***************************************************************************** // Private methods *****************************************************************************

View File

@ -26,7 +26,7 @@ data class DefaultRoom(


override fun liveTimeline(): LiveData<PagedList<Event>> { override fun liveTimeline(): LiveData<PagedList<Event>> {
val realmDataSourceFactory = monarchy.createDataSourceFactory { realm -> val realmDataSourceFactory = monarchy.createDataSourceFactory { realm ->
val lastChunk = ChunkEntity.where(realm, roomId).findAll().last() val lastChunk = ChunkEntity.where(realm, roomId).findAll().last(null)
if (lastChunk == null) { if (lastChunk == null) {
EventEntity.where(realm, roomId) EventEntity.where(realm, roomId)
} else { } else {

View File

@ -25,7 +25,7 @@ class DefaultRoomService(private val monarchy: Monarchy) : RoomService {
return room return room
} }


override fun rooms(): LiveData<List<Room>> { override fun liveRooms(): LiveData<List<Room>> {
return monarchy.findAllMappedWithChanges( return monarchy.findAllMappedWithChanges(
{ realm -> RoomEntity.where(realm) }, { realm -> RoomEntity.where(realm) },
{ DefaultRoom(it.roomId) } { DefaultRoom(it.roomId) }

View File

@ -6,10 +6,10 @@ import arrow.core.leftIfNull
import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.failure.Failure import im.vector.matrix.android.api.failure.Failure
import im.vector.matrix.android.api.util.Cancelable import im.vector.matrix.android.api.util.Cancelable
import im.vector.matrix.android.internal.session.sync.model.SyncResponse
import im.vector.matrix.android.internal.legacy.rest.model.filter.FilterBody import im.vector.matrix.android.internal.legacy.rest.model.filter.FilterBody
import im.vector.matrix.android.internal.legacy.util.FilterUtil import im.vector.matrix.android.internal.legacy.util.FilterUtil
import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.network.executeRequest
import im.vector.matrix.android.internal.session.sync.model.SyncResponse
import im.vector.matrix.android.internal.util.CancelableCoroutine import im.vector.matrix.android.internal.util.CancelableCoroutine
import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
@ -22,7 +22,7 @@ class SyncRequest(private val syncAPI: SyncAPI,




fun execute(token: String?, callback: MatrixCallback<SyncResponse>): Cancelable { fun execute(token: String?, callback: MatrixCallback<SyncResponse>): Cancelable {
val job = GlobalScope.launch(coroutineDispatchers.main) { val job = GlobalScope.launch {
val syncOrFailure = execute(token) val syncOrFailure = execute(token)
syncOrFailure.bimap({ callback.onFailure(it) }, { callback.onSuccess(it) }) syncOrFailure.bimap({ callback.onFailure(it) }, { callback.onSuccess(it) })
} }
@ -35,7 +35,7 @@ class SyncRequest(private val syncAPI: SyncAPI,
FilterUtil.enableLazyLoading(filterBody, true) FilterUtil.enableLazyLoading(filterBody, true)
var timeout = 0 var timeout = 0
if (token != null) { if (token != null) {
params["since"] = token as String params["since"] = token
timeout = 30000 timeout = 30000
} }
params["timeout"] = timeout.toString() params["timeout"] = timeout.toString()