diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt index 65383f1007..736d3ce35e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt @@ -244,6 +244,15 @@ interface RoomService { sortOrder: RoomSortOrder = RoomSortOrder.ACTIVITY ): LiveData> + /** + * Only notifies when this query has changes. + * It doesn't load any items in memory + */ + fun roomSummariesChangesLive( + queryParams: RoomSummaryQueryParams, + sortOrder: RoomSortOrder = RoomSortOrder.ACTIVITY + ): LiveData> + /** * Get's a live paged list from a filter that can be dynamically updated. * diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt index 6d72b8ef20..1c8b994b62 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt @@ -154,6 +154,12 @@ internal class DefaultRoomService @Inject constructor( return roomSummaryDataSource.getSortedPagedRoomSummariesLive(queryParams, pagedListConfig, sortOrder) } + override fun roomSummariesChangesLive( + queryParams: RoomSummaryQueryParams, + sortOrder: RoomSortOrder): LiveData> { + return roomSummaryDataSource.getRoomSummariesChangesLive(queryParams, sortOrder) + } + override fun getFilteredPagedRoomSummariesLive( queryParams: RoomSummaryQueryParams, pagedListConfig: PagedList.Config, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt index 5c4ed8012b..abba1a9f5a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt @@ -130,6 +130,18 @@ internal class RoomSummaryDataSource @Inject constructor( ) } + fun getRoomSummariesChangesLive( + queryParams: RoomSummaryQueryParams, + sortOrder: RoomSortOrder = RoomSortOrder.NONE + ): LiveData> { + return monarchy.findAllMappedWithChanges( + { + roomSummariesQuery(it, queryParams).process(sortOrder) + }, + { emptyList() } + ) + } + fun getSpaceSummariesLive( queryParams: SpaceSummaryQueryParams, sortOrder: RoomSortOrder = RoomSortOrder.NONE diff --git a/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/RustCryptoService.kt b/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/RustCryptoService.kt index e3b89fd0bd..140cbde3be 100755 --- a/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/RustCryptoService.kt +++ b/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/RustCryptoService.kt @@ -192,10 +192,13 @@ internal class RustCryptoService @Inject constructor( } override suspend fun fetchDevicesList(): List { - val devicesList = tryOrNull { - getDevicesTask.execute(Unit).devices - }.orEmpty() - cryptoStore.saveMyDevicesInfo(devicesList) + val devicesList: List + withContext(coroutineDispatchers.io) { + devicesList = tryOrNull { + getDevicesTask.execute(Unit).devices + }.orEmpty() + cryptoStore.saveMyDevicesInfo(devicesList) + } return devicesList } @@ -239,7 +242,7 @@ internal class RustCryptoService @Inject constructor( */ override fun start() { internalStart() - cryptoCoroutineScope.launch { + cryptoCoroutineScope.launch(coroutineDispatchers.io) { cryptoStore.open() // Just update fetchDevicesList() diff --git a/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt b/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt index 9658ba001f..ca9bed5d8b 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt @@ -25,6 +25,7 @@ import dagger.assisted.AssistedInject import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.di.MavericksAssistedViewModelFactory import im.vector.app.core.di.hiltMavericksViewModelFactory +import im.vector.app.core.dispatchers.CoroutineDispatchers import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.pushers.EnsureFcmTokenIsRetrievedUseCase import im.vector.app.core.pushers.PushersManager @@ -92,6 +93,7 @@ class HomeActivityViewModel @AssistedInject constructor( private val registerUnifiedPushUseCase: RegisterUnifiedPushUseCase, private val unregisterUnifiedPushUseCase: UnregisterUnifiedPushUseCase, private val ensureFcmTokenIsRetrievedUseCase: EnsureFcmTokenIsRetrievedUseCase, + private val coroutineDispatchers: CoroutineDispatchers ) : VectorViewModel(initialState) { @AssistedFactory @@ -116,7 +118,9 @@ class HomeActivityViewModel @AssistedInject constructor( if (isInitialized) return isInitialized = true registerUnifiedPushIfNeeded() - cleanupFiles() + viewModelScope.launch(coroutineDispatchers.io) { + cleanupFiles() + } observeInitialSync() checkSessionPushIsOn() observeCrossSigningReset() diff --git a/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt b/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt index 25781e68f0..a54ae7085e 100644 --- a/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt @@ -75,7 +75,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor( private val roomService = session.roomService() init { - roomService.getPagedRoomSummariesLive( + roomService.roomSummariesChangesLive( roomSummaryQueryParams { this.memberships = listOf(Membership.JOIN) this.spaceFilter = SpaceFilter.OrphanRooms @@ -111,7 +111,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor( combine( spaceStateHandler.getSelectedSpaceFlow().distinctUntilChanged(), spaceStateHandler.getSelectedSpaceFlow().flatMapLatest { - roomService.getPagedRoomSummariesLive( + roomService.roomSummariesChangesLive( roomSummaryQueryParams { this.memberships = Membership.activeMemberships() }, sortOrder = RoomSortOrder.NONE diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt index 99f6a254b8..b297a73cbf 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt @@ -93,7 +93,7 @@ class SpaceListViewModel @AssistedInject constructor( } // XXX there should be a way to refactor this and share it - session.roomService().getPagedRoomSummariesLive( + session.roomService().roomSummariesChangesLive( roomSummaryQueryParams { this.memberships = listOf(Membership.JOIN) this.spaceFilter = roomsInSpaceFilter() @@ -268,9 +268,7 @@ class SpaceListViewModel @AssistedInject constructor( combine( session.flow().liveSpaceSummaries(params), - session.accountDataService() - .getLiveRoomAccountDataEvents(setOf(RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER)) - .asFlow() + session.flow().liveRoomAccountData(setOf(RoomAccountDataTypes.EVENT_TYPE_SPACE_ORDER)) ) { spaces, _ -> spaces }.execute { asyncSpaces ->