Search in sources :

Example 1 with ResponseLoadArchived

use of im.actor.core.api.rpc.ResponseLoadArchived in project actor-platform by actorapp.

the class ArchivedDialogsActor method onLoadMore.

private void onLoadMore(boolean init, RpcCallback<ResponseLoadArchived> callback) {
    if (init || isLoading) {
        //
        if (lastCallback != null) {
            lastCallback.onError(new RpcException(TAG, 0, "callback replaced", false, null));
        }
    }
    lastCallback = callback;
    if (isLoading && !init) {
        return;
    }
    if (init) {
        if (lastRequest != -1) {
            cancelRequest(lastRequest);
        }
        nextOffset = null;
    }
    isLoading = true;
    Log.d(TAG, "Loading archived dialogs");
    api(new RequestLoadArchived(nextOffset, LIMIT, ApiSupportConfiguration.OPTIMIZATIONS)).chain(r -> updates().applyRelatedData(r.getUsers(), r.getGroups())).chain(r -> updates().loadRequiredPeers(r.getUserPeers(), r.getGroupPeers())).then(r -> onLoadedMore(r)).failure(e -> lastCallback.onError((RpcException) e));
}
Also used : RequestLoadArchived(im.actor.core.api.rpc.RequestLoadArchived) ApiSupportConfiguration(im.actor.core.modules.api.ApiSupportConfiguration) ModuleContext(im.actor.core.modules.ModuleContext) ModuleActor(im.actor.core.modules.ModuleActor) Consumer(im.actor.runtime.function.Consumer) Void(im.actor.runtime.actors.messages.Void) RpcCallback(im.actor.core.network.RpcCallback) Log(im.actor.runtime.Log) ResponseLoadArchived(im.actor.core.api.rpc.ResponseLoadArchived) RpcException(im.actor.core.network.RpcException) RpcException(im.actor.core.network.RpcException) RequestLoadArchived(im.actor.core.api.rpc.RequestLoadArchived)

Example 2 with ResponseLoadArchived

use of im.actor.core.api.rpc.ResponseLoadArchived in project actor-platform by actorapp.

the class JsFacade method loadArchivedDialogs.

@UsedByApp
private JsPromise loadArchivedDialogs(final boolean init) {
    return JsPromise.create(new JsPromiseExecutor() {

        @Override
        public void execute() {
            messenger.loadArchivedDialogs(init, new RpcCallback<ResponseLoadArchived>() {

                @Override
                public void onResult(ResponseLoadArchived response) {
                    JsArray<JsDialogShort> res = JsArray.createArray().cast();
                    for (ApiDialog d : response.getDialogs()) {
                        res.push(JsDialogShort.create(messenger.buildPeerInfo(EntityConverter.convert(d.getPeer())), d.getUnreadCount()));
                    }
                    Log.d(TAG, "loadArchivedDialogs:result");
                    resolve(res);
                }

                @Override
                public void onError(RpcException e) {
                    Log.d(TAG, "loadArchivedDialogs:error");
                    reject(e.getMessage());
                }
            });
        }
    });
}
Also used : JsPromiseExecutor(im.actor.runtime.js.utils.JsPromiseExecutor) ApiDialog(im.actor.core.api.ApiDialog) RpcException(im.actor.core.network.RpcException) RpcCallback(im.actor.core.network.RpcCallback) ResponseLoadArchived(im.actor.core.api.rpc.ResponseLoadArchived) UsedByApp(im.actor.core.js.annotations.UsedByApp)

Aggregations

ResponseLoadArchived (im.actor.core.api.rpc.ResponseLoadArchived)2 RpcCallback (im.actor.core.network.RpcCallback)2 RpcException (im.actor.core.network.RpcException)2 ApiDialog (im.actor.core.api.ApiDialog)1 RequestLoadArchived (im.actor.core.api.rpc.RequestLoadArchived)1 UsedByApp (im.actor.core.js.annotations.UsedByApp)1 ModuleActor (im.actor.core.modules.ModuleActor)1 ModuleContext (im.actor.core.modules.ModuleContext)1 ApiSupportConfiguration (im.actor.core.modules.api.ApiSupportConfiguration)1 Log (im.actor.runtime.Log)1 Void (im.actor.runtime.actors.messages.Void)1 Consumer (im.actor.runtime.function.Consumer)1 JsPromiseExecutor (im.actor.runtime.js.utils.JsPromiseExecutor)1