diff --git a/src/Mastodon/Helper.elm b/src/Mastodon/Helper.elm index bd96e84..95e9f9a 100644 --- a/src/Mastodon/Helper.elm +++ b/src/Mastodon/Helper.elm @@ -6,7 +6,7 @@ module Mastodon.Helper , notificationToAggregate ) -import List.Extra exposing (groupWhile) +import List.Extra exposing (groupWhile, uniqueBy) import Mastodon.Model exposing ( Notification @@ -114,7 +114,7 @@ aggregateNotifications notifications = extractAggregate statusGroup = let accounts = - List.map .account statusGroup + statusGroup |> List.map .account |> uniqueBy .id in case statusGroup of notification :: _ -> diff --git a/tests/Fixtures.elm b/tests/Fixtures.elm index b18eaf9..40010d0 100644 --- a/tests/Fixtures.elm +++ b/tests/Fixtures.elm @@ -198,6 +198,14 @@ notifications = ] +duplicateAccountNotifications : List Notification +duplicateAccountNotifications = + [ notificationSkroFollowsVjousse + , notificationSkroFollowsVjousse + , notificationSkroFollowsVjousse + ] + + notificationAggregates : List NotificationAggregate notificationAggregates = [ { type_ = "mention" diff --git a/tests/MastodonTest/HelperTest.elm b/tests/MastodonTest/HelperTest.elm index 6b1efcc..d927e99 100644 --- a/tests/MastodonTest/HelperTest.elm +++ b/tests/MastodonTest/HelperTest.elm @@ -26,6 +26,12 @@ all = , created_at = "2017-04-24T20:13:47.431Z" } ] + , test "Dedupes aggregated accounts" <| + \() -> + Fixtures.duplicateAccountNotifications + |> Mastodon.Helper.aggregateNotifications + |> List.map (.accounts >> List.length) + |> Expect.equal [ 1 ] , test "Add follows notification to aggregate" <| \() -> Fixtures.notifications