mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
Revert status to RoomMembersLoadStatusType.NONE) in case of failure
This commit is contained in:
parent
9f3176c49c
commit
cc01f25d8f
1 changed files with 17 additions and 7 deletions
|
@ -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<RoomMembersResponse>(eventBus) {
|
||||
apiCall = roomAPI.getMembers(params.roomId, lastToken, null, params.excludeMembership?.value)
|
||||
val response = try {
|
||||
executeRequest<RoomMembersResponse>(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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue