use of im.actor.core.api.updates.UpdateMessageReadByMe 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;
}
use of im.actor.core.api.updates.UpdateMessageReadByMe 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);
}
use of im.actor.core.api.updates.UpdateMessageReadByMe in project actor-platform by actorapp.
the class UpdateProcessor method applyDifferenceUpdate.
//
// Difference
//
public Promise<Void> applyDifferenceUpdate(List<Update> updates) {
CombinedDifference combinedDifference = GetDiffCombiner.buildDiff(updates);
ArrayList<Supplier<Promise<Void>>> pending = new ArrayList<>();
pending.add(() -> messagesProcessor.onDifferenceStart());
for (Peer peer : combinedDifference.getReceived().keySet()) {
long time = combinedDifference.getReceived().get(peer);
pending.add(() -> processUpdate(new UpdateMessageReceived(buildApiPeer(peer), time, 0)));
}
for (Peer peer : combinedDifference.getRead().keySet()) {
long time = combinedDifference.getRead().get(peer);
pending.add(() -> processUpdate(new UpdateMessageRead(buildApiPeer(peer), time, 0)));
}
for (Peer peer : combinedDifference.getReadByMe().keySet()) {
CombinedDifference.ReadByMeValue time = combinedDifference.getReadByMe().get(peer);
pending.add(() -> processUpdate(new UpdateMessageReadByMe(buildApiPeer(peer), time.getDate(), time.getCounter())));
}
for (Peer peer : combinedDifference.getMessages().keySet()) {
pending.add(() -> messagesProcessor.onDifferenceMessages(buildApiPeer(peer), combinedDifference.getMessages().get(peer)));
}
for (Update u : combinedDifference.getOtherUpdates()) {
pending.add(() -> processUpdate(u));
}
pending.add(() -> messagesProcessor.onDifferenceEnd());
return Promises.traverse(pending).map(v -> null);
}
Aggregations