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);
}
}
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;
}
Aggregations