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;
}
}
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;
}
}
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;
}
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);
}
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());
});
}
Aggregations