Search in sources :

Example 6 with PhotoContent

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

the class SenderActor method performSendContent.

// Sending content
private void performSendContent(final Peer peer, final long rid, AbsContent content) {
    WakeLock wakeLock = im.actor.runtime.Runtime.makeWakeLock();
    ApiMessage message;
    if (content instanceof TextContent) {
        message = new ApiTextMessage(((TextContent) content).getText(), ((TextContent) content).getMentions(), ((TextContent) content).getTextMessageEx());
    } else if (content instanceof DocumentContent) {
        DocumentContent documentContent = (DocumentContent) content;
        FileRemoteSource source = (FileRemoteSource) documentContent.getSource();
        ApiDocumentEx documentEx = null;
        if (content instanceof PhotoContent) {
            PhotoContent photoContent = (PhotoContent) content;
            documentEx = new ApiDocumentExPhoto(photoContent.getW(), photoContent.getH());
        } else if (content instanceof VideoContent) {
            VideoContent videoContent = (VideoContent) content;
            documentEx = new ApiDocumentExVideo(videoContent.getW(), videoContent.getH(), videoContent.getDuration());
        } else if (content instanceof AnimationContent) {
            AnimationContent animationContent = (AnimationContent) content;
            documentEx = new ApiDocumentExAnimation(animationContent.getW(), animationContent.getH());
        } else if (content instanceof VoiceContent) {
            VoiceContent voiceContent = (VoiceContent) content;
            documentEx = new ApiDocumentExVoice(voiceContent.getDuration());
        }
        ApiFastThumb fastThumb = null;
        if (documentContent.getFastThumb() != null) {
            fastThumb = new ApiFastThumb(documentContent.getFastThumb().getW(), documentContent.getFastThumb().getH(), documentContent.getFastThumb().getImage());
        }
        message = new ApiDocumentMessage(source.getFileReference().getFileId(), source.getFileReference().getAccessHash(), source.getFileReference().getFileSize(), source.getFileReference().getFileName(), documentContent.getMimeType(), fastThumb, documentEx);
    } else if (content instanceof LocationContent) {
        message = new ApiJsonMessage(((LocationContent) content).getRawJson());
    } else if (content instanceof ContactContent) {
        message = new ApiJsonMessage(((ContactContent) content).getRawJson());
    } else if (content instanceof JsonContent) {
        message = new ApiJsonMessage(((JsonContent) content).getRawJson());
    } else if (content instanceof StickerContent) {
        message = ((ContentRemoteContainer) content.getContentContainer()).getMessage();
    } else {
        return;
    }
    performSendApiContent(peer, rid, message, wakeLock);
}
Also used : ApiFastThumb(im.actor.core.api.ApiFastThumb) ApiDocumentEx(im.actor.core.api.ApiDocumentEx) ApiDocumentExVoice(im.actor.core.api.ApiDocumentExVoice) StickerContent(im.actor.core.entity.content.StickerContent) LocationContent(im.actor.core.entity.content.LocationContent) WakeLock(im.actor.runtime.power.WakeLock) VideoContent(im.actor.core.entity.content.VideoContent) ApiTextMessage(im.actor.core.api.ApiTextMessage) JsonContent(im.actor.core.entity.content.JsonContent) AnimationContent(im.actor.core.entity.content.AnimationContent) ContactContent(im.actor.core.entity.content.ContactContent) ApiJsonMessage(im.actor.core.api.ApiJsonMessage) FileRemoteSource(im.actor.core.entity.content.FileRemoteSource) VoiceContent(im.actor.core.entity.content.VoiceContent) DocumentContent(im.actor.core.entity.content.DocumentContent) ApiMessage(im.actor.core.api.ApiMessage) ApiDocumentExPhoto(im.actor.core.api.ApiDocumentExPhoto) ApiDocumentExAnimation(im.actor.core.api.ApiDocumentExAnimation) ApiDocumentMessage(im.actor.core.api.ApiDocumentMessage) ContentRemoteContainer(im.actor.core.entity.content.internal.ContentRemoteContainer) ApiDocumentExVideo(im.actor.core.api.ApiDocumentExVideo) TextContent(im.actor.core.entity.content.TextContent) PhotoContent(im.actor.core.entity.content.PhotoContent)

