Search in sources :

Example 1 with RequestSubscribeToGroupOnline

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

ApiGroupOutPeer (im.actor.core.api.ApiGroupOutPeer)1 ApiUserOutPeer (im.actor.core.api.ApiUserOutPeer)1 RequestSubscribeToGroupOnline (im.actor.core.api.rpc.RequestSubscribeToGroupOnline)1 RequestSubscribeToOnline (im.actor.core.api.rpc.RequestSubscribeToOnline)1 ResponseVoid (im.actor.core.api.rpc.ResponseVoid)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 PeerInfoOpened (im.actor.core.events.PeerInfoOpened)1 UserVisible (im.actor.core.events.UserVisible)1 ModuleActor (im.actor.core.modules.ModuleActor)1 ModuleContext (im.actor.core.modules.ModuleContext)1 GroupVM (im.actor.core.viewmodel.GroupVM)1 UserPresence (im.actor.core.viewmodel.UserPresence)1 UserVM (im.actor.core.viewmodel.UserVM)1 Log (im.actor.runtime.Log)1