Search in sources :

Example 1 with UpdateCountersChanged

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

Aggregations

ApiDialogGroup (im.actor.core.api.ApiDialogGroup)1 ApiDialogShort (im.actor.core.api.ApiDialogShort)1 UpdateChatGroupsChanged (im.actor.core.api.updates.UpdateChatGroupsChanged)1 UpdateCountersChanged (im.actor.core.api.updates.UpdateCountersChanged)1 UpdateMessage (im.actor.core.api.updates.UpdateMessage)1 UpdateMessageRead (im.actor.core.api.updates.UpdateMessageRead)1 UpdateMessageReadByMe (im.actor.core.api.updates.UpdateMessageReadByMe)1 UpdateMessageReceived (im.actor.core.api.updates.UpdateMessageReceived)1 Update (im.actor.core.network.parser.Update)1 ArrayList (java.util.ArrayList)1