diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationChannels.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationChannels.java index 47e048003..61f51025c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationChannels.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationChannels.java @@ -62,6 +62,7 @@ public class NotificationChannels { public static final String LOCKED_STATUS = "locked_status_v2"; public static final String OTHER = "other_v3"; public static final String VOICE_NOTES = "voice_notes"; + public static final String JOIN_EVENTS = "join_events"; /** * Ensures all of the notification channels are created. No harm in repeat calls. Call is safely @@ -519,6 +520,7 @@ public class NotificationChannels { NotificationChannel lockedStatus = new NotificationChannel(LOCKED_STATUS, context.getString(R.string.NotificationChannel_locked_status), NotificationManager.IMPORTANCE_LOW); NotificationChannel other = new NotificationChannel(OTHER, context.getString(R.string.NotificationChannel_other), NotificationManager.IMPORTANCE_LOW); NotificationChannel voiceNotes = new NotificationChannel(VOICE_NOTES, context.getString(R.string.NotificationChannel_voice_notes), NotificationManager.IMPORTANCE_LOW); + NotificationChannel joinEvents = new NotificationChannel(JOIN_EVENTS, context.getString(R.string.NotificationChannel_contact_joined_signal), NotificationManager.IMPORTANCE_DEFAULT); messages.setGroup(CATEGORY_MESSAGES); messages.enableVibration(TextSecurePreferences.isNotificationVibrateEnabled(context)); @@ -532,8 +534,9 @@ public class NotificationChannels { other.setVibrationPattern(new long[]{0}); other.enableVibration(true); voiceNotes.setShowBadge(false); + joinEvents.setShowBadge(false); - notificationManager.createNotificationChannels(Arrays.asList(messages, calls, failures, backups, lockedStatus, other, voiceNotes)); + notificationManager.createNotificationChannels(Arrays.asList(messages, calls, failures, backups, lockedStatus, other, voiceNotes, joinEvents)); if (BuildConfig.PLAY_STORE_DISABLED) { NotificationChannel appUpdates = new NotificationChannel(APP_UPDATES, context.getString(R.string.NotificationChannel_app_updates), NotificationManager.IMPORTANCE_HIGH); diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/v2/NotificationConversation.kt b/app/src/main/java/org/thoughtcrime/securesms/notifications/v2/NotificationConversation.kt index d128a9ee8..d2ccc31e1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/v2/NotificationConversation.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/v2/NotificationConversation.kt @@ -15,6 +15,7 @@ import org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto import org.thoughtcrime.securesms.conversation.ConversationIntents import org.thoughtcrime.securesms.notifications.DeleteNotificationReceiver import org.thoughtcrime.securesms.notifications.MarkReadReceiver +import org.thoughtcrime.securesms.notifications.NotificationChannels import org.thoughtcrime.securesms.notifications.NotificationIds import org.thoughtcrime.securesms.notifications.RemoteReplyReceiver import org.thoughtcrime.securesms.notifications.ReplyMethod @@ -41,6 +42,7 @@ class NotificationConversation( val sortKey: Long = Long.MAX_VALUE - mostRecentNotification.timestamp val messageCount: Int = notificationItems.size val isGroup: Boolean = recipient.isGroup + val isOnlyContactJoinedEvent: Boolean = messageCount == 1 && mostRecentNotification.isJoined fun getContentTitle(context: Context): CharSequence { return if (TextSecurePreferences.getNotificationPrivacy(context).isDisplayContact) { @@ -119,6 +121,14 @@ class NotificationConversation( return notificationItems.any { it.isNewNotification } } + fun getChannelId(context: Context): String { + return if (isOnlyContactJoinedEvent) { + NotificationChannels.JOIN_EVENTS + } else { + recipient.notificationChannel ?: NotificationChannels.getMessagesChannel(context) + } + } + fun getPendingIntent(context: Context): PendingIntent { val intent: Intent = ConversationIntents.createBuilder(context, recipient.id, threadId) .withStartingPosition(mostRecentNotification.getStartingPosition(context)) diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/v2/NotificationFactory.kt b/app/src/main/java/org/thoughtcrime/securesms/notifications/v2/NotificationFactory.kt index a71ddaec4..c44ac6f2e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/v2/NotificationFactory.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/v2/NotificationFactory.kt @@ -66,7 +66,6 @@ object NotificationFactory { notifyForConversation( context = context, conversation = conversation, - recipient = conversation.recipient, targetThreadId = targetThreadId, defaultBubbleState = defaultBubbleState ) @@ -112,7 +111,6 @@ object NotificationFactory { private fun notifyForConversation( context: Context, conversation: NotificationConversation, - recipient: Recipient, targetThreadId: Long, defaultBubbleState: BubbleUtil.BubbleState ) { @@ -124,11 +122,11 @@ object NotificationFactory { setCategory(NotificationCompat.CATEGORY_MESSAGE) setGroup(DefaultMessageNotifier.NOTIFICATION_GROUP) setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN) - setChannelId(recipient.notificationChannel ?: NotificationChannels.getMessagesChannel(context)) + setChannelId(conversation.getChannelId(context)) setContentTitle(conversation.getContentTitle(context)) setLargeIcon(conversation.getLargeIcon(context)) - addPerson(recipient) - setShortcutId(ConversationUtil.getShortcutId(recipient)) + addPerson(conversation.recipient) + setShortcutId(ConversationUtil.getShortcutId(conversation.recipient)) setContentInfo(conversation.messageCount.toString()) setNumber(conversation.messageCount) setContentText(conversation.getContentText(context)) @@ -146,7 +144,7 @@ object NotificationFactory { setBubbleMetadata(conversation, if (targetThreadId == conversation.threadId) defaultBubbleState else BubbleUtil.BubbleState.HIDDEN) } - if (conversation.messageCount == 1 && conversation.mostRecentNotification.isJoined) { + if (conversation.isOnlyContactJoinedEvent) { builder.addTurnOffJoinedNotificationsAction(conversation.getTurnOffJoinedNotificationsIntent(context)) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 07be3c490..ba921f425 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1727,6 +1727,7 @@ Messages Unknown Voice Notes + Contact joined Signal No activity available to open notification channel settings.