Example 7 with PhotoContent

use of im.actor.core.entity.content.PhotoContent 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)

Example 8 with PhotoContent

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

the class JsContent method createContent.

public static JsContent createContent(AbsContent src, int sender) {
    JsMessenger messenger = JsMessenger.getInstance();
    JsContent content;
    if (src instanceof TextContent) {
        TextContent textContent = (TextContent) src;
        if (textContent.getTextMessageEx() instanceof ApiTextModernMessage) {
            ApiTextModernMessage modernMessage = (ApiTextModernMessage) textContent.getTextMessageEx();
            String text = modernMessage.getText();
            JsParagraphStyle paragraphStyle = JsParagraphStyle.create(modernMessage.getStyle());
            JsArray<JsAttach> attaches = JsArray.createArray().cast();
            for (ApiTextModernAttach srcAttach : modernMessage.getAttaches()) {
                JsArray<JsAttachField> fields = JsArray.createArray().cast();
                for (ApiTextModernField f : srcAttach.getFields()) {
                    boolean isShort = f.isShort() != null ? f.isShort() : true;
                    fields.push(JsAttachField.create(f.getTitle(), f.getValue(), isShort));
                }
                attaches.push(JsAttach.create(srcAttach.getTitle(), srcAttach.getTitleUrl(), srcAttach.getText(), JsParagraphStyle.create(srcAttach.getStyle()), fields));
            }
            content = JsContentTextModern.create(text, paragraphStyle, attaches);
        } else {
            content = JsContentText.create(((TextContent) src).getText());
        }
    } else if (src instanceof ServiceContent) {
        content = JsContentService.create(messenger.getFormatter().formatFullServiceMessage(sender, (ServiceContent) src, false));
    } else if (src instanceof DocumentContent) {
        DocumentContent doc = (DocumentContent) src;
        String fileName = doc.getName();
        String fileExtension = doc.getExt();
        String fileSize = messenger.getFormatter().formatFileSize(doc.getSource().getSize());
        String fileUrl = null;
        if (doc.getSource() instanceof FileRemoteSource) {
            fileUrl = messenger.getFileUrl(((FileRemoteSource) doc.getSource()).getFileReference());
        }
        boolean isUploading = doc.getSource() instanceof FileLocalSource;
        String thumb = null;
        if (doc.getFastThumb() != null) {
            String thumbBase64 = Base64Utils.toBase64(doc.getFastThumb().getImage());
            thumb = "data:image/jpg;base64," + thumbBase64;
        }
        if (src instanceof PhotoContent && thumb != null) {
            PhotoContent photoContent = (PhotoContent) src;
            content = JsContentPhoto.create(fileName, fileExtension, fileSize, photoContent.getW(), photoContent.getH(), thumb, fileUrl, isUploading);
        } else if (src instanceof AnimationContent) {
            AnimationContent animationContent = (AnimationContent) src;
            content = JsContentAnimation.create(fileName, fileExtension, fileSize, animationContent.getW(), animationContent.getH(), thumb, fileUrl, isUploading);
        } else if (src instanceof VoiceContent) {
            VoiceContent voiceContent = (VoiceContent) src;
            content = JsContentVoice.create(fileName, fileExtension, fileSize, fileUrl, isUploading, voiceContent.getDuration());
        } else {
            content = JsContentDocument.create(fileName, fileExtension, fileSize, thumb, fileUrl, isUploading);
        }
    } else if (src instanceof StickerContent) {
        StickerContent sticker = (StickerContent) src;
        ImageLocation stickerImage = sticker.getImage256();
        if (sticker.getImage512() != null) {
            stickerImage = sticker.getImage512();
        }
        String fileUrl = messenger.getFileUrl(stickerImage.getReference());
        String fileSize = messenger.getFormatter().formatFileSize(stickerImage.getReference().getFileSize());
        content = JsContentSticker.create(stickerImage.getReference().getFileName(), ".webp", fileSize, stickerImage.getWidth(), stickerImage.getHeight(), null, fileUrl, false);
    } else if (src instanceof ContactContent) {
        ContactContent contactContent = (ContactContent) src;
        JsArrayString phones = JsArray.createArray().cast();
        JsArrayString emails = JsArray.createArray().cast();
        for (String s : contactContent.getEmails()) {
            emails.push(s);
        }
        for (String s : contactContent.getPhones()) {
            phones.push(s);
        }
        content = JsContentContact.create(contactContent.getName(), contactContent.getPhoto64(), phones, emails);
    } else if (src instanceof LocationContent) {
        LocationContent locationContent = (LocationContent) src;
        content = JsContentLocation.create(locationContent.getLongitude(), locationContent.getLatitude(), locationContent.getStreet(), locationContent.getPlace());
    } else {
        content = JsContentUnsupported.create();
    }
    return content;
}
Also used : LocationContent(im.actor.core.entity.content.LocationContent) ApiTextModernField(im.actor.core.api.ApiTextModernField) AnimationContent(im.actor.core.entity.content.AnimationContent) JsArrayString(com.google.gwt.core.client.JsArrayString) ContactContent(im.actor.core.entity.content.ContactContent) ImageLocation(im.actor.core.entity.ImageLocation) ApiTextModernMessage(im.actor.core.api.ApiTextModernMessage) JsMessenger(im.actor.core.js.JsMessenger) ServiceContent(im.actor.core.entity.content.ServiceContent) FileLocalSource(im.actor.core.entity.content.FileLocalSource) PhotoContent(im.actor.core.entity.content.PhotoContent) StickerContent(im.actor.core.entity.content.StickerContent) JsArrayString(com.google.gwt.core.client.JsArrayString) ApiTextModernAttach(im.actor.core.api.ApiTextModernAttach) FileRemoteSource(im.actor.core.entity.content.FileRemoteSource) VoiceContent(im.actor.core.entity.content.VoiceContent) DocumentContent(im.actor.core.entity.content.DocumentContent) TextContent(im.actor.core.entity.content.TextContent)

