fix: Show message sender in push notifications for groups

This commit is contained in:
charles 2022-10-03 16:31:29 +11:00
parent fbd1721eaf
commit c537da6acd
2 changed files with 17 additions and 15 deletions

View File

@ -52,8 +52,8 @@ public class MultipleRecipientNotificationBuilder extends AbstractNotificationBu
public void setMostRecentSender(Recipient recipient, Recipient threadRecipient) {
String displayName = recipient.toShortString();
if (threadRecipient.isOpenGroupRecipient()) {
displayName = getOpenGroupDisplayName(recipient);
if (threadRecipient.isGroupRecipient()) {
displayName = getGroupDisplayName(recipient, threadRecipient.isOpenGroupRecipient());
}
if (privacy.isDisplayContact()) {
setContentText(context.getString(R.string.MessageNotifier_most_recent_from_s, displayName));
@ -78,8 +78,8 @@ public class MultipleRecipientNotificationBuilder extends AbstractNotificationBu
public void addMessageBody(@NonNull Recipient sender, Recipient threadRecipient, @Nullable CharSequence body) {
String displayName = sender.toShortString();
if (threadRecipient.isOpenGroupRecipient()) {
displayName = getOpenGroupDisplayName(sender);
if (threadRecipient.isGroupRecipient()) {
displayName = getGroupDisplayName(sender, threadRecipient.isOpenGroupRecipient());
}
if (privacy.isDisplayMessage()) {
SpannableStringBuilder builder = new SpannableStringBuilder();
@ -113,14 +113,15 @@ public class MultipleRecipientNotificationBuilder extends AbstractNotificationBu
}
/**
* @param recipient the * individual * recipient for which to get the open group display name.
* @param recipient the * individual * recipient for which to get the display name.
* @param openGroupRecipient whether in an open group context
*/
private String getOpenGroupDisplayName(Recipient recipient) {
private String getGroupDisplayName(Recipient recipient, boolean openGroupRecipient) {
SessionContactDatabase contactDB = DatabaseComponent.get(context).sessionContactDatabase();
String sessionID = recipient.getAddress().serialize();
Contact contact = contactDB.getContactWithSessionID(sessionID);
if (contact == null) { return sessionID; }
String displayName = contact.displayName(Contact.ContactContext.OPEN_GROUP);
String displayName = contact.displayName(openGroupRecipient ? Contact.ContactContext.OPEN_GROUP : Contact.ContactContext.REGULAR);
if (displayName == null) { return sessionID; }
return displayName;
}

View File

@ -117,15 +117,15 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
setNumber(messageCount);
}
public void setPrimaryMessageBody(@NonNull Recipient threadRecipients,
public void setPrimaryMessageBody(@NonNull Recipient threadRecipient,
@NonNull Recipient individualRecipient,
@NonNull CharSequence message,
@Nullable SlideDeck slideDeck)
{
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
if (privacy.isDisplayContact() && threadRecipients.isOpenGroupRecipient()) {
String displayName = getOpenGroupDisplayName(individualRecipient);
if (privacy.isDisplayContact() && threadRecipient.isGroupRecipient()) {
String displayName = getGroupDisplayName(individualRecipient, threadRecipient.isOpenGroupRecipient());
stringBuilder.append(Util.getBoldedString(displayName + ": "));
}
@ -214,8 +214,8 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
{
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
if (privacy.isDisplayContact() && threadRecipient.isOpenGroupRecipient()) {
String displayName = getOpenGroupDisplayName(individualRecipient);
if (privacy.isDisplayContact() && threadRecipient.isGroupRecipient()) {
String displayName = getGroupDisplayName(individualRecipient, threadRecipient.isOpenGroupRecipient());
stringBuilder.append(Util.getBoldedString(displayName + ": "));
}
@ -334,14 +334,15 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
}
/**
* @param recipient the * individual * recipient for which to get the open group display name.
* @param recipient the * individual * recipient for which to get the display name.
* @param openGroupRecipient whether in an open group context
*/
private String getOpenGroupDisplayName(Recipient recipient) {
private String getGroupDisplayName(Recipient recipient, boolean openGroupRecipient) {
SessionContactDatabase contactDB = DatabaseComponent.get(context).sessionContactDatabase();
String sessionID = recipient.getAddress().serialize();
Contact contact = contactDB.getContactWithSessionID(sessionID);
if (contact == null) { return sessionID; }
String displayName = contact.displayName(Contact.ContactContext.OPEN_GROUP);
String displayName = contact.displayName(openGroupRecipient ? Contact.ContactContext.OPEN_GROUP : Contact.ContactContext.REGULAR);
if (displayName == null) { return sessionID; }
return displayName;
}