Search in sources :

Example 1 with ApiGroupOutPeer

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

the class GroupAvatarChangeActor method removeAvatar.

public void removeAvatar(final int gid) {
    if (currentTasks.containsKey(gid)) {
        context().getFilesModule().cancelUpload(currentTasks.get(gid));
        currentTasks.remove(gid);
    }
    final long rid = RandomUtils.nextRid();
    currentTasks.put(gid, rid);
    tasksMap.put(rid, gid);
    Group group = context().getGroupsModule().getGroups().getValue(gid);
    ApiGroupOutPeer outPeer = new ApiGroupOutPeer(gid, group.getAccessHash());
    context().getProfileModule().getOwnAvatarVM().getUploadState().change(new AvatarUploadState(null, true));
    api(new RequestRemoveGroupAvatar(outPeer, rid, ApiSupportConfiguration.OPTIMIZATIONS)).flatMap(responseSeqDate -> updates().applyUpdate(responseSeqDate.getSeq(), responseSeqDate.getState(), new UpdateGroupAvatarChangedObsolete(gid, rid, myUid(), null, responseSeqDate.getDate()))).then(aVoid -> avatarChanged(gid, rid)).failure(e -> {
        if (!tasksMap.containsKey(rid)) {
            return;
        }
        final int gid2 = tasksMap.get(rid);
        if (currentTasks.get(gid) != rid) {
            return;
        }
        currentTasks.remove(gid2);
        tasksMap.remove(rid);
        context().getGroupsModule().getAvatarVM(gid2).getUploadState().change(new AvatarUploadState(null, false));
    });
}
Also used : ApiSupportConfiguration(im.actor.core.modules.api.ApiSupportConfiguration) ResponseEditGroupAvatar(im.actor.core.api.rpc.ResponseEditGroupAvatar) ModuleContext(im.actor.core.modules.ModuleContext) ResponseSeqDate(im.actor.core.api.rpc.ResponseSeqDate) ExecuteAfter(im.actor.core.modules.sequence.internal.ExecuteAfter) Void(im.actor.runtime.actors.messages.Void) RequestEditGroupAvatar(im.actor.core.api.rpc.RequestEditGroupAvatar) UpdateGroupAvatarChanged(im.actor.core.api.updates.UpdateGroupAvatarChanged) RandomUtils(im.actor.core.util.RandomUtils) HashMap(java.util.HashMap) Group(im.actor.core.entity.Group) RpcException(im.actor.core.network.RpcException) RequestRemoveGroupAvatar(im.actor.core.api.rpc.RequestRemoveGroupAvatar) ModuleActor(im.actor.core.modules.ModuleActor) Consumer(im.actor.runtime.function.Consumer) FileReference(im.actor.core.entity.FileReference) ApiFileLocation(im.actor.core.api.ApiFileLocation) UpdateGroupAvatarChangedObsolete(im.actor.core.api.updates.UpdateGroupAvatarChangedObsolete) RpcCallback(im.actor.core.network.RpcCallback) ApiGroupOutPeer(im.actor.core.api.ApiGroupOutPeer) UploadManager(im.actor.core.modules.file.UploadManager) AvatarUploadState(im.actor.core.viewmodel.AvatarUploadState) SeqUpdate(im.actor.core.api.base.SeqUpdate) Group(im.actor.core.entity.Group) UpdateGroupAvatarChangedObsolete(im.actor.core.api.updates.UpdateGroupAvatarChangedObsolete) RequestRemoveGroupAvatar(im.actor.core.api.rpc.RequestRemoveGroupAvatar) AvatarUploadState(im.actor.core.viewmodel.AvatarUploadState) ApiGroupOutPeer(im.actor.core.api.ApiGroupOutPeer)

Example 2 with ApiGroupOutPeer

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

the class SearchModule method findPublicGroupById.

public Promise<Peer> findPublicGroupById(int gid) {
    ArrayList<ApiGroupOutPeer> groups = new ArrayList<>();
    groups.add(new ApiGroupOutPeer(gid, 0));
    return updates().loadRequiredPeers(new ArrayList<>(), groups).map(aVoid -> Peer.group(gid));
}
Also used : ArrayList(java.util.ArrayList) ApiGroupOutPeer(im.actor.core.api.ApiGroupOutPeer)

