Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update notifications rules: make a sound for each notification #5796

Merged
merged 5 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/46312.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Notify the user for each new message
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ class NotificationUtils @Inject constructor(private val context: Context,

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ data class RoomEventGroupInfo(
var shouldBing: Boolean = false
var customSound: String? = null
var hasSmartReplyError: Boolean = false
var isUpdated: Boolean = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down