Search in sources :

Example 1 with UpdateGroupOwnerChanged

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

Aggregations

ApiDialogGroup (im.actor.core.api.ApiDialogGroup)1 ApiDialogShort (im.actor.core.api.ApiDialogShort)1 ApiMember (im.actor.core.api.ApiMember)1 UpdateChatGroupsChanged (im.actor.core.api.updates.UpdateChatGroupsChanged)1 UpdateContactRegistered (im.actor.core.api.updates.UpdateContactRegistered)1 UpdateContactsAdded (im.actor.core.api.updates.UpdateContactsAdded)1 UpdateContactsRemoved (im.actor.core.api.updates.UpdateContactsRemoved)1 UpdateGroupExtChanged (im.actor.core.api.updates.UpdateGroupExtChanged)1 UpdateGroupFullExtChanged (im.actor.core.api.updates.UpdateGroupFullExtChanged)1 UpdateGroupMemberAdminChanged (im.actor.core.api.updates.UpdateGroupMemberAdminChanged)1 UpdateGroupMemberChanged (im.actor.core.api.updates.UpdateGroupMemberChanged)1 UpdateGroupMemberDiff (im.actor.core.api.updates.UpdateGroupMemberDiff)1 UpdateGroupMembersCountChanged (im.actor.core.api.updates.UpdateGroupMembersCountChanged)1 UpdateGroupMembersUpdated (im.actor.core.api.updates.UpdateGroupMembersUpdated)1 UpdateGroupOwnerChanged (im.actor.core.api.updates.UpdateGroupOwnerChanged)1 UpdateMessage (im.actor.core.api.updates.UpdateMessage)1 UpdateUserLocalNameChanged (im.actor.core.api.updates.UpdateUserLocalNameChanged)1 HashSet (java.util.HashSet)1