Example 3 with ApiGroupOutPeer

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

the class GroupsModule method loadMembers.

public Promise<GroupMembersSlice> loadMembers(int gid, int limit, byte[] next) {
    return getGroups().getValueAsync(gid).flatMap(group -> api(new RequestLoadMembers(new ApiGroupOutPeer(group.getGroupId(), group.getAccessHash()), limit, next))).chain(r -> updates().loadRequiredPeers(r.getUsers(), new ArrayList<>())).map(r -> {
        ArrayList<GroupMember> members = new ArrayList<>();
        for (ApiMember p : r.getMembers()) {
            boolean isAdmin = p.isAdmin() != null ? p.isAdmin() : false;
            members.add(new GroupMember(p.getUid(), p.getInviterUid(), p.getInviterUid(), isAdmin));
        }
        return new GroupMembersSlice(members, r.getNext());
    });
}
Also used : ModuleContext(im.actor.core.modules.ModuleContext) ApiGroupType(im.actor.core.api.ApiGroupType) RequestKickUser(im.actor.core.api.rpc.RequestKickUser) RequestLoadAdminSettings(im.actor.core.api.rpc.RequestLoadAdminSettings) ResponseInviteUrl(im.actor.core.api.rpc.ResponseInviteUrl) RandomUtils(im.actor.core.util.RandomUtils) RequestEditGroupShortName(im.actor.core.api.rpc.RequestEditGroupShortName) RequestInviteUser(im.actor.core.api.rpc.RequestInviteUser) RequestTransferOwnership(im.actor.core.api.rpc.RequestTransferOwnership) RequestEditGroupTitle(im.actor.core.api.rpc.RequestEditGroupTitle) RequestJoinGroupByPeer(im.actor.core.api.rpc.RequestJoinGroupByPeer) ApiSupportConfiguration(im.actor.core.modules.api.ApiSupportConfiguration) ApiAdminSettings(im.actor.core.api.ApiAdminSettings) RequestGetIntegrationToken(im.actor.core.api.rpc.RequestGetIntegrationToken) Void(im.actor.runtime.actors.messages.Void) RequestRevokeInviteUrl(im.actor.core.api.rpc.RequestRevokeInviteUrl) GroupMember(im.actor.core.entity.GroupMember) ApiOutPeer(im.actor.core.api.ApiOutPeer) RequestCreateGroup(im.actor.core.api.rpc.RequestCreateGroup) MVVMCollection(im.actor.runtime.mvvm.MVVMCollection) ActorSystem.system(im.actor.runtime.actors.ActorSystem.system) RequestLeaveAndDelete(im.actor.core.api.rpc.RequestLeaveAndDelete) GroupAvatarVM(im.actor.core.viewmodel.GroupAvatarVM) List(java.util.List) RequestEditGroupAbout(im.actor.core.api.rpc.RequestEditGroupAbout) Peer(im.actor.core.entity.Peer) ApiUserOutPeer(im.actor.core.api.ApiUserOutPeer) Function(im.actor.runtime.function.Function) ApiPeerType(im.actor.core.api.ApiPeerType) RequestMakeUserAdminObsolete(im.actor.core.api.rpc.RequestMakeUserAdminObsolete) Promise(im.actor.runtime.promise.Promise) HashMap(java.util.HashMap) GroupVM(im.actor.core.viewmodel.GroupVM) ArrayList(java.util.ArrayList) AbsModule(im.actor.core.modules.AbsModule) User(im.actor.core.entity.User) BusSubscriber(im.actor.runtime.eventbus.BusSubscriber) GroupAvatarChangeActor(im.actor.core.modules.profile.avatar.GroupAvatarChangeActor) RequestSaveAdminSettings(im.actor.core.api.rpc.RequestSaveAdminSettings) RequestRevokeIntegrationToken(im.actor.core.api.rpc.RequestRevokeIntegrationToken) GroupMembersSlice(im.actor.core.entity.GroupMembersSlice) PeerChatOpened(im.actor.core.events.PeerChatOpened) ActorRef(im.actor.runtime.actors.ActorRef) RequestDismissUserAdmin(im.actor.core.api.rpc.RequestDismissUserAdmin) PeerType(im.actor.core.entity.PeerType) RequestLeaveGroup(im.actor.core.api.rpc.RequestLeaveGroup) RequestLoadMembers(im.actor.core.api.rpc.RequestLoadMembers) RequestShareHistory(im.actor.core.api.rpc.RequestShareHistory) RequestJoinGroup(im.actor.core.api.rpc.RequestJoinGroup) ApiMember(im.actor.core.api.ApiMember) Group(im.actor.core.entity.Group) PeerInfoOpened(im.actor.core.events.PeerInfoOpened) GroupRouterInt(im.actor.core.modules.groups.router.GroupRouterInt) RequestDeleteGroup(im.actor.core.api.rpc.RequestDeleteGroup) Storage(im.actor.runtime.Storage) ResponseIntegrationToken(im.actor.core.api.rpc.ResponseIntegrationToken) RequestGetGroupInviteUrl(im.actor.core.api.rpc.RequestGetGroupInviteUrl) ApiGroupOutPeer(im.actor.core.api.ApiGroupOutPeer) ResponseVoid(im.actor.core.api.rpc.ResponseVoid) GroupPermissions(im.actor.core.entity.GroupPermissions) KeyValueEngine(im.actor.runtime.storage.KeyValueEngine) Event(im.actor.runtime.eventbus.Event) RequestEditGroupTopic(im.actor.core.api.rpc.RequestEditGroupTopic) Promises(im.actor.runtime.promise.Promises) GroupMember(im.actor.core.entity.GroupMember) RequestLoadMembers(im.actor.core.api.rpc.RequestLoadMembers) ArrayList(java.util.ArrayList) GroupMembersSlice(im.actor.core.entity.GroupMembersSlice) ApiGroupOutPeer(im.actor.core.api.ApiGroupOutPeer) ApiMember(im.actor.core.api.ApiMember)