Aggregations

PhotoContent (im.actor.core.entity.content.PhotoContent)8 AnimationContent (im.actor.core.entity.content.AnimationContent)5 DocumentContent (im.actor.core.entity.content.DocumentContent)5 FileRemoteSource (im.actor.core.entity.content.FileRemoteSource)5 VideoContent (im.actor.core.entity.content.VideoContent)5 FileLocalSource (im.actor.core.entity.content.FileLocalSource)4 ContactContent (im.actor.core.entity.content.ContactContent)3 LocationContent (im.actor.core.entity.content.LocationContent)3 TextContent (im.actor.core.entity.content.TextContent)3 VoiceContent (im.actor.core.entity.content.VoiceContent)3 ApiDocumentMessage (im.actor.core.api.ApiDocumentMessage)2 ApiJsonMessage (im.actor.core.api.ApiJsonMessage)2 ApiMessage (im.actor.core.api.ApiMessage)2 ApiTextMessage (im.actor.core.api.ApiTextMessage)2 FileReference (im.actor.core.entity.FileReference)2 Message (im.actor.core.entity.Message)2 StickerContent (im.actor.core.entity.content.StickerContent)2 PendingMessage (im.actor.core.modules.messaging.actions.entity.PendingMessage)2 FileCallback (im.actor.core.viewmodel.FileCallback)2 UploadFileCallback (im.actor.core.viewmodel.UploadFileCallback)2