From 6e3992e70ed90eccba68dbd4bfab47659bb6db54 Mon Sep 17 00:00:00 2001 From: ganfra Date: Fri, 19 Oct 2018 17:18:24 +0200 Subject: [PATCH] Fix some issues with sync (bad thread, bad use of last() ) --- .idea/caches/build_file_checksums.ser | Bin 651 -> 653 bytes .../features/home/RoomListFragment.kt | 2 +- .../android/api/session/room/RoomService.kt | 2 +- .../database/query/ChunkEntityQueries.kt | 2 +- .../database/query/EventEntityQueries.kt | 2 +- .../android/internal/session/DefaultSession.kt | 4 ++-- .../internal/session/room/DefaultRoom.kt | 2 +- .../internal/session/room/DefaultRoomService.kt | 2 +- .../internal/session/sync/SyncRequest.kt | 6 +++--- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 70dd0b4177406c7ac4a8b3c810e73942c41eb57a..998ced454bc6582b55c9a51d94786a0b64fe885a 100644 GIT binary patch delta 68 zcmV-K0K5N-1&sxenFHbAhLN0zlb-=RlV|}qliLAABAqkc65@?7i4E+OV(}pfPILe% aFI978a&s?ca$#;`Z)tOrG66P|F#=l9p&EVw delta 71 zcmV-N0J#5+1&alcnFDNgE0LUt4ks^Fb7gXKFK1zHW^!SZ{Q)+UU;#IiBmq1D43lpG d7L%?4Ef9a!%%GHYJ> { renderRooms(it) }) + currentSession.liveRooms().observe(this, Observer> { renderRooms(it) }) } private fun renderRooms(rooms: List?) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/RoomService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/RoomService.kt index 98532787..f2504a7c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/RoomService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/RoomService.kt @@ -8,6 +8,6 @@ interface RoomService { fun getAllRooms(): List - fun rooms(): LiveData> + fun liveRooms(): LiveData> } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/ChunkEntityQueries.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/ChunkEntityQueries.kt index dd812d3b..c81a26c5 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/ChunkEntityQueries.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/ChunkEntityQueries.kt @@ -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): RealmResults { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/EventEntityQueries.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/EventEntityQueries.kt index 0182d4c4..7331c422 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/EventEntityQueries.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/EventEntityQueries.kt @@ -23,5 +23,5 @@ fun RealmResults.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) } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt index 8bd4fbca..a318e102 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt @@ -66,8 +66,8 @@ class DefaultSession(private val sessionParams: SessionParams) : Session, KoinCo return roomService.getAllRooms() } - override fun rooms(): LiveData> { - return roomService.rooms() + override fun liveRooms(): LiveData> { + return roomService.liveRooms() } // Private methods ***************************************************************************** diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoom.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoom.kt index d5248371..8ab61e59 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoom.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoom.kt @@ -26,7 +26,7 @@ data class DefaultRoom( override fun liveTimeline(): LiveData> { 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 { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoomService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoomService.kt index 0a09c7cd..ab9fca1c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoomService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/DefaultRoomService.kt @@ -25,7 +25,7 @@ class DefaultRoomService(private val monarchy: Monarchy) : RoomService { return room } - override fun rooms(): LiveData> { + override fun liveRooms(): LiveData> { return monarchy.findAllMappedWithChanges( { realm -> RoomEntity.where(realm) }, { DefaultRoom(it.roomId) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncRequest.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncRequest.kt index 1d216a17..a0543935 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncRequest.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncRequest.kt @@ -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): 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()