Search in sources :

Example 31 with Mention

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

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 32 with Mention

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

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)

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