Search in sources :

Example 6 with Contact

use of org.thoughtcrime.securesms.contactshare.Contact in project Signal-Android by WhisperSystems.

the class ThreadBodyUtil method getFormattedBodyForMms.

@NonNull
private static String getFormattedBodyForMms(@NonNull Context context, @NonNull MmsMessageRecord record) {
    if (record.getSharedContacts().size() > 0) {
        Contact contact = record.getSharedContacts().get(0);
        return ContactUtil.getStringSummary(context, contact).toString();
    } else if (record.getSlideDeck().getDocumentSlide() != null) {
        return format(context, record, EmojiStrings.FILE, R.string.ThreadRecord_file);
    } else if (record.getSlideDeck().getAudioSlide() != null) {
        return format(context, record, EmojiStrings.AUDIO, R.string.ThreadRecord_voice_message);
    } else if (MessageRecordUtil.hasSticker(record)) {
        String emoji = getStickerEmoji(record);
        return format(context, record, emoji, R.string.ThreadRecord_sticker);
    }
    boolean hasImage = false;
    boolean hasVideo = false;
    boolean hasGif = false;
    for (Slide slide : record.getSlideDeck().getSlides()) {
        hasVideo |= slide.hasVideo();
        hasImage |= slide.hasImage();
        hasGif |= slide instanceof GifSlide || slide.isVideoGif();
    }
    if (hasGif) {
        return format(context, record, EmojiStrings.GIF, R.string.ThreadRecord_gif);
    } else if (hasVideo) {
        return format(context, record, EmojiStrings.VIDEO, R.string.ThreadRecord_video);
    } else if (hasImage) {
        return format(context, record, EmojiStrings.PHOTO, R.string.ThreadRecord_photo);
    } else if (TextUtils.isEmpty(record.getBody())) {
        return context.getString(R.string.ThreadRecord_media_message);
    } else {
        return getBody(context, record);
    }
}
Also used : StickerSlide(org.thoughtcrime.securesms.mms.StickerSlide) GifSlide(org.thoughtcrime.securesms.mms.GifSlide) Slide(org.thoughtcrime.securesms.mms.Slide) GifSlide(org.thoughtcrime.securesms.mms.GifSlide) Contact(org.thoughtcrime.securesms.contactshare.Contact) NonNull(androidx.annotation.NonNull)

Example 7 with Contact

use of org.thoughtcrime.securesms.contactshare.Contact in project Signal-Android by WhisperSystems.

the class SendJob method markAttachmentsUploaded.

protected void markAttachmentsUploaded(long messageId, @NonNull OutgoingMediaMessage message) {
    List<Attachment> attachments = new LinkedList<>();
    attachments.addAll(message.getAttachments());
    attachments.addAll(Stream.of(message.getLinkPreviews()).map(lp -> lp.getThumbnail().orNull()).withoutNulls().toList());
    attachments.addAll(Stream.of(message.getSharedContacts()).map(Contact::getAvatarAttachment).withoutNulls().toList());
    if (message.getOutgoingQuote() != null) {
        attachments.addAll(message.getOutgoingQuote().getAttachments());
    }
    AttachmentDatabase database = SignalDatabase.attachments();
    for (Attachment attachment : attachments) {
        database.markAttachmentUploaded(messageId, attachment);
    }
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) TextSecureExpiredException(org.thoughtcrime.securesms.TextSecureExpiredException) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Stream(com.annimon.stream.Stream) Contact(org.thoughtcrime.securesms.contactshare.Contact) Util(org.thoughtcrime.securesms.util.Util) NonNull(androidx.annotation.NonNull) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase) Collectors(java.util.stream.Collectors) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) Log(org.signal.core.util.logging.Log) List(java.util.List) Job(org.thoughtcrime.securesms.jobmanager.Job) LinkedList(java.util.LinkedList) BuildConfig(org.thoughtcrime.securesms.BuildConfig) Attachment(org.thoughtcrime.securesms.attachments.Attachment) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) LinkedList(java.util.LinkedList) AttachmentDatabase(org.thoughtcrime.securesms.database.AttachmentDatabase)