Example 4 with ApiGroupOutPeer

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

the class GroupRouter method onRequestLoadFullGroup.

private void onRequestLoadFullGroup(int gid) {
    if (requestedFullGroups.contains(gid)) {
        return;
    }
    requestedFullGroups.add(gid);
    freeze();
    groups().getValueAsync(gid).flatMap(new Function<Group, Promise<Group>>() {

        @Override
        public Promise<Group> apply(Group group) {
            if (!group.isHaveExtension()) {
                ArrayList<ApiGroupOutPeer> groups = new ArrayList<>();
                groups.add(new ApiGroupOutPeer(gid, group.getAccessHash()));
                return api(new RequestLoadFullGroups(groups)).map(r -> group.updateExt(r.getGroups().get(0)));
            } else {
                return Promise.failure(new RuntimeException("Already loaded"));
            }
        }
    }).then(r -> groups().addOrUpdateItem(r)).after((r, e) -> unfreeze());
}
Also used : ModuleContext(im.actor.core.modules.ModuleContext) RouterApplyGroups(im.actor.core.modules.groups.router.entity.RouterApplyGroups) Promise(im.actor.runtime.promise.Promise) UpdateGroupAvatarChanged(im.actor.core.api.updates.UpdateGroupAvatarChanged) RouterLoadFullGroup(im.actor.core.modules.groups.router.entity.RouterLoadFullGroup) UpdateGroupFullPermissionsChanged(im.actor.core.api.updates.UpdateGroupFullPermissionsChanged) RouterFetchMissingGroups(im.actor.core.modules.groups.router.entity.RouterFetchMissingGroups) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UpdateGroupMemberChanged(im.actor.core.api.updates.UpdateGroupMemberChanged) ApiMapValue(im.actor.core.api.ApiMapValue) PromisesArray(im.actor.runtime.promise.PromisesArray) UpdateGroupMemberAdminChanged(im.actor.core.api.updates.UpdateGroupMemberAdminChanged) UpdateGroupTitleChanged(im.actor.core.api.updates.UpdateGroupTitleChanged) UpdateGroupTopicChanged(im.actor.core.api.updates.UpdateGroupTopicChanged) RouterInt(im.actor.core.modules.messaging.router.RouterInt) RouterGroupUpdate(im.actor.core.modules.groups.router.entity.RouterGroupUpdate) UpdateGroupMemberDiff(im.actor.core.api.updates.UpdateGroupMemberDiff) Tuple2(im.actor.runtime.function.Tuple2) ApiGroup(im.actor.core.api.ApiGroup) UpdateGroupDeleted(im.actor.core.api.updates.UpdateGroupDeleted) Void(im.actor.runtime.actors.messages.Void) UpdateGroupOwnerChanged(im.actor.core.api.updates.UpdateGroupOwnerChanged) Verified(im.actor.runtime.annotations.Verified) ApiMember(im.actor.core.api.ApiMember) Group(im.actor.core.entity.Group) UpdateGroupAboutChanged(im.actor.core.api.updates.UpdateGroupAboutChanged) UpdateGroupFullExtChanged(im.actor.core.api.updates.UpdateGroupFullExtChanged) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ModuleActor(im.actor.core.modules.ModuleActor) UpdateGroupPermissionsChanged(im.actor.core.api.updates.UpdateGroupPermissionsChanged) UpdateGroupMembersCountChanged(im.actor.core.api.updates.UpdateGroupMembersCountChanged) UpdateGroupMembersBecameAsync(im.actor.core.api.updates.UpdateGroupMembersBecameAsync) ApiGroupOutPeer(im.actor.core.api.ApiGroupOutPeer) ApiAvatar(im.actor.core.api.ApiAvatar) UpdateGroupHistoryShared(im.actor.core.api.updates.UpdateGroupHistoryShared) UpdateGroupShortNameChanged(im.actor.core.api.updates.UpdateGroupShortNameChanged) Function(im.actor.runtime.function.Function) RequestLoadFullGroups(im.actor.core.api.rpc.RequestLoadFullGroups) UpdateGroupExtChanged(im.actor.core.api.updates.UpdateGroupExtChanged) Update(im.actor.core.network.parser.Update) UpdateGroupMembersUpdated(im.actor.core.api.updates.UpdateGroupMembersUpdated) RouterLoadFullGroup(im.actor.core.modules.groups.router.entity.RouterLoadFullGroup) ApiGroup(im.actor.core.api.ApiGroup) Group(im.actor.core.entity.Group) Promise(im.actor.runtime.promise.Promise) RequestLoadFullGroups(im.actor.core.api.rpc.RequestLoadFullGroups) ArrayList(java.util.ArrayList) ApiGroupOutPeer(im.actor.core.api.ApiGroupOutPeer)

Example 5 with ApiGroupOutPeer

use of im.actor.core.api.ApiGroupOutPeer 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)7 ModuleContext (im.actor.core.modules.ModuleContext)6 Group (im.actor.core.entity.Group)5 ModuleActor (im.actor.core.modules.ModuleActor)5 Void (im.actor.runtime.actors.messages.Void)5 ArrayList (java.util.ArrayList)5 Promise (im.actor.runtime.promise.Promise)4 HashMap (java.util.HashMap)4 List (java.util.List)4 ApiUserOutPeer (im.actor.core.api.ApiUserOutPeer)3 UpdateGroupAvatarChanged (im.actor.core.api.updates.UpdateGroupAvatarChanged)3 ApiSupportConfiguration (im.actor.core.modules.api.ApiSupportConfiguration)3 RandomUtils (im.actor.core.util.RandomUtils)3 Consumer (im.actor.runtime.function.Consumer)3 Function (im.actor.runtime.function.Function)3 PromisesArray (im.actor.runtime.promise.PromisesArray)3 ApiFileLocation (im.actor.core.api.ApiFileLocation)2 ApiGroup (im.actor.core.api.ApiGroup)2 ApiMember (im.actor.core.api.ApiMember)2 ResponseVoid (im.actor.core.api.rpc.ResponseVoid)2