Revert status to RoomMembersLoadStatusType.NONE) in case of failure
This commit is contained in:
parent
9f3176c49c
commit
cc01f25d8f
|
@ -82,16 +82,19 @@ internal class DefaultLoadRoomMembersTask @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun doRequest(params: LoadRoomMembersTask.Params) {
|
private suspend fun doRequest(params: LoadRoomMembersTask.Params) {
|
||||||
monarchy.awaitTransaction { realm ->
|
setRoomMembersLoadStatus(params.roomId, RoomMembersLoadStatusType.LOADING)
|
||||||
val roomEntity = RoomEntity.where(realm, params.roomId).findFirst()
|
|
||||||
?: realm.createObject(params.roomId)
|
|
||||||
roomEntity.membersLoadStatus = RoomMembersLoadStatusType.LOADING
|
|
||||||
}
|
|
||||||
|
|
||||||
val lastToken = syncTokenStore.getLastToken()
|
val lastToken = syncTokenStore.getLastToken()
|
||||||
val response = executeRequest<RoomMembersResponse>(eventBus) {
|
val response = try {
|
||||||
|
executeRequest<RoomMembersResponse>(eventBus) {
|
||||||
apiCall = roomAPI.getMembers(params.roomId, lastToken, null, params.excludeMembership?.value)
|
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)
|
insertInDb(response, params.roomId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,4 +128,11 @@ internal class DefaultLoadRoomMembersTask @Inject constructor(
|
||||||
}
|
}
|
||||||
return result ?: RoomMembersLoadStatusType.NONE
|
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 New Issue