use of im.actor.core.api.ApiMessageReaction 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.ApiMessageReaction in project actor-platform by actorapp.
the class ConversationHistoryActor method applyHistory.
private Promise<Void> applyHistory(Peer peer, List<ApiMessageContainer> history) {
ArrayList<Message> messages = new ArrayList<>();
long maxLoadedDate = Long.MAX_VALUE;
long maxReadDate = 0;
long maxReceiveDate = 0;
for (ApiMessageContainer historyMessage : history) {
AbsContent content = AbsContent.fromMessage(historyMessage.getMessage());
MessageState state = EntityConverter.convert(historyMessage.getState());
ArrayList<Reaction> reactions = new ArrayList<>();
for (ApiMessageReaction r : historyMessage.getReactions()) {
reactions.add(new Reaction(r.getCode(), r.getUsers()));
}
messages.add(new Message(historyMessage.getRid(), historyMessage.getDate(), historyMessage.getDate(), historyMessage.getSenderUid(), state, content, reactions, 0));
maxLoadedDate = Math.min(historyMessage.getDate(), maxLoadedDate);
if (historyMessage.getState() == ApiMessageState.RECEIVED) {
maxReceiveDate = Math.max(historyMessage.getDate(), maxReceiveDate);
} else if (historyMessage.getState() == ApiMessageState.READ) {
maxReceiveDate = Math.max(historyMessage.getDate(), maxReceiveDate);
maxReadDate = Math.max(historyMessage.getDate(), maxReadDate);
}
}
boolean isEnded = history.size() < LIMIT;
// Sending updates to conversation actor
final long finalMaxLoadedDate = maxLoadedDate;
return context().getMessagesModule().getRouter().onChatHistoryLoaded(peer, messages, maxReceiveDate, maxReadDate, isEnded).map(r -> {
// Saving Internal State
if (isEnded) {
historyLoaded = true;
} else {
historyLoaded = false;
historyMaxDate = finalMaxLoadedDate;
}
preferences().putLong(KEY_LOADED_DATE, finalMaxLoadedDate);
preferences().putBool(KEY_LOADED, historyLoaded);
preferences().putBool(KEY_LOADED_INIT, true);
return r;
});
}
Aggregations