Search in sources :

Example 1 with ApiDialog

use of im.actor.core.api.ApiDialog 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)

Example 2 with ApiDialog

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

the class DialogsHistoryActor method onLoadedMore.

private void onLoadedMore(List<ApiDialog> rawDialogs) {
    final ArrayList<DialogHistory> dialogs = new ArrayList<>();
    long maxLoadedDate = Long.MAX_VALUE;
    for (ApiDialog dialog : rawDialogs) {
        dialogs.add(new DialogHistory(convert(dialog.getPeer()), dialog.getUnreadCount(), dialog.getSortDate(), dialog.getRid(), dialog.getDate(), dialog.getSenderUid(), AbsContent.fromMessage(dialog.getMessage()), dialog.getState() == ApiMessageState.READ, dialog.getState() == ApiMessageState.RECEIVED));
        maxLoadedDate = Math.min(dialog.getSortDate(), maxLoadedDate);
    }
    if (dialogs.size() > 0) {
        final long finalMaxLoadedDate = maxLoadedDate;
        context().getMessagesModule().getRouter().onDialogsHistoryLoaded(dialogs).then((v) -> {
            if (dialogs.size() < LIMIT) {
                markAsLoaded();
            } else {
                markAsSliceLoaded(finalMaxLoadedDate);
            }
        });
    } else {
        markAsLoaded();
    }
}
Also used : ApiDialog(im.actor.core.api.ApiDialog) DialogHistory(im.actor.core.modules.messaging.history.entity.DialogHistory) ArrayList(java.util.ArrayList)

Aggregations

ApiDialog (im.actor.core.api.ApiDialog)2 ResponseLoadArchived (im.actor.core.api.rpc.ResponseLoadArchived)1 UsedByApp (im.actor.core.js.annotations.UsedByApp)1 DialogHistory (im.actor.core.modules.messaging.history.entity.DialogHistory)1 RpcCallback (im.actor.core.network.RpcCallback)1 RpcException (im.actor.core.network.RpcException)1 JsPromiseExecutor (im.actor.runtime.js.utils.JsPromiseExecutor)1 ArrayList (java.util.ArrayList)1