Search in sources :

Example 1 with ResponseSeq

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

the class OwnAvatarChangeActor method removeAvatar.

public void removeAvatar() {
    if (currentChangeTask != 0) {
        context().getFilesModule().cancelUpload(currentChangeTask);
        currentChangeTask = 0;
    }
    currentChangeTask = RandomUtils.nextRid();
    context().getProfileModule().getOwnAvatarVM().getUploadState().change(new AvatarUploadState(null, true));
    final long currentRid = currentChangeTask;
    request(new RequestRemoveAvatar(), new RpcCallback<ResponseSeq>() {

        @Override
        public void onResult(ResponseSeq response) {
            updates().onUpdateReceived(new SeqUpdate(response.getSeq(), response.getState(), UpdateUserAvatarChanged.HEADER, new UpdateUserAvatarChanged(myUid(), null).toByteArray()));
            // After update applied turn of uploading state
            updates().onUpdateReceived(new ExecuteAfter(response.getSeq(), () -> self().send(new AvatarChanged(currentRid))));
        }

        @Override
        public void onError(RpcException e) {
            if (currentRid != currentChangeTask) {
                return;
            }
            currentChangeTask = 0;
            context().getProfileModule().getOwnAvatarVM().getUploadState().change(new AvatarUploadState(null, false));
        }
    });
}
Also used : SeqUpdate(im.actor.core.api.base.SeqUpdate) ResponseSeq(im.actor.core.api.rpc.ResponseSeq) UpdateUserAvatarChanged(im.actor.core.api.updates.UpdateUserAvatarChanged) RpcException(im.actor.core.network.RpcException) ExecuteAfter(im.actor.core.modules.sequence.internal.ExecuteAfter) UpdateUserAvatarChanged(im.actor.core.api.updates.UpdateUserAvatarChanged) AvatarUploadState(im.actor.core.viewmodel.AvatarUploadState) RequestRemoveAvatar(im.actor.core.api.rpc.RequestRemoveAvatar)

Example 2 with ResponseSeq

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

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

Example 4 with ResponseSeq

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

the class MessageDeleteActor method performDelete.

public void performDelete(final Peer peer, final List<Long> rids) {
    final ApiOutPeer outPeer = buidOutPeer(peer);
    final ApiPeer apiPeer = buildApiPeer(peer);
    request(new RequestDeleteMessage(outPeer, rids), new RpcCallback<ResponseSeq>() {

        @Override
        public void onResult(ResponseSeq response) {
            if (deleteStorage.getPendingDeletions().containsKey(peer)) {
                deleteStorage.getPendingDeletions().get(peer).getRids().removeAll(rids);
                saveStorage();
            }
            updates().onUpdateReceived(new SeqUpdate(response.getSeq(), response.getState(), UpdateMessageDelete.HEADER, new UpdateMessageDelete(apiPeer, rids).toByteArray()));
        }

        @Override
        public void onError(RpcException e) {
        }
    });
}
Also used : SeqUpdate(im.actor.core.api.base.SeqUpdate) RequestDeleteMessage(im.actor.core.api.rpc.RequestDeleteMessage) ResponseSeq(im.actor.core.api.rpc.ResponseSeq) RpcException(im.actor.core.network.RpcException) UpdateMessageDelete(im.actor.core.api.updates.UpdateMessageDelete) ApiOutPeer(im.actor.core.api.ApiOutPeer) ApiPeer(im.actor.core.api.ApiPeer)

Aggregations

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