From e0c11998c3a1d199ad51c68278dc2bb617c3d018 Mon Sep 17 00:00:00 2001 From: Alan Evans Date: Wed, 13 Mar 2019 18:28:16 -0300 Subject: [PATCH] Make DisplayRecord take context as argument, so locale is more likely to be correct. --- .../securesms/ConversationListItem.java | 2 +- .../conversation/ConversationFragment.java | 4 ++-- .../securesms/conversation/ConversationItem.java | 10 +++++----- .../conversation/ConversationUpdateItem.java | 14 +++++++------- .../securesms/database/MmsDatabase.java | 6 +++--- .../securesms/database/SmsDatabase.java | 4 ++-- .../securesms/database/ThreadDatabase.java | 2 +- .../securesms/database/model/DisplayRecord.java | 6 ++---- .../database/model/MediaMmsMessageRecord.java | 11 ++++------- .../securesms/database/model/MessageRecord.java | 7 ++++--- .../securesms/database/model/MmsMessageRecord.java | 4 ++-- .../model/NotificationMmsMessageRecord.java | 7 ++++--- .../securesms/database/model/SmsMessageRecord.java | 9 +++++---- .../securesms/database/model/ThreadRecord.java | 8 +++----- .../securesms/notifications/MessageNotifier.java | 2 +- 15 files changed, 46 insertions(+), 50 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ConversationListItem.java b/src/org/thoughtcrime/securesms/ConversationListItem.java index 7add0076ce..37230fb112 100644 --- a/src/org/thoughtcrime/securesms/ConversationListItem.java +++ b/src/org/thoughtcrime/securesms/ConversationListItem.java @@ -156,7 +156,7 @@ public class ConversationListItem extends RelativeLayout this.typingView.stopAnimation(); this.subjectView.setVisibility(VISIBLE); - this.subjectView.setText(thread.getDisplayBody()); + this.subjectView.setText(thread.getDisplayBody(getContext())); this.subjectView.setTypeface(unreadCount == 0 ? LIGHT_TYPEFACE : BOLD_TYPEFACE); this.subjectView.setTextColor(unreadCount == 0 ? ThemeUtil.getThemedColor(getContext(), R.attr.conversation_list_item_subject_color) : ThemeUtil.getThemedColor(getContext(), R.attr.conversation_list_item_unread_color)); diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationFragment.java b/src/org/thoughtcrime/securesms/conversation/ConversationFragment.java index 939efb8850..3859eb13cd 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationFragment.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationFragment.java @@ -451,7 +451,7 @@ public class ConversationFragment extends Fragment ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); for (MessageRecord messageRecord : messageList) { - String body = messageRecord.getDisplayBody().toString(); + String body = messageRecord.getDisplayBody(requireContext()).toString(); if (!TextUtils.isEmpty(body)) { bodyBuilder.append(body).append('\n'); } @@ -522,7 +522,7 @@ public class ConversationFragment extends Fragment private void handleForwardMessage(MessageRecord message) { SimpleTask.run(getLifecycle(), () -> { Intent composeIntent = new Intent(getActivity(), ShareActivity.class); - composeIntent.putExtra(Intent.EXTRA_TEXT, message.getDisplayBody().toString()); + composeIntent.putExtra(Intent.EXTRA_TEXT, message.getDisplayBody(requireContext()).toString()); if (message.isMms()) { MmsMessageRecord mediaMessage = (MmsMessageRecord) message; diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationItem.java b/src/org/thoughtcrime/securesms/conversation/ConversationItem.java index 53b4805c47..a825994d97 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationItem.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationItem.java @@ -387,7 +387,7 @@ public class ConversationItem extends LinearLayout } private boolean isCaptionlessMms(MessageRecord messageRecord) { - return TextUtils.isEmpty(messageRecord.getDisplayBody()) && messageRecord.isMms() && ((MmsMessageRecord) messageRecord).getSlideDeck().getTextSlide() == null; + return TextUtils.isEmpty(messageRecord.getDisplayBody(getContext())) && messageRecord.isMms() && ((MmsMessageRecord) messageRecord).getSlideDeck().getTextSlide() == null; } private boolean hasAudio(MessageRecord messageRecord) { @@ -433,7 +433,7 @@ public class ConversationItem extends LinearLayout if (isCaptionlessMms(messageRecord)) { bodyText.setVisibility(View.GONE); } else { - Spannable styledText = linkifyMessageBody(messageRecord.getDisplayBody(), batchSelected.isEmpty()); + Spannable styledText = linkifyMessageBody(messageRecord.getDisplayBody(getContext()), batchSelected.isEmpty()); styledText = SearchUtil.getHighlightedSpan(locale, () -> new BackgroundColorSpan(Color.YELLOW), styledText, searchQuery); styledText = SearchUtil.getHighlightedSpan(locale, () -> new ForegroundColorSpan(Color.BLACK), styledText, searchQuery); @@ -558,7 +558,7 @@ public class ConversationItem extends LinearLayout mediaThumbnailStub.get().setDownloadClickListener(downloadClickListener); mediaThumbnailStub.get().setOnLongClickListener(passthroughClickListener); mediaThumbnailStub.get().setOnClickListener(passthroughClickListener); - mediaThumbnailStub.get().showShade(TextUtils.isEmpty(messageRecord.getDisplayBody()) && !hasExtraText(messageRecord)); + mediaThumbnailStub.get().showShade(TextUtils.isEmpty(messageRecord.getDisplayBody(getContext())) && !hasExtraText(messageRecord)); mediaThumbnailStub.get().setConversationColor(messageRecord.isOutgoing() ? defaultBubbleColor : messageRecord.getRecipient().getColor().toConversationColor(context)); @@ -620,7 +620,7 @@ public class ConversationItem extends LinearLayout } } - if (!TextUtils.isEmpty(current.getDisplayBody())) { + if (!TextUtils.isEmpty(current.getDisplayBody(getContext()))) { bottomLeft = 0; bottomRight = 0; } @@ -787,7 +787,7 @@ public class ConversationItem extends LinearLayout private ConversationItemFooter getActiveFooter(@NonNull MessageRecord messageRecord) { if (hasSharedContact(messageRecord)) { return sharedContactStub.get().getFooter(); - } else if (hasOnlyThumbnail(messageRecord) && TextUtils.isEmpty(messageRecord.getDisplayBody())) { + } else if (hasOnlyThumbnail(messageRecord) && TextUtils.isEmpty(messageRecord.getDisplayBody(getContext()))) { return mediaThumbnailStub.get().getFooter(); } else { return footer; diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationUpdateItem.java b/src/org/thoughtcrime/securesms/conversation/ConversationUpdateItem.java index e2985d5085..541ab96955 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationUpdateItem.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationUpdateItem.java @@ -123,7 +123,7 @@ public class ConversationUpdateItem extends LinearLayout else if (messageRecord.isOutgoingCall()) icon.setImageResource(R.drawable.ic_call_made_grey600_24dp); else icon.setImageResource(R.drawable.ic_call_missed_grey600_24dp); - body.setText(messageRecord.getDisplayBody()); + body.setText(messageRecord.getDisplayBody(getContext())); date.setText(DateUtils.getExtendedRelativeTimeSpanString(getContext(), locale, messageRecord.getDateReceived())); title.setVisibility(GONE); @@ -141,7 +141,7 @@ public class ConversationUpdateItem extends LinearLayout } title.setText(ExpirationUtil.getExpirationDisplayValue(getContext(), (int)(messageRecord.getExpiresIn() / 1000))); - body.setText(messageRecord.getDisplayBody()); + body.setText(messageRecord.getDisplayBody(getContext())); title.setVisibility(VISIBLE); body.setVisibility(VISIBLE); @@ -151,7 +151,7 @@ public class ConversationUpdateItem extends LinearLayout private void setIdentityRecord(final MessageRecord messageRecord) { icon.setImageResource(R.drawable.ic_security_white_24dp); icon.setColorFilter(new PorterDuffColorFilter(Color.parseColor("#757575"), PorterDuff.Mode.MULTIPLY)); - body.setText(messageRecord.getDisplayBody()); + body.setText(messageRecord.getDisplayBody(getContext())); title.setVisibility(GONE); body.setVisibility(VISIBLE); @@ -163,7 +163,7 @@ public class ConversationUpdateItem extends LinearLayout else icon.setImageResource(R.drawable.ic_info_outline_white_24dp); icon.setColorFilter(new PorterDuffColorFilter(Color.parseColor("#757575"), PorterDuff.Mode.MULTIPLY)); - body.setText(messageRecord.getDisplayBody()); + body.setText(messageRecord.getDisplayBody(getContext())); title.setVisibility(GONE); body.setVisibility(VISIBLE); @@ -175,7 +175,7 @@ public class ConversationUpdateItem extends LinearLayout icon.clearColorFilter(); GroupUtil.getDescription(getContext(), messageRecord.getBody()).addListener(this); - body.setText(messageRecord.getDisplayBody()); + body.setText(messageRecord.getDisplayBody(getContext())); title.setVisibility(GONE); body.setVisibility(VISIBLE); @@ -185,7 +185,7 @@ public class ConversationUpdateItem extends LinearLayout private void setJoinedRecord(MessageRecord messageRecord) { icon.setImageResource(R.drawable.ic_favorite_grey600_24dp); icon.clearColorFilter(); - body.setText(messageRecord.getDisplayBody()); + body.setText(messageRecord.getDisplayBody(getContext())); title.setVisibility(GONE); body.setVisibility(VISIBLE); @@ -195,7 +195,7 @@ public class ConversationUpdateItem extends LinearLayout private void setEndSessionRecord(MessageRecord messageRecord) { icon.setImageResource(R.drawable.ic_refresh_white_24dp); icon.setColorFilter(new PorterDuffColorFilter(Color.parseColor("#757575"), PorterDuff.Mode.MULTIPLY)); - body.setText(messageRecord.getDisplayBody()); + body.setText(messageRecord.getDisplayBody(getContext())); title.setVisibility(GONE); body.setVisibility(VISIBLE); diff --git a/src/org/thoughtcrime/securesms/database/MmsDatabase.java b/src/org/thoughtcrime/securesms/database/MmsDatabase.java index 5dcd36343f..fe93bd51c4 100644 --- a/src/org/thoughtcrime/securesms/database/MmsDatabase.java +++ b/src/org/thoughtcrime/securesms/database/MmsDatabase.java @@ -1291,7 +1291,7 @@ public class MmsDatabase extends MessagingDatabase { public MessageRecord getCurrent() { SlideDeck slideDeck = new SlideDeck(context, message.getAttachments()); - return new MediaMmsMessageRecord(context, id, message.getRecipient(), message.getRecipient(), + return new MediaMmsMessageRecord(id, message.getRecipient(), message.getRecipient(), 1, System.currentTimeMillis(), System.currentTimeMillis(), 0, threadId, message.getBody(), slideDeck, slideDeck.getSlides().size(), @@ -1372,7 +1372,7 @@ public class MmsDatabase extends MessagingDatabase { SlideDeck slideDeck = new SlideDeck(context, new MmsNotificationAttachment(status, messageSize)); - return new NotificationMmsMessageRecord(context, id, recipient, recipient, + return new NotificationMmsMessageRecord(id, recipient, recipient, addressDeviceId, dateSent, dateReceived, deliveryReceiptCount, threadId, contentLocationBytes, messageSize, expiry, status, transactionIdBytes, mailbox, subscriptionId, slideDeck, @@ -1413,7 +1413,7 @@ public class MmsDatabase extends MessagingDatabase { SlideDeck slideDeck = getSlideDeck(Stream.of(attachments).filterNot(contactAttachments::contains).filterNot(previewAttachments::contains).toList()); Quote quote = getQuote(cursor); - return new MediaMmsMessageRecord(context, id, recipient, recipient, + return new MediaMmsMessageRecord(id, recipient, recipient, addressDeviceId, dateSent, dateReceived, deliveryReceiptCount, threadId, body, slideDeck, partCount, box, mismatches, networkFailures, subscriptionId, expiresIn, expireStarted, diff --git a/src/org/thoughtcrime/securesms/database/SmsDatabase.java b/src/org/thoughtcrime/securesms/database/SmsDatabase.java index 0abe0a50f7..e7d6655502 100644 --- a/src/org/thoughtcrime/securesms/database/SmsDatabase.java +++ b/src/org/thoughtcrime/securesms/database/SmsDatabase.java @@ -828,7 +828,7 @@ public class SmsDatabase extends MessagingDatabase { } public MessageRecord getCurrent() { - return new SmsMessageRecord(context, id, message.getMessageBody(), + return new SmsMessageRecord(id, message.getMessageBody(), message.getRecipient(), message.getRecipient(), 1, System.currentTimeMillis(), System.currentTimeMillis(), 0, message.isSecureMessage() ? MmsSmsColumns.Types.getOutgoingEncryptedMessageType() : MmsSmsColumns.Types.getOutgoingSmsMessageType(), @@ -883,7 +883,7 @@ public class SmsDatabase extends MessagingDatabase { List mismatches = getMismatches(mismatchDocument); Recipient recipient = Recipient.from(context, address, true); - return new SmsMessageRecord(context, messageId, body, recipient, + return new SmsMessageRecord(messageId, body, recipient, recipient, addressDeviceId, dateSent, dateReceived, deliveryReceiptCount, type, diff --git a/src/org/thoughtcrime/securesms/database/ThreadDatabase.java b/src/org/thoughtcrime/securesms/database/ThreadDatabase.java index 500f6c04f7..030c638c9e 100644 --- a/src/org/thoughtcrime/securesms/database/ThreadDatabase.java +++ b/src/org/thoughtcrime/securesms/database/ThreadDatabase.java @@ -687,7 +687,7 @@ public class ThreadDatabase extends Database { readReceiptCount = 0; } - return new ThreadRecord(context, body, snippetUri, recipient, date, count, + return new ThreadRecord(body, snippetUri, recipient, date, count, unreadCount, threadId, deliveryReceiptCount, status, type, distributionType, archived, expiresIn, lastSeen, readReceiptCount); } diff --git a/src/org/thoughtcrime/securesms/database/model/DisplayRecord.java b/src/org/thoughtcrime/securesms/database/model/DisplayRecord.java index dbe83adfbb..b0a22c36c0 100644 --- a/src/org/thoughtcrime/securesms/database/model/DisplayRecord.java +++ b/src/org/thoughtcrime/securesms/database/model/DisplayRecord.java @@ -34,7 +34,6 @@ import org.thoughtcrime.securesms.recipients.Recipient; public abstract class DisplayRecord { - protected final Context context; protected final long type; private final Recipient recipient; @@ -46,11 +45,10 @@ public abstract class DisplayRecord { private final int deliveryReceiptCount; private final int readReceiptCount; - DisplayRecord(Context context, String body, Recipient recipient, long dateSent, + DisplayRecord(String body, Recipient recipient, long dateSent, long dateReceived, long threadId, int deliveryStatus, int deliveryReceiptCount, long type, int readReceiptCount) { - this.context = context.getApplicationContext(); this.threadId = threadId; this.recipient = recipient; this.dateSent = dateSent; @@ -83,7 +81,7 @@ public abstract class DisplayRecord { return MmsSmsColumns.Types.isOutgoingMessageType(type); } - public abstract SpannableString getDisplayBody(); + public abstract SpannableString getDisplayBody(@NonNull Context context); public Recipient getRecipient() { return recipient; diff --git a/src/org/thoughtcrime/securesms/database/model/MediaMmsMessageRecord.java b/src/org/thoughtcrime/securesms/database/model/MediaMmsMessageRecord.java index 6fe7183e5e..9e9acbf2f7 100644 --- a/src/org/thoughtcrime/securesms/database/model/MediaMmsMessageRecord.java +++ b/src/org/thoughtcrime/securesms/database/model/MediaMmsMessageRecord.java @@ -44,10 +44,9 @@ import java.util.List; public class MediaMmsMessageRecord extends MmsMessageRecord { private final static String TAG = MediaMmsMessageRecord.class.getSimpleName(); - private final Context context; private final int partCount; - public MediaMmsMessageRecord(Context context, long id, Recipient conversationRecipient, + public MediaMmsMessageRecord(long id, Recipient conversationRecipient, Recipient individualRecipient, int recipientDeviceId, long dateSent, long dateReceived, int deliveryReceiptCount, long threadId, String body, @@ -59,12 +58,10 @@ public class MediaMmsMessageRecord extends MmsMessageRecord { @Nullable Quote quote, @Nullable List contacts, @Nullable List linkPreviews, boolean unidentified) { - super(context, id, body, conversationRecipient, individualRecipient, recipientDeviceId, dateSent, + super(id, body, conversationRecipient, individualRecipient, recipientDeviceId, dateSent, dateReceived, threadId, Status.STATUS_NONE, deliveryReceiptCount, mailbox, mismatches, failures, subscriptionId, expiresIn, expireStarted, slideDeck, readReceiptCount, quote, contacts, linkPreviews, unidentified); - - this.context = context.getApplicationContext(); this.partCount = partCount; } @@ -78,7 +75,7 @@ public class MediaMmsMessageRecord extends MmsMessageRecord { } @Override - public SpannableString getDisplayBody() { + public SpannableString getDisplayBody(@NonNull Context context) { if (MmsDatabase.Types.isFailedDecryptType(type)) { return emphasisAdded(context.getString(R.string.MmsMessageRecord_bad_encrypted_mms_message)); } else if (MmsDatabase.Types.isDuplicateMessageType(type)) { @@ -89,6 +86,6 @@ public class MediaMmsMessageRecord extends MmsMessageRecord { return emphasisAdded(context.getString(R.string.MessageRecord_message_encrypted_with_a_legacy_protocol_version_that_is_no_longer_supported)); } - return super.getDisplayBody(); + return super.getDisplayBody(context); } } diff --git a/src/org/thoughtcrime/securesms/database/model/MessageRecord.java b/src/org/thoughtcrime/securesms/database/model/MessageRecord.java index 15b2c025d1..635a864aa9 100644 --- a/src/org/thoughtcrime/securesms/database/model/MessageRecord.java +++ b/src/org/thoughtcrime/securesms/database/model/MessageRecord.java @@ -17,6 +17,7 @@ package org.thoughtcrime.securesms.database.model; import android.content.Context; +import android.support.annotation.NonNull; import android.text.Spannable; import android.text.SpannableString; import android.text.style.RelativeSizeSpan; @@ -53,7 +54,7 @@ public abstract class MessageRecord extends DisplayRecord { private final long expireStarted; private final boolean unidentified; - MessageRecord(Context context, long id, String body, Recipient conversationRecipient, + MessageRecord(long id, String body, Recipient conversationRecipient, Recipient individualRecipient, int recipientDeviceId, long dateSent, long dateReceived, long threadId, int deliveryStatus, int deliveryReceiptCount, long type, @@ -62,7 +63,7 @@ public abstract class MessageRecord extends DisplayRecord { int subscriptionId, long expiresIn, long expireStarted, int readReceiptCount, boolean unidentified) { - super(context, body, conversationRecipient, dateSent, dateReceived, + super(body, conversationRecipient, dateSent, dateReceived, threadId, deliveryStatus, deliveryReceiptCount, type, readReceiptCount); this.id = id; this.individualRecipient = individualRecipient; @@ -87,7 +88,7 @@ public abstract class MessageRecord extends DisplayRecord { } @Override - public SpannableString getDisplayBody() { + public SpannableString getDisplayBody(@NonNull Context context) { if (isGroupUpdate() && isOutgoing()) { return new SpannableString(context.getString(R.string.MessageRecord_you_updated_group)); } else if (isGroupUpdate()) { diff --git a/src/org/thoughtcrime/securesms/database/model/MmsMessageRecord.java b/src/org/thoughtcrime/securesms/database/model/MmsMessageRecord.java index e8b1e5b18e..9657f3151b 100644 --- a/src/org/thoughtcrime/securesms/database/model/MmsMessageRecord.java +++ b/src/org/thoughtcrime/securesms/database/model/MmsMessageRecord.java @@ -23,7 +23,7 @@ public abstract class MmsMessageRecord extends MessageRecord { private final @NonNull List contacts = new LinkedList<>(); private final @NonNull List linkPreviews = new LinkedList<>(); - MmsMessageRecord(Context context, long id, String body, Recipient conversationRecipient, + MmsMessageRecord(long id, String body, Recipient conversationRecipient, Recipient individualRecipient, int recipientDeviceId, long dateSent, long dateReceived, long threadId, int deliveryStatus, int deliveryReceiptCount, long type, List mismatches, @@ -32,7 +32,7 @@ public abstract class MmsMessageRecord extends MessageRecord { @Nullable Quote quote, @NonNull List contacts, @NonNull List linkPreviews, boolean unidentified) { - super(context, id, body, conversationRecipient, individualRecipient, recipientDeviceId, dateSent, dateReceived, threadId, deliveryStatus, deliveryReceiptCount, type, mismatches, networkFailures, subscriptionId, expiresIn, expireStarted, readReceiptCount, unidentified); + super(id, body, conversationRecipient, individualRecipient, recipientDeviceId, dateSent, dateReceived, threadId, deliveryStatus, deliveryReceiptCount, type, mismatches, networkFailures, subscriptionId, expiresIn, expireStarted, readReceiptCount, unidentified); this.slideDeck = slideDeck; this.quote = quote; diff --git a/src/org/thoughtcrime/securesms/database/model/NotificationMmsMessageRecord.java b/src/org/thoughtcrime/securesms/database/model/NotificationMmsMessageRecord.java index f0ebdd3d8e..fafb2e9519 100644 --- a/src/org/thoughtcrime/securesms/database/model/NotificationMmsMessageRecord.java +++ b/src/org/thoughtcrime/securesms/database/model/NotificationMmsMessageRecord.java @@ -17,6 +17,7 @@ package org.thoughtcrime.securesms.database.model; import android.content.Context; +import android.support.annotation.NonNull; import android.text.SpannableString; import org.thoughtcrime.securesms.R; @@ -46,14 +47,14 @@ public class NotificationMmsMessageRecord extends MmsMessageRecord { private final int status; private final byte[] transactionId; - public NotificationMmsMessageRecord(Context context, long id, Recipient conversationRecipient, + public NotificationMmsMessageRecord(long id, Recipient conversationRecipient, Recipient individualRecipient, int recipientDeviceId, long dateSent, long dateReceived, int deliveryReceiptCount, long threadId, byte[] contentLocation, long messageSize, long expiry, int status, byte[] transactionId, long mailbox, int subscriptionId, SlideDeck slideDeck, int readReceiptCount) { - super(context, id, "", conversationRecipient, individualRecipient, recipientDeviceId, + super(id, "", conversationRecipient, individualRecipient, recipientDeviceId, dateSent, dateReceived, threadId, Status.STATUS_NONE, deliveryReceiptCount, mailbox, new LinkedList(), new LinkedList(), subscriptionId, 0, 0, slideDeck, readReceiptCount, null, Collections.emptyList(), Collections.emptyList(), false); @@ -111,7 +112,7 @@ public class NotificationMmsMessageRecord extends MmsMessageRecord { } @Override - public SpannableString getDisplayBody() { + public SpannableString getDisplayBody(@NonNull Context context) { if (status == MmsDatabase.Status.DOWNLOAD_INITIALIZED) { return emphasisAdded(context.getString(R.string.NotificationMmsMessageRecord_multimedia_message)); } else if (status == MmsDatabase.Status.DOWNLOAD_CONNECTING) { diff --git a/src/org/thoughtcrime/securesms/database/model/SmsMessageRecord.java b/src/org/thoughtcrime/securesms/database/model/SmsMessageRecord.java index 1f3c501496..beede83f28 100644 --- a/src/org/thoughtcrime/securesms/database/model/SmsMessageRecord.java +++ b/src/org/thoughtcrime/securesms/database/model/SmsMessageRecord.java @@ -18,6 +18,7 @@ package org.thoughtcrime.securesms.database.model; import android.content.Context; +import android.support.annotation.NonNull; import android.text.SpannableString; import org.thoughtcrime.securesms.R; @@ -38,7 +39,7 @@ import java.util.List; public class SmsMessageRecord extends MessageRecord { - public SmsMessageRecord(Context context, long id, + public SmsMessageRecord(long id, String body, Recipient recipient, Recipient individualRecipient, int recipientDeviceId, @@ -49,7 +50,7 @@ public class SmsMessageRecord extends MessageRecord { int subscriptionId, long expiresIn, long expireStarted, int readReceiptCount, boolean unidentified) { - super(context, id, body, recipient, individualRecipient, recipientDeviceId, + super(id, body, recipient, individualRecipient, recipientDeviceId, dateSent, dateReceived, threadId, status, deliveryReceiptCount, type, mismatches, new LinkedList<>(), subscriptionId, expiresIn, expireStarted, readReceiptCount, unidentified); @@ -60,7 +61,7 @@ public class SmsMessageRecord extends MessageRecord { } @Override - public SpannableString getDisplayBody() { + public SpannableString getDisplayBody(@NonNull Context context) { if (SmsDatabase.Types.isFailedDecryptType(type)) { return emphasisAdded(context.getString(R.string.MessageDisplayHelper_bad_encrypted_message)); } else if (isCorruptedKeyExchange()) { @@ -84,7 +85,7 @@ public class SmsMessageRecord extends MessageRecord { } else if (isEndSession()) { return emphasisAdded(context.getString(R.string.SmsMessageRecord_secure_session_reset_s, getIndividualRecipient().toShortString())); } else { - return super.getDisplayBody(); + return super.getDisplayBody(context); } } diff --git a/src/org/thoughtcrime/securesms/database/model/ThreadRecord.java b/src/org/thoughtcrime/securesms/database/model/ThreadRecord.java index 2bc29f5137..12a38cc253 100644 --- a/src/org/thoughtcrime/securesms/database/model/ThreadRecord.java +++ b/src/org/thoughtcrime/securesms/database/model/ThreadRecord.java @@ -40,7 +40,6 @@ import org.thoughtcrime.securesms.util.ExpirationUtil; */ public class ThreadRecord extends DisplayRecord { - private @NonNull final Context context; private @Nullable final Uri snippetUri; private final long count; private final int unreadCount; @@ -49,14 +48,13 @@ public class ThreadRecord extends DisplayRecord { private final long expiresIn; private final long lastSeen; - public ThreadRecord(@NonNull Context context, @NonNull String body, @Nullable Uri snippetUri, + public ThreadRecord(@NonNull String body, @Nullable Uri snippetUri, @NonNull Recipient recipient, long date, long count, int unreadCount, long threadId, int deliveryReceiptCount, int status, long snippetType, int distributionType, boolean archived, long expiresIn, long lastSeen, int readReceiptCount) { - super(context, body, recipient, date, date, threadId, status, deliveryReceiptCount, snippetType, readReceiptCount); - this.context = context.getApplicationContext(); + super(body, recipient, date, date, threadId, status, deliveryReceiptCount, snippetType, readReceiptCount); this.snippetUri = snippetUri; this.count = count; this.unreadCount = unreadCount; @@ -71,7 +69,7 @@ public class ThreadRecord extends DisplayRecord { } @Override - public SpannableString getDisplayBody() { + public SpannableString getDisplayBody(@NonNull Context context) { if (isGroupUpdate()) { return emphasisAdded(context.getString(R.string.ThreadRecord_group_updated)); } else if (isGroupQuit()) { diff --git a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java index e786e099eb..7819029641 100644 --- a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java +++ b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java @@ -437,7 +437,7 @@ public class MessageNotifier { Recipient recipient = record.getIndividualRecipient(); Recipient conversationRecipient = record.getRecipient(); long threadId = record.getThreadId(); - CharSequence body = record.getDisplayBody(); + CharSequence body = record.getDisplayBody(context); Recipient threadRecipients = null; SlideDeck slideDeck = null; long timestamp = record.getTimestamp();