mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 13:08:46 +00:00
Fix spoiler in notification with emoji prefix.
This commit is contained in:
committed by
Nicholas Tinsley
parent
326b95bd10
commit
784b705265
@@ -1,9 +1,11 @@
|
||||
package org.thoughtcrime.securesms.database;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
@@ -32,24 +34,28 @@ public final class ThreadBodyUtil {
|
||||
|
||||
public static @NonNull ThreadBody getFormattedBodyFor(@NonNull Context context, @NonNull MessageRecord record) {
|
||||
if (record.isMms()) {
|
||||
return getFormattedBodyForMms(context, (MmsMessageRecord) record);
|
||||
return getFormattedBodyForMms(context, (MmsMessageRecord) record, null);
|
||||
}
|
||||
|
||||
return new ThreadBody(record.getBody());
|
||||
}
|
||||
|
||||
private static @NonNull ThreadBody getFormattedBodyForMms(@NonNull Context context, @NonNull MmsMessageRecord record) {
|
||||
public static @NonNull CharSequence getFormattedBodyForNotification(@NonNull Context context, @NonNull MessageRecord record, @Nullable CharSequence bodyOverride) {
|
||||
return getFormattedBodyForMms(context, (MmsMessageRecord) record, bodyOverride).body;
|
||||
}
|
||||
|
||||
private static @NonNull ThreadBody getFormattedBodyForMms(@NonNull Context context, @NonNull MmsMessageRecord record, @Nullable CharSequence bodyOverride) {
|
||||
if (record.getSharedContacts().size() > 0) {
|
||||
Contact contact = record.getSharedContacts().get(0);
|
||||
|
||||
return new ThreadBody(ContactUtil.getStringSummary(context, contact).toString());
|
||||
} else if (record.getSlideDeck().getDocumentSlide() != null) {
|
||||
return format(context, record, EmojiStrings.FILE, R.string.ThreadRecord_file);
|
||||
return format(context, record, EmojiStrings.FILE, R.string.ThreadRecord_file, bodyOverride);
|
||||
} else if (record.getSlideDeck().getAudioSlide() != null) {
|
||||
return format(context, record, EmojiStrings.AUDIO, R.string.ThreadRecord_voice_message);
|
||||
return format(context, record, EmojiStrings.AUDIO, R.string.ThreadRecord_voice_message, bodyOverride);
|
||||
} else if (MessageRecordUtil.hasSticker(record)) {
|
||||
String emoji = getStickerEmoji(record);
|
||||
return format(context, record, emoji, R.string.ThreadRecord_sticker);
|
||||
return format(context, record, emoji, R.string.ThreadRecord_sticker, bodyOverride);
|
||||
} else if (MessageRecordUtil.hasGiftBadge(record)) {
|
||||
return format(EmojiStrings.GIFT, getGiftSummary(context, record));
|
||||
} else if (MessageRecordUtil.isStoryReaction(record)) {
|
||||
@@ -77,11 +83,11 @@ public final class ThreadBodyUtil {
|
||||
}
|
||||
|
||||
if (hasGif) {
|
||||
return format(context, record, EmojiStrings.GIF, R.string.ThreadRecord_gif);
|
||||
return format(context, record, EmojiStrings.GIF, R.string.ThreadRecord_gif, bodyOverride);
|
||||
} else if (hasVideo) {
|
||||
return format(context, record, EmojiStrings.VIDEO, R.string.ThreadRecord_video);
|
||||
return format(context, record, EmojiStrings.VIDEO, R.string.ThreadRecord_video, bodyOverride);
|
||||
} else if (hasImage) {
|
||||
return format(context, record, EmojiStrings.PHOTO, R.string.ThreadRecord_photo);
|
||||
return format(context, record, EmojiStrings.PHOTO, R.string.ThreadRecord_photo, bodyOverride);
|
||||
} else if (TextUtils.isEmpty(record.getBody())) {
|
||||
return new ThreadBody(context.getString(R.string.ThreadRecord_media_message));
|
||||
} else {
|
||||
@@ -153,18 +159,25 @@ public final class ThreadBodyUtil {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static @NonNull ThreadBody format(@NonNull Context context, @NonNull MessageRecord record, @NonNull String emoji, @StringRes int defaultStringRes) {
|
||||
CharSequence body = getBodyOrDefault(context, record, defaultStringRes).getBody();
|
||||
|
||||
private static @NonNull ThreadBody format(@NonNull Context context,
|
||||
@NonNull MessageRecord record,
|
||||
@NonNull String emoji,
|
||||
@StringRes int defaultStringRes,
|
||||
@Nullable CharSequence bodyOverride)
|
||||
{
|
||||
CharSequence body = !TextUtils.isEmpty(bodyOverride) ? bodyOverride
|
||||
: TextUtils.isEmpty(record.getBody()) ? context.getString(defaultStringRes)
|
||||
: getBody(context, record).getBody();
|
||||
return format(emoji, body);
|
||||
}
|
||||
|
||||
private static @NonNull ThreadBody format(@NonNull CharSequence prefix, @NonNull CharSequence body) {
|
||||
return new ThreadBody(String.format("%s %s", prefix, body), prefix.length() + 1);
|
||||
}
|
||||
|
||||
private static @NonNull ThreadBody getBodyOrDefault(@NonNull Context context, @NonNull MessageRecord record, @StringRes int defaultStringRes) {
|
||||
return TextUtils.isEmpty(record.getBody()) ? new ThreadBody(context.getString(defaultStringRes)) : getBody(context, record);
|
||||
SpannableStringBuilder builder = new SpannableStringBuilder();
|
||||
builder.append(prefix)
|
||||
.append(" ")
|
||||
.append(body);
|
||||
return new ThreadBody(builder, prefix.length() + 1);
|
||||
}
|
||||
|
||||
private static @NonNull ThreadBody getBody(@NonNull Context context, @NonNull MessageRecord record) {
|
||||
|
||||
@@ -225,15 +225,15 @@ class MessageNotification(threadRecipient: Recipient, record: MessageRecord) : N
|
||||
} else if (record.isRemoteDelete) {
|
||||
SpanUtil.italic(context.getString(R.string.MessageNotifier_this_message_was_deleted))
|
||||
} else if (record.isMms && !record.isMmsNotification && (record as MmsMessageRecord).slideDeck.slides.isNotEmpty()) {
|
||||
ThreadBodyUtil.getFormattedBodyFor(context, record).body
|
||||
ThreadBodyUtil.getFormattedBodyForNotification(context, record, getBodyWithMentionsAndStyles(context, record))
|
||||
} else if (record.isGroupCall) {
|
||||
MessageRecord.getGroupCallUpdateDescription(context, record.body, false).spannable
|
||||
} else if (record.hasGiftBadge()) {
|
||||
ThreadBodyUtil.getFormattedBodyFor(context, record).body
|
||||
ThreadBodyUtil.getFormattedBodyForNotification(context, record, null)
|
||||
} else if (record.isStoryReaction()) {
|
||||
ThreadBodyUtil.getFormattedBodyFor(context, record).body
|
||||
ThreadBodyUtil.getFormattedBodyForNotification(context, record, null)
|
||||
} else if (record.isPaymentNotification) {
|
||||
ThreadBodyUtil.getFormattedBodyFor(context, record).body
|
||||
ThreadBodyUtil.getFormattedBodyForNotification(context, record, null)
|
||||
} else {
|
||||
getBodyWithMentionsAndStyles(context, record)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user