use of im.actor.core.entity.ConversationState in project actor-platform by actorapp.
the class RouterActor method updateChatState.
private void updateChatState(Peer peer) {
boolean isEmpty = conversation(peer).isEmpty();
ConversationState state = conversationStates.getValue(peer.getUnuqueId());
if (state.isEmpty() != isEmpty) {
state = state.changeIsEmpty(isEmpty);
}
conversationStates.addOrUpdateItem(state);
}
use of im.actor.core.entity.ConversationState in project actor-platform by actorapp.
the class RouterActor method onMessageReadByMe.
private Promise<Void> onMessageReadByMe(Peer peer, long date, int counter) {
ConversationState state = conversationStates.getValue(peer.getUnuqueId());
if (state.getInReadDate() >= date) {
return Promise.success(null);
}
state = state.changeCounter(counter).changeInReadDate(date);
conversationStates.addOrUpdateItem(state);
Promise<Void> res = getDialogsRouter().onCounterChanged(peer, counter);
notifyActiveDialogsVM();
context().getNotificationsModule().onOwnRead(peer, date);
return res;
}
use of im.actor.core.entity.ConversationState in project actor-platform by actorapp.
the class RouterActor method onMessageReceived.
private Promise<Void> onMessageReceived(Peer peer, long date) {
ConversationState state = conversationStates.getValue(peer.getUnuqueId());
if (date > state.getOutReceiveDate()) {
state = state.changeOutReceiveDate(date);
conversationStates.addOrUpdateItem(state);
return getDialogsRouter().onPeerReceiveChanged(peer, date);
} else {
return Promise.success(null);
}
}
use of im.actor.core.entity.ConversationState in project actor-platform by actorapp.
the class RouterActor method onNewMessages.
//
// Incoming Messages
//
private Promise<Void> onNewMessages(Peer peer, List<Message> messages) {
assertTrue(messages.size() != 0);
boolean isConversationVisible = isConversationVisible(peer);
//
// Collecting Information
//
ConversationState state = conversationStates.getValue(peer.getUnuqueId());
Message topMessage = null;
int unreadCount = 0;
long maxInReadDate = 0;
long maxInDate = 0;
for (Message m : messages) {
if (topMessage == null || topMessage.getSortDate() < m.getSortDate()) {
topMessage = m;
}
if (m.getSenderId() != myUid()) {
if (m.getSortDate() > state.getInReadDate()) {
unreadCount++;
maxInReadDate = Math.max(maxInReadDate, m.getSortDate());
}
if (m.getSortDate() > state.getInMaxMessageDate()) {
maxInDate = Math.max(maxInDate, m.getSortDate());
}
}
}
//
// Writing to Conversation
//
conversation(peer).addOrUpdateItems(messages);
//
// Update Chat State
//
updateChatState(peer);
//
// Updating Counter
//
boolean isRead = false;
if (unreadCount != 0) {
if (isConversationVisible) {
// Auto Reading message
boolean needUpdateState = false;
if (maxInReadDate > 0) {
if (state.getInReadDate() < maxInReadDate) {
state = state.changeInReadDate(maxInReadDate);
}
state = state.changeCounter(0);
context().getMessagesModule().getPlainReadActor().send(new CursorReaderActor.MarkRead(peer, maxInReadDate));
context().getNotificationsModule().onOwnRead(peer, maxInReadDate);
isRead = true;
needUpdateState = true;
}
if (state.getInMaxMessageDate() < maxInDate) {
state.changeInMaxDate(maxInDate);
needUpdateState = true;
}
if (needUpdateState) {
conversationStates.addOrUpdateItem(state);
}
} else {
// Updating counter
state = state.changeCounter(state.getUnreadCount() + unreadCount);
if (state.getInMaxMessageDate() < maxInDate) {
state = state.changeInMaxDate(maxInDate);
}
conversationStates.addOrUpdateItem(state);
notifyActiveDialogsVM();
}
}
//
if (maxInReadDate > 0 && !isRead) {
context().getMessagesModule().getPlainReceiverActor().send(new CursorReceiverActor.MarkReceived(peer, maxInReadDate));
}
//
// Updating Dialog List
//
Promise<Void> res = getDialogsRouter().onMessage(peer, topMessage, state.getUnreadCount());
//
if (!isConversationVisible) {
for (Message m : messages) {
if (m.getSenderId() != myUid()) {
boolean hasCurrentMention = false;
if (m.getContent() instanceof TextContent) {
if (((TextContent) m.getContent()).getMentions().contains(myUid())) {
hasCurrentMention = true;
}
}
int messagesCount = 0;
int dialogsCount = 0;
for (Peer activePeer : activeDialogStorage.getAllPeers()) {
int activeDialogueUnreadCount = conversationStates.getValue(activePeer.getUnuqueId()).getUnreadCount();
if (activeDialogueUnreadCount > 0) {
dialogsCount++;
messagesCount += activeDialogueUnreadCount;
}
}
context().getNotificationsModule().onInMessage(peer, m.getSenderId(), m.getSortDate(), ContentDescription.fromContent(m.getContent()), hasCurrentMention, messagesCount, dialogsCount);
}
}
}
return res;
}
Aggregations