Search in sources :

Example 6 with ConversationState

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);
}
Also used : UpdateMessage(im.actor.core.api.updates.UpdateMessage) Message(im.actor.core.entity.Message) RouterOutgoingMessage(im.actor.core.modules.messaging.router.entity.RouterOutgoingMessage) ArrayList(java.util.ArrayList) ConversationState(im.actor.core.entity.ConversationState)

Example 7 with ConversationState

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);
}
Also used : ConversationState(im.actor.core.entity.ConversationState)

Example 8 with ConversationState

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);
    }
}
Also used : UpdateMessage(im.actor.core.api.updates.UpdateMessage) Message(im.actor.core.entity.Message) RouterOutgoingMessage(im.actor.core.modules.messaging.router.entity.RouterOutgoingMessage) ConversationState(im.actor.core.entity.ConversationState)

Example 9 with ConversationState

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);
}
Also used : ConversationState(im.actor.core.entity.ConversationState)

Example 10 with ConversationState

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;
}
Also used : ConversationState(im.actor.core.entity.ConversationState) Void(im.actor.runtime.actors.messages.Void)

Aggregations

ConversationState (im.actor.core.entity.ConversationState)14 UpdateMessage (im.actor.core.api.updates.UpdateMessage)4 Message (im.actor.core.entity.Message)4 RouterOutgoingMessage (im.actor.core.modules.messaging.router.entity.RouterOutgoingMessage)4 Void (im.actor.runtime.actors.messages.Void)3 Peer (im.actor.core.entity.Peer)2 CursorReaderActor (im.actor.core.modules.messaging.actions.CursorReaderActor)2 ArrayList (java.util.ArrayList)2 ApiDialogGroup (im.actor.core.api.ApiDialogGroup)1 ApiDialogShort (im.actor.core.api.ApiDialogShort)1 TextContent (im.actor.core.entity.content.TextContent)1 CursorReceiverActor (im.actor.core.modules.messaging.actions.CursorReceiverActor)1 DialogHistory (im.actor.core.modules.messaging.history.entity.DialogHistory)1 ActiveDialogGroup (im.actor.core.modules.messaging.router.entity.ActiveDialogGroup)1