Search in sources :

Example 6 with Mention

use of org.thoughtcrime.securesms.database.model.Mention in project Signal-Android by WhisperSystems.

the class ConversationParentFragment method sendMediaMessage.

private void sendMediaMessage(@NonNull MediaSendActivityResult result) {
    long thread = this.threadId;
    long expiresIn = TimeUnit.SECONDS.toMillis(recipient.get().getExpiresInSeconds());
    QuoteModel quote = result.isViewOnce() ? null : inputPanel.getQuote().orNull();
    List<Mention> mentions = new ArrayList<>(result.getMentions());
    OutgoingMediaMessage message = new OutgoingMediaMessage(recipient.get(), new SlideDeck(), result.getBody(), System.currentTimeMillis(), -1, expiresIn, result.isViewOnce(), distributionType, quote, Collections.emptyList(), Collections.emptyList(), mentions);
    OutgoingMediaMessage secureMessage = new OutgoingSecureMediaMessage(message);
    final Context context = requireContext().getApplicationContext();
    ApplicationDependencies.getTypingStatusSender().onTypingStopped(thread);
    inputPanel.clearQuote();
    attachmentManager.clear(glideRequests, false);
    silentlySetComposeText("");
    long id = fragment.stageOutgoingMessage(secureMessage);
    SimpleTask.run(() -> {
        long resultId = MessageSender.sendPushWithPreUploadedMedia(context, secureMessage, result.getPreUploadResults(), thread, null);
        int deleted = SignalDatabase.attachments().deleteAbandonedPreuploadedAttachments();
        Log.i(TAG, "Deleted " + deleted + " abandoned attachments.");
        return resultId;
    }, this::sendComplete);
}
Also used : Context(android.content.Context) OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage) Mention(org.thoughtcrime.securesms.database.model.Mention) ArrayList(java.util.ArrayList) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) QuoteModel(org.thoughtcrime.securesms.mms.QuoteModel) SuppressLint(android.annotation.SuppressLint)

Example 7 with Mention

use of org.thoughtcrime.securesms.database.model.Mention in project Signal-Android by WhisperSystems.

the class ConversationParentFragment method getDraftsForCurrentState.

private Drafts getDraftsForCurrentState() {
    Drafts drafts = new Drafts();
    if (recipient.get().isGroup() && !recipient.get().isActiveGroup()) {
        return drafts;
    }
    if (!Util.isEmpty(composeText)) {
        drafts.add(new Draft(Draft.TEXT, composeText.getTextTrimmed().toString()));
        List<Mention> draftMentions = composeText.getMentions();
        if (!draftMentions.isEmpty()) {
            drafts.add(new Draft(Draft.MENTION, Base64.encodeBytes(MentionUtil.mentionsToBodyRangeList(draftMentions).toByteArray())));
        }
    }
    for (Slide slide : attachmentManager.buildSlideDeck().getSlides()) {
        if (slide.hasAudio() && slide.getUri() != null)
            drafts.add(new Draft(Draft.AUDIO, slide.getUri().toString()));
        else if (slide.hasVideo() && slide.getUri() != null)
            drafts.add(new Draft(Draft.VIDEO, slide.getUri().toString()));
        else if (slide.hasLocation())
            drafts.add(new Draft(Draft.LOCATION, ((LocationSlide) slide).getPlace().serialize()));
        else if (slide.hasImage() && slide.getUri() != null)
            drafts.add(new Draft(Draft.IMAGE, slide.getUri().toString()));
    }
    Optional<QuoteModel> quote = inputPanel.getQuote();
    if (quote.isPresent()) {
        drafts.add(new Draft(Draft.QUOTE, new QuoteId(quote.get().getId(), quote.get().getAuthor()).serialize()));
    }
    Draft voiceNoteDraft = draftViewModel.getVoiceNoteDraft();
    if (voiceNoteDraft != null) {
        drafts.add(voiceNoteDraft);
    }
    return drafts;
}
Also used : LocationSlide(org.thoughtcrime.securesms.mms.LocationSlide) VoiceNoteDraft(org.thoughtcrime.securesms.components.voice.VoiceNoteDraft) Draft(org.thoughtcrime.securesms.database.DraftDatabase.Draft) LocationSlide(org.thoughtcrime.securesms.mms.LocationSlide) StickerSlide(org.thoughtcrime.securesms.mms.StickerSlide) Slide(org.thoughtcrime.securesms.mms.Slide) GifSlide(org.thoughtcrime.securesms.mms.GifSlide) ImageSlide(org.thoughtcrime.securesms.mms.ImageSlide) AudioSlide(org.thoughtcrime.securesms.mms.AudioSlide) VideoSlide(org.thoughtcrime.securesms.mms.VideoSlide) QuoteId(org.thoughtcrime.securesms.mms.QuoteId) Mention(org.thoughtcrime.securesms.database.model.Mention) QuoteModel(org.thoughtcrime.securesms.mms.QuoteModel) Drafts(org.thoughtcrime.securesms.database.DraftDatabase.Drafts)