Example 8 with Contact

use of org.thoughtcrime.securesms.contactshare.Contact in project Signal-Android by WhisperSystems.

the class ConversationParentFragment method handleReplyMessage.

@Override
public void handleReplyMessage(ConversationMessage conversationMessage) {
    MessageRecord messageRecord = conversationMessage.getMessageRecord();
    Recipient author;
    if (messageRecord.isOutgoing()) {
        author = Recipient.self();
    } else {
        author = messageRecord.getIndividualRecipient();
    }
    if (messageRecord.isMms() && !((MmsMessageRecord) messageRecord).getSharedContacts().isEmpty()) {
        Contact contact = ((MmsMessageRecord) messageRecord).getSharedContacts().get(0);
        String displayName = ContactUtil.getDisplayName(contact);
        String body = getString(R.string.ConversationActivity_quoted_contact_message, EmojiStrings.BUST_IN_SILHOUETTE, displayName);
        SlideDeck slideDeck = new SlideDeck();
        if (contact.getAvatarAttachment() != null) {
            slideDeck.addSlide(MediaUtil.getSlideForAttachment(requireContext(), contact.getAvatarAttachment()));
        }
        inputPanel.setQuote(GlideApp.with(this), messageRecord.getDateSent(), author, body, slideDeck);
    } else if (messageRecord.isMms() && !((MmsMessageRecord) messageRecord).getLinkPreviews().isEmpty()) {
        LinkPreview linkPreview = ((MmsMessageRecord) messageRecord).getLinkPreviews().get(0);
        SlideDeck slideDeck = new SlideDeck();
        if (linkPreview.getThumbnail().isPresent()) {
            slideDeck.addSlide(MediaUtil.getSlideForAttachment(requireContext(), linkPreview.getThumbnail().get()));
        }
        inputPanel.setQuote(GlideApp.with(this), messageRecord.getDateSent(), author, conversationMessage.getDisplayBody(requireContext()), slideDeck);
    } else {
        SlideDeck slideDeck = messageRecord.isMms() ? ((MmsMessageRecord) messageRecord).getSlideDeck() : new SlideDeck();
        if (messageRecord.isMms() && ((MmsMessageRecord) messageRecord).isViewOnce()) {
            Attachment attachment = new TombstoneAttachment(MediaUtil.VIEW_ONCE, true);
            slideDeck = new SlideDeck();
            slideDeck.addSlide(MediaUtil.getSlideForAttachment(requireContext(), attachment));
        }
        inputPanel.setQuote(GlideApp.with(this), messageRecord.getDateSent(), author, conversationMessage.getDisplayBody(requireContext()), slideDeck);
    }
    inputPanel.clickOnComposeInput();
}
Also used : TombstoneAttachment(org.thoughtcrime.securesms.attachments.TombstoneAttachment) LinkPreview(org.thoughtcrime.securesms.linkpreview.LinkPreview) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Attachment(org.thoughtcrime.securesms.attachments.Attachment) TombstoneAttachment(org.thoughtcrime.securesms.attachments.TombstoneAttachment) SpannableString(android.text.SpannableString) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) Contact(org.thoughtcrime.securesms.contactshare.Contact)

Example 9 with Contact

use of org.thoughtcrime.securesms.contactshare.Contact in project Signal-Android by signalapp.

the class ConversationParentFragment method handleReplyMessage.

