Update notifications rules: make a sound for each notification

This commit is contained in:
ClaireG 2022-05-05 14:02:11 +02:00 committed by GitHub
parent 83f8a8f278
commit c9bd1f32b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 21 additions and 8 deletions

1
changelog.d/46312.misc Normal file
View File

@ -0,0 +1 @@
Notify the user for each new message

View File

@ -28,5 +28,6 @@ data class InviteNotifiableEvent(
val type: String?, val type: String?,
val timestamp: Long, val timestamp: Long,
val soundName: String?, val soundName: String?,
override val isRedacted: Boolean = false override val isRedacted: Boolean = false,
override val isUpdated: Boolean = false
) : NotifiableEvent ) : NotifiableEvent

View File

@ -27,4 +27,5 @@ sealed interface NotifiableEvent : Serializable {
// Used to know if event should be replaced with the one coming from eventstream // Used to know if event should be replaced with the one coming from eventstream
val canBeReplaced: Boolean val canBeReplaced: Boolean
val isRedacted: Boolean val isRedacted: Boolean
val isUpdated: Boolean
} }

View File

@ -38,7 +38,8 @@ data class NotifiableMessageEvent(
// This is used for >N notification, as the result of a smart reply // This is used for >N notification, as the result of a smart reply
val outGoingMessage: Boolean = false, val outGoingMessage: Boolean = false,
val outGoingMessageFailed: Boolean = false, val outGoingMessageFailed: Boolean = false,
override val isRedacted: Boolean = false override val isRedacted: Boolean = false,
override val isUpdated: Boolean = false
) : NotifiableEvent { ) : NotifiableEvent {
val type: String = EventType.MESSAGE val type: String = EventType.MESSAGE

View File

@ -112,7 +112,13 @@ data class NotificationEventQueue(
private fun replace(replace: NotifiableEvent, with: NotifiableEvent) { private fun replace(replace: NotifiableEvent, with: NotifiableEvent) {
queue.remove(replace) 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) { fun clearMemberShipNotificationForRoom(roomId: String) {

View File

@ -592,7 +592,7 @@ class NotificationUtils @Inject constructor(
val channelID = if (roomInfo.shouldBing) NOISY_NOTIFICATION_CHANNEL_ID else SILENT_NOTIFICATION_CHANNEL_ID val channelID = if (roomInfo.shouldBing) NOISY_NOTIFICATION_CHANNEL_ID else SILENT_NOTIFICATION_CHANNEL_ID
return NotificationCompat.Builder(context, channelID) return NotificationCompat.Builder(context, channelID)
.setOnlyAlertOnce(true) .setOnlyAlertOnce(roomInfo.isUpdated)
.setWhen(lastMessageTimestamp) .setWhen(lastMessageTimestamp)
// MESSAGING_STYLE sets title and content for API 16 and above devices. // MESSAGING_STYLE sets title and content for API 16 and above devices.
.setStyle(messageStyle) .setStyle(messageStyle)

View File

@ -31,4 +31,5 @@ data class RoomEventGroupInfo(
var shouldBing: Boolean = false var shouldBing: Boolean = false
var customSound: String? = null var customSound: String? = null
var hasSmartReplyError: Boolean = false var hasSmartReplyError: Boolean = false
var isUpdated: Boolean = false
} }

View File

@ -72,6 +72,7 @@ class RoomGroupMessageCreator @Inject constructor(
it.hasSmartReplyError = smartReplyErrors.isNotEmpty() it.hasSmartReplyError = smartReplyErrors.isNotEmpty()
it.shouldBing = meta.shouldBing it.shouldBing = meta.shouldBing
it.customSound = events.last().soundName it.customSound = events.last().soundName
it.isUpdated = events.last().isUpdated
}, },
largeIcon = largeBitmap, largeIcon = largeBitmap,
lastMessageTimestamp, lastMessageTimestamp,

View File

@ -26,5 +26,6 @@ data class SimpleNotifiableEvent(
val timestamp: Long, val timestamp: Long,
val soundName: String?, val soundName: String?,
override var canBeReplaced: Boolean, override var canBeReplaced: Boolean,
override val isRedacted: Boolean = false override val isRedacted: Boolean = false,
override val isUpdated: Boolean = false
) : NotifiableEvent ) : NotifiableEvent

View File

@ -145,7 +145,7 @@ class NotificationEventQueueTest {
@Test @Test
fun `given replaceable event when adding event with same id then updates existing event`() { fun `given replaceable event when adding event with same id then updates existing event`() {
val replaceableEvent = aSimpleNotifiableEvent(canBeReplaced = true) 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)) val queue = givenQueue(listOf(replaceableEvent))
queue.add(updatedEvent) queue.add(updatedEvent)
@ -167,7 +167,7 @@ class NotificationEventQueueTest {
@Test @Test
fun `given event when adding new event with edited event id matching the existing event id then updates existing event`() { 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 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)) val queue = givenQueue(listOf(editedEvent))
queue.add(updatedEvent) queue.add(updatedEvent)
@ -178,7 +178,7 @@ class NotificationEventQueueTest {
@Test @Test
fun `given event when adding new event with edited event id matching the existing event edited id then updates existing event`() { 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 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)) val queue = givenQueue(listOf(editedEvent))
queue.add(updatedEvent) queue.add(updatedEvent)