Example 8 with Mention

use of org.thoughtcrime.securesms.database.model.Mention in project Signal-Android by WhisperSystems.

the class ConversationDataSource method load.

@Override
@Nullable
public ConversationMessage load(@NonNull MessageId messageId) {
    Stopwatch stopwatch = new Stopwatch("load(" + messageId + "), thread " + threadId);
    MessageDatabase database = messageId.isMms() ? SignalDatabase.mms() : SignalDatabase.sms();
    MessageRecord record = database.getMessageRecordOrNull(messageId.getId());
    stopwatch.split("message");
    try {
        if (record != null) {
            List<Mention> mentions;
            if (messageId.isMms()) {
                mentions = SignalDatabase.mentions().getMentionsForMessage(messageId.getId());
            } else {
                mentions = Collections.emptyList();
            }
            stopwatch.split("mentions");
            List<ReactionRecord> reactions = SignalDatabase.reactions().getReactions(messageId);
            record = ReactionHelper.recordWithReactions(record, reactions);
            stopwatch.split("reactions");
            if (messageId.isMms()) {
                List<DatabaseAttachment> attachments = SignalDatabase.attachments().getAttachmentsForMessage(messageId.getId());
                if (attachments.size() > 0) {
                    record = ((MediaMmsMessageRecord) record).withAttachments(context, attachments);
                }
            }
            stopwatch.split("attachments");
            return ConversationMessage.ConversationMessageFactory.createWithUnresolvedData(ApplicationDependencies.getApplication(), record, mentions);
        } else {
            return null;
        }
    } finally {
        stopwatch.stop(TAG);
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) Mention(org.thoughtcrime.securesms.database.model.Mention) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) InMemoryMessageRecord(org.thoughtcrime.securesms.database.model.InMemoryMessageRecord) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) ReactionRecord(org.thoughtcrime.securesms.database.model.ReactionRecord) Nullable(androidx.annotation.Nullable)

Example 9 with Mention

use of org.thoughtcrime.securesms.database.model.Mention in project Signal-Android by WhisperSystems.

the class SearchRepository method queryMessages.

