Don't always show the sender in notifications (#3441), Always show "~" before overridden sender names (#3442)

* Don't always show the sender in notifications

In 1:1 chats, don't prepend the sender name to every line. The exception is when the display name is not equal to the chat name (i.e. there is an OverwriteSenderDisplayname), in this case we still prepend it.

* Always show the "~" before the sender name if it's overridden

When we introduced this, I assume that we weren't sure whether we should
do it and only showed it in some places. But I think it's nicer to
show the same sender name everywhere, i.e. always add the "~".
This commit is contained in:
Hocuri 2024-11-25 14:44:31 +01:00 committed by GitHub
parent 3965319ef4
commit 60e9a9101a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 16 additions and 15 deletions

View file

@ -166,10 +166,10 @@ public class DcMsg {
public native String getError (); public native String getError ();
public native String getOverrideSenderName(); public native String getOverrideSenderName();
public String getSenderName(DcContact dcContact, boolean markOverride) { public String getSenderName(DcContact dcContact) {
String overrideName = getOverrideSenderName(); String overrideName = getOverrideSenderName();
if (overrideName != null) { if (overrideName != null) {
return (markOverride ? "~" : "") + overrideName; return "~" + overrideName;
} else { } else {
return dcContact.getDisplayName(); return dcContact.getDisplayName();
} }

View file

@ -24,7 +24,6 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
@ -427,7 +426,7 @@ public class ConversationFragment extends MessageSelectorFragment
if (msg.getFromId() != prevMsg.getFromId() && !singleMsg) { if (msg.getFromId() != prevMsg.getFromId() && !singleMsg) {
DcContact contact = dcContext.getContact(msg.getFromId()); DcContact contact = dcContext.getContact(msg.getFromId());
result.append(msg.getSenderName(contact, false)).append(":\n"); result.append(msg.getSenderName(contact)).append(":\n");
} }
if (msg.getType() == DcMsg.DC_MSG_TEXT || (singleMsg && !msg.getText().isEmpty())) { if (msg.getType() == DcMsg.DC_MSG_TEXT || (singleMsg && !msg.getText().isEmpty())) {
result.append(msg.getText()); result.append(msg.getText());

View file

@ -22,12 +22,10 @@ import android.content.res.TypedArray;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Build;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
@ -791,14 +789,14 @@ public class ConversationItem extends BaseConversationItem
if (messageRecord.isForwarded()) { if (messageRecord.isForwarded()) {
if (showSender && dcContact !=null) { if (showSender && dcContact !=null) {
this.groupSender.setText(context.getString(R.string.forwarded_by, messageRecord.getSenderName(dcContact, false))); this.groupSender.setText(context.getString(R.string.forwarded_by, messageRecord.getSenderName(dcContact)));
} else { } else {
this.groupSender.setText(context.getString(R.string.forwarded_message)); this.groupSender.setText(context.getString(R.string.forwarded_message));
} }
this.groupSender.setTextColor(context.getResources().getColor(R.color.unknown_sender)); this.groupSender.setTextColor(context.getResources().getColor(R.color.unknown_sender));
} }
else if (showSender && dcContact !=null) { else if (showSender && dcContact !=null) {
this.groupSender.setText(messageRecord.getSenderName(dcContact, true)); this.groupSender.setText(messageRecord.getSenderName(dcContact));
this.groupSender.setTextColor(Util.rgbToArgbColor(dcContact.getColor())); this.groupSender.setTextColor(Util.rgbToArgbColor(dcContact.getColor()));
} }
} }

View file

@ -4,7 +4,6 @@ package org.thoughtcrime.securesms.components;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
@ -16,7 +15,6 @@ import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import com.annimon.stream.Stream; import com.annimon.stream.Stream;
import com.b44t.messenger.DcContact; import com.b44t.messenger.DcContact;
@ -155,7 +153,7 @@ public class QuoteView extends FrameLayout implements RecipientForeverObserver {
if (contact == null) { if (contact == null) {
authorView.setText(getContext().getString(R.string.forwarded_message)); authorView.setText(getContext().getString(R.string.forwarded_message));
} else { } else {
authorView.setText(getContext().getString(R.string.forwarded_by, quotedMsg.getSenderName(contact, false))); authorView.setText(getContext().getString(R.string.forwarded_by, quotedMsg.getSenderName(contact)));
} }
authorView.setTextColor(getForwardedColor()); authorView.setTextColor(getForwardedColor());
quoteBarView.setBackgroundColor(getForwardedColor()); quoteBarView.setBackgroundColor(getForwardedColor());
@ -166,7 +164,7 @@ public class QuoteView extends FrameLayout implements RecipientForeverObserver {
quoteBarView.setBackgroundColor(getForwardedColor()); quoteBarView.setBackgroundColor(getForwardedColor());
} else { } else {
authorView.setVisibility(VISIBLE); authorView.setVisibility(VISIBLE);
authorView.setText(quotedMsg.getSenderName(contact, true)); authorView.setText(quotedMsg.getSenderName(contact));
if (hasSticker) { if (hasSticker) {
authorView.setTextColor(getResources().getColor(R.color.core_dark_05)); authorView.setTextColor(getResources().getColor(R.color.core_dark_05));
quoteBarView.setBackgroundColor(getResources().getColor(R.color.core_dark_05)); quoteBarView.setBackgroundColor(getResources().getColor(R.color.core_dark_05));

View file

@ -345,11 +345,17 @@ public class NotificationCenter {
String shortLine = privacy.isDisplayMessage()? dcMsg.getSummarytext(2000) : context.getString(R.string.notify_new_message); String shortLine = privacy.isDisplayMessage()? dcMsg.getSummarytext(2000) : context.getString(R.string.notify_new_message);
if (dcChat.isMultiUser() && privacy.isDisplayContact()) { if (dcChat.isMultiUser() && privacy.isDisplayContact()) {
shortLine = dcMsg.getSenderName(dcContext.getContact(dcMsg.getFromId()), false) + ": " + shortLine; shortLine = dcMsg.getSenderName(dcContext.getContact(dcMsg.getFromId())) + ": " + shortLine;
} }
String tickerLine = shortLine; String tickerLine = shortLine;
if (!dcChat.isMultiUser() && privacy.isDisplayContact()) { if (!dcChat.isMultiUser() && privacy.isDisplayContact()) {
tickerLine = dcMsg.getSenderName(dcContext.getContact(dcMsg.getFromId()), false) + ": " + tickerLine; tickerLine = dcMsg.getSenderName(dcContext.getContact(dcMsg.getFromId())) + ": " + tickerLine;
if (dcMsg.getOverrideSenderName() != null) {
// There is an "overridden" display name on the message, so, we need to prepend the display name to the message,
// i.e. set the shortLine to be the same as the tickerLine.
shortLine = tickerLine;
}
} }
maybeAddNotification(accountId, dcChat, msgId, shortLine, tickerLine, true); maybeAddNotification(accountId, dcChat, msgId, shortLine, tickerLine, true);
@ -549,7 +555,7 @@ public class NotificationCenter {
lines = new ArrayList<>(); lines = new ArrayList<>();
accountInbox.put(chatId, lines); accountInbox.put(chatId, lines);
} }
lines.add(tickerLine); lines.add(shortLine);
for (int l = 0; l < lines.size(); l++) { for (int l = 0; l < lines.size(); l++) {
inboxStyle.addLine(lines.get(l)); inboxStyle.addLine(lines.get(l));