Search in sources :

Example 6 with TextContent

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

the class MessagesModule method updateMessage.

public Promise<Void> updateMessage(final Peer peer, final String message, final long rid) {
    context().getTypingModule().onMessageSent(peer);
    ArrayList<Integer> mentions = new ArrayList<>();
    TextContent content = TextContent.create(message, null, mentions);
    if (peer.getPeerType() == PeerType.GROUP) {
        Group group = groups().getValue(peer.getPeerId());
        String lowText = message.toLowerCase();
        for (GroupMember member : group.getMembers()) {
            User user = users().getValue(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());
                }
            }
        }
    }
    ApiMessage editMessage = new ApiTextMessage(message, content.getMentions(), content.getTextMessageEx());
    return buildOutPeer(peer).flatMap(apiOutPeer -> api(new RequestUpdateMessage(apiOutPeer, rid, editMessage))).flatMap(responseSeqDate -> updates().applyUpdate(responseSeqDate.getSeq(), responseSeqDate.getState(), new UpdateMessageContentChanged(new ApiPeer(peer.getPeerType().toApi(), peer.getPeerId()), rid, editMessage)));
}
Also used : RequestMessageSetReaction(im.actor.core.api.rpc.RequestMessageSetReaction) DialogsInt(im.actor.core.modules.messaging.dialogs.DialogsInt) ModuleContext(im.actor.core.modules.ModuleContext) ConversationVM(im.actor.core.viewmodel.ConversationVM) FastThumb(im.actor.core.entity.content.FastThumb) RequestDeleteChat(im.actor.core.api.rpc.RequestDeleteChat) UpdateChatGroupsChanged(im.actor.core.api.updates.UpdateChatGroupsChanged) DialogGroupsVM(im.actor.core.viewmodel.DialogGroupsVM) ResponseReactionsResponse(im.actor.core.api.rpc.ResponseReactionsResponse) JsonContent(im.actor.core.entity.content.JsonContent) SyncKeyValue(im.actor.runtime.storage.SyncKeyValue) RouterInt(im.actor.core.modules.messaging.router.RouterInt) RequestFavouriteDialog(im.actor.core.api.rpc.RequestFavouriteDialog) RequestUnfavouriteDialog(im.actor.core.api.rpc.RequestUnfavouriteDialog) Actor(im.actor.runtime.actors.Actor) ApiPeer(im.actor.core.api.ApiPeer) CommandCallback(im.actor.core.viewmodel.CommandCallback) MessageDeleteActor(im.actor.core.modules.messaging.actions.MessageDeleteActor) TextContent(im.actor.core.entity.content.TextContent) Sticker(im.actor.core.entity.Sticker) RpcInternalException(im.actor.core.network.RpcInternalException) ApiTextMessage(im.actor.core.api.ApiTextMessage) UpdateReactionsUpdate(im.actor.core.api.updates.UpdateReactionsUpdate) Void(im.actor.runtime.actors.messages.Void) ResponseDialogsOrder(im.actor.core.api.rpc.ResponseDialogsOrder) GroupMember(im.actor.core.entity.GroupMember) ArchivedDialogsActor(im.actor.core.modules.messaging.history.ArchivedDialogsActor) ApiOutPeer(im.actor.core.api.ApiOutPeer) MVVMCollection(im.actor.runtime.mvvm.MVVMCollection) ActorSystem.system(im.actor.runtime.actors.ActorSystem.system) DialogsHistoryActor(im.actor.core.modules.messaging.history.DialogsHistoryActor) Nullable(org.jetbrains.annotations.Nullable) CursorReceiverActor(im.actor.core.modules.messaging.actions.CursorReceiverActor) PromiseResolver(im.actor.runtime.promise.PromiseResolver) RequestClearChat(im.actor.core.api.rpc.RequestClearChat) UpdateMessageContentChanged(im.actor.core.api.updates.UpdateMessageContentChanged) Peer(im.actor.core.entity.Peer) Props(im.actor.runtime.actors.Props) Message(im.actor.core.entity.Message) Dialog(im.actor.core.entity.Dialog) NotNull(org.jetbrains.annotations.NotNull) Function(im.actor.runtime.function.Function) ApiPeerType(im.actor.core.api.ApiPeerType) RequestArchiveChat(im.actor.core.api.rpc.RequestArchiveChat) RequestUpdateMessage(im.actor.core.api.rpc.RequestUpdateMessage) ResponseSeq(im.actor.core.api.rpc.ResponseSeq) RequestMessageRemoveReaction(im.actor.core.api.rpc.RequestMessageRemoveReaction) ResponseSeqDate(im.actor.core.api.rpc.ResponseSeqDate) ActorCreator(im.actor.runtime.actors.ActorCreator) Promise(im.actor.runtime.promise.Promise) HashMap(java.util.HashMap) UpdateChatClear(im.actor.core.api.updates.UpdateChatClear) PromiseFunc(im.actor.runtime.promise.PromiseFunc) ArrayList(java.util.ArrayList) ConversationState(im.actor.core.entity.ConversationState) AbsModule(im.actor.core.modules.AbsModule) User(im.actor.core.entity.User) BusSubscriber(im.actor.runtime.eventbus.BusSubscriber) ConversationHistoryActor(im.actor.core.modules.messaging.history.ConversationHistoryActor) PeerChatOpened(im.actor.core.events.PeerChatOpened) RpcCallback(im.actor.core.network.RpcCallback) ActorRef(im.actor.runtime.actors.ActorRef) ListEngine(im.actor.runtime.storage.ListEngine) PeerType(im.actor.core.entity.PeerType) Command(im.actor.core.viewmodel.Command) ConversationHistory(im.actor.core.modules.messaging.history.ConversationHistory) AbsContent(im.actor.core.entity.content.AbsContent) PeerChatPreload(im.actor.core.events.PeerChatPreload) ApiMessage(im.actor.core.api.ApiMessage) Group(im.actor.core.entity.Group) RpcException(im.actor.core.network.RpcException) CursorReaderActor(im.actor.core.modules.messaging.actions.CursorReaderActor) Storage(im.actor.runtime.Storage) DialogsActor(im.actor.core.modules.messaging.dialogs.DialogsActor) SenderActor(im.actor.core.modules.messaging.actions.SenderActor) FileSystemReference(im.actor.runtime.files.FileSystemReference) ResponseLoadArchived(im.actor.core.api.rpc.ResponseLoadArchived) UpdateChatDelete(im.actor.core.api.updates.UpdateChatDelete) Event(im.actor.runtime.eventbus.Event) SeqUpdate(im.actor.core.api.base.SeqUpdate) Group(im.actor.core.entity.Group) GroupMember(im.actor.core.entity.GroupMember) UpdateMessageContentChanged(im.actor.core.api.updates.UpdateMessageContentChanged) User(im.actor.core.entity.User) ApiTextMessage(im.actor.core.api.ApiTextMessage) ArrayList(java.util.ArrayList) ApiMessage(im.actor.core.api.ApiMessage) TextContent(im.actor.core.entity.content.TextContent) RequestUpdateMessage(im.actor.core.api.rpc.RequestUpdateMessage) ApiPeer(im.actor.core.api.ApiPeer)

