diff --git a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java index f4c71c732..d5ff712b2 100644 --- a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java +++ b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java @@ -200,10 +200,12 @@ public class MessageNotifier { SingleRecipientNotificationBuilder builder = new SingleRecipientNotificationBuilder(context, masterSecret, TextSecurePreferences.getNotificationPrivacy(context)); List notifications = notificationState.getNotifications(); + Recipients recipients = notifications.get(0).getRecipients(); - builder.setSender(notifications.get(0).getIndividualRecipient()); + builder.setThread(notifications.get(0).getRecipients()); builder.setMessageCount(notificationState.getMessageCount()); - builder.setPrimaryMessageBody(notifications.get(0).getText(), notifications.get(0).getSlideDeck()); + builder.setPrimaryMessageBody(recipients, notifications.get(0).getIndividualRecipient(), + notifications.get(0).getText(), notifications.get(0).getSlideDeck()); builder.setContentIntent(notifications.get(0).getPendingIntent(context)); long timestamp = notifications.get(0).getTimestamp(); @@ -217,8 +219,8 @@ public class MessageNotifier { ListIterator iterator = notifications.listIterator(notifications.size()); while(iterator.hasPrevious()) { - builder.addMessageBody(iterator.previous().getText()); - + NotificationItem item = iterator.previous(); + builder.addMessageBody(item.getRecipients(), item.getIndividualRecipient(), item.getText()); } if (signal) { diff --git a/src/org/thoughtcrime/securesms/notifications/NotificationItem.java b/src/org/thoughtcrime/securesms/notifications/NotificationItem.java index 9b8677715..ee4a41ec1 100644 --- a/src/org/thoughtcrime/securesms/notifications/NotificationItem.java +++ b/src/org/thoughtcrime/securesms/notifications/NotificationItem.java @@ -4,28 +4,28 @@ import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.net.Uri; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import org.thoughtcrime.securesms.ConversationActivity; import org.thoughtcrime.securesms.mms.SlideDeck; import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.Recipients; -import org.thoughtcrime.securesms.util.ListenableFutureTask; -import org.thoughtcrime.securesms.util.concurrent.ListenableFuture; public class NotificationItem { - private final Recipients recipients; - private final Recipient individualRecipient; - private final Recipients threadRecipients; + private final @NonNull Recipients recipients; + private final @NonNull Recipient individualRecipient; + private final @Nullable Recipients threadRecipients; private final long threadId; - private final CharSequence text; + private final @Nullable CharSequence text; private final long timestamp; private final @Nullable SlideDeck slideDeck; - public NotificationItem(Recipient individualRecipient, Recipients recipients, - Recipients threadRecipients, long threadId, - CharSequence text, long timestamp, + public NotificationItem(@NonNull Recipient individualRecipient, + @NonNull Recipients recipients, + @Nullable Recipients threadRecipients, + long threadId, @Nullable CharSequence text, long timestamp, @Nullable SlideDeck slideDeck) { this.individualRecipient = individualRecipient; @@ -37,11 +37,11 @@ public class NotificationItem { this.slideDeck = slideDeck; } - public Recipients getRecipients() { + public @NonNull Recipients getRecipients() { return threadRecipients == null ? recipients : threadRecipients; } - public Recipient getIndividualRecipient() { + public @NonNull Recipient getIndividualRecipient() { return individualRecipient; } diff --git a/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java b/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java index 9f46ba026..169028e1b 100644 --- a/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java +++ b/src/org/thoughtcrime/securesms/notifications/SingleRecipientNotificationBuilder.java @@ -24,7 +24,9 @@ import org.thoughtcrime.securesms.mms.Slide; import org.thoughtcrime.securesms.mms.SlideDeck; import org.thoughtcrime.securesms.preferences.NotificationPrivacyPreference; import org.thoughtcrime.securesms.recipients.Recipient; +import org.thoughtcrime.securesms.recipients.Recipients; import org.thoughtcrime.securesms.util.BitmapUtil; +import org.thoughtcrime.securesms.util.Util; import java.util.LinkedList; import java.util.List; @@ -53,16 +55,16 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil setDeleteIntent(PendingIntent.getBroadcast(context, 0, new Intent(MessageNotifier.DeleteReceiver.DELETE_REMINDER_ACTION), 0)); } - public void setSender(@NonNull Recipient recipient) { + public void setThread(@NonNull Recipients recipients) { if (privacy.isDisplayContact()) { - setContentTitle(recipient.toShortString()); + setContentTitle(recipients.toShortString()); - if (recipient.getContactUri() != null) { - addPerson(recipient.getContactUri().toString()); + if (recipients.isSingleRecipient() && recipients.getPrimaryRecipient().getContactUri() != null) { + addPerson(recipients.getPrimaryRecipient().getContactUri().toString()); } - setLargeIcon(recipient.getContactPhoto() - .asDrawable(context, recipient.getColor() + setLargeIcon(recipients.getContactPhoto() + .asDrawable(context, recipients.getColor() .toConversationColor(context))); } else { setContentTitle(context.getString(R.string.SingleRecipientNotificationBuilder_signal)); @@ -79,12 +81,22 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil setNumber(messageCount); } - public void setPrimaryMessageBody(CharSequence message, @Nullable SlideDeck slideDeck) { + public void setPrimaryMessageBody(@NonNull Recipients threadRecipients, + @NonNull Recipient individualRecipient, + @NonNull CharSequence message, + @Nullable SlideDeck slideDeck) + { + SpannableStringBuilder stringBuilder = new SpannableStringBuilder(); + + if (privacy.isDisplayContact() && (threadRecipients.isGroupRecipient() || !threadRecipients.isSingleRecipient())) { + stringBuilder.append(Util.getBoldedString(individualRecipient.toShortString() + ": ")); + } + if (privacy.isDisplayMessage()) { - setContentText(message); + setContentText(stringBuilder.append(message)); this.slideDeck = slideDeck; } else { - setContentText(context.getString(R.string.SingleRecipientNotificationBuilder_new_message)); + setContentText(stringBuilder.append(context.getString(R.string.SingleRecipientNotificationBuilder_new_message))); } } @@ -121,9 +133,20 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil } } - public void addMessageBody(@Nullable CharSequence messageBody) { + public void addMessageBody(@NonNull Recipients threadRecipients, + @NonNull Recipient individualRecipient, + @Nullable CharSequence messageBody) + { + SpannableStringBuilder stringBuilder = new SpannableStringBuilder(); + + if (privacy.isDisplayContact() && (threadRecipients.isGroupRecipient() || !threadRecipients.isSingleRecipient())) { + stringBuilder.append(Util.getBoldedString(individualRecipient.toShortString() + ": ")); + } + if (privacy.isDisplayMessage()) { - messageBodies.add(messageBody == null ? "" : messageBody); + messageBodies.add(stringBuilder.append(messageBody == null ? "" : messageBody)); + } else { + messageBodies.add(stringBuilder.append(context.getString(R.string.SingleRecipientNotificationBuilder_new_message))); } }