From cc01f25d8f00e6c3cdee9b1cc98155e76413ac24 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 28 Dec 2020 14:52:49 +0100 Subject: [PATCH] Revert status to RoomMembersLoadStatusType.NONE) in case of failure --- .../room/membership/LoadRoomMembersTask.kt | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/LoadRoomMembersTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/LoadRoomMembersTask.kt index 55dd747fdb..53fa73c624 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/LoadRoomMembersTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/LoadRoomMembersTask.kt @@ -82,16 +82,19 @@ internal class DefaultLoadRoomMembersTask @Inject constructor( } private suspend fun doRequest(params: LoadRoomMembersTask.Params) { - monarchy.awaitTransaction { realm -> - val roomEntity = RoomEntity.where(realm, params.roomId).findFirst() - ?: realm.createObject(params.roomId) - roomEntity.membersLoadStatus = RoomMembersLoadStatusType.LOADING - } + setRoomMembersLoadStatus(params.roomId, RoomMembersLoadStatusType.LOADING) val lastToken = syncTokenStore.getLastToken() - val response = executeRequest(eventBus) { - apiCall = roomAPI.getMembers(params.roomId, lastToken, null, params.excludeMembership?.value) + val response = try { + executeRequest(eventBus) { + apiCall = roomAPI.getMembers(params.roomId, lastToken, null, params.excludeMembership?.value) + } + } catch (throwable: Throwable) { + // Revert status to NONE + setRoomMembersLoadStatus(params.roomId, RoomMembersLoadStatusType.NONE) + throw throwable } + // This will also set the status to LOADED insertInDb(response, params.roomId) } @@ -125,4 +128,11 @@ internal class DefaultLoadRoomMembersTask @Inject constructor( } return result ?: RoomMembersLoadStatusType.NONE } + + private suspend fun setRoomMembersLoadStatus(roomId: String, status: RoomMembersLoadStatusType) { + monarchy.awaitTransaction { realm -> + val roomEntity = RoomEntity.where(realm, roomId).findFirst() ?: realm.createObject(roomId) + roomEntity.membersLoadStatus = status + } + } }