Search in sources :

Example 1 with UpdateChatGroupsChanged

use of im.actor.core.api.updates.UpdateChatGroupsChanged 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 2 with UpdateChatGroupsChanged

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

the class GetDiffCombiner method buildDiff.

public static CombinedDifference buildDiff(List<Update> updates) {
    CombinedDifference res = new CombinedDifference();
    UpdateChatGroupsChanged chatGroupsChanged = null;
    for (Update u : updates) {
        if (u instanceof UpdateMessage) {
            res.putMessage((UpdateMessage) u);
        } else if (u instanceof UpdateMessageRead) {
            UpdateMessageRead read = (UpdateMessageRead) u;
            res.putRead(convert(read.getPeer()), read.getStartDate());
        } else if (u instanceof UpdateMessageReceived) {
            UpdateMessageReceived received = (UpdateMessageReceived) u;
            res.putReceived(convert(received.getPeer()), received.getStartDate());
        } else if (u instanceof UpdateMessageReadByMe) {
            UpdateMessageReadByMe readByMe = (UpdateMessageReadByMe) u;
            int counter = 0;
            if (readByMe.getUnreadCounter() != null) {
                counter = readByMe.getUnreadCounter();
            }
            res.putReadByMe(convert(readByMe.getPeer()), readByMe.getStartDate(), counter);
        } else if (u instanceof UpdateCountersChanged) {
        // Ignore
        } else if (u instanceof UpdateChatGroupsChanged) {
            chatGroupsChanged = (UpdateChatGroupsChanged) u;
        } else {
            res.getOtherUpdates().add(u);
        }
    }
    // Handling reordering of updates
    if (chatGroupsChanged != null) {
        ArrayList<ApiDialogGroup> dialogs = new ArrayList<>();
        for (ApiDialogGroup dg : chatGroupsChanged.getDialogs()) {
            ArrayList<ApiDialogShort> dialogShorts = new ArrayList<>();
            for (ApiDialogShort ds : dg.getDialogs()) {
                CombinedDifference.ReadByMeValue val = res.getReadByMe().get(convert(ds.getPeer()));
                if (val != null) {
                    dialogShorts.add(new ApiDialogShort(ds.getPeer(), val.getCounter(), ds.getDate()));
                } else {
                    dialogShorts.add(ds);
                }
            }
            dialogs.add(new ApiDialogGroup(dg.getTitle(), dg.getKey(), dialogShorts));
        }
        res.getOtherUpdates().add(new UpdateChatGroupsChanged(dialogs));
    }
    return res;
}
Also used : UpdateMessage(im.actor.core.api.updates.UpdateMessage) ArrayList(java.util.ArrayList) UpdateMessageReadByMe(im.actor.core.api.updates.UpdateMessageReadByMe) UpdateCountersChanged(im.actor.core.api.updates.UpdateCountersChanged) UpdateMessageReceived(im.actor.core.api.updates.UpdateMessageReceived) Update(im.actor.core.network.parser.Update) UpdateChatGroupsChanged(im.actor.core.api.updates.UpdateChatGroupsChanged) UpdateMessageRead(im.actor.core.api.updates.UpdateMessageRead) ApiDialogGroup(im.actor.core.api.ApiDialogGroup) ApiDialogShort(im.actor.core.api.ApiDialogShort)

Example 3 with UpdateChatGroupsChanged

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

the class RouterActor method onUpdate.

