Search in sources :

Example 1 with ResponseVoid

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

the class CursorReceiverActor method perform.

@Override
protected void perform(final Peer peer, final long date) {
    ApiOutPeer outPeer = buidOutPeer(peer);
    if (outPeer == null) {
        return;
    }
    request(new RequestMessageReceived(outPeer, date), new RpcCallback<ResponseVoid>() {

        @Override
        public void onResult(ResponseVoid response) {
            onCompleted(peer, date);
        }

        @Override
        public void onError(RpcException e) {
            CursorReceiverActor.this.onError(peer, date);
        }
    });
}
Also used : ResponseVoid(im.actor.core.api.rpc.ResponseVoid) RpcException(im.actor.core.network.RpcException) ApiOutPeer(im.actor.core.api.ApiOutPeer) RequestMessageReceived(im.actor.core.api.rpc.RequestMessageReceived)

Example 2 with ResponseVoid

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

the class KeyManagerActor method onMainKeysReady.

private void onMainKeysReady() {
    Log.d(TAG, "Main Keys are ready");
    // 
    // Generation required pre keys
    // 
    int missingKeysCount = Math.max(0, Configuration.EPHEMERAL_KEYS_COUNT - ownKeys.getPreKeys().length);
    if (missingKeysCount > 0) {
        ownKeys = ownKeys.appendPreKeys(ManagedList.of(PrivateKey.GENERATOR, missingKeysCount).toArray(new PrivateKey[0]));
        encryptionKeysStorage.addOrUpdateItem(0, ownKeys.toByteArray());
    }
    // 
    // Uploading own pre keys
    // 
    final ManagedList<PrivateKey> pendingEphermalKeys = ManagedList.of(ownKeys.getPreKeys()).filter(PrivateKey.NOT_UPLOADED);
    if (pendingEphermalKeys.size() > 0) {
        ArrayList<ApiEncryptionKey> uploadingKeys = pendingEphermalKeys.map(PrivateKey.TO_API);
        ArrayList<ApiEncryptionKeySignature> uploadingSignatures = pendingEphermalKeys.map(PrivateKey.SIGN(ownKeys.getIdentityKey()));
        api(new RequestUploadPreKey(ownKeys.getKeyGroupId(), uploadingKeys, uploadingSignatures)).then(new Consumer<ResponseVoid>() {

            @Override
            public void apply(ResponseVoid responseVoid) {
                ownKeys = ownKeys.markAsUploaded(pendingEphermalKeys.toArray(new PrivateKey[pendingEphermalKeys.size()]));
                encryptionKeysStorage.addOrUpdateItem(0, ownKeys.toByteArray());
                onAllKeysReady();
            }
        }).failure(new Consumer<Exception>() {

            @Override
            public void apply(Exception e) {
                Log.w(TAG, "Ephemeral keys upload error");
                Log.e(TAG, e);
            // Ignore. This will freeze all encryption operations.
            }
        });
    } else {
        onAllKeysReady();
    }
}
Also used : ResponseVoid(im.actor.core.api.rpc.ResponseVoid) PrivateKey(im.actor.core.modules.encryption.entity.PrivateKey) RequestUploadPreKey(im.actor.core.api.rpc.RequestUploadPreKey) IOException(java.io.IOException) Consumer(im.actor.runtime.function.Consumer) ApiEncryptionKeySignature(im.actor.core.api.ApiEncryptionKeySignature) ApiEncryptionKey(im.actor.core.api.ApiEncryptionKey)

Example 3 with ResponseVoid

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

the class CursorReaderActor method perform.

@Override
protected void perform(final Peer peer, final long date) {
    ApiOutPeer outPeer = buidOutPeer(peer);
    if (outPeer == null) {
        return;
    }
    request(new RequestMessageRead(outPeer, date), new RpcCallback<ResponseVoid>() {

        @Override
        public void onResult(ResponseVoid response) {
            onCompleted(peer, date);
        }

        @Override
        public void onError(RpcException e) {
            CursorReaderActor.this.onError(peer, date);
        }
    });
}
Also used : ResponseVoid(im.actor.core.api.rpc.ResponseVoid) RpcException(im.actor.core.network.RpcException) ApiOutPeer(im.actor.core.api.ApiOutPeer) RequestMessageRead(im.actor.core.api.rpc.RequestMessageRead)

Example 4 with ResponseVoid

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

the class PresenceActor method onCheckQueue.

