Search in sources :

Example 1 with GetUsersOfRoomsProcedure

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);
        }
    });
}
Also used : MethodCallHelper(chat.rocket.android.api.MethodCallHelper) Context(android.content.Context) Realm(io.realm.Realm) List(java.util.List) JSONObject(org.json.JSONObject) RealmResults(io.realm.RealmResults) RealmHelper(chat.rocket.persistence.realm.RealmHelper) SyncState(chat.rocket.core.SyncState) GetUsersOfRoomsProcedure(chat.rocket.persistence.realm.models.internal.GetUsersOfRoomsProcedure) DDPClientRef(chat.rocket.android.service.DDPClientRef) RCLog(chat.rocket.android.log.RCLog) Task(bolts.Task) JSONObject(org.json.JSONObject) GetUsersOfRoomsProcedure(chat.rocket.persistence.realm.models.internal.GetUsersOfRoomsProcedure)

Aggregations

Context (android.content.Context)1 Task (bolts.Task)1 MethodCallHelper (chat.rocket.android.api.MethodCallHelper)1 RCLog (chat.rocket.android.log.RCLog)1 DDPClientRef (chat.rocket.android.service.DDPClientRef)1 SyncState (chat.rocket.core.SyncState)1 RealmHelper (chat.rocket.persistence.realm.RealmHelper)1 GetUsersOfRoomsProcedure (chat.rocket.persistence.realm.models.internal.GetUsersOfRoomsProcedure)1 Realm (io.realm.Realm)1 RealmResults (io.realm.RealmResults)1 List (java.util.List)1 JSONObject (org.json.JSONObject)1