Search in sources :

Example 1 with DialogHistory

use of im.actor.core.modules.messaging.history.entity.DialogHistory in project actor-platform by actorapp.

the class RouterActor method onDialogHistoryLoaded.

//
// History Messages
//
private Promise<Void> onDialogHistoryLoaded(List<DialogHistory> dialogs) {
    for (DialogHistory d : dialogs) {
        ConversationState state = conversationStates.getValue(d.getPeer().getUnuqueId());
        if (d.getUnreadCount() > 0) {
            state = state.changeCounter(d.getUnreadCount()).changeInMaxDate(d.getDate());
        }
        if (d.isRead()) {
            state = state.changeOutReadDate(d.getDate()).changeOutReceiveDate(d.getDate());
        } else if (d.isReceived()) {
            state = state.changeOutReceiveDate(d.getDate());
        }
        conversationStates.addOrUpdateItem(state);
    }
    return getDialogsRouter().onHistoryLoaded(dialogs);
}
Also used : DialogHistory(im.actor.core.modules.messaging.history.entity.DialogHistory) ConversationState(im.actor.core.entity.ConversationState)

Example 2 with DialogHistory

use of im.actor.core.modules.messaging.history.entity.DialogHistory in project actor-platform by actorapp.

the class DialogsActor method onHistoryLoaded.

@Verified
private Promise<Void> onHistoryLoaded(List<DialogHistory> history) {
    ArrayList<Dialog> updated = new ArrayList<Dialog>();
    for (DialogHistory dialogHistory : history) {
        // Ignore already available dialogs
        if (dialogs.getValue(dialogHistory.getPeer().getUnuqueId()) != null) {
            continue;
        }
        PeerDesc peerDesc = buildPeerDesc(dialogHistory.getPeer());
        if (peerDesc == null) {
            continue;
        }
        ContentDescription description = ContentDescription.fromContent(dialogHistory.getContent());
        DialogBuilder builder = new DialogBuilder().setPeer(dialogHistory.getPeer()).setDialogTitle(peerDesc.getTitle()).setDialogAvatar(peerDesc.getAvatar()).setSortKey(dialogHistory.getSortDate()).setRid(dialogHistory.getRid()).setTime(dialogHistory.getDate()).setMessageType(description.getContentType()).setText(description.getText()).setSenderId(dialogHistory.getSenderId()).setRelatedUid(description.getRelatedUser()).setUnreadCount(dialogHistory.getUnreadCount());
        if (dialogHistory.isRead()) {
            builder.updateKnownReadDate(dialogHistory.getDate());
            builder.updateKnownReceiveDate(dialogHistory.getDate());
        } else if (dialogHistory.isReceived()) {
            builder.updateKnownReceiveDate(dialogHistory.getDate());
        }
        updated.add(builder.createDialog());
    }
    addOrUpdateItems(updated);
    updateSearch(updated);
    notifyState(true);
    return Promise.success(null);
}
Also used : Dialog(im.actor.core.entity.Dialog) DialogHistory(im.actor.core.modules.messaging.history.entity.DialogHistory) ArrayList(java.util.ArrayList) ContentDescription(im.actor.core.entity.ContentDescription) DialogBuilder(im.actor.core.entity.DialogBuilder) Verified(im.actor.runtime.annotations.Verified)

Example 3 with DialogHistory

use of im.actor.core.modules.messaging.history.entity.DialogHistory in project actor-platform by actorapp.

the class DialogsHistoryActor method onLoadedMore.

private void onLoadedMore(List<ApiDialog> rawDialogs) {
    final ArrayList<DialogHistory> dialogs = new ArrayList<>();
    long maxLoadedDate = Long.MAX_VALUE;
    for (ApiDialog dialog : rawDialogs) {
        dialogs.add(new DialogHistory(convert(dialog.getPeer()), dialog.getUnreadCount(), dialog.getSortDate(), dialog.getRid(), dialog.getDate(), dialog.getSenderUid(), AbsContent.fromMessage(dialog.getMessage()), dialog.getState() == ApiMessageState.READ, dialog.getState() == ApiMessageState.RECEIVED));
        maxLoadedDate = Math.min(dialog.getSortDate(), maxLoadedDate);
    }
    if (dialogs.size() > 0) {
        final long finalMaxLoadedDate = maxLoadedDate;
        context().getMessagesModule().getRouter().onDialogsHistoryLoaded(dialogs).then((v) -> {
            if (dialogs.size() < LIMIT) {
                markAsLoaded();
            } else {
                markAsSliceLoaded(finalMaxLoadedDate);
            }
        });
    } else {
        markAsLoaded();
    }
}
Also used : ApiDialog(im.actor.core.api.ApiDialog) DialogHistory(im.actor.core.modules.messaging.history.entity.DialogHistory) ArrayList(java.util.ArrayList)

Aggregations

DialogHistory (im.actor.core.modules.messaging.history.entity.DialogHistory)3 ArrayList (java.util.ArrayList)2 ApiDialog (im.actor.core.api.ApiDialog)1 ContentDescription (im.actor.core.entity.ContentDescription)1 ConversationState (im.actor.core.entity.ConversationState)1 Dialog (im.actor.core.entity.Dialog)1 DialogBuilder (im.actor.core.entity.DialogBuilder)1 Verified (im.actor.runtime.annotations.Verified)1