Search in sources :

Example 1 with ConversationState

use of im.actor.core.entity.ConversationState in project actor-platform by actorapp.

the class RouterActor method onChatDelete.

private Promise<Void> onChatDelete(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().onChatDelete(peer).chain(aVoid -> onChatDropCache(peer));
}
Also used : ConversationState(im.actor.core.entity.ConversationState)

Example 2 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 3 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 4 with ConversationState

use of im.actor.core.entity.ConversationState in project actor-platform by actorapp.

the class RouterActor method onMessageDeleted.

// 
// Message Deletions
// 
private Promise<Void> onMessageDeleted(Peer peer, List<Long> rids) {
    // Delete Messages
    conversation(peer).removeItems(JavaUtil.unbox(rids));
    updateChatState(peer);
    Message head = conversation(peer).getHeadValue();
    if (head != null) {
        ConversationState state = conversationStates.getValue(peer.getUnuqueId());
        state = state.changeInReadDate(head.getSortDate()).changeOutSendDate(head.getSortDate());
        conversationStates.addOrUpdateItem(state);
        if (head.getMessageState() == MessageState.PENDING) {
            head = null;
        }
    }
    return getDialogsRouter().onMessageDeleted(peer, head);
}
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 5 with ConversationState

use of im.actor.core.entity.ConversationState in project actor-platform by actorapp.

the class RouterActor method onActiveDialogsChanged.

// 
// Active Dialogs
// 
private void onActiveDialogsChanged(List<ApiDialogGroup> dialogs, boolean showArchived, boolean showInvite) {
    // 
    // Updating Counters
    // 
    ArrayList<ConversationState> convStates = new ArrayList<>();
    for (ApiDialogGroup g : dialogs) {
        for (ApiDialogShort s : g.getDialogs()) {
            Peer peer = convert(s.getPeer());
            ConversationState state = conversationStates.getValue(peer.getUnuqueId());
            boolean isChanged = false;
            if (state.getUnreadCount() != s.getCounter() && !isConversationVisible(peer)) {
                state = state.changeCounter(s.getCounter());
                isChanged = true;
            }
            if (state.getInMaxMessageDate() < s.getDate()) {
                state = state.changeInMaxDate(s.getDate());
                isChanged = true;
            }
            if (isChanged) {
                convStates.add(state);
            }
        }
    }
    conversationStates.addOrUpdateItems(convStates);
    // 
    // Updating storage
    // 
    activeDialogStorage.setHaveArchived(showArchived);
    activeDialogStorage.setShowInvite(showInvite);
    activeDialogStorage.setLoaded(true);
    activeDialogStorage.getGroups().clear();
    for (ApiDialogGroup g : dialogs) {
        ArrayList<Peer> peers = new ArrayList<>();
        for (ApiDialogShort s : g.getDialogs()) {
            Peer peer = convert(s.getPeer());
            peers.add(peer);
        }
        activeDialogStorage.getGroups().add(new ActiveDialogGroup(g.getKey(), g.getTitle(), peers));
    }
    context().getStorageModule().getBlobStorage().addOrUpdateItem(AbsModule.BLOB_DIALOGS_ACTIVE, activeDialogStorage.toByteArray());
    // 
    // Notify VM
    // 
    notifyActiveDialogsVM();
    // 
    // Unstash all messages after initial loading
    // 
    unstashAll();
}
Also used : Peer(im.actor.core.entity.Peer) ArrayList(java.util.ArrayList) ActiveDialogGroup(im.actor.core.modules.messaging.router.entity.ActiveDialogGroup) ConversationState(im.actor.core.entity.ConversationState) ApiDialogGroup(im.actor.core.api.ApiDialogGroup) ApiDialogShort(im.actor.core.api.ApiDialogShort)

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