From c9bd1f32b90527b8af3c614663612a500d664390 Mon Sep 17 00:00:00 2001 From: ClaireG Date: Thu, 5 May 2022 14:02:11 +0200 Subject: [PATCH] Update notifications rules: make a sound for each notification --- changelog.d/46312.misc | 1 + .../app/features/notifications/InviteNotifiableEvent.kt | 3 ++- .../vector/app/features/notifications/NotifiableEvent.kt | 1 + .../app/features/notifications/NotifiableMessageEvent.kt | 3 ++- .../app/features/notifications/NotificationEventQueue.kt | 8 +++++++- .../app/features/notifications/NotificationUtils.kt | 2 +- .../app/features/notifications/RoomEventGroupInfo.kt | 1 + .../app/features/notifications/RoomGroupMessageCreator.kt | 1 + .../app/features/notifications/SimpleNotifiableEvent.kt | 3 ++- .../features/notifications/NotificationEventQueueTest.kt | 6 +++--- 10 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 changelog.d/46312.misc diff --git a/changelog.d/46312.misc b/changelog.d/46312.misc new file mode 100644 index 0000000000..5e0112372f --- /dev/null +++ b/changelog.d/46312.misc @@ -0,0 +1 @@ +Notify the user for each new message diff --git a/vector/src/main/java/im/vector/app/features/notifications/InviteNotifiableEvent.kt b/vector/src/main/java/im/vector/app/features/notifications/InviteNotifiableEvent.kt index 832f97bc4e..eb0735f2be 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/InviteNotifiableEvent.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/InviteNotifiableEvent.kt @@ -28,5 +28,6 @@ data class InviteNotifiableEvent( val type: String?, val timestamp: Long, val soundName: String?, - override val isRedacted: Boolean = false + override val isRedacted: Boolean = false, + override val isUpdated: Boolean = false ) : NotifiableEvent diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotifiableEvent.kt b/vector/src/main/java/im/vector/app/features/notifications/NotifiableEvent.kt index 52d8119cbb..a9ad79febf 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/NotifiableEvent.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotifiableEvent.kt @@ -27,4 +27,5 @@ sealed interface NotifiableEvent : Serializable { // Used to know if event should be replaced with the one coming from eventstream val canBeReplaced: Boolean val isRedacted: Boolean + val isUpdated: Boolean } diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotifiableMessageEvent.kt b/vector/src/main/java/im/vector/app/features/notifications/NotifiableMessageEvent.kt index 35718666b0..d13e41daa8 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/NotifiableMessageEvent.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotifiableMessageEvent.kt @@ -38,7 +38,8 @@ data class NotifiableMessageEvent( // This is used for >N notification, as the result of a smart reply val outGoingMessage: Boolean = false, val outGoingMessageFailed: Boolean = false, - override val isRedacted: Boolean = false + override val isRedacted: Boolean = false, + override val isUpdated: Boolean = false ) : NotifiableEvent { val type: String = EventType.MESSAGE diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotificationEventQueue.kt b/vector/src/main/java/im/vector/app/features/notifications/NotificationEventQueue.kt index 04506b218b..7c933c389d 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/NotificationEventQueue.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotificationEventQueue.kt @@ -112,7 +112,13 @@ data class NotificationEventQueue( private fun replace(replace: NotifiableEvent, with: NotifiableEvent) { queue.remove(replace) - queue.add(with) + queue.add( + when (with) { + is InviteNotifiableEvent -> with.copy(isUpdated = true) + is NotifiableMessageEvent -> with.copy(isUpdated = true) + is SimpleNotifiableEvent -> with.copy(isUpdated = true) + } + ) } fun clearMemberShipNotificationForRoom(roomId: String) { diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt b/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt index 08f6ccc2f3..b480253636 100755 --- a/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt @@ -592,7 +592,7 @@ class NotificationUtils @Inject constructor( val channelID = if (roomInfo.shouldBing) NOISY_NOTIFICATION_CHANNEL_ID else SILENT_NOTIFICATION_CHANNEL_ID return NotificationCompat.Builder(context, channelID) - .setOnlyAlertOnce(true) + .setOnlyAlertOnce(roomInfo.isUpdated) .setWhen(lastMessageTimestamp) // MESSAGING_STYLE sets title and content for API 16 and above devices. .setStyle(messageStyle) diff --git a/vector/src/main/java/im/vector/app/features/notifications/RoomEventGroupInfo.kt b/vector/src/main/java/im/vector/app/features/notifications/RoomEventGroupInfo.kt index 64e40ed748..6ec4645382 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/RoomEventGroupInfo.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/RoomEventGroupInfo.kt @@ -31,4 +31,5 @@ data class RoomEventGroupInfo( var shouldBing: Boolean = false var customSound: String? = null var hasSmartReplyError: Boolean = false + var isUpdated: Boolean = false } diff --git a/vector/src/main/java/im/vector/app/features/notifications/RoomGroupMessageCreator.kt b/vector/src/main/java/im/vector/app/features/notifications/RoomGroupMessageCreator.kt index 8310c15daa..535ac8b62e 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/RoomGroupMessageCreator.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/RoomGroupMessageCreator.kt @@ -72,6 +72,7 @@ class RoomGroupMessageCreator @Inject constructor( it.hasSmartReplyError = smartReplyErrors.isNotEmpty() it.shouldBing = meta.shouldBing it.customSound = events.last().soundName + it.isUpdated = events.last().isUpdated }, largeIcon = largeBitmap, lastMessageTimestamp, diff --git a/vector/src/main/java/im/vector/app/features/notifications/SimpleNotifiableEvent.kt b/vector/src/main/java/im/vector/app/features/notifications/SimpleNotifiableEvent.kt index 8c72372204..a58f22087d 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/SimpleNotifiableEvent.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/SimpleNotifiableEvent.kt @@ -26,5 +26,6 @@ data class SimpleNotifiableEvent( val timestamp: Long, val soundName: String?, override var canBeReplaced: Boolean, - override val isRedacted: Boolean = false + override val isRedacted: Boolean = false, + override val isUpdated: Boolean = false ) : NotifiableEvent diff --git a/vector/src/test/java/im/vector/app/features/notifications/NotificationEventQueueTest.kt b/vector/src/test/java/im/vector/app/features/notifications/NotificationEventQueueTest.kt index 3429f882f8..e7349b6151 100644 --- a/vector/src/test/java/im/vector/app/features/notifications/NotificationEventQueueTest.kt +++ b/vector/src/test/java/im/vector/app/features/notifications/NotificationEventQueueTest.kt @@ -145,7 +145,7 @@ class NotificationEventQueueTest { @Test fun `given replaceable event when adding event with same id then updates existing event`() { val replaceableEvent = aSimpleNotifiableEvent(canBeReplaced = true) - val updatedEvent = replaceableEvent.copy(title = "updated title") + val updatedEvent = replaceableEvent.copy(title = "updated title", isUpdated = true) val queue = givenQueue(listOf(replaceableEvent)) queue.add(updatedEvent) @@ -167,7 +167,7 @@ class NotificationEventQueueTest { @Test fun `given event when adding new event with edited event id matching the existing event id then updates existing event`() { val editedEvent = aSimpleNotifiableEvent(eventId = "id-to-edit") - val updatedEvent = editedEvent.copy(eventId = "1", editedEventId = "id-to-edit", title = "updated title") + val updatedEvent = editedEvent.copy(eventId = "1", editedEventId = "id-to-edit", title = "updated title", isUpdated = true) val queue = givenQueue(listOf(editedEvent)) queue.add(updatedEvent) @@ -178,7 +178,7 @@ class NotificationEventQueueTest { @Test fun `given event when adding new event with edited event id matching the existing event edited id then updates existing event`() { val editedEvent = aSimpleNotifiableEvent(eventId = "0", editedEventId = "id-to-edit") - val updatedEvent = editedEvent.copy(eventId = "1", editedEventId = "id-to-edit", title = "updated title") + val updatedEvent = editedEvent.copy(eventId = "1", editedEventId = "id-to-edit", title = "updated title", isUpdated = true) val queue = givenQueue(listOf(editedEvent)) queue.add(updatedEvent)