//
// Messages
//
public Promise<Void> onUpdate(Update update) {
    if (update instanceof UpdateMessage) {
        UpdateMessage msg = (UpdateMessage) update;
        Peer peer = convert(msg.getPeer());
        AbsContent msgContent = AbsContent.fromMessage(msg.getMessage());
        Message message = new Message(msg.getRid(), msg.getDate(), msg.getDate(), msg.getSenderUid(), myUid() == msg.getSenderUid() ? MessageState.SENT : MessageState.UNKNOWN, msgContent);
        ArrayList<Message> messages = new ArrayList<>();
        messages.add(message);
        return onNewMessages(peer, messages);
    } else if (update instanceof UpdateMessageSent) {
        UpdateMessageSent messageSent = (UpdateMessageSent) update;
        Peer peer = convert(messageSent.getPeer());
        if (isValidPeer(peer)) {
            // Notify Sender
            context().getMessagesModule().getSendMessageActor().send(new SenderActor.MessageSent(peer, messageSent.getRid()));
            return onOutgoingSent(peer, messageSent.getRid(), messageSent.getDate());
        }
        return Promise.success(null);
    } else if (update instanceof UpdateMessageRead) {
        UpdateMessageRead read = (UpdateMessageRead) update;
        Peer peer = convert(read.getPeer());
        if (isValidPeer(peer)) {
            return onMessageRead(peer, read.getStartDate());
        }
        return Promise.success(null);
    } else if (update instanceof UpdateMessageReadByMe) {
        UpdateMessageReadByMe readByMe = (UpdateMessageReadByMe) update;
        Peer peer = convert(readByMe.getPeer());
        if (isValidPeer(peer)) {
            int counter = 0;
            if (readByMe.getUnreadCounter() != null) {
                counter = readByMe.getUnreadCounter();
            }
            return onMessageReadByMe(peer, readByMe.getStartDate(), counter);
        }
        return Promise.success(null);
    } else if (update instanceof UpdateMessageReceived) {
        UpdateMessageReceived received = (UpdateMessageReceived) update;
        Peer peer = convert(received.getPeer());
        if (isValidPeer(peer)) {
            return onMessageReceived(peer, received.getStartDate());
        }
        return Promise.success(null);
    } else if (update instanceof UpdateChatDelete) {
        UpdateChatDelete delete = (UpdateChatDelete) update;
        Peer peer = convert(delete.getPeer());
        if (isValidPeer(peer)) {
            return onChatDelete(peer);
        }
        return Promise.success(null);
    } else if (update instanceof UpdateChatClear) {
        UpdateChatClear clear = (UpdateChatClear) update;
        Peer peer = convert(clear.getPeer());
        if (isValidPeer(peer)) {
            return onChatClear(peer);
        }
        return Promise.success(null);
    } else if (update instanceof UpdateChatDropCache) {
        UpdateChatDropCache dropCache = (UpdateChatDropCache) update;
        Peer peer = convert(dropCache.getPeer());
        if (isValidPeer(peer)) {
            return onChatDropCache(peer);
        }
        return Promise.success(null);
    } else if (update instanceof UpdateChatGroupsChanged) {
        UpdateChatGroupsChanged chatGroupsChanged = (UpdateChatGroupsChanged) update;
        onActiveDialogsChanged(chatGroupsChanged.getDialogs(), true, true);
        return Promise.success(null);
    } else if (update instanceof UpdateMessageDelete) {
        UpdateMessageDelete delete = (UpdateMessageDelete) update;
        Peer peer = convert(delete.getPeer());
        if (isValidPeer(peer)) {
            return onMessageDeleted(peer, delete.getRids());
        }
        return Promise.success(null);
    } else if (update instanceof UpdateMessageContentChanged) {
        UpdateMessageContentChanged contentChanged = (UpdateMessageContentChanged) update;
        Peer peer = convert(contentChanged.getPeer());
        if (isValidPeer(peer)) {
            AbsContent content = AbsContent.fromMessage(contentChanged.getMessage());
            return onContentUpdate(peer, contentChanged.getRid(), content);
        }
        return Promise.success(null);
    } else if (update instanceof UpdateReactionsUpdate) {
        UpdateReactionsUpdate reactionsUpdate = (UpdateReactionsUpdate) update;
        Peer peer = convert(reactionsUpdate.getPeer());
        if (isValidPeer(peer)) {
            ArrayList<Reaction> reactions = new ArrayList<>();
            for (ApiMessageReaction r : reactionsUpdate.getReactions()) {
                reactions.add(new Reaction(r.getCode(), r.getUsers()));
            }
            return onReactionsUpdate(peer, reactionsUpdate.getRid(), reactions);
        }
        return Promise.success(null);
    }
    return Promise.success(null);
}
Also used : UpdateMessage(im.actor.core.api.updates.UpdateMessage) UpdateMessageSent(im.actor.core.api.updates.UpdateMessageSent) UpdateMessageContentChanged(im.actor.core.api.updates.UpdateMessageContentChanged) UpdateChatClear(im.actor.core.api.updates.UpdateChatClear) UpdateMessage(im.actor.core.api.updates.UpdateMessage) Message(im.actor.core.entity.Message) RouterOutgoingMessage(im.actor.core.modules.messaging.router.entity.RouterOutgoingMessage) Peer(im.actor.core.entity.Peer) ApiMessageReaction(im.actor.core.api.ApiMessageReaction) AbsContent(im.actor.core.entity.content.AbsContent) ArrayList(java.util.ArrayList) UpdateChatDelete(im.actor.core.api.updates.UpdateChatDelete) UpdateChatDropCache(im.actor.core.api.updates.UpdateChatDropCache) UpdateMessageReadByMe(im.actor.core.api.updates.UpdateMessageReadByMe) UpdateMessageReceived(im.actor.core.api.updates.UpdateMessageReceived) ApiMessageReaction(im.actor.core.api.ApiMessageReaction) Reaction(im.actor.core.entity.Reaction) UpdateChatGroupsChanged(im.actor.core.api.updates.UpdateChatGroupsChanged) UpdateMessageDelete(im.actor.core.api.updates.UpdateMessageDelete) UpdateReactionsUpdate(im.actor.core.api.updates.UpdateReactionsUpdate) UpdateMessageSent(im.actor.core.api.updates.UpdateMessageSent) UpdateMessageRead(im.actor.core.api.updates.UpdateMessageRead)

Aggregations

UpdateChatGroupsChanged (im.actor.core.api.updates.UpdateChatGroupsChanged)3 UpdateMessage (im.actor.core.api.updates.UpdateMessage)3 ApiDialogGroup (im.actor.core.api.ApiDialogGroup)2 ApiDialogShort (im.actor.core.api.ApiDialogShort)2 UpdateMessageRead (im.actor.core.api.updates.UpdateMessageRead)2 UpdateMessageReadByMe (im.actor.core.api.updates.UpdateMessageReadByMe)2 UpdateMessageReceived (im.actor.core.api.updates.UpdateMessageReceived)2 ArrayList (java.util.ArrayList)2 ApiMember (im.actor.core.api.ApiMember)1 ApiMessageReaction (im.actor.core.api.ApiMessageReaction)1 UpdateChatClear (im.actor.core.api.updates.UpdateChatClear)1 UpdateChatDelete (im.actor.core.api.updates.UpdateChatDelete)1 UpdateChatDropCache (im.actor.core.api.updates.UpdateChatDropCache)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 UpdateCountersChanged (im.actor.core.api.updates.UpdateCountersChanged)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