Search in sources :

Example 6 with RpcCallback

use of im.actor.core.network.RpcCallback 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 7 with RpcCallback

use of im.actor.core.network.RpcCallback in project actor-platform by actorapp.

the class ContactsModule method removeContact.

public Command<Boolean> removeContact(final int uid) {
    return callback -> {
        User user = users().getValue(uid);
        if (user == null) {
            runOnUiThread(() -> callback.onError(new RpcInternalException()));
            return;
        }
        request(new RequestRemoveContact(uid, user.getAccessHash()), new RpcCallback<ResponseSeq>() {

            @Override
            public void onResult(ResponseSeq response) {
                ArrayList<Integer> uids = new ArrayList<>();
                uids.add(uid);
                SeqUpdate update = new SeqUpdate(response.getSeq(), response.getState(), UpdateContactsRemoved.HEADER, new UpdateContactsRemoved(uids).toByteArray());
                updates().onUpdateReceived(update);
                runOnUiThread(() -> callback.onResult(true));
            }

            @Override
            public void onError(RpcException e) {
                runOnUiThread(() -> callback.onError(new RpcInternalException()));
            }
        });
    };
}
Also used : ResponseSeq(im.actor.core.api.rpc.ResponseSeq) RequestRemoveContact(im.actor.core.api.rpc.RequestRemoveContact) Promise(im.actor.runtime.promise.Promise) ApiUser(im.actor.core.api.ApiUser) ArrayList(java.util.ArrayList) AbsModule(im.actor.core.modules.AbsModule) User(im.actor.core.entity.User) SyncKeyValue(im.actor.runtime.storage.SyncKeyValue) Modules(im.actor.core.modules.Modules) RpcCallback(im.actor.core.network.RpcCallback) ActorRef(im.actor.runtime.actors.ActorRef) ListEngine(im.actor.runtime.storage.ListEngine) Contact(im.actor.core.entity.Contact) ApiSupportConfiguration(im.actor.core.modules.api.ApiSupportConfiguration) Command(im.actor.core.viewmodel.Command) RpcInternalException(im.actor.core.network.RpcInternalException) RequestSearchContacts(im.actor.core.api.rpc.RequestSearchContacts) UpdateContactsAdded(im.actor.core.api.updates.UpdateContactsAdded) UpdateContactsRemoved(im.actor.core.api.updates.UpdateContactsRemoved) ApiOutPeer(im.actor.core.api.ApiOutPeer) ActorSystem.system(im.actor.runtime.actors.ActorSystem.system) RpcException(im.actor.core.network.RpcException) Storage(im.actor.runtime.Storage) UserVM(im.actor.core.viewmodel.UserVM) Props(im.actor.runtime.actors.Props) RequestAddContact(im.actor.core.api.rpc.RequestAddContact) ApiUserOutPeer(im.actor.core.api.ApiUserOutPeer) SeqUpdate(im.actor.core.api.base.SeqUpdate) ApiUser(im.actor.core.api.ApiUser) User(im.actor.core.entity.User) SeqUpdate(im.actor.core.api.base.SeqUpdate) RpcInternalException(im.actor.core.network.RpcInternalException) RequestRemoveContact(im.actor.core.api.rpc.RequestRemoveContact) ResponseSeq(im.actor.core.api.rpc.ResponseSeq) RpcException(im.actor.core.network.RpcException) ArrayList(java.util.ArrayList) RpcCallback(im.actor.core.network.RpcCallback) UpdateContactsRemoved(im.actor.core.api.updates.UpdateContactsRemoved)

Example 8 with RpcCallback

use of im.actor.core.network.RpcCallback in project actor-platform by actorapp.

the class ContactsModule method addContact.