@Override
public void handleReplyMessage(ConversationMessage conversationMessage) {
    MessageRecord messageRecord = conversationMessage.getMessageRecord();
    Recipient author;
    if (messageRecord.isOutgoing()) {
        author = Recipient.self();
    } else {
        author = messageRecord.getIndividualRecipient();
    }
    if (messageRecord.isMms() && !((MmsMessageRecord) messageRecord).getSharedContacts().isEmpty()) {
        Contact contact = ((MmsMessageRecord) messageRecord).getSharedContacts().get(0);
        String displayName = ContactUtil.getDisplayName(contact);
        String body = getString(R.string.ConversationActivity_quoted_contact_message, EmojiStrings.BUST_IN_SILHOUETTE, displayName);
        SlideDeck slideDeck = new SlideDeck();
        if (contact.getAvatarAttachment() != null) {
            slideDeck.addSlide(MediaUtil.getSlideForAttachment(requireContext(), contact.getAvatarAttachment()));
        }
        inputPanel.setQuote(GlideApp.with(this), messageRecord.getDateSent(), author, body, slideDeck);
    } else if (messageRecord.isMms() && !((MmsMessageRecord) messageRecord).getLinkPreviews().isEmpty()) {
        LinkPreview linkPreview = ((MmsMessageRecord) messageRecord).getLinkPreviews().get(0);
        SlideDeck slideDeck = new SlideDeck();
        if (linkPreview.getThumbnail().isPresent()) {
            slideDeck.addSlide(MediaUtil.getSlideForAttachment(requireContext(), linkPreview.getThumbnail().get()));
        }
        inputPanel.setQuote(GlideApp.with(this), messageRecord.getDateSent(), author, conversationMessage.getDisplayBody(requireContext()), slideDeck);
    } else {
        SlideDeck slideDeck = messageRecord.isMms() ? ((MmsMessageRecord) messageRecord).getSlideDeck() : new SlideDeck();
        if (messageRecord.isMms() && ((MmsMessageRecord) messageRecord).isViewOnce()) {
            Attachment attachment = new TombstoneAttachment(MediaUtil.VIEW_ONCE, true);
            slideDeck = new SlideDeck();
            slideDeck.addSlide(MediaUtil.getSlideForAttachment(requireContext(), attachment));
        }
        inputPanel.setQuote(GlideApp.with(this), messageRecord.getDateSent(), author, conversationMessage.getDisplayBody(requireContext()), slideDeck);
    }
    inputPanel.clickOnComposeInput();
}
Also used : TombstoneAttachment(org.thoughtcrime.securesms.attachments.TombstoneAttachment) LinkPreview(org.thoughtcrime.securesms.linkpreview.LinkPreview) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Attachment(org.thoughtcrime.securesms.attachments.Attachment) TombstoneAttachment(org.thoughtcrime.securesms.attachments.TombstoneAttachment) SpannableString(android.text.SpannableString) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) Contact(org.thoughtcrime.securesms.contactshare.Contact)

Example 10 with Contact

use of org.thoughtcrime.securesms.contactshare.Contact in project Signal-Android by signalapp.

the class MmsDatabase method insertMediaMessage.

