Dedupe multiple account references in notifs. (#101)

This commit is contained in:
Nicolas Perriault 2017-04-28 19:08:46 +02:00 committed by GitHub
parent 29b053b130
commit 3ea6aaade2
3 changed files with 16 additions and 2 deletions

View File

@ -6,7 +6,7 @@ module Mastodon.Helper
, notificationToAggregate , notificationToAggregate
) )
import List.Extra exposing (groupWhile) import List.Extra exposing (groupWhile, uniqueBy)
import Mastodon.Model import Mastodon.Model
exposing exposing
( Notification ( Notification
@ -114,7 +114,7 @@ aggregateNotifications notifications =
extractAggregate statusGroup = extractAggregate statusGroup =
let let
accounts = accounts =
List.map .account statusGroup statusGroup |> List.map .account |> uniqueBy .id
in in
case statusGroup of case statusGroup of
notification :: _ -> notification :: _ ->

View File

@ -198,6 +198,14 @@ notifications =
] ]
duplicateAccountNotifications : List Notification
duplicateAccountNotifications =
[ notificationSkroFollowsVjousse
, notificationSkroFollowsVjousse
, notificationSkroFollowsVjousse
]
notificationAggregates : List NotificationAggregate notificationAggregates : List NotificationAggregate
notificationAggregates = notificationAggregates =
[ { type_ = "mention" [ { type_ = "mention"

View File

@ -26,6 +26,12 @@ all =
, created_at = "2017-04-24T20:13:47.431Z" , 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" <| , test "Add follows notification to aggregate" <|
\() -> \() ->
Fixtures.notifications Fixtures.notifications