public Command<Boolean> addContact(final int uid) {
    return callback -> {
        User user = users().getValue(uid);
        if (user == null) {
            runOnUiThread(() -> callback.onError(new RpcInternalException()));
            return;
        }
        request(new RequestAddContact(uid, user.getAccessHash()), new RpcCallback<ResponseSeq>() {

            @Override
            public void onResult(ResponseSeq response) {
                ArrayList<Integer> uids = new ArrayList<>();
                uids.add(uid);
                SeqUpdate update = new SeqUpdate(response.getSeq(), response.getState(), UpdateContactsAdded.HEADER, new UpdateContactsAdded(uids).toByteArray());
                updates().onUpdateReceived(update);
                runOnUiThread(() -> callback.onResult(true));
            }

            @Override
            public void onError(RpcException e) {
                runOnUiThread(() -> callback.onError(new RpcInternalException()));
            }
        });
    };
}
Also used : ResponseSeq(im.actor.core.api.rpc.ResponseSeq) RequestRemoveContact(im.actor.core.api.rpc.RequestRemoveContact) Promise(im.actor.runtime.promise.Promise) ApiUser(im.actor.core.api.ApiUser) ArrayList(java.util.ArrayList) AbsModule(im.actor.core.modules.AbsModule) User(im.actor.core.entity.User) SyncKeyValue(im.actor.runtime.storage.SyncKeyValue) Modules(im.actor.core.modules.Modules) RpcCallback(im.actor.core.network.RpcCallback) ActorRef(im.actor.runtime.actors.ActorRef) ListEngine(im.actor.runtime.storage.ListEngine) Contact(im.actor.core.entity.Contact) ApiSupportConfiguration(im.actor.core.modules.api.ApiSupportConfiguration) Command(im.actor.core.viewmodel.Command) RpcInternalException(im.actor.core.network.RpcInternalException) RequestSearchContacts(im.actor.core.api.rpc.RequestSearchContacts) UpdateContactsAdded(im.actor.core.api.updates.UpdateContactsAdded) UpdateContactsRemoved(im.actor.core.api.updates.UpdateContactsRemoved) ApiOutPeer(im.actor.core.api.ApiOutPeer) ActorSystem.system(im.actor.runtime.actors.ActorSystem.system) RpcException(im.actor.core.network.RpcException) Storage(im.actor.runtime.Storage) UserVM(im.actor.core.viewmodel.UserVM) Props(im.actor.runtime.actors.Props) RequestAddContact(im.actor.core.api.rpc.RequestAddContact) ApiUserOutPeer(im.actor.core.api.ApiUserOutPeer) SeqUpdate(im.actor.core.api.base.SeqUpdate) UpdateContactsAdded(im.actor.core.api.updates.UpdateContactsAdded) ApiUser(im.actor.core.api.ApiUser) User(im.actor.core.entity.User) SeqUpdate(im.actor.core.api.base.SeqUpdate) RpcInternalException(im.actor.core.network.RpcInternalException) ResponseSeq(im.actor.core.api.rpc.ResponseSeq) RpcException(im.actor.core.network.RpcException) ArrayList(java.util.ArrayList) RpcCallback(im.actor.core.network.RpcCallback) RequestAddContact(im.actor.core.api.rpc.RequestAddContact)

Aggregations

RpcCallback (im.actor.core.network.RpcCallback)8 RpcException (im.actor.core.network.RpcException)8 ArrayList (java.util.ArrayList)6 User (im.actor.core.entity.User)5 ApiSupportConfiguration (im.actor.core.modules.api.ApiSupportConfiguration)5 ApiUser (im.actor.core.api.ApiUser)4 ApiUserOutPeer (im.actor.core.api.ApiUserOutPeer)4 AbsModule (im.actor.core.modules.AbsModule)3 ModuleActor (im.actor.core.modules.ModuleActor)3 ModuleContext (im.actor.core.modules.ModuleContext)3 Modules (im.actor.core.modules.Modules)3 Command (im.actor.core.viewmodel.Command)3 Log (im.actor.runtime.Log)3 Void (im.actor.runtime.actors.messages.Void)3 Promise (im.actor.runtime.promise.Promise)3 ApiConfiguration (im.actor.core.ApiConfiguration)2 AuthState (im.actor.core.AuthState)2 ApiEmailActivationType (im.actor.core.api.ApiEmailActivationType)2 ApiOutPeer (im.actor.core.api.ApiOutPeer)2 ApiPhoneActivationType (im.actor.core.api.ApiPhoneActivationType)2