private void onCheckQueue() {
    if (isRequesting) {
        return;
    }
    if (pendingPeers.size() == 0) {
        return;
    }
    ArrayList<Peer> destPeers = new ArrayList<>(pendingPeers);
    pendingPeers.clear();
    ArrayList<ApiUserOutPeer> outUserPeers = new ArrayList<>();
    ArrayList<ApiGroupOutPeer> outGroupPeers = new ArrayList<>();
    for (Peer p : destPeers) {
        if (p.getPeerType() == PeerType.GROUP) {
            Group g = getGroup(p.getPeerId());
            if (g != null) {
                outGroupPeers.add(new ApiGroupOutPeer(p.getPeerId(), g.getAccessHash()));
            }
        } else if (p.getPeerType() == PeerType.PRIVATE) {
            User u = getUser(p.getPeerId());
            if (u != null) {
                outUserPeers.add(new ApiUserOutPeer(p.getPeerId(), u.getAccessHash()));
            }
        }
    }
    ArrayList<Promise<ResponseVoid>> requests = new ArrayList<>();
    if (outUserPeers.size() > 0) {
        requests.add(api(new RequestSubscribeToOnline(outUserPeers)));
    }
    if (outGroupPeers.size() > 0) {
        requests.add(api(new RequestSubscribeToGroupOnline(outGroupPeers)));
    }
    if (requests.size() > 0) {
        isRequesting = true;
        PromisesArray.ofPromises(requests).zip().then(responseVoids -> {
            isRequesting = false;
            onCheckQueue();
        }).failure(e -> {
            isRequesting = false;
            onCheckQueue();
        });
    }
}
Also used : ModuleContext(im.actor.core.modules.ModuleContext) ActorCancellable(im.actor.runtime.actors.ActorCancellable) ActorCreator(im.actor.runtime.actors.ActorCreator) Promise(im.actor.runtime.promise.Promise) UserPresence(im.actor.core.viewmodel.UserPresence) HashMap(java.util.HashMap) GroupVM(im.actor.core.viewmodel.GroupVM) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RequestSubscribeToOnline(im.actor.core.api.rpc.RequestSubscribeToOnline) User(im.actor.core.entity.User) BusSubscriber(im.actor.runtime.eventbus.BusSubscriber) PromisesArray(im.actor.runtime.promise.PromisesArray) ActorSystem(im.actor.runtime.actors.ActorSystem) PeerChatOpened(im.actor.core.events.PeerChatOpened) ActorRef(im.actor.runtime.actors.ActorRef) GroupType(im.actor.core.entity.GroupType) PeerType(im.actor.core.entity.PeerType) UserVisible(im.actor.core.events.UserVisible) Verified(im.actor.runtime.annotations.Verified) Group(im.actor.core.entity.Group) PeerInfoOpened(im.actor.core.events.PeerInfoOpened) RequestSubscribeToGroupOnline(im.actor.core.api.rpc.RequestSubscribeToGroupOnline) List(java.util.List) ModuleActor(im.actor.core.modules.ModuleActor) UserVM(im.actor.core.viewmodel.UserVM) Consumer(im.actor.runtime.function.Consumer) Peer(im.actor.core.entity.Peer) Props(im.actor.runtime.actors.Props) ApiGroupOutPeer(im.actor.core.api.ApiGroupOutPeer) ApiUserOutPeer(im.actor.core.api.ApiUserOutPeer) ResponseVoid(im.actor.core.api.rpc.ResponseVoid) Log(im.actor.runtime.Log) Event(im.actor.runtime.eventbus.Event) NewSessionCreated(im.actor.core.events.NewSessionCreated) Group(im.actor.core.entity.Group) User(im.actor.core.entity.User) ApiUserOutPeer(im.actor.core.api.ApiUserOutPeer) Peer(im.actor.core.entity.Peer) ApiGroupOutPeer(im.actor.core.api.ApiGroupOutPeer) ApiUserOutPeer(im.actor.core.api.ApiUserOutPeer) ArrayList(java.util.ArrayList) Promise(im.actor.runtime.promise.Promise) RequestSubscribeToGroupOnline(im.actor.core.api.rpc.RequestSubscribeToGroupOnline) ApiGroupOutPeer(im.actor.core.api.ApiGroupOutPeer) RequestSubscribeToOnline(im.actor.core.api.rpc.RequestSubscribeToOnline)

Aggregations

ResponseVoid (im.actor.core.api.rpc.ResponseVoid)4 ApiOutPeer (im.actor.core.api.ApiOutPeer)2 RpcException (im.actor.core.network.RpcException)2 Consumer (im.actor.runtime.function.Consumer)2 ApiEncryptionKey (im.actor.core.api.ApiEncryptionKey)1 ApiEncryptionKeySignature (im.actor.core.api.ApiEncryptionKeySignature)1 ApiGroupOutPeer (im.actor.core.api.ApiGroupOutPeer)1 ApiUserOutPeer (im.actor.core.api.ApiUserOutPeer)1 RequestMessageRead (im.actor.core.api.rpc.RequestMessageRead)1 RequestMessageReceived (im.actor.core.api.rpc.RequestMessageReceived)1 RequestSubscribeToGroupOnline (im.actor.core.api.rpc.RequestSubscribeToGroupOnline)1 RequestSubscribeToOnline (im.actor.core.api.rpc.RequestSubscribeToOnline)1 RequestUploadPreKey (im.actor.core.api.rpc.RequestUploadPreKey)1 Group (im.actor.core.entity.Group)1 GroupType (im.actor.core.entity.GroupType)1 Peer (im.actor.core.entity.Peer)1 PeerType (im.actor.core.entity.PeerType)1 User (im.actor.core.entity.User)1 NewSessionCreated (im.actor.core.events.NewSessionCreated)1 PeerChatOpened (im.actor.core.events.PeerChatOpened)1