Search in sources :

Example 1 with DialogBuilder

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

the class DialogsActor method onMessageContentChanged.

@Verified
private Promise<Void> onMessageContentChanged(Peer peer, long rid, AbsContent content) {
    Dialog dialog = dialogs.getValue(peer.getUnuqueId());
    // If message is on top
    if (dialog != null && dialog.getRid() == rid) {
        ContentDescription description = ContentDescription.fromContent(content);
        addOrUpdateItem(new DialogBuilder(dialog).setText(description.getText()).setRelatedUid(description.getRelatedUser()).setMessageType(description.getContentType()).createDialog());
    }
    return Promise.success(null);
}
Also used : Dialog(im.actor.core.entity.Dialog) ContentDescription(im.actor.core.entity.ContentDescription) DialogBuilder(im.actor.core.entity.DialogBuilder) Verified(im.actor.runtime.annotations.Verified)

Example 2 with DialogBuilder

use of im.actor.core.entity.DialogBuilder 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 DialogBuilder

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

the class DialogsActor method onMessage.

@Verified
private Promise<Void> onMessage(Peer peer, Message message, boolean forceWrite, int counter) {
    long start = im.actor.runtime.Runtime.getCurrentTime();
    PeerDesc peerDesc = buildPeerDesc(peer);
    if (peerDesc == null) {
        Log.d("DialogsActor", "unknown peer desc");
        return Promise.success(null);
    }
    if (message == null) {
        // Ignore empty message if not forcing write
        if (!forceWrite) {
            Log.d("DialogsActor", "not force");
            return Promise.success(null);
        }
        // Else perform chat clear
        onChatClear(peer);
    } else {
        Dialog dialog = dialogs.getValue(peer.getUnuqueId());
        ContentDescription contentDescription = ContentDescription.fromContent(message.getContent());
        DialogBuilder builder = new DialogBuilder().setRid(message.getRid()).setTime(message.getDate()).setMessageType(contentDescription.getContentType()).setText(contentDescription.getText()).setRelatedUid(contentDescription.getRelatedUser()).setSenderId(message.getSenderId()).setDialogTitle(peerDesc.getTitle()).setDialogAvatar(peerDesc.getAvatar()).setIsBot(peerDesc.isBot()).setIsChannel(peerDesc.isChannel());
        if (counter >= 0) {
            builder.setUnreadCount(counter);
        }
        boolean forceUpdate = false;
        boolean needUpdateSearch = false;
        if (dialog != null) {
            // Ignore old messages if no force
            if (!forceWrite && dialog.getSortDate() > message.getSortDate()) {
                Log.d("DialogsActor", "too old");
                return Promise.success(null);
            }
            builder.setPeer(dialog.getPeer()).setSortKey(dialog.getSortDate()).updateKnownReceiveDate(dialog.getKnownReceiveDate()).updateKnownReadDate(dialog.getKnownReadDate());
            // Do not push up dialogs for silent messages
            if (!contentDescription.isSilent()) {
                builder.setSortKey(message.getSortDate());
            }
        } else {
            // Do not create dialogs for silent messages
            if (contentDescription.isSilent()) {
                Log.d("DialogsActor", "is silent in");
                return Promise.success(null);
            }
            builder.setPeer(peer).setSortKey(message.getSortDate());
            needUpdateSearch = true;
            forceUpdate = true;
        }
        Dialog dialog1 = builder.createDialog();
        addOrUpdateItem(dialog1);
        if (needUpdateSearch) {
            updateSearch(dialog1);
        }
        notifyState(forceUpdate);
    }
    return Promise.success(null);
}
Also used : Dialog(im.actor.core.entity.Dialog) ContentDescription(im.actor.core.entity.ContentDescription) DialogBuilder(im.actor.core.entity.DialogBuilder) Verified(im.actor.runtime.annotations.Verified)

Aggregations

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