private long insertMediaMessage(long threadId, @Nullable String body, @NonNull List<Attachment> attachments, @NonNull List<Attachment> quoteAttachments, @NonNull List<Contact> sharedContacts, @NonNull List<LinkPreview> linkPreviews, @NonNull List<Mention> mentions, @Nullable BodyRangeList messageRanges, @NonNull ContentValues contentValues, @Nullable InsertListener insertListener, boolean updateThread) throws MmsException {
    SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
    AttachmentDatabase partsDatabase = SignalDatabase.attachments();
    MentionDatabase mentionDatabase = SignalDatabase.mentions();
    boolean mentionsSelf = Stream.of(mentions).filter(m -> Recipient.resolved(m.getRecipientId()).isSelf()).findFirst().isPresent();
    List<Attachment> allAttachments = new LinkedList<>();
    List<Attachment> contactAttachments = Stream.of(sharedContacts).map(Contact::getAvatarAttachment).filter(a -> a != null).toList();
    List<Attachment> previewAttachments = Stream.of(linkPreviews).filter(lp -> lp.getThumbnail().isPresent()).map(lp -> lp.getThumbnail().get()).toList();
    allAttachments.addAll(attachments);
    allAttachments.addAll(contactAttachments);
    allAttachments.addAll(previewAttachments);
    contentValues.put(BODY, body);
    contentValues.put(PART_COUNT, allAttachments.size());
    contentValues.put(MENTIONS_SELF, mentionsSelf ? 1 : 0);
    if (messageRanges != null) {
        contentValues.put(MESSAGE_RANGES, messageRanges.toByteArray());
    }
    db.beginTransaction();
    try {
        long messageId = db.insert(TABLE_NAME, null, contentValues);
        mentionDatabase.insert(threadId, messageId, mentions);
        Map<Attachment, AttachmentId> insertedAttachments = partsDatabase.insertAttachmentsForMessage(messageId, allAttachments, quoteAttachments);
        String serializedContacts = getSerializedSharedContacts(insertedAttachments, sharedContacts);
        String serializedPreviews = getSerializedLinkPreviews(insertedAttachments, linkPreviews);
        if (!TextUtils.isEmpty(serializedContacts)) {
            ContentValues contactValues = new ContentValues();
            contactValues.put(SHARED_CONTACTS, serializedContacts);
            SQLiteDatabase database = databaseHelper.getSignalReadableDatabase();
            int rows = database.update(TABLE_NAME, contactValues, ID + " = ?", new String[] { String.valueOf(messageId) });
            if (rows <= 0) {
                Log.w(TAG, "Failed to update message with shared contact data.");
            }
        }
        if (!TextUtils.isEmpty(serializedPreviews)) {
            ContentValues contactValues = new ContentValues();
            contactValues.put(LINK_PREVIEWS, serializedPreviews);
            SQLiteDatabase database = databaseHelper.getSignalReadableDatabase();
            int rows = database.update(TABLE_NAME, contactValues, ID + " = ?", new String[] { String.valueOf(messageId) });
            if (rows <= 0) {
                Log.w(TAG, "Failed to update message with link preview data.");
            }
        }
        db.setTransactionSuccessful();
        return messageId;
    } finally {
        db.endTransaction();
        if (insertListener != null) {
            insertListener.onComplete();
        }
        long contentValuesThreadId = contentValues.getAsLong(THREAD_ID);
        if (updateThread) {
            SignalDatabase.threads().setLastScrolled(contentValuesThreadId, 0);
            SignalDatabase.threads().update(threadId, true);
        }
    }
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) GroupMigrationMembershipChange(org.thoughtcrime.securesms.groups.GroupMigrationMembershipChange) LinkPreview(org.thoughtcrime.securesms.linkpreview.LinkPreview) NonNull(androidx.annotation.NonNull) Avatar(org.thoughtcrime.securesms.contactshare.Contact.Avatar) MessageGroupContext(org.thoughtcrime.securesms.mms.MessageGroupContext) Mention(org.thoughtcrime.securesms.database.model.Mention) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) SecureRandom(java.security.SecureRandom) JSONException(org.json.JSONException) JsonUtils(org.thoughtcrime.securesms.util.JsonUtils) JSONObject(org.json.JSONObject) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) BodyRangeList(org.thoughtcrime.securesms.database.model.databaseprotos.BodyRangeList) SqlUtil(org.thoughtcrime.securesms.util.SqlUtil) IdentityKeyMismatchSet(org.thoughtcrime.securesms.database.documents.IdentityKeyMismatchSet) Map(java.util.Map) ViewOnceUtil(org.thoughtcrime.securesms.revealable.ViewOnceUtil) Recipient(org.thoughtcrime.securesms.recipients.Recipient) OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) OutgoingGroupUpdateMessage(org.thoughtcrime.securesms.mms.OutgoingGroupUpdateMessage) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) NotificationInd(com.google.android.mms.pdu_alt.NotificationInd) ACI(org.whispersystems.signalservice.api.push.ACI) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Collection(java.util.Collection) OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage) Set(java.util.Set) UUID(java.util.UUID) OutgoingExpirationUpdateMessage(org.thoughtcrime.securesms.mms.OutgoingExpirationUpdateMessage) Log(org.signal.core.util.logging.Log) NetworkFailureSet(org.thoughtcrime.securesms.database.documents.NetworkFailureSet) List(java.util.List) Nullable(androidx.annotation.Nullable) ContentValues(android.content.ContentValues) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) Attachment(org.thoughtcrime.securesms.attachments.Attachment) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) MediaUtil(org.thoughtcrime.securesms.util.MediaUtil) Context(android.content.Context) Stream(com.annimon.stream.Stream) Util(org.thoughtcrime.securesms.util.Util) HashMap(java.util.HashMap) SQLiteStatement(net.zetetic.database.sqlcipher.SQLiteStatement) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) ArrayList(java.util.ArrayList) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) HashSet(java.util.HashSet) Pair(org.whispersystems.libsignal.util.Pair) MmsNotificationAttachment(org.thoughtcrime.securesms.attachments.MmsNotificationAttachment) NotificationMmsMessageRecord(org.thoughtcrime.securesms.database.model.NotificationMmsMessageRecord) QuoteModel(org.thoughtcrime.securesms.mms.QuoteModel) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) LinkedList(java.util.LinkedList) PduHeaders(com.google.android.mms.pdu_alt.PduHeaders) Cursor(android.database.Cursor) MessageId(org.thoughtcrime.securesms.database.model.MessageId) Collectors(com.annimon.stream.Collectors) Contact(org.thoughtcrime.securesms.contactshare.Contact) IdentityKeyMismatch(org.thoughtcrime.securesms.database.documents.IdentityKeyMismatch) MmsException(org.thoughtcrime.securesms.mms.MmsException) TextUtils(android.text.TextUtils) IOException(java.io.IOException) Quote(org.thoughtcrime.securesms.database.model.Quote) Optional(org.whispersystems.libsignal.util.guava.Optional) CursorUtil(org.thoughtcrime.securesms.util.CursorUtil) ViewOnceExpirationInfo(org.thoughtcrime.securesms.revealable.ViewOnceExpirationInfo) AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId) NetworkFailure(org.thoughtcrime.securesms.database.documents.NetworkFailure) TrimThreadJob(org.thoughtcrime.securesms.jobs.TrimThreadJob) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) Collections(java.util.Collections) JSONArray(org.json.JSONArray) IncomingMediaMessage(org.thoughtcrime.securesms.mms.IncomingMediaMessage) ContentValues(android.content.ContentValues) Attachment(org.thoughtcrime.securesms.attachments.Attachment) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) MmsNotificationAttachment(org.thoughtcrime.securesms.attachments.MmsNotificationAttachment) LinkedList(java.util.LinkedList) AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId) Contact(org.thoughtcrime.securesms.contactshare.Contact)

Aggregations

Contact (org.thoughtcrime.securesms.contactshare.Contact)24 NonNull (androidx.annotation.NonNull)14 LinkedList (java.util.LinkedList)14 Attachment (org.thoughtcrime.securesms.attachments.Attachment)14 Nullable (androidx.annotation.Nullable)12 List (java.util.List)12 AttachmentId (org.thoughtcrime.securesms.attachments.AttachmentId)12 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)12 Context (android.content.Context)10 Stream (com.annimon.stream.Stream)10 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 Log (org.signal.core.util.logging.Log)10 Recipient (org.thoughtcrime.securesms.recipients.Recipient)10 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)10 Collections (java.util.Collections)8 Map (java.util.Map)8 LinkPreview (org.thoughtcrime.securesms.linkpreview.LinkPreview)8 Collection (java.util.Collection)6