From aef0adb71411af7105ee7d63f163f89bee88bce4 Mon Sep 17 00:00:00 2001 From: fanchao Date: Fri, 6 Sep 2024 14:41:26 +1000 Subject: [PATCH] [SES-2695] Incorrect message request approval on home screen --- .../securesms/database/model/DisplayRecord.java | 6 +----- .../database/model/MediaMmsMessageRecord.java | 6 +----- .../securesms/database/model/MessageRecord.java | 2 +- .../database/model/SmsMessageRecord.java | 7 +++---- .../securesms/database/model/ThreadRecord.java | 15 ++++++++++++++- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/model/DisplayRecord.java b/app/src/main/java/org/thoughtcrime/securesms/database/model/DisplayRecord.java index 639ea0db09..6ae671c065 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/model/DisplayRecord.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/model/DisplayRecord.java @@ -17,15 +17,11 @@ package org.thoughtcrime.securesms.database.model; import android.content.Context; -import android.text.SpannableString; import androidx.annotation.NonNull; import org.session.libsession.utilities.recipients.Recipient; -import org.session.libsignal.utilities.Log; -import org.thoughtcrime.securesms.database.MmsDatabase; import org.thoughtcrime.securesms.database.MmsSmsColumns; -import org.thoughtcrime.securesms.database.MmsSmsDatabase; import org.thoughtcrime.securesms.database.SmsDatabase; /** @@ -68,7 +64,7 @@ public abstract class DisplayRecord { public @NonNull String getBody() { return body == null ? "" : body; } - public abstract SpannableString getDisplayBody(@NonNull Context context); + public abstract CharSequence getDisplayBody(@NonNull Context context); public Recipient getRecipient() { return recipient; } public long getDateSent() { return dateSent; } public long getDateReceived() { return dateReceived; } diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/model/MediaMmsMessageRecord.java b/app/src/main/java/org/thoughtcrime/securesms/database/model/MediaMmsMessageRecord.java index e56d9fc38e..0383d17bda 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/model/MediaMmsMessageRecord.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/model/MediaMmsMessageRecord.java @@ -17,7 +17,6 @@ package org.thoughtcrime.securesms.database.model; import android.content.Context; -import android.text.SpannableString; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -27,14 +26,11 @@ import org.session.libsession.utilities.Contact; import org.session.libsession.utilities.IdentityKeyMismatch; import org.session.libsession.utilities.NetworkFailure; import org.session.libsession.utilities.recipients.Recipient; -import org.thoughtcrime.securesms.database.MmsDatabase; import org.thoughtcrime.securesms.database.SmsDatabase.Status; import org.thoughtcrime.securesms.mms.SlideDeck; import java.util.List; -import network.loki.messenger.R; - /** * Represents the message record model for MMS messages that contain * media (ie: they've been downloaded). @@ -76,7 +72,7 @@ public class MediaMmsMessageRecord extends MmsMessageRecord { } @Override - public SpannableString getDisplayBody(@NonNull Context context) { + public CharSequence getDisplayBody(@NonNull Context context) { return super.getDisplayBody(context); } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/model/MessageRecord.java b/app/src/main/java/org/thoughtcrime/securesms/database/model/MessageRecord.java index a61b78b4b6..5f6257ee92 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/model/MessageRecord.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/model/MessageRecord.java @@ -115,7 +115,7 @@ public abstract class MessageRecord extends DisplayRecord { } @Override - public SpannableString getDisplayBody(@NonNull Context context) { + public CharSequence getDisplayBody(@NonNull Context context) { if (isGroupUpdateMessage()) { UpdateMessageData updateMessageData = UpdateMessageData.Companion.fromJSON(getBody()); return new SpannableString(UpdateMessageBuilder.INSTANCE.buildGroupUpdateMessage(context, updateMessageData, getIndividualRecipient().getAddress().serialize(), isOutgoing())); diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/model/SmsMessageRecord.java b/app/src/main/java/org/thoughtcrime/securesms/database/model/SmsMessageRecord.java index 65c8861ff9..70e80d720e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/model/SmsMessageRecord.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/model/SmsMessageRecord.java @@ -18,14 +18,13 @@ package org.thoughtcrime.securesms.database.model; import android.content.Context; -import android.text.SpannableString; + import androidx.annotation.NonNull; import org.session.libsession.utilities.IdentityKeyMismatch; import org.session.libsession.utilities.recipients.Recipient; -import org.thoughtcrime.securesms.database.SmsDatabase; + import java.util.LinkedList; import java.util.List; -import network.loki.messenger.R; /** * The message record model which represents standard SMS messages. @@ -56,7 +55,7 @@ public class SmsMessageRecord extends MessageRecord { } @Override - public SpannableString getDisplayBody(@NonNull Context context) { + public CharSequence getDisplayBody(@NonNull Context context) { return super.getDisplayBody(context); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/model/ThreadRecord.java b/app/src/main/java/org/thoughtcrime/securesms/database/model/ThreadRecord.java index 96cd5e8881..56228ef85a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/model/ThreadRecord.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/model/ThreadRecord.java @@ -32,10 +32,14 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.squareup.phrase.Phrase; import org.session.libsession.utilities.ExpirationUtil; +import org.session.libsession.utilities.TextSecurePreferences; import org.session.libsession.utilities.recipients.Recipient; import org.session.libsignal.utilities.Log; import org.thoughtcrime.securesms.database.MmsSmsColumns; import org.thoughtcrime.securesms.database.SmsDatabase; +import org.thoughtcrime.securesms.ui.UtilKt; + +import kotlin.Pair; import network.loki.messenger.R; /** @@ -113,7 +117,7 @@ public class ThreadRecord extends DisplayRecord { } @Override - public SpannableString getDisplayBody(@NonNull Context context) { + public CharSequence getDisplayBody(@NonNull Context context) { if (isGroupUpdateMessage()) { return emphasisAdded(context.getString(R.string.groupUpdated)); } else if (isOpenGroupInvitation()) { @@ -173,6 +177,15 @@ public class ThreadRecord extends DisplayRecord { return emphasisAdded(txt); } else if (MmsSmsColumns.Types.isMessageRequestResponse(type)) { + if (lastMessage.getRecipient().getAddress().serialize().equals( + TextSecurePreferences.getLocalNumber(context))) { + return UtilKt.getSubbedCharSequence( + context, + R.string.messageRequestYouHaveAccepted, + new Pair<>(NAME_KEY, getName()) + ); + } + return emphasisAdded(context.getString(R.string.messageRequestsAccepted)); } else if (getCount() == 0) { return new SpannableString(context.getString(R.string.messageEmpty));