@NonNull
private List<MessageResult> queryMessages(@NonNull String query) {
    if (Util.isEmpty(query)) {
        return Collections.emptyList();
    }
    List<MessageResult> results;
    try (Cursor cursor = searchDatabase.queryMessages(query)) {
        results = readToList(cursor, new MessageModelBuilder());
    }
    List<Long> messageIds = new LinkedList<>();
    for (MessageResult result : results) {
        if (result.isMms()) {
            messageIds.add(result.getMessageId());
        }
    }
    if (messageIds.isEmpty()) {
        return results;
    }
    Map<Long, List<Mention>> mentions = SignalDatabase.mentions().getMentionsForMessages(messageIds);
    if (mentions.isEmpty()) {
        return results;
    }
    List<MessageResult> updatedResults = new ArrayList<>(results.size());
    for (MessageResult result : results) {
        if (result.isMms() && mentions.containsKey(result.getMessageId())) {
            List<Mention> messageMentions = mentions.get(result.getMessageId());
            // noinspection ConstantConditions
            String updatedBody = MentionUtil.updateBodyAndMentionsWithDisplayNames(context, result.getBody(), messageMentions).getBody().toString();
            String updatedSnippet = updateSnippetWithDisplayNames(result.getBody(), result.getBodySnippet(), messageMentions);
            // noinspection ConstantConditions
            updatedResults.add(new MessageResult(result.getConversationRecipient(), result.getMessageRecipient(), updatedBody, updatedSnippet, result.getThreadId(), result.getMessageId(), result.getReceivedTimestampMs(), result.isMms()));
        } else {
            updatedResults.add(result);
        }
    }
    return updatedResults;
}
Also used : ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) MergeCursor(android.database.MergeCursor) LinkedList(java.util.LinkedList) Mention(org.thoughtcrime.securesms.database.model.Mention) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) NonNull(androidx.annotation.NonNull)

Example 10 with Mention

use of org.thoughtcrime.securesms.database.model.Mention in project Signal-Android by WhisperSystems.

the class SearchRepository method updateSnippetWithDisplayNames.

@NonNull
private String updateSnippetWithDisplayNames(@NonNull String body, @NonNull String bodySnippet, @NonNull List<Mention> mentions) {
    String cleanSnippet = bodySnippet;
    int startOffset = 0;
    if (cleanSnippet.startsWith(SNIPPET_WRAP)) {
        cleanSnippet = cleanSnippet.substring(SNIPPET_WRAP.length());
        startOffset = SNIPPET_WRAP.length();
    }
    if (cleanSnippet.endsWith(SNIPPET_WRAP)) {
        cleanSnippet = cleanSnippet.substring(0, cleanSnippet.length() - SNIPPET_WRAP.length());
    }
    int startIndex = body.indexOf(cleanSnippet);
    if (startIndex != -1) {
        List<Mention> adjustMentions = new ArrayList<>(mentions.size());
        for (Mention mention : mentions) {
            int adjustedStart = mention.getStart() - startIndex + startOffset;
            if (adjustedStart >= 0 && adjustedStart + mention.getLength() <= cleanSnippet.length()) {
                adjustMentions.add(new Mention(mention.getRecipientId(), adjustedStart, mention.getLength()));
            }
        }
        // noinspection ConstantConditions
        return MentionUtil.updateBodyAndMentionsWithDisplayNames(context, bodySnippet, adjustMentions).getBody().toString();
    }
    return bodySnippet;
}
Also used : Mention(org.thoughtcrime.securesms.database.model.Mention) ArrayList(java.util.ArrayList) NonNull(androidx.annotation.NonNull)

Aggregations

Mention (org.thoughtcrime.securesms.database.model.Mention)32 NonNull (androidx.annotation.NonNull)20 ArrayList (java.util.ArrayList)20 LinkedList (java.util.LinkedList)14 List (java.util.List)14 Context (android.content.Context)12 Nullable (androidx.annotation.Nullable)12 MessageRecord (org.thoughtcrime.securesms.database.model.MessageRecord)12 QuoteModel (org.thoughtcrime.securesms.mms.QuoteModel)12 SlideDeck (org.thoughtcrime.securesms.mms.SlideDeck)12 Recipient (org.thoughtcrime.securesms.recipients.Recipient)12 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)10 OutgoingSecureMediaMessage (org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage)10 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)10 Cursor (android.database.Cursor)8 Collectors (com.annimon.stream.Collectors)8 Stream (com.annimon.stream.Stream)8 IOException (java.io.IOException)8 SecureRandom (java.security.SecureRandom)8 Collections (java.util.Collections)8