Search in sources :

Example 6 with Message

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

the class SenderActor method doSendPhoto.

public void doSendPhoto(Peer peer, FastThumb fastThumb, String descriptor, String fileName, int fileSize, int w, int h) {
    long rid = RandomUtils.nextRid();
    long date = createPendingDate();
    long sortDate = date + 365 * 24 * 60 * 60 * 1000L;
    PhotoContent photoContent = PhotoContent.createLocalPhoto(descriptor, fileName, fileSize, w, h, fastThumb);
    Message message = new Message(rid, sortDate, date, myUid(), MessageState.PENDING, photoContent);
    context().getMessagesModule().getRouter().onOutgoingMessage(peer, message);
    pendingMessages.getPendingMessages().add(new PendingMessage(peer, rid, photoContent));
    savePending();
    performUploadFile(rid, descriptor, fileName);
}
Also used : PendingMessage(im.actor.core.modules.messaging.actions.entity.PendingMessage) ApiTextMessage(im.actor.core.api.ApiTextMessage) Message(im.actor.core.entity.Message) ApiDocumentMessage(im.actor.core.api.ApiDocumentMessage) RequestSendMessage(im.actor.core.api.rpc.RequestSendMessage) ApiMessage(im.actor.core.api.ApiMessage) ApiJsonMessage(im.actor.core.api.ApiJsonMessage) PhotoContent(im.actor.core.entity.content.PhotoContent) PendingMessage(im.actor.core.modules.messaging.actions.entity.PendingMessage)

Example 7 with Message

use of im.actor.core.entity.Message 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 8 with Message

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

the class RouterActor method onUpdate.

// 
// Messages
// 
public Promise<Void> onUpdate(Update update) {
    if (update instanceof UpdateMessage) {
        UpdateMessage msg = (UpdateMessage) update;
        Peer peer = convert(msg.getPeer());
        AbsContent msgContent = AbsContent.fromMessage(msg.getMessage());
        Message message = new Message(msg.getRid(), msg.getDate(), msg.getDate(), msg.getSenderUid(), myUid() == msg.getSenderUid() ? MessageState.SENT : MessageState.UNKNOWN, msgContent);
        ArrayList<Message> messages = new ArrayList<>();
        messages.add(message);
        return onNewMessages(peer, messages);
    } else if (update instanceof UpdateMessageSent) {
        UpdateMessageSent messageSent = (UpdateMessageSent) update;
        Peer peer = convert(messageSent.getPeer());
        if (isValidPeer(peer)) {
            // Notify Sender
            context().getMessagesModule().getSendMessageActor().send(new SenderActor.MessageSent(peer, messageSent.getRid()));
            return onOutgoingSent(peer, messageSent.getRid(), messageSent.getDate());
        }
        return Promise.success(null);
    } else if (update instanceof UpdateMessageRead) {
        UpdateMessageRead read = (UpdateMessageRead) update;
        Peer peer = convert(read.getPeer());
        if (isValidPeer(peer)) {
            return onMessageRead(peer, read.getStartDate());
        }
        return Promise.success(null);
    } else if (update instanceof UpdateMessageReadByMe) {
        UpdateMessageReadByMe readByMe = (UpdateMessageReadByMe) update;
        Peer peer = convert(readByMe.getPeer());
        if (isValidPeer(peer)) {
            int counter = 0;
            if (readByMe.getUnreadCounter() != null) {
                counter = readByMe.getUnreadCounter();
            }
            return onMessageReadByMe(peer, readByMe.getStartDate(), counter);
        }
        return Promise.success(null);
    } else if (update instanceof UpdateMessageReceived) {
        UpdateMessageReceived received = (UpdateMessageReceived) update;
        Peer peer = convert(received.getPeer());
        if (isValidPeer(peer)) {
            return onMessageReceived(peer, received.getStartDate());
        }
        return Promise.success(null);
    } else if (update instanceof UpdateChatDelete) {
        UpdateChatDelete delete = (UpdateChatDelete) update;
        Peer peer = convert(delete.getPeer());
        if (isValidPeer(peer)) {
            return onChatDelete(peer);
        }
        return Promise.success(null);
    } else if (update instanceof UpdateChatClear) {
        UpdateChatClear clear = (UpdateChatClear) update;
        Peer peer = convert(clear.getPeer());
        if (isValidPeer(peer)) {
            return onChatClear(peer);
        }
        return Promise.success(null);
    } else if (update instanceof UpdateChatDropCache) {
        UpdateChatDropCache dropCache = (UpdateChatDropCache) update;
        Peer peer = convert(dropCache.getPeer());
        if (isValidPeer(peer)) {
            return onChatDropCache(peer);
        }
        return Promise.success(null);
    } else if (update instanceof UpdateChatGroupsChanged) {
        UpdateChatGroupsChanged chatGroupsChanged = (UpdateChatGroupsChanged) update;
        onActiveDialogsChanged(chatGroupsChanged.getDialogs(), true, true);
        return Promise.success(null);
    } else if (update instanceof UpdateMessageDelete) {
        UpdateMessageDelete delete = (UpdateMessageDelete) update;
        Peer peer = convert(delete.getPeer());
        if (isValidPeer(peer)) {
            return onMessageDeleted(peer, delete.getRids());
        }
        return Promise.success(null);
    } else if (update instanceof UpdateMessageContentChanged) {
        UpdateMessageContentChanged contentChanged = (UpdateMessageContentChanged) update;
        Peer peer = convert(contentChanged.getPeer());
        if (isValidPeer(peer)) {
            AbsContent content = AbsContent.fromMessage(contentChanged.getMessage());
            return onContentUpdate(peer, contentChanged.getRid(), content);
        }
        return Promise.success(null);
    } else if (update instanceof UpdateReactionsUpdate) {
        UpdateReactionsUpdate reactionsUpdate = (UpdateReactionsUpdate) update;
        Peer peer = convert(reactionsUpdate.getPeer());
        if (isValidPeer(peer)) {
            ArrayList<Reaction> reactions = new ArrayList<>();
            for (ApiMessageReaction r : reactionsUpdate.getReactions()) {
                reactions.add(new Reaction(r.getCode(), r.getUsers()));
            }
            return onReactionsUpdate(peer, reactionsUpdate.getRid(), reactions);
        }
        return Promise.success(null);
    }
    return Promise.success(null);
}
Also used : UpdateMessage(im.actor.core.api.updates.UpdateMessage) UpdateMessageSent(im.actor.core.api.updates.UpdateMessageSent) UpdateMessageContentChanged(im.actor.core.api.updates.UpdateMessageContentChanged) UpdateChatClear(im.actor.core.api.updates.UpdateChatClear) UpdateMessage(im.actor.core.api.updates.UpdateMessage) Message(im.actor.core.entity.Message) RouterOutgoingMessage(im.actor.core.modules.messaging.router.entity.RouterOutgoingMessage) Peer(im.actor.core.entity.Peer) ApiMessageReaction(im.actor.core.api.ApiMessageReaction) AbsContent(im.actor.core.entity.content.AbsContent) ArrayList(java.util.ArrayList) UpdateChatDelete(im.actor.core.api.updates.UpdateChatDelete) UpdateChatDropCache(im.actor.core.api.updates.UpdateChatDropCache) UpdateMessageReadByMe(im.actor.core.api.updates.UpdateMessageReadByMe) UpdateMessageReceived(im.actor.core.api.updates.UpdateMessageReceived) ApiMessageReaction(im.actor.core.api.ApiMessageReaction) Reaction(im.actor.core.entity.Reaction) UpdateChatGroupsChanged(im.actor.core.api.updates.UpdateChatGroupsChanged) UpdateMessageDelete(im.actor.core.api.updates.UpdateMessageDelete) UpdateReactionsUpdate(im.actor.core.api.updates.UpdateReactionsUpdate) UpdateMessageSent(im.actor.core.api.updates.UpdateMessageSent) UpdateMessageRead(im.actor.core.api.updates.UpdateMessageRead)

