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

View File

@ -34,7 +34,7 @@ class RoomListFragment : RiotFragment(), RoomController.Callback {
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
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>?) {

View File

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

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()
.isNull("nextToken")
.findAll()
.last()
.last(null)
}

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) {
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()
}

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

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

View File

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

override fun liveTimeline(): LiveData<PagedList<Event>> {
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) {
EventEntity.where(realm, roomId)
} else {

View File

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

override fun rooms(): LiveData<List<Room>> {
override fun liveRooms(): LiveData<List<Room>> {
return monarchy.findAllMappedWithChanges(
{ realm -> RoomEntity.where(realm) },
{ 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.failure.Failure
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.util.FilterUtil
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.MatrixCoroutineDispatchers
import kotlinx.coroutines.GlobalScope
@ -22,7 +22,7 @@ class SyncRequest(private val syncAPI: SyncAPI,


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