From 2fbafdbe533f2477fb3807cc96046a85ea891409 Mon Sep 17 00:00:00 2001 From: Vincent Jousse Date: Thu, 1 Jun 2017 12:01:13 +0200 Subject: [PATCH] Add follow date in notification aggregate (#190) Add follow date in notification aggregate Closes #176 --- public/style.css | 8 ++++++++ src/Mastodon/Helper.elm | 22 ++++++++++++++++++---- src/Mastodon/Model.elm | 9 ++++++++- src/View/Common.elm | 11 +++++++++++ src/View/Notification.elm | 26 ++++++++++++++++---------- src/View/Status.elm | 12 +----------- 6 files changed, 62 insertions(+), 26 deletions(-) diff --git a/public/style.css b/public/style.css index 4629958..be4894d 100644 --- a/public/style.css +++ b/public/style.css @@ -270,6 +270,14 @@ span.applink { text-overflow: ellipsis; } +.follow-profile-date { + font-weight: normal; +} + +.follow-profile-date > .glyphicon { + margin-right: 5px; +} + /* Thread */ .thread-target { diff --git a/src/Mastodon/Helper.elm b/src/Mastodon/Helper.elm index 80a8b0d..731cbff 100644 --- a/src/Mastodon/Helper.elm +++ b/src/Mastodon/Helper.elm @@ -56,7 +56,7 @@ notificationToAggregate notification = notification.id notification.type_ notification.status - [ notification.account ] + [ { account = notification.account, created_at = notification.created_at } ] notification.created_at @@ -68,7 +68,13 @@ addNotificationToAggregates notification aggregates = case ( aggregate.status, notification.status ) of ( Just aggregateStatus, Just notificationStatus ) -> if aggregateStatus.id == notificationStatus.id then - { aggregate | accounts = notification.account :: aggregate.accounts } + { aggregate + | accounts = + { account = notification.account + , created_at = notification.created_at + } + :: aggregate.accounts + } else aggregate @@ -91,7 +97,13 @@ addNotificationToAggregates notification aggregates = Add the new following account. -} ( "follow", "follow" ) -> - { aggregate | accounts = notification.account :: aggregate.accounts } + { aggregate + | accounts = + { account = notification.account + , created_at = notification.created_at + } + :: aggregate.accounts + } {- Notification is of type follow, but current aggregate @@ -139,7 +151,9 @@ aggregateNotifications notifications = extractAggregate statusGroup = let accounts = - statusGroup |> List.map .account |> uniqueBy .id + statusGroup + |> List.map (\s -> { account = s.account, created_at = s.created_at }) + |> uniqueBy (.account >> .id) in case statusGroup of notification :: _ -> diff --git a/src/Mastodon/Model.elm b/src/Mastodon/Model.elm index aec42bc..54b50f7 100644 --- a/src/Mastodon/Model.elm +++ b/src/Mastodon/Model.elm @@ -3,6 +3,7 @@ module Mastodon.Model ( AccessTokenResult , AppRegistration , Account + , AccountNotificationDate , Application , Attachment , Client @@ -146,11 +147,17 @@ type alias Notification = } +type alias AccountNotificationDate = + { account : Account + , created_at : String + } + + type alias NotificationAggregate = { id : Int , type_ : String , status : Maybe Status - , accounts : List Account + , accounts : List AccountNotificationDate , created_at : String } diff --git a/src/View/Common.elm b/src/View/Common.elm index fd52a14..159c232 100644 --- a/src/View/Common.elm +++ b/src/View/Common.elm @@ -9,8 +9,12 @@ module View.Common , justifiedButtonGroup , loadMoreBtn , confirmView + , formatDate ) +import Date +import Date.Extra.Config.Config_en_au as DateEn +import Date.Extra.Format as DateFormat import Html exposing (..) import Html.Attributes exposing (..) import Html.Events exposing (..) @@ -150,3 +154,10 @@ confirmView { message, onConfirm, onCancel } = ] ] ] + + +formatDate : String -> String +formatDate dateString = + Date.fromString dateString + |> Result.withDefault (Date.fromTime 0) + |> DateFormat.format DateEn.config "%d/%m/%Y %H:%M" diff --git a/src/View/Notification.elm b/src/View/Notification.elm index 62dc454..fd75e99 100644 --- a/src/View/Notification.elm +++ b/src/View/Notification.elm @@ -55,28 +55,29 @@ filterNotifications filter notifications = List.filter applyFilter notifications -notificationHeading : List Account -> String -> String -> Html Msg -notificationHeading accounts str iconType = +notificationHeading : List AccountNotificationDate -> String -> String -> Html Msg +notificationHeading accountsAndDate str iconType = let ( firstAccounts, finalStr ) = - case accounts of + case accountsAndDate of [ a1 ] -> - ( [ a1 ], str ) + ( [ a1.account ], str ) [ a1, a2 ] -> - ( [ a1, a2 ], str ) + ( [ a1.account, a2.account ], str ) [ a1, a2, a3 ] -> - ( [ a1, a2, a3 ], str ) + ( [ a1.account, a2.account, a3.account ], str ) a1 :: a2 :: a3 :: xs -> - ( [ a1, a2, a3 ], " and " ++ (toString <| List.length xs) ++ " others " ++ str ) + ( [ a1.account, a2.account, a3.account ], " and " ++ (toString <| List.length xs) ++ " others " ++ str ) _ -> ( [], "" ) in div [ class "status-info" ] - [ div [ class "avatars" ] <| List.map (Common.accountAvatarLink False) accounts + [ div [ class "avatars" ] <| + List.map (Common.accountAvatarLink False) (List.map .account accountsAndDate) , p [ class "status-info-text" ] <| List.intersperse (text " ") [ Common.icon iconType @@ -106,10 +107,15 @@ notificationStatusView ( context, currentUser, status, { type_, accounts } ) = notificationFollowView : CurrentUser -> NotificationAggregate -> Html Msg notificationFollowView currentUser { accounts } = let - profileView account = + profileView : AccountNotificationDate -> Html Msg + profileView { account, created_at } = div [ class "status follow-profile" ] [ Common.accountAvatarLink False account - , div [ class "username" ] [ Common.accountLink False account ] + , div [ class "username" ] + [ Common.accountLink False account + , span [ class "btn-sm follow-profile-date" ] + [ Common.icon "time", text <| Common.formatDate created_at ] + ] , formatContent account.note [] |> div [ class "status-text" diff --git a/src/View/Status.elm b/src/View/Status.elm index 24c48f8..d297113 100644 --- a/src/View/Status.elm +++ b/src/View/Status.elm @@ -5,9 +5,6 @@ module View.Status , statusEntryView ) -import Date -import Date.Extra.Config.Config_en_au as DateEn -import Date.Extra.Format as DateFormat import Html exposing (..) import Html.Attributes exposing (..) import Html.Keyed as Keyed @@ -108,13 +105,6 @@ statusActionsView status currentUser showApp = _ -> ( baseBtnClasses, AddFavorite sourceStatus ) - - statusDate = - Date.fromString status.created_at - |> Result.withDefault (Date.fromTime 0) - - formatDate = - text <| DateFormat.format DateEn.config "%d/%m/%Y %H:%M" statusDate in div [ class "btn-group actions" ] [ a @@ -147,7 +137,7 @@ statusActionsView status currentUser showApp = text "" , a [ class baseBtnClasses, href (Maybe.withDefault "#" status.url), target "_blank" ] - [ Common.icon "time", formatDate ] + [ Common.icon "time", text <| Common.formatDate status.created_at ] , if showApp then Common.appLink (baseBtnClasses ++ " applink") status.application else