Example 7 with TextContent

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

the class SenderActor method preStart.

@Override
public void preStart() {
    pendingMessages = new PendingMessagesStorage();
    byte[] p = preferences().getBytes(PREFERENCES);
    if (p != null) {
        try {
            pendingMessages = PendingMessagesStorage.fromBytes(p);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    boolean isChanged = false;
    ArrayList<PendingMessage> messages = pendingMessages.getPendingMessages();
    for (PendingMessage pending : messages.toArray(new PendingMessage[messages.size()])) {
        if (pending.getContent() instanceof TextContent) {
            performSendContent(pending.getPeer(), pending.getRid(), pending.getContent());
        } else if (pending.getContent() instanceof DocumentContent) {
            DocumentContent documentContent = (DocumentContent) pending.getContent();
            if (documentContent.getSource() instanceof FileLocalSource) {
                if (Storage.isFsPersistent()) {
                    performUploadFile(pending.getRid(), ((FileLocalSource) documentContent.getSource()).getFileDescriptor(), ((FileLocalSource) documentContent.getSource()).getFileName());
                } else {
                    List<Long> rids = new ArrayList<>();
                    rids.add(pending.getRid());
                    context().getMessagesModule().getRouter().onMessagesDeleted(pending.getPeer(), rids);
                    pendingMessages.getPendingMessages().remove(pending);
                    isChanged = true;
                }
            } else {
                performSendContent(pending.getPeer(), pending.getRid(), pending.getContent());
            }
        }
    }
    if (isChanged) {
        savePending();
    }
}
Also used : PendingMessagesStorage(im.actor.core.modules.messaging.actions.entity.PendingMessagesStorage) DocumentContent(im.actor.core.entity.content.DocumentContent) FileLocalSource(im.actor.core.entity.content.FileLocalSource) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TextContent(im.actor.core.entity.content.TextContent) PendingMessage(im.actor.core.modules.messaging.actions.entity.PendingMessage)

Example 8 with TextContent

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

the class RouterActor method onNewMessages.

// 
// Incoming Messages
// 
private Promise<Void> onNewMessages(Peer peer, List<Message> messages) {
    assertTrue(messages.size() != 0);
    boolean isConversationVisible = isConversationVisible(peer);
    // 
    // Collecting Information
    // 
    ConversationState state = conversationStates.getValue(peer.getUnuqueId());
    Message topMessage = null;
    int unreadCount = 0;
    long maxInReadDate = 0;
    long maxInDate = 0;
    for (Message m : messages) {
        if (topMessage == null || topMessage.getSortDate() < m.getSortDate()) {
            topMessage = m;
        }
        if (m.getSenderId() != myUid()) {
            if (m.getSortDate() > state.getInReadDate()) {
                unreadCount++;
                maxInReadDate = Math.max(maxInReadDate, m.getSortDate());
            }
            if (m.getSortDate() > state.getInMaxMessageDate()) {
                maxInDate = Math.max(maxInDate, m.getSortDate());
            }
        }
    }
    // 
    // Writing to Conversation
    // 
    conversation(peer).addOrUpdateItems(messages);
    // 
    // Update Chat State
    // 
    updateChatState(peer);
    // 
    // Updating Counter
    // 
    boolean isRead = false;
    if (unreadCount != 0) {
        if (isConversationVisible) {
            // Auto Reading message
            boolean needUpdateState = false;
            if (maxInReadDate > 0) {
                if (state.getInReadDate() < maxInReadDate) {
                    state = state.changeInReadDate(maxInReadDate);
                }
                state = state.changeCounter(0);
                context().getMessagesModule().getPlainReadActor().send(new CursorReaderActor.MarkRead(peer, maxInReadDate));
                context().getNotificationsModule().onOwnRead(peer, maxInReadDate);
                isRead = true;
                needUpdateState = true;
            }
            if (state.getInMaxMessageDate() < maxInDate) {
                state.changeInMaxDate(maxInDate);
                needUpdateState = true;
            }
            if (needUpdateState) {
                conversationStates.addOrUpdateItem(state);
            }
        } else {
            // Updating counter
            state = state.changeCounter(state.getUnreadCount() + unreadCount);
            if (state.getInMaxMessageDate() < maxInDate) {
                state = state.changeInMaxDate(maxInDate);
            }
            conversationStates.addOrUpdateItem(state);
            notifyActiveDialogsVM();
        }
    }
    // 
    if (maxInReadDate > 0 && !isRead) {
        context().getMessagesModule().getPlainReceiverActor().send(new CursorReceiverActor.MarkReceived(peer, maxInReadDate));
    }
    // 
    // Updating Dialog List
    // 
    Promise<Void> res = getDialogsRouter().onMessage(peer, topMessage, state.getUnreadCount());
    // 
    if (!isConversationVisible) {
        for (Message m : messages) {
            if (m.getSenderId() != myUid()) {
                boolean hasCurrentMention = false;
                if (m.getContent() instanceof TextContent) {
                    if (((TextContent) m.getContent()).getMentions().contains(myUid())) {
                        hasCurrentMention = true;
                    }
                }
                int messagesCount = 0;
                int dialogsCount = 0;
                for (Peer activePeer : activeDialogStorage.getAllPeers()) {
                    int activeDialogueUnreadCount = conversationStates.getValue(activePeer.getUnuqueId()).getUnreadCount();
                    if (activeDialogueUnreadCount > 0) {
                        dialogsCount++;
                        messagesCount += activeDialogueUnreadCount;
                    }
                }
                context().getNotificationsModule().onInMessage(peer, m.getSenderId(), m.getSortDate(), ContentDescription.fromContent(m.getContent()), hasCurrentMention, messagesCount, dialogsCount);
            }
        }
    }
    return res;
}
Also used : 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) ConversationState(im.actor.core.entity.ConversationState) CursorReaderActor(im.actor.core.modules.messaging.actions.CursorReaderActor) CursorReceiverActor(im.actor.core.modules.messaging.actions.CursorReceiverActor) Void(im.actor.runtime.actors.messages.Void) TextContent(im.actor.core.entity.content.TextContent)

Example 9 with TextContent

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

the class MessagesDefaultFragment method onLongClick.

@Override
public boolean onLongClick(final Message message, final boolean hasMyReaction) {
    if (actionMode == null) {
        messagesAdapter.clearSelection();
        messagesAdapter.setSelected(message, true);
        actionMode = ((AppCompatActivity) getActivity()).startSupportActionMode(new ActionMode.Callback() {

            @Override
            public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
                getActivity().getMenuInflater().inflate(R.menu.messages_context, menu);
                return true;
            }

            @Override
            public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
                Message[] selected = messagesAdapter.getSelected();
                if (selected.length > 0) {
                    actionMode.setTitle("" + selected.length);
                }
                boolean isAllText = true;
                for (Message k : selected) {
                    if (!(k.getContent() instanceof TextContent)) {
                        isAllText = false;
                        break;
                    }
                }
                menu.findItem(R.id.copy).setVisible(isAllText);
                menu.findItem(R.id.quote).setVisible(isAllText);
                menu.findItem(R.id.forward).setVisible(selected.length == 1 || isAllText);
                menu.findItem(R.id.like).setVisible(selected.length == 1);
                return false;
            }

            @Override
            public boolean onActionItemClicked(final ActionMode actionMode, MenuItem menuItem) {
                if (menuItem.getItemId() == R.id.delete) {
                    Message[] selected = messagesAdapter.getSelected();
                    final long[] rids = new long[selected.length];
                    for (int i = 0; i < rids.length; i++) {
                        rids[i] = selected[i].getRid();
                    }
                    new AlertDialog.Builder(getActivity()).setMessage(getString(R.string.alert_delete_messages_text).replace("{0}", "" + rids.length)).setPositiveButton(R.string.alert_delete_messages_yes, (dialog, which) -> {
                        messenger().deleteMessages(peer, rids);
                        actionMode.finish();
                    }).setNegativeButton(R.string.dialog_cancel, null).show().setCanceledOnTouchOutside(true);
                    return true;
                } else if (menuItem.getItemId() == R.id.copy) {
                    String text = messenger().getFormatter().formatMessagesExport(messagesAdapter.getSelected());
                    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                    android.content.ClipData clip = android.content.ClipData.newPlainText("Messages", text);
                    clipboard.setPrimaryClip(clip);
                    Toast.makeText(getActivity(), R.string.toast_messages_copied, Toast.LENGTH_SHORT).show();
                    actionMode.finish();
                    return true;
                } else if (menuItem.getItemId() == R.id.like) {
                    Message currentMessage = messagesAdapter.getSelected()[0];
                    if (hasMyReaction) {
                        ActorSDK.sharedActor().getMessenger().removeReaction(getPeer(), currentMessage.getRid(), "\u2764").start(new CommandCallback<Void>() {

                            @Override
                            public void onResult(Void res) {
                            }

                            @Override
                            public void onError(Exception e) {
                            }
                        });
                    } else {
                        ActorSDK.sharedActor().getMessenger().addReaction(getPeer(), currentMessage.getRid(), "\u2764").start(new CommandCallback<Void>() {

                            @Override
                            public void onResult(Void res) {
                            }

                            @Override
                            public void onError(Exception e) {
                            }
                        });
                    }
                    actionMode.finish();
                    return true;
                } else if (menuItem.getItemId() == R.id.quote) {
                    String rawQuote = "";
                    int i = 0;
                    for (Message m : messagesAdapter.getSelected()) {
                        if (m.getContent() instanceof TextContent) {
                            UserVM user = users().get(m.getSenderId());
                            String nick = user.getNick().get();
                            String name = (nick != null && !nick.isEmpty()) ? "@" + nick : user.getName().get();
                            String text = ((TextContent) m.getContent()).getText();
                            rawQuote = rawQuote + name + ": " + text + "\n";
                        }
                    }
                    Fragment fragment = getParentFragment();
                    if (fragment instanceof MessagesFragmentCallback) {
                        ((MessagesFragmentCallback) fragment).onMessageQuote(rawQuote);
                    }
                    actionMode.finish();
                    return true;
                } else if (menuItem.getItemId() == R.id.forward) {
                    Intent i = new Intent(getActivity(), ShareActivity.class);
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    if (messagesAdapter.getSelected().length == 1) {
                        Message m = messagesAdapter.getSelected()[0];
                        if (m.getContent() instanceof TextContent) {
                            UserVM user = users().get(m.getSenderId());
                            String nick = user.getNick().get();
                            String name = (nick != null && !nick.isEmpty()) ? "@".concat(nick) : user.getName().get();
                            String text = ((TextContent) m.getContent()).getText();
                            String forward = name.concat(": ").concat(text).concat("\n");
                            i.putExtra(Intents.EXTRA_FORWARD_TEXT, forward);
                            i.putExtra(Intents.EXTRA_FORWARD_TEXT_RAW, forward);
                        } else if (!(m.getContent() instanceof UnsupportedContent)) {
                            AbsContent fileMessage = m.getContent();
                            try {
                                i.putExtra(Intents.EXTRA_FORWARD_CONTENT, AbsContent.serialize(fileMessage));
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    } else {
                        String quote = "";
                        String rawQuote = "";
                        int j = 0;
                        for (Message m : messagesAdapter.getSelected()) {
                            if (m.getContent() instanceof TextContent) {
                                UserVM user = users().get(m.getSenderId());
                                String nick = user.getNick().get();
                                String name = (nick != null && !nick.isEmpty()) ? "@".concat(nick) : user.getName().get();
                                String text = ((TextContent) m.getContent()).getText();
                                quote = quote.concat(name).concat(": ").concat(text);
                                rawQuote = rawQuote.concat(name).concat(": ").concat(text).concat("\n");
                                if (j++ != messagesAdapter.getSelectedCount() - 1) {
                                    quote += ";\n";
                                } else {
                                    quote += "\n";
                                }
                            }
                        }
                        i.putExtra(Intents.EXTRA_FORWARD_TEXT, quote);
                        i.putExtra(Intents.EXTRA_FORWARD_TEXT_RAW, rawQuote);
                    }
                    actionMode.finish();
                    startActivity(i);
                    getActivity().finish();
                    return true;
                }
                return false;
            }

            @Override
            public void onDestroyActionMode(ActionMode actionMode) {
                MessagesDefaultFragment.this.actionMode = null;
                messagesAdapter.clearSelection();
            }
        });
    } else {
        if (messagesAdapter.isSelected(message)) {
            messagesAdapter.setSelected(message, false);
            if (messagesAdapter.getSelectedCount() == 0) {
                actionMode.finish();
                actionMode = null;
            } else {
                actionMode.invalidate();
            }
        } else {
            messagesAdapter.setSelected(message, true);
            actionMode.invalidate();
        }
    }
    return true;
}
Also used : AlertDialog(android.app.AlertDialog) Context(android.content.Context) Bundle(android.os.Bundle) ActorSDKMessenger.myUid(im.actor.sdk.util.ActorSDKMessenger.myUid) ActorSDKMessenger.messenger(im.actor.sdk.util.ActorSDKMessenger.messenger) Intent(android.content.Intent) MenuItem(android.view.MenuItem) Toast(android.widget.Toast) Menu(android.view.Menu) CommandCallback(im.actor.core.viewmodel.CommandCallback) TextContent(im.actor.core.entity.content.TextContent) Intents(im.actor.sdk.controllers.Intents) ActorSDK(im.actor.sdk.ActorSDK) AbsContent(im.actor.core.entity.content.AbsContent) ActorSDKLauncher(im.actor.sdk.ActorSDKLauncher) ActionMode(android.support.v7.view.ActionMode) Void(im.actor.runtime.actors.messages.Void) Fragment(android.support.v4.app.Fragment) ActorSDKMessenger.users(im.actor.sdk.util.ActorSDKMessenger.users) IOException(java.io.IOException) UnsupportedContent(im.actor.core.entity.content.UnsupportedContent) AppCompatActivity(android.support.v7.app.AppCompatActivity) AlertDialog(android.app.AlertDialog) UserVM(im.actor.core.viewmodel.UserVM) R(im.actor.sdk.R) ChatActivity(im.actor.sdk.controllers.conversation.ChatActivity) Peer(im.actor.core.entity.Peer) ShareActivity(im.actor.sdk.controllers.share.ShareActivity) Message(im.actor.core.entity.Message) Message(im.actor.core.entity.Message) UnsupportedContent(im.actor.core.entity.content.UnsupportedContent) Fragment(android.support.v4.app.Fragment) Menu(android.view.Menu) Void(im.actor.runtime.actors.messages.Void) AbsContent(im.actor.core.entity.content.AbsContent) MenuItem(android.view.MenuItem) Intent(android.content.Intent) IOException(java.io.IOException) IOException(java.io.IOException) UserVM(im.actor.core.viewmodel.UserVM) CommandCallback(im.actor.core.viewmodel.CommandCallback) ActionMode(android.support.v7.view.ActionMode) TextContent(im.actor.core.entity.content.TextContent)

Example 10 with TextContent

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

the class ChatListProcessor method process.

@Nullable
@Override
public Object process(@NotNull List<Message> items, @Nullable Object previous) {
    // Init tools
    if (mobileInvitePattern == null) {
        mobileInvitePattern = Pattern.compile("(actor:\\\\/\\\\/)(invite\\\\?token=)([0-9-a-z]{1,64})");
    }
    if (invitePattern == null) {
        invitePattern = Pattern.compile("(https:\\/\\/)(quit\\.email\\/join\\/)([0-9-a-z]{1,64})");
    }
    if (peoplePattern == null) {
        peoplePattern = Pattern.compile("(people:\\\\/\\\\/)([0-9]{1,20})");
    }
    if (mentionPattern == null) {
        mentionPattern = Pattern.compile("(@)([0-9a-zA-Z_]{5,32})");
    }
    ArrayList<PreprocessedData> preprocessedDatas = new ArrayList<PreprocessedData>();
    for (Message msg : items) {
        // Preprocess message
        // Assume user is cached
        messenger().getUser(msg.getSenderId());
        // Process reactions
        boolean isImage = msg.getContent() instanceof PhotoContent || msg.getContent() instanceof VideoContent || msg.getContent() instanceof LocationContent;
        boolean hasReactions = msg.getReactions() != null && msg.getReactions().size() > 0;
        Spannable reactions = null;
        if (hasReactions) {
            SpannableStringBuilder builder = new SpannableStringBuilder();
            SpannableString s;
            boolean hasMyReaction = false;
            for (Reaction r : msg.getReactions()) {
                s = new SpannableString(Integer.toString(r.getUids().size()).concat(r.getCode()).concat("  "));
                for (Integer uid : r.getUids()) {
                    if (uid == myUid()) {
                        hasMyReaction = true;
                        break;
                    }
                }
                s.setSpan(new ReactionSpan(r.getCode(), hasMyReaction, peer, msg.getRid(), isImage ? Color.WHITE : ActorSDK.sharedActor().style.getConvTimeColor()), 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                reactions = builder.append(s);
            }
        }
        // Process Content
        if (msg.getContent() instanceof TextContent) {
            int updatedCounter = msg.getContent().getUpdatedCounter();
            if (!preprocessedTexts.containsKey(msg.getRid()) || (!updatedTexts.containsKey(msg.getRid()) || updatedTexts.get(msg.getRid()) != updatedCounter)) {
                TextContent text = (TextContent) msg.getContent();
                Spannable spannableString = new SpannableString(text.getText());
                boolean hasSpannable = false;
                // Wait Emoji to load
                emoji().waitForEmoji();
                // Process markdown
                Spannable markdown = AndroidMarkdown.processText(text.getText());
                if (markdown != null) {
                    spannableString = markdown;
                    hasSpannable = true;
                }
                // Process links
                if (Linkify.addLinks(spannableString, Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS | Linkify.WEB_URLS)) {
                    hasSpannable = true;
                }
                if (fixLinkifyCustomLinks(spannableString, mobileInvitePattern, false)) {
                    hasSpannable = true;
                }
                if (fixLinkifyCustomLinks(spannableString, invitePattern, false)) {
                    hasSpannable = true;
                }
                if (fixLinkifyCustomLinks(spannableString, peoplePattern, true)) {
                    hasSpannable = true;
                }
                if (fixLinkifyCustomLinks(spannableString, mentionPattern, true)) {
                    hasSpannable = true;
                }
                // Append Sender name for groups
                if (isGroup && msg.getSenderId() != myUid()) {
                    String name;
                    UserVM userModel = users().get(msg.getSenderId());
                    if (userModel != null) {
                        String userName = userModel.getName().get();
                        if (userName.equals("Bot")) {
                            name = group.getName().get();
                        } else {
                            name = userName;
                        }
                    } else {
                        name = "???";
                    }
                    SpannableStringBuilder builder = new SpannableStringBuilder();
                    builder.append(name);
                    builder.setSpan(new ForegroundColorSpan(colors[Math.abs(msg.getSenderId()) % colors.length]), 0, name.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                    builder.append("\n");
                    spannableString = builder.append(spannableString);
                    hasSpannable = true;
                }
                // Process Emoji
                if (SmileProcessor.containsEmoji(spannableString)) {
                    spannableString = emoji().processEmojiCompatMutable(spannableString, SmileProcessor.CONFIGURATION_BUBBLES);
                    hasSpannable = true;
                }
                updatedTexts.put(msg.getRid(), updatedCounter);
                preprocessedTexts.put(msg.getRid(), new PreprocessedTextData(reactions, text.getText(), hasSpannable ? spannableString : null));
            } else {
                PreprocessedTextData text = preprocessedTexts.get(msg.getRid());
                preprocessedTexts.put(msg.getRid(), new PreprocessedTextData(reactions, text.getText(), text.getSpannableString()));
            }
            preprocessedDatas.add(preprocessedTexts.get(msg.getRid()));
        } else if (msg.getContent() instanceof ContactContent) {
            ContactContent contact = (ContactContent) msg.getContent();
            String text = "";
            for (String phone : contact.getPhones()) {
                text += "\n".concat(phone);
            }
            for (String email : contact.getEmails()) {
                text += "\n".concat(email);
            }
            Spannable spannableString = new SpannableString(text);
            SpannableStringBuilder builder = new SpannableStringBuilder();
            String name;
            name = contact.getName();
            builder.append(name);
            builder.setSpan(new ForegroundColorSpan(colors[Math.abs(msg.getSenderId()) % colors.length]), 0, name.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            // builder.append("\n");
            spannableString = builder.append(spannableString);
            preprocessedTexts.put(msg.getRid(), new PreprocessedTextData(reactions, text, spannableString));
            preprocessedDatas.add(preprocessedTexts.get(msg.getRid()));
        } else {
            // Nothing to do yet
            preprocessedDatas.add(new PreprocessedData(reactions));
        }
    }
    return new PreprocessedList(preprocessedDatas.toArray(new PreprocessedData[preprocessedDatas.size()]));
}
Also used : LocationContent(im.actor.core.entity.content.LocationContent) VideoContent(im.actor.core.entity.content.VideoContent) Message(im.actor.core.entity.Message) ForegroundColorSpan(android.text.style.ForegroundColorSpan) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) Reaction(im.actor.core.entity.Reaction) ContactContent(im.actor.core.entity.content.ContactContent) SpannableString(android.text.SpannableString) ReactionSpan(im.actor.sdk.controllers.conversation.view.ReactionSpan) UserVM(im.actor.core.viewmodel.UserVM) TextContent(im.actor.core.entity.content.TextContent) Spannable(android.text.Spannable) SpannableStringBuilder(android.text.SpannableStringBuilder) PhotoContent(im.actor.core.entity.content.PhotoContent) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

TextContent (im.actor.core.entity.content.TextContent)10 Message (im.actor.core.entity.Message)6 ApiMessage (im.actor.core.api.ApiMessage)3 ApiTextMessage (im.actor.core.api.ApiTextMessage)3 Peer (im.actor.core.entity.Peer)3 ContactContent (im.actor.core.entity.content.ContactContent)3 DocumentContent (im.actor.core.entity.content.DocumentContent)3 LocationContent (im.actor.core.entity.content.LocationContent)3 PhotoContent (im.actor.core.entity.content.PhotoContent)3 Void (im.actor.runtime.actors.messages.Void)3 ArrayList (java.util.ArrayList)3 Fragment (android.support.v4.app.Fragment)2 ApiDocumentMessage (im.actor.core.api.ApiDocumentMessage)2 ApiJsonMessage (im.actor.core.api.ApiJsonMessage)2 ConversationState (im.actor.core.entity.ConversationState)2 AbsContent (im.actor.core.entity.content.AbsContent)2 FileLocalSource (im.actor.core.entity.content.FileLocalSource)2 CursorReaderActor (im.actor.core.modules.messaging.actions.CursorReaderActor)2 CursorReceiverActor (im.actor.core.modules.messaging.actions.CursorReceiverActor)2 CommandCallback (im.actor.core.viewmodel.CommandCallback)2