Search in sources :

Example 1 with Message

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

the class SenderActor method doSendText.

// Sending text
public void doSendText(@NotNull Peer peer, @NotNull String text, @Nullable ArrayList<Integer> mentions, /*Ignored*/
@Nullable String markDownText, boolean autoDetect) {
    text = text.trim();
    long rid = RandomUtils.nextRid();
    long date = createPendingDate();
    long sortDate = date + 365 * 24 * 60 * 60 * 1000L;
    if (autoDetect) {
        mentions = new ArrayList<>();
        if (peer.getPeerType() == PeerType.GROUP) {
            Group group = getGroup(peer.getPeerId());
            String lowText = text.toLowerCase();
            if (group.getMembers() != null) {
                for (GroupMember member : group.getMembers()) {
                    User user = getUser(member.getUid());
                    if (user.getNick() != null) {
                        String nick = "@" + user.getNick().toLowerCase();
                        // TODO: Better filtering
                        if (lowText.contains(nick + ":") || lowText.contains(nick + " ") || lowText.contains(" " + nick) || lowText.endsWith(nick) || lowText.equals(nick)) {
                            mentions.add(user.getUid());
                        }
                    }
                }
            }
        }
    }
    TextContent content = TextContent.create(text, null, mentions);
    Message message = new Message(rid, sortDate, date, myUid(), MessageState.PENDING, content);
    context().getMessagesModule().getRouter().onOutgoingMessage(peer, message);
    pendingMessages.getPendingMessages().add(new PendingMessage(peer, rid, content));
    savePending();
    performSendContent(peer, rid, content);
}
Also used : Group(im.actor.core.entity.Group) GroupMember(im.actor.core.entity.GroupMember) User(im.actor.core.entity.User) 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) TextContent(im.actor.core.entity.content.TextContent) PendingMessage(im.actor.core.modules.messaging.actions.entity.PendingMessage)

Example 2 with Message

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

the class SenderActor method doSendDocument.

// Sending documents
public void doSendDocument(Peer peer, String fileName, String mimeType, int fileSize, FastThumb fastThumb, String descriptor) {
    long rid = RandomUtils.nextRid();
    long date = createPendingDate();
    long sortDate = date + 365 * 24 * 60 * 60 * 1000L;
    DocumentContent documentContent = DocumentContent.createLocal(fileName, fileSize, descriptor, mimeType, fastThumb);
    Message message = new Message(rid, sortDate, date, myUid(), MessageState.PENDING, documentContent);
    context().getMessagesModule().getRouter().onOutgoingMessage(peer, message);
    pendingMessages.getPendingMessages().add(new PendingMessage(peer, rid, documentContent));
    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) DocumentContent(im.actor.core.entity.content.DocumentContent) PendingMessage(im.actor.core.modules.messaging.actions.entity.PendingMessage)

Example 3 with Message

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

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

the class SenderActor method doSendJson.

public void doSendJson(Peer peer, JsonContent content) {
    long rid = RandomUtils.nextRid();
    long date = createPendingDate();
    long sortDate = date + 365 * 24 * 60 * 60 * 1000L;
    Message message = new Message(rid, sortDate, date, myUid(), MessageState.PENDING, content);
    context().getMessagesModule().getRouter().onOutgoingMessage(peer, message);
    pendingMessages.getPendingMessages().add(new PendingMessage(peer, rid, content));
    savePending();
    performSendContent(peer, rid, content);
}
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) PendingMessage(im.actor.core.modules.messaging.actions.entity.PendingMessage)

Example 5 with Message

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

the class SenderActor method doSendAudio.

public void doSendAudio(Peer peer, String descriptor, String fileName, int fileSize, int duration) {
    long rid = RandomUtils.nextRid();
    long date = createPendingDate();
    long sortDate = date + 365 * 24 * 60 * 60 * 1000L;
    VoiceContent audioContent = VoiceContent.createLocalAudio(descriptor, fileName, fileSize, duration);
    Message message = new Message(rid, sortDate, date, myUid(), MessageState.PENDING, audioContent);
    context().getMessagesModule().getRouter().onOutgoingMessage(peer, message);
    pendingMessages.getPendingMessages().add(new PendingMessage(peer, rid, audioContent));
    savePending();
    performUploadFile(rid, descriptor, fileName);
}
Also used : VoiceContent(im.actor.core.entity.content.VoiceContent) 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) PendingMessage(im.actor.core.modules.messaging.actions.entity.PendingMessage)

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