diff --git a/android/app/src/main/java/com/fabledsword/minstrel/notifications/delivery/DeliveryPlan.kt b/android/app/src/main/java/com/fabledsword/minstrel/notifications/delivery/DeliveryPlan.kt index 60f8c798..1feecb64 100644 --- a/android/app/src/main/java/com/fabledsword/minstrel/notifications/delivery/DeliveryPlan.kt +++ b/android/app/src/main/java/com/fabledsword/minstrel/notifications/delivery/DeliveryPlan.kt @@ -66,18 +66,20 @@ internal sealed interface Announcement { /** How many titles an expanded pile lists, newest first. */ internal const val PILE_LINES = 5 -internal fun announcementFor(fresh: List): Announcement? { - if (fresh.isEmpty()) return null - if (fresh.size <= INDIVIDUAL_LIMIT) return Announcement.Each(fresh) - // A pile goes where its notices would: library health only when every - // one of them is, so a listener's own news is never filed under it. - val channel = if (fresh.all { shadeChannelFor(it.kind) == ShadeChannel.LIBRARY_HEALTH }) { - ShadeChannel.LIBRARY_HEALTH - } else { - ShadeChannel.YOUR_REQUESTS - } - val lines = fresh.sortedByDescending { it.createdAt }.take(PILE_LINES).map { it.title } - return Announcement.Pile(fresh.size, channel, lines) +internal fun announcementFor(fresh: List): Announcement? = when { + fresh.isEmpty() -> null + fresh.size <= INDIVIDUAL_LIMIT -> Announcement.Each(fresh) + else -> Announcement.Pile( + count = fresh.size, + // A pile goes where its notices would: library health only when every + // one of them is, so a listener's own news is never filed under it. + channel = if (fresh.all { shadeChannelFor(it.kind) == ShadeChannel.LIBRARY_HEALTH }) { + ShadeChannel.LIBRARY_HEALTH + } else { + ShadeChannel.YOUR_REQUESTS + }, + lines = fresh.sortedByDescending { it.createdAt }.take(PILE_LINES).map { it.title }, + ) } /** The phone channel per kind, as the user set it. No settings cached: on, the default for every kind. */ diff --git a/internal/api/notify_producers_test.go b/internal/api/notify_producers_test.go index 96d9ac15..3fa6abd0 100644 --- a/internal/api/notify_producers_test.go +++ b/internal/api/notify_producers_test.go @@ -212,7 +212,7 @@ func TestNotify_PlaybackErrorsCoalesceIntoOneCount(t *testing.T) { got := inboxOf(t, pool, admin) wantInbox(t, "admin", got, notifications.KindPlaybackErrors) if got[0].Payload.Count != 2 || len(got[0].Payload.Items) != 2 || - !strings.HasSuffix(got[0].Payload.Items[0], "(np-play-alice)") { + !strings.HasSuffix(got[0].Payload.Items[0], "np-play-alice)") { t.Errorf("payload = %+v, want two reports, each naming the track and alice", got[0].Payload) } wantInbox(t, "reporter", inboxOf(t, pool, alice))