use of im.actor.core.entity.ConversationState in project actor-platform by actorapp.
the class RouterActor method onChatHistoryLoaded.
private Promise<Void> onChatHistoryLoaded(Peer peer, List<Message> messages, Long maxReadDate, Long maxReceiveDate, boolean isEnded) {
Log.d(TAG, "History Loaded");
long maxMessageDate = 0;
// Processing all new messages
ArrayList<Message> updated = new ArrayList<>();
for (Message historyMessage : messages) {
// Ignore already present messages
if (conversation(peer).getValue(historyMessage.getEngineId()) != null) {
continue;
}
updated.add(historyMessage);
if (historyMessage.getSenderId() != myUid()) {
maxMessageDate = Math.max(maxMessageDate, historyMessage.getSortDate());
}
}
// Writing messages
conversation(peer).addOrUpdateItems(updated);
// Updating conversation state
ConversationState state = conversationStates.getValue(peer.getUnuqueId());
boolean isChanged = false;
if (state.getInMaxMessageDate() < maxMessageDate) {
state = state.changeInMaxDate(maxMessageDate);
isChanged = true;
}
if (maxReadDate != null && maxReadDate != 0 && state.getOutReadDate() < maxMessageDate) {
state = state.changeOutReadDate(maxReadDate);
isChanged = true;
}
if (maxReceiveDate != null && maxReceiveDate != 0 && state.getOutReceiveDate() < maxReceiveDate) {
state = state.changeOutReceiveDate(maxReceiveDate);
isChanged = true;
}
if (state.isLoaded() != isEnded) {
state = state.changeIsLoaded(isEnded);
isChanged = true;
}
boolean isEmpty = conversation(peer).isEmpty();
if (state.isEmpty() != isEmpty) {
state = state.changeIsEmpty(isEmpty);
isChanged = true;
}
if (isChanged) {
conversationStates.addOrUpdateItem(state);
}
// Reading messages if needed
markAsReadIfNeeded(peer);
return Promise.success(null);
}
use of im.actor.core.entity.ConversationState in project actor-platform by actorapp.
the class RouterActor method onChatClear.
private Promise<Void> onChatClear(Peer peer) {
conversation(peer).clear();
ConversationState state = conversationStates.getValue(peer.getUnuqueId());
if (!state.isLoaded()) {
state = state.changeIsLoaded(true);
conversationStates.addOrUpdateItem(state);
}
updateChatState(peer);
return getDialogsRouter().onChatClear(peer);
}
use of im.actor.core.entity.ConversationState in project actor-platform by actorapp.
the class RouterActor method onOutgoingSent.
private Promise<Void> onOutgoingSent(Peer peer, long rid, long date) {
Message msg = conversation(peer).getValue(rid);
// If we have pending message
if (msg != null && (msg.getMessageState() == MessageState.PENDING)) {
// Updating message
Message updatedMsg = msg.changeAllDate(date).changeState(MessageState.SENT);
conversation(peer).addOrUpdateItem(updatedMsg);
ConversationState state = conversationStates.getValue(peer.getUnuqueId());
conversationStates.addOrUpdateItem(state.changeOutSendDate(date));
updateChatState(peer);
// Notify dialogs
return getDialogsRouter().onMessage(peer, updatedMsg, -1);
} else {
return Promise.success(null);
}
}
use of im.actor.core.entity.ConversationState in project actor-platform by actorapp.
the class RouterActor method onChatReset.
private Promise<Void> onChatReset(Peer peer) {
Log.d(TAG, "onChatReset");
conversation(peer).clear();
ConversationState state = conversationStates.getValue(peer.getUnuqueId());
state = state.changeIsLoaded(false);
conversationStates.addOrUpdateItem(state);
updateChatState(peer);
return Promise.success(null);
}
use of im.actor.core.entity.ConversationState in project actor-platform by actorapp.
the class RouterActor method onMessageRead.
//
// Read States
//
private Promise<Void> onMessageRead(Peer peer, long date) {
ConversationState state = conversationStates.getValue(peer.getUnuqueId());
boolean isChanged = false;
Promise<Void> res;
if (date > state.getOutReadDate()) {
state = state.changeOutReadDate(date);
res = getDialogsRouter().onPeerReadChanged(peer, date);
isChanged = true;
} else {
res = Promise.success(null);
}
if (date > state.getOutReceiveDate()) {
state = state.changeOutReceiveDate(date);
isChanged = true;
}
if (isChanged) {
conversationStates.addOrUpdateItem(state);
}
return res;
}
Aggregations