Search in sources :

Example 1 with RequestAddContact

use of im.actor.core.api.rpc.RequestAddContact 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

ApiOutPeer (im.actor.core.api.ApiOutPeer)1 ApiUser (im.actor.core.api.ApiUser)1 ApiUserOutPeer (im.actor.core.api.ApiUserOutPeer)1 SeqUpdate (im.actor.core.api.base.SeqUpdate)1 RequestAddContact (im.actor.core.api.rpc.RequestAddContact)1 RequestRemoveContact (im.actor.core.api.rpc.RequestRemoveContact)1 RequestSearchContacts (im.actor.core.api.rpc.RequestSearchContacts)1 ResponseSeq (im.actor.core.api.rpc.ResponseSeq)1 UpdateContactsAdded (im.actor.core.api.updates.UpdateContactsAdded)1 UpdateContactsRemoved (im.actor.core.api.updates.UpdateContactsRemoved)1 Contact (im.actor.core.entity.Contact)1 User (im.actor.core.entity.User)1 AbsModule (im.actor.core.modules.AbsModule)1 Modules (im.actor.core.modules.Modules)1 ApiSupportConfiguration (im.actor.core.modules.api.ApiSupportConfiguration)1 RpcCallback (im.actor.core.network.RpcCallback)1 RpcException (im.actor.core.network.RpcException)1 RpcInternalException (im.actor.core.network.RpcInternalException)1 Command (im.actor.core.viewmodel.Command)1 UserVM (im.actor.core.viewmodel.UserVM)1