mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-24 11:45:28 +00:00
Fix bug with processing and displaying long messages with mentions.
This commit is contained in:
@@ -132,10 +132,20 @@ public class ConversationMessage {
|
||||
*/
|
||||
@WorkerThread
|
||||
public static @NonNull ConversationMessage createWithUnresolvedData(@NonNull Context context, @NonNull MessageRecord messageRecord) {
|
||||
return createWithUnresolvedData(context, messageRecord, messageRecord.getDisplayBody(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link ConversationMessage} wrapping the provided MessageRecord and body, and will query for potential mentions. If mentions
|
||||
* are found, the body of the provided message will be updated and modified to match actual mentions. This will perform
|
||||
* database operations to query for mentions and then to resolve mentions to display names.
|
||||
*/
|
||||
@WorkerThread
|
||||
public static @NonNull ConversationMessage createWithUnresolvedData(@NonNull Context context, @NonNull MessageRecord messageRecord, @NonNull CharSequence body) {
|
||||
if (messageRecord.isMms()) {
|
||||
List<Mention> mentions = DatabaseFactory.getMentionDatabase(context).getMentionsForMessage(messageRecord.getId());
|
||||
if (!mentions.isEmpty()) {
|
||||
MentionUtil.UpdatedBodyAndMentions updated = MentionUtil.updateBodyAndMentionsWithDisplayNames(context, messageRecord, mentions);
|
||||
MentionUtil.UpdatedBodyAndMentions updated = MentionUtil.updateBodyAndMentionsWithDisplayNames(context, body, mentions);
|
||||
return new ConversationMessage(messageRecord, updated.getBody(), updated.getMentions());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public final class MentionUtil {
|
||||
|
||||
for (Mention mention : sortedMentions) {
|
||||
if (invalidMention(body, mention)) {
|
||||
return new UpdatedBodyAndMentions(body, Collections.emptyList());
|
||||
continue;
|
||||
}
|
||||
|
||||
updatedBody.append(body.subSequence(bodyIndex, mention.getStart()));
|
||||
|
||||
@@ -15,11 +15,9 @@ import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||
class LongMessage {
|
||||
|
||||
private final ConversationMessage conversationMessage;
|
||||
private final String fullBody;
|
||||
|
||||
LongMessage(@NonNull ConversationMessage conversationMessage, @NonNull String fullBody) {
|
||||
LongMessage(@NonNull ConversationMessage conversationMessage) {
|
||||
this.conversationMessage = conversationMessage;
|
||||
this.fullBody = fullBody;
|
||||
}
|
||||
|
||||
@NonNull MessageRecord getMessageRecord() {
|
||||
@@ -27,6 +25,6 @@ class LongMessage {
|
||||
}
|
||||
|
||||
@NonNull CharSequence getFullBody(@NonNull Context context) {
|
||||
return !TextUtils.isEmpty(fullBody) ? fullBody : conversationMessage.getDisplayBody(context);
|
||||
return conversationMessage.getDisplayBody(context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,9 +54,9 @@ class LongMessageRepository {
|
||||
TextSlide textSlide = record.get().getSlideDeck().getTextSlide();
|
||||
|
||||
if (textSlide != null && textSlide.getUri() != null) {
|
||||
return Optional.of(new LongMessage(ConversationMessageFactory.createWithUnresolvedData(context, record.get()), readFullBody(context, textSlide.getUri())));
|
||||
return Optional.of(new LongMessage(ConversationMessageFactory.createWithUnresolvedData(context, record.get(), readFullBody(context, textSlide.getUri()))));
|
||||
} else {
|
||||
return Optional.of(new LongMessage(ConversationMessageFactory.createWithUnresolvedData(context, record.get()), ""));
|
||||
return Optional.of(new LongMessage(ConversationMessageFactory.createWithUnresolvedData(context, record.get())));
|
||||
}
|
||||
} else {
|
||||
return Optional.absent();
|
||||
@@ -68,7 +68,7 @@ class LongMessageRepository {
|
||||
Optional<MessageRecord> record = getSmsMessage(smsDatabase, messageId);
|
||||
|
||||
if (record.isPresent()) {
|
||||
return Optional.of(new LongMessage(ConversationMessageFactory.createWithUnresolvedData(context, record.get()), ""));
|
||||
return Optional.of(new LongMessage(ConversationMessageFactory.createWithUnresolvedData(context, record.get())));
|
||||
} else {
|
||||
return Optional.absent();
|
||||
}
|
||||
@@ -89,7 +89,7 @@ class LongMessageRepository {
|
||||
}
|
||||
}
|
||||
|
||||
private String readFullBody(@NonNull Context context, @NonNull Uri uri) {
|
||||
private @NonNull String readFullBody(@NonNull Context context, @NonNull Uri uri) {
|
||||
try (InputStream stream = PartAuthority.getAttachmentStream(context, uri)) {
|
||||
return StreamUtil.readFullyAsString(stream);
|
||||
} catch (IOException e) {
|
||||
|
||||
Reference in New Issue
Block a user