From 3ac9df765df98138243e51af1e6feb1baa41d8f3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Jul 2022 05:34:28 +0000 Subject: [PATCH 1/2] Bump junit-jupiter-engine from 5.8.2 to 5.9.0 Bumps [junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.8.2 to 5.9.0. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.8.2...r5.9.0) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 2bdc19a..d3b79c0 100644 --- a/build.gradle +++ b/build.gradle @@ -136,7 +136,7 @@ ext.kotlinTest = { dependencies -> dependencies.testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4' dependencies.testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' - dependencies.testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2' + dependencies.testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0' } ext.kotlinFixtures = { dependencies -> From 8c1265c957c57aa6d6dd8a536e15d1212a85f3ae Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Thu, 28 Jul 2022 19:43:27 +0100 Subject: [PATCH 2/2] avoiding notification overlap by only using alerting summary group instead of all notifications --- .../st/notifications/NotificationChannels.kt | 13 +++++++++++++ .../st/notifications/NotificationFactory.kt | 15 +++++++++------ .../st/notifications/NotificationRenderer.kt | 3 ++- .../notifications/NotificationFactoryTest.kt | 18 ++++++++++++++---- .../kotlin/fixture/NotificationFixtures.kt | 4 +++- 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationChannels.kt b/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationChannels.kt index 0ca041f..12dbd8d 100644 --- a/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationChannels.kt +++ b/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationChannels.kt @@ -7,6 +7,7 @@ import android.os.Build const val DIRECT_CHANNEL_ID = "direct_channel_id" const val GROUP_CHANNEL_ID = "group_channel_id" +const val SUMMARY_CHANNEL_ID = "summary_channel_id" private const val CHATS_NOTIFICATION_GROUP_ID = "chats_notification_group" @@ -43,6 +44,18 @@ class NotificationChannels( } ) } + + if (notificationManager.getNotificationChannel(SUMMARY_CHANNEL_ID) == null) { + notificationManager.createNotificationChannel( + NotificationChannel( + SUMMARY_CHANNEL_ID, + "Other notifications", + NotificationManager.IMPORTANCE_DEFAULT, + ).also { + it.group = CHATS_NOTIFICATION_GROUP_ID + } + ) + } } } diff --git a/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationFactory.kt b/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationFactory.kt index 87068cb..50e8193 100644 --- a/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationFactory.kt +++ b/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationFactory.kt @@ -37,10 +37,7 @@ class NotificationFactory( val last = sortedEvents.last() return NotificationTypes.Room( AndroidNotification( - channelId = when { - roomOverview.isDm() -> DIRECT_CHANNEL_ID - else -> GROUP_CHANNEL_ID - }, + channelId = SUMMARY_CHANNEL_ID, whenTimestamp = last.utcTimestamp, groupId = GROUP_ID, groupAlertBehavior = deviceMeta.whenPOrHigher( @@ -59,7 +56,11 @@ class NotificationFactory( roomId = roomOverview.roomId, summary = last.content, messageCount = sortedEvents.size, - isAlerting = shouldAlertMoreThanOnce + isAlerting = shouldAlertMoreThanOnce, + summaryChannelId = when { + roomOverview.isDm() -> DIRECT_CHANNEL_ID + else -> GROUP_CHANNEL_ID + } ) } @@ -67,7 +68,7 @@ class NotificationFactory( val summaryInboxStyle = notificationStyleFactory.summary(notifications) val openAppIntent = intentFactory.notificationOpenApp(context) return AndroidNotification( - channelId = notifications.firstOrNull { it.isAlerting }?.notification?.channelId ?: notifications.first().notification.channelId, + channelId = notifications.mostRecent().summaryChannelId, messageStyle = summaryInboxStyle, alertMoreThanOnce = notifications.any { it.isAlerting }, smallIcon = R.drawable.ic_notification_small_icon, @@ -83,4 +84,6 @@ class NotificationFactory( } } +private fun List.mostRecent() = this.sortedBy { it.notification.whenTimestamp }.first() + private fun RoomOverview.isDm() = !this.isGroup diff --git a/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationRenderer.kt b/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationRenderer.kt index 5d4e177..5a2cc7c 100644 --- a/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationRenderer.kt +++ b/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationRenderer.kt @@ -68,7 +68,8 @@ sealed interface NotificationTypes { val roomId: RoomId, val summary: String, val messageCount: Int, - val isAlerting: Boolean + val isAlerting: Boolean, + val summaryChannelId: String, ) : NotificationTypes data class DismissRoom(val roomId: RoomId) : NotificationTypes diff --git a/features/notifications/src/test/kotlin/app/dapk/st/notifications/NotificationFactoryTest.kt b/features/notifications/src/test/kotlin/app/dapk/st/notifications/NotificationFactoryTest.kt index af98498..0c466b6 100644 --- a/features/notifications/src/test/kotlin/app/dapk/st/notifications/NotificationFactoryTest.kt +++ b/features/notifications/src/test/kotlin/app/dapk/st/notifications/NotificationFactoryTest.kt @@ -32,7 +32,6 @@ private val EVENTS = listOf( aNotifiable("message two", utcTimestamp = 2), ) - class NotificationFactoryTest { private val fakeContext = FakeContext() @@ -50,7 +49,12 @@ class NotificationFactoryTest { @Test fun `given alerting room notification, when creating summary, then is alerting`() { - val notifications = listOf(aRoomNotification(notification = anAndroidNotification(channelId = A_CHANNEL_ID), isAlerting = true)) + val notifications = listOf( + aRoomNotification( + summaryChannelId = A_CHANNEL_ID, + notification = anAndroidNotification(channelId = A_CHANNEL_ID), isAlerting = true + ) + ) fakeIntentFactory.givenNotificationOpenApp(fakeContext.instance).returns(AN_OPEN_APP_INTENT) fakeNotificationStyleFactory.givenSummary(notifications).returns(anInboxStyle()) @@ -61,7 +65,12 @@ class NotificationFactoryTest { @Test fun `given non alerting room notification, when creating summary, then is alerting`() { - val notifications = listOf(aRoomNotification(notification = anAndroidNotification(channelId = A_CHANNEL_ID), isAlerting = false)) + val notifications = listOf( + aRoomNotification( + summaryChannelId = A_CHANNEL_ID, + notification = anAndroidNotification(channelId = A_CHANNEL_ID), isAlerting = false + ) + ) fakeIntentFactory.givenNotificationOpenApp(fakeContext.instance).returns(AN_OPEN_APP_INTENT) fakeNotificationStyleFactory.givenSummary(notifications).returns(anInboxStyle()) @@ -129,7 +138,7 @@ class NotificationFactoryTest { shouldAlertMoreThanOnce: Boolean, ) = NotificationTypes.Room( AndroidNotification( - channelId = channel, + channelId = SUMMARY_CHANNEL_ID, whenTimestamp = LATEST_EVENT.utcTimestamp, groupId = "st", groupAlertBehavior = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) Notification.GROUP_ALERT_SUMMARY else null, @@ -146,6 +155,7 @@ class NotificationFactoryTest { summary = LATEST_EVENT.content, messageCount = EVENTS.size, isAlerting = shouldAlertMoreThanOnce, + summaryChannelId = channel, ) private fun expectedSummary(channelId: String, shouldAlertMoreThanOnce: Boolean) = AndroidNotification( diff --git a/features/notifications/src/test/kotlin/fixture/NotificationFixtures.kt b/features/notifications/src/test/kotlin/fixture/NotificationFixtures.kt index caa8a7a..46d824a 100644 --- a/features/notifications/src/test/kotlin/fixture/NotificationFixtures.kt +++ b/features/notifications/src/test/kotlin/fixture/NotificationFixtures.kt @@ -18,12 +18,14 @@ object NotificationFixtures { summary: String = "a summary line", messageCount: Int = 1, isAlerting: Boolean = false, + summaryChannelId: String = "a-summary-channel-id", ) = NotificationTypes.Room( notification, aRoomId(), summary = summary, messageCount = messageCount, - isAlerting = isAlerting + isAlerting = isAlerting, + summaryChannelId = summaryChannelId ) fun aDismissRoomNotification(