Example 9 with Message

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

the class I18nEngine method formatMessagesExport.

// 
// Exporting messages
// 
/**
 * Formatting messages for exporting
 *
 * @param messages messages to export
 * @return formatted text
 */
@ObjectiveCName("formatMessagesExport:")
public String formatMessagesExport(Message[] messages) {
    String text = "";
    Arrays.sort(messages, new Comparator<Message>() {

        int compare(long lhs, long rhs) {
            return lhs < rhs ? -1 : (lhs == rhs ? 0 : 1);
        }

        @Override
        public int compare(Message lhs, Message rhs) {
            return compare(lhs.getEngineSort(), rhs.getEngineSort());
        }
    });
    if (messages.length == 1) {
        for (Message model : messages) {
            if (!(model.getContent() instanceof TextContent)) {
                continue;
            }
            text += ((TextContent) model.getContent()).getText();
        }
    } else {
        for (Message model : messages) {
            if (!(model.getContent() instanceof TextContent)) {
                continue;
            }
            if (text.length() > 0) {
                text += "\n";
            }
            text += getUser(model.getSenderId()).getName() + ": ";
            text += ((TextContent) model.getContent()).getText();
        }
    }
    return text;
}
Also used : Message(im.actor.core.entity.Message) TextContent(im.actor.core.entity.content.TextContent) ObjectiveCName(com.google.j2objc.annotations.ObjectiveCName)

Example 10 with Message

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

the class MessagesAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(AbsMessageViewHolder dialogHolder, int index, Message item) {
    Message prev = null;
    Message next = null;
    if (index > 1) {
        next = getItem(index - 1);
    }
    if (index < getItemCount() - 1) {
        prev = getItem(index + 1);
    }
    PreprocessedList list = ((PreprocessedList) getPreprocessedList());
    dialogHolder.bindData(item, prev, next, readDate, receiveDate, list.getPreprocessedData()[index]);
}
Also used : Message(im.actor.core.entity.Message) PreprocessedList(im.actor.sdk.controllers.conversation.messages.content.preprocessor.PreprocessedList)

Aggregations

Message (im.actor.core.entity.Message)28 ApiMessage (im.actor.core.api.ApiMessage)13 ApiTextMessage (im.actor.core.api.ApiTextMessage)12 ApiDocumentMessage (im.actor.core.api.ApiDocumentMessage)11 ApiJsonMessage (im.actor.core.api.ApiJsonMessage)11 RequestSendMessage (im.actor.core.api.rpc.RequestSendMessage)11 PendingMessage (im.actor.core.modules.messaging.actions.entity.PendingMessage)11 UpdateMessage (im.actor.core.api.updates.UpdateMessage)7 TextContent (im.actor.core.entity.content.TextContent)6 RouterOutgoingMessage (im.actor.core.modules.messaging.router.entity.RouterOutgoingMessage)6 ArrayList (java.util.ArrayList)6 ConversationState (im.actor.core.entity.ConversationState)5 Peer (im.actor.core.entity.Peer)5 AbsContent (im.actor.core.entity.content.AbsContent)5 Reaction (im.actor.core.entity.Reaction)3 UserVM (im.actor.core.viewmodel.UserVM)3 Void (im.actor.runtime.actors.messages.Void)3 ApiPeer (im.actor.core.api.ApiPeer)2 Dialog (im.actor.core.entity.Dialog)2 Sticker (im.actor.core.entity.Sticker)2