Search in sources :

Example 1 with ApiMember

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

the class Group method editMemberChangedAdmin.

public Group editMemberChangedAdmin(int uid, Boolean isAdmin) {
    if (getWrappedExt() != null) {
        ApiGroupFull e = getWrappedExt();
        ArrayList<ApiMember> nMembers = new ArrayList<>(e.getMembers());
        for (int i = 0; i < nMembers.size(); i++) {
            ApiMember m = nMembers.get(i);
            if (m.getUid() == uid) {
                nMembers.remove(m);
                nMembers.add(i, new ApiMember(m.getUid(), m.getInviterUid(), m.getDate(), isAdmin));
                break;
            }
        }
        ApiGroupFull fullExt = new ApiGroupFull(e.getId(), e.getCreateDate(), e.getOwnerUid(), nMembers, e.getTheme(), e.getAbout(), e.getExt(), e.isAsyncMembers(), e.isSharedHistory(), e.getShortName(), e.getPermissions());
        fullExt.setUnmappedObjects(e.getUnmappedObjects());
        return new Group(getWrapped(), fullExt);
    } else {
        return this;
    }
}
Also used : ApiGroup(im.actor.core.api.ApiGroup) ArrayList(java.util.ArrayList) ApiGroupFull(im.actor.core.api.ApiGroupFull) ApiMember(im.actor.core.api.ApiMember)

Example 2 with ApiMember

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

the class Group method applyWrapped.

@Override
protected void applyWrapped(@NotNull ApiGroup wrapped, @Nullable ApiGroupFull ext) {
    this.groupId = wrapped.getId();
    this.accessHash = wrapped.getAccessHash();
    this.title = wrapped.getTitle();
    this.avatar = wrapped.getAvatar() != null ? new Avatar(wrapped.getAvatar()) : null;
    this.isHidden = wrapped.isHidden() != null ? wrapped.isHidden() : false;
    this.membersCount = wrapped.getMembersCount() != null ? wrapped.getMembersCount() : 0;
    this.isMember = wrapped.isMember() != null ? wrapped.isMember() : true;
    this.isDeleted = wrapped.isDeleted() != null ? wrapped.isDeleted() : false;
    this.ext = wrapped.getExt();
    if (wrapped.getGroupType() == null) {
        this.groupType = GroupType.GROUP;
    } else {
        switch(wrapped.getGroupType()) {
            case CHANNEL:
                this.groupType = GroupType.CHANNEL;
                break;
            case GROUP:
                this.groupType = GroupType.GROUP;
                break;
            default:
            case UNSUPPORTED_VALUE:
                this.groupType = GroupType.OTHER;
                break;
        }
    }
    long permissions = 0;
    if (wrapped.getPermissions() != null) {
        permissions = wrapped.getPermissions();
    }
    /*
         # 0 - canSendMessage. Default is FALSE.
         # 1 - canClear. Default is FALSE.
         # 2 - canLeave. Default is FALSE.
         # 3 - canDelete. Default is FALSE.
         */
    this.isCanSendMessage = BitMaskUtil.getBitValue(permissions, ApiGroupPermissions.SEND_MESSAGE);
    this.isCanClear = BitMaskUtil.getBitValue(permissions, ApiGroupPermissions.CLEAR);
    this.isCanLeave = BitMaskUtil.getBitValue(permissions, ApiGroupPermissions.LEAVE);
    this.isCanDelete = BitMaskUtil.getBitValue(permissions, ApiGroupPermissions.DELETE);
    this.isCanJoin = BitMaskUtil.getBitValue(permissions, ApiGroupPermissions.JOIN);
    this.isCanViewInfo = BitMaskUtil.getBitValue(permissions, ApiGroupPermissions.VIEW_INFO);
    if (ext != null) {
        this.haveExtension = true;
        this.ownerId = ext.getOwnerUid();
        this.about = ext.getAbout();
        this.topic = ext.getTheme();
        this.shortName = ext.getShortName();
        this.isAsyncMembers = ext.isAsyncMembers() != null ? ext.isAsyncMembers() : false;
        this.isSharedHistory = ext.isSharedHistory() != null ? ext.isSharedHistory() : false;
        /*
             # 0 - canEditInfo. Default is FALSE.
             # 1 - canViewMembers. Default is FALSE.
             # 2 - canInviteMembers. Default is FALSE.
             # 3 - canInviteViaLink. Default is FALSE.
             # 4 - canCall. Default is FALSE.
             # 5 - canEditAdminSettings. Default is FALSE.
             # 6 - canViewAdmins. Default is FALSE.
             # 7 - canEditAdmins. Default is FALSE.
             # 8 - canKickInvited. Default is FALSE.
             # 9 - canKickAnyone. Default is FALSE.
             # 10 - canEditForeign. Default is FALSE.
             # 11 - canDeleteForeign. Default is FALSE.
             */
        long fullPermissions = 0;
        if (ext.getPermissions() != null) {
            fullPermissions = ext.getPermissions();
        }
        this.isCanEditInfo = BitMaskUtil.getBitValue(fullPermissions, ApiGroupFullPermissions.EDIT_INFO);
        this.isCanViewMembers = BitMaskUtil.getBitValue(fullPermissions, ApiGroupFullPermissions.VIEW_MEMBERS);
        this.isCanInviteMembers = BitMaskUtil.getBitValue(fullPermissions, ApiGroupFullPermissions.INVITE_MEMBERS);
        this.isCanInviteViaLink = BitMaskUtil.getBitValue(fullPermissions, ApiGroupFullPermissions.INVITE_VIA_LINK);
        this.isCanCall = BitMaskUtil.getBitValue(fullPermissions, ApiGroupFullPermissions.CALL);
        this.isCanEditAdministration = BitMaskUtil.getBitValue(fullPermissions, ApiGroupFullPermissions.EDIT_ADMIN_SETTINGS);
        this.isCanViewAdmins = BitMaskUtil.getBitValue(fullPermissions, ApiGroupFullPermissions.VIEW_ADMINS);
        this.isCanEditAdmins = BitMaskUtil.getBitValue(fullPermissions, ApiGroupFullPermissions.EDIT_ADMINS);
        this.isCanKickInvited = BitMaskUtil.getBitValue(fullPermissions, ApiGroupFullPermissions.KICK_INVITED);
        this.isCanKickAnyone = BitMaskUtil.getBitValue(fullPermissions, ApiGroupFullPermissions.KICK_ANYONE);
        this.isCanEditForeign = BitMaskUtil.getBitValue(fullPermissions, ApiGroupFullPermissions.EDIT_FOREIGN);
        this.isCanDeleteForeign = BitMaskUtil.getBitValue(fullPermissions, ApiGroupFullPermissions.DELETE_FOREIGN);
        this.members = new ArrayList<>();
        for (ApiMember m : ext.getMembers()) {
            this.members.add(new GroupMember(m.getUid(), m.getInviterUid(), m.getDate(), m.isAdmin() != null ? m.isAdmin() : false));
        }
    } else {
        this.haveExtension = false;
        this.ownerId = 0;
        this.about = null;
        this.topic = null;
        this.shortName = null;
        this.members = new ArrayList<>();
        this.isAsyncMembers = false;
        this.isCanViewMembers = false;
        this.isCanInviteMembers = false;
        this.isSharedHistory = false;
        this.isCanEditInfo = false;
        this.isCanEditAdministration = false;
        this.isCanViewAdmins = false;
        this.isCanEditAdmins = false;
        this.isCanInviteViaLink = false;
        this.isCanKickInvited = false;
        this.isCanKickAnyone = false;
        this.isCanEditForeign = false;
        this.isCanDeleteForeign = false;
    }
}
Also used : ApiMember(im.actor.core.api.ApiMember) ApiAvatar(im.actor.core.api.ApiAvatar)

Example 3 with ApiMember

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

the class UpdateValidator method isCausesInvalidation.

public boolean isCausesInvalidation(Update update) {
    HashSet<Integer> users = new HashSet<>();
    HashSet<Integer> groups = new HashSet<>();
    if (update instanceof UpdateMessage) {
        UpdateMessage updateMessage = (UpdateMessage) update;
        users.add(updateMessage.getSenderUid());
        if (updateMessage.getPeer().getType() == ApiPeerType.GROUP) {
            groups.add(updateMessage.getPeer().getId());
        }
        if (updateMessage.getPeer().getType() == ApiPeerType.PRIVATE) {
            users.add(updateMessage.getPeer().getId());
        }
    } else if (update instanceof UpdateContactRegistered) {
        UpdateContactRegistered contactRegistered = (UpdateContactRegistered) update;
        users.add(contactRegistered.getUid());
    } else if (update instanceof UpdateContactsAdded) {
        users.addAll(((UpdateContactsAdded) update).getUids());
    } else if (update instanceof UpdateContactsRemoved) {
        users.addAll(((UpdateContactsRemoved) update).getUids());
    } else if (update instanceof UpdateUserLocalNameChanged) {
        UpdateUserLocalNameChanged localNameChanged = (UpdateUserLocalNameChanged) update;
        users.add(localNameChanged.getUid());
    } else if (update instanceof UpdateChatGroupsChanged) {
        UpdateChatGroupsChanged changed = (UpdateChatGroupsChanged) update;
        for (ApiDialogGroup group : changed.getDialogs()) {
            for (ApiDialogShort dialog : group.getDialogs()) {
                if (dialog.getPeer().getType() == ApiPeerType.PRIVATE) {
                    users.add(dialog.getPeer().getId());
                } else if (dialog.getPeer().getType() == ApiPeerType.GROUP) {
                    groups.add(dialog.getPeer().getId());
                }
            }
        }
    } else if (update instanceof UpdateGroupMemberChanged) {
        UpdateGroupMemberChanged memberChanged = (UpdateGroupMemberChanged) update;
        groups.add(memberChanged.getGroupId());
    } else if (update instanceof UpdateGroupMemberDiff) {
        UpdateGroupMemberDiff diff = (UpdateGroupMemberDiff) update;
        groups.add(diff.getGroupId());
        for (Integer u : diff.getRemovedUsers()) {
            users.add(u);
        }
        for (ApiMember m : diff.getAddedMembers()) {
            users.add(m.getInviterUid());
            users.add(m.getUid());
        }
    } else if (update instanceof UpdateGroupMembersUpdated) {
        UpdateGroupMembersUpdated u = (UpdateGroupMembersUpdated) update;
        groups.add(u.getGroupId());
        for (ApiMember m : u.getMembers()) {
            users.add(m.getInviterUid());
            users.add(m.getUid());
        }
    } else if (update instanceof UpdateGroupMemberAdminChanged) {
        UpdateGroupMemberAdminChanged u = (UpdateGroupMemberAdminChanged) update;
        users.add(u.getUserId());
        groups.add(u.getGroupId());
    } else if (update instanceof UpdateGroupMembersCountChanged) {
        UpdateGroupMembersCountChanged countChanged = (UpdateGroupMembersCountChanged) update;
        groups.add(countChanged.getGroupId());
    } else if (update instanceof UpdateGroupOwnerChanged) {
        UpdateGroupOwnerChanged ownerChanged = (UpdateGroupOwnerChanged) update;
        groups.add(ownerChanged.getGroupId());
        users.add(ownerChanged.getUserId());
    } else if (update instanceof UpdateGroupFullExtChanged) {
        UpdateGroupFullExtChanged fullExtChanged = (UpdateGroupFullExtChanged) update;
        groups.add(fullExtChanged.getGroupId());
    } else if (update instanceof UpdateGroupExtChanged) {
        UpdateGroupExtChanged extChanged = (UpdateGroupExtChanged) update;
        groups.add(extChanged.getGroupId());
    }
    if (!hasUsers(users)) {
        return true;
    }
    if (!hasGroups(groups)) {
        return true;
    }
    return false;
}
Also used : UpdateContactsAdded(im.actor.core.api.updates.UpdateContactsAdded) UpdateGroupExtChanged(im.actor.core.api.updates.UpdateGroupExtChanged) UpdateMessage(im.actor.core.api.updates.UpdateMessage) UpdateGroupMemberChanged(im.actor.core.api.updates.UpdateGroupMemberChanged) UpdateContactRegistered(im.actor.core.api.updates.UpdateContactRegistered) UpdateGroupFullExtChanged(im.actor.core.api.updates.UpdateGroupFullExtChanged) UpdateGroupMemberDiff(im.actor.core.api.updates.UpdateGroupMemberDiff) ApiMember(im.actor.core.api.ApiMember) UpdateChatGroupsChanged(im.actor.core.api.updates.UpdateChatGroupsChanged) UpdateGroupMemberAdminChanged(im.actor.core.api.updates.UpdateGroupMemberAdminChanged) UpdateGroupMembersCountChanged(im.actor.core.api.updates.UpdateGroupMembersCountChanged) UpdateUserLocalNameChanged(im.actor.core.api.updates.UpdateUserLocalNameChanged) UpdateGroupOwnerChanged(im.actor.core.api.updates.UpdateGroupOwnerChanged) UpdateContactsRemoved(im.actor.core.api.updates.UpdateContactsRemoved) ApiDialogGroup(im.actor.core.api.ApiDialogGroup) UpdateGroupMembersUpdated(im.actor.core.api.updates.UpdateGroupMembersUpdated) HashSet(java.util.HashSet) ApiDialogShort(im.actor.core.api.ApiDialogShort)

Example 4 with ApiMember

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

the class Group method editMembers.

public Group editMembers(List<ApiMember> added, List<Integer> removed, int count) {
    ApiGroupFull fullExt = null;
    if (getWrappedExt() != null) {
        ApiGroupFull e = getWrappedExt();
        ArrayList<ApiMember> nMembers = new ArrayList<>(e.getMembers());
        // Remove members
        for (Integer i : removed) {
            for (ApiMember m : nMembers) {
                if (m.getUid() == i) {
                    nMembers.remove(m);
                    break;
                }
            }
        }
        // Adding members
        for (ApiMember a : added) {
            for (ApiMember m : nMembers) {
                if (m.getUid() == a.getUid()) {
                    nMembers.remove(m);
                    break;
                }
            }
            nMembers.add(a);
        }
        fullExt = new ApiGroupFull(e.getId(), e.getCreateDate(), e.getOwnerUid(), nMembers, e.getTheme(), e.getAbout(), e.getExt(), e.isAsyncMembers(), e.isSharedHistory(), e.getShortName(), e.getPermissions());
        fullExt.setUnmappedObjects(e.getUnmappedObjects());
    }
    ApiGroup w = getWrapped();
    ApiGroup res = new ApiGroup(w.getId(), w.getAccessHash(), w.getTitle(), w.getAvatar(), count, w.isMember(), w.isHidden(), w.getGroupType(), w.getPermissions(), w.isDeleted(), w.getExt());
    return new Group(res, fullExt);
}
Also used : ApiGroup(im.actor.core.api.ApiGroup) ApiGroup(im.actor.core.api.ApiGroup) ArrayList(java.util.ArrayList) ApiGroupFull(im.actor.core.api.ApiGroupFull) ApiMember(im.actor.core.api.ApiMember)

Example 5 with ApiMember

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

Aggregations

ApiMember (im.actor.core.api.ApiMember)5 ArrayList (java.util.ArrayList)3 ApiGroup (im.actor.core.api.ApiGroup)2 ApiGroupFull (im.actor.core.api.ApiGroupFull)2 ApiAdminSettings (im.actor.core.api.ApiAdminSettings)1 ApiAvatar (im.actor.core.api.ApiAvatar)1 ApiDialogGroup (im.actor.core.api.ApiDialogGroup)1 ApiDialogShort (im.actor.core.api.ApiDialogShort)1 ApiGroupOutPeer (im.actor.core.api.ApiGroupOutPeer)1 ApiGroupType (im.actor.core.api.ApiGroupType)1 ApiOutPeer (im.actor.core.api.ApiOutPeer)1 ApiPeerType (im.actor.core.api.ApiPeerType)1 ApiUserOutPeer (im.actor.core.api.ApiUserOutPeer)1 RequestCreateGroup (im.actor.core.api.rpc.RequestCreateGroup)1 RequestDeleteGroup (im.actor.core.api.rpc.RequestDeleteGroup)1 RequestDismissUserAdmin (im.actor.core.api.rpc.RequestDismissUserAdmin)1 RequestEditGroupAbout (im.actor.core.api.rpc.RequestEditGroupAbout)1 RequestEditGroupShortName (im.actor.core.api.rpc.RequestEditGroupShortName)1 RequestEditGroupTitle (im.actor.core.api.rpc.RequestEditGroupTitle)1 RequestEditGroupTopic (im.actor.core.api.rpc.RequestEditGroupTopic)1