use of chat.rocket.persistence.realm.models.internal.GetUsersOfRoomsProcedure in project Rocket.Chat.Android by RocketChat.
the class GetUsersOfRoomsProcedureObserver method onUpdateResults.
@Override
public void onUpdateResults(List<GetUsersOfRoomsProcedure> results) {
if (results == null || results.isEmpty()) {
return;
}
GetUsersOfRoomsProcedure procedure = results.get(0);
final String roomId = procedure.getRoomId();
final boolean showAll = procedure.isShowAll();
realmHelper.executeTransaction(realm -> realm.createOrUpdateObjectFromJson(GetUsersOfRoomsProcedure.class, new JSONObject().put(GetUsersOfRoomsProcedure.ID, roomId).put(GetUsersOfRoomsProcedure.SYNC_STATE, SyncState.SYNCING))).onSuccessTask(task -> methodCall.getUsersOfRoom(roomId, showAll).onSuccessTask(_task -> {
JSONObject result = _task.getResult().put("roomId", roomId).put("syncstate", SyncState.SYNCED);
return realmHelper.executeTransaction(realm -> realm.createOrUpdateObjectFromJson(GetUsersOfRoomsProcedure.class, result));
})).continueWithTask(task -> {
if (task.isFaulted()) {
RCLog.w(task.getError());
return realmHelper.executeTransaction(realm -> realm.createOrUpdateObjectFromJson(GetUsersOfRoomsProcedure.class, new JSONObject().put(GetUsersOfRoomsProcedure.ID, roomId).put(GetUsersOfRoomsProcedure.SYNC_STATE, SyncState.FAILED)));
} else {
return Task.forResult(null);
}
});
}
Aggregations