Add follow date in notification aggregate (#190)

Add follow date in notification aggregate
Closes #176
This commit is contained in:
Vincent Jousse 2017-06-01 12:01:13 +02:00 committed by GitHub
parent a7c17ab6f1
commit 2fbafdbe53
6 changed files with 62 additions and 26 deletions

View File

@ -270,6 +270,14 @@ span.applink {
text-overflow: ellipsis; text-overflow: ellipsis;
} }
.follow-profile-date {
font-weight: normal;
}
.follow-profile-date > .glyphicon {
margin-right: 5px;
}
/* Thread */ /* Thread */
.thread-target { .thread-target {

View File

@ -56,7 +56,7 @@ notificationToAggregate notification =
notification.id notification.id
notification.type_ notification.type_
notification.status notification.status
[ notification.account ] [ { account = notification.account, created_at = notification.created_at } ]
notification.created_at notification.created_at
@ -68,7 +68,13 @@ addNotificationToAggregates notification aggregates =
case ( aggregate.status, notification.status ) of case ( aggregate.status, notification.status ) of
( Just aggregateStatus, Just notificationStatus ) -> ( Just aggregateStatus, Just notificationStatus ) ->
if aggregateStatus.id == notificationStatus.id then 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 else
aggregate aggregate
@ -91,7 +97,13 @@ addNotificationToAggregates notification aggregates =
Add the new following account. Add the new following account.
-} -}
( "follow", "follow" ) -> ( "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 Notification is of type follow, but current aggregate
@ -139,7 +151,9 @@ aggregateNotifications notifications =
extractAggregate statusGroup = extractAggregate statusGroup =
let let
accounts = accounts =
statusGroup |> List.map .account |> uniqueBy .id statusGroup
|> List.map (\s -> { account = s.account, created_at = s.created_at })
|> uniqueBy (.account >> .id)
in in
case statusGroup of case statusGroup of
notification :: _ -> notification :: _ ->

View File

@ -3,6 +3,7 @@ module Mastodon.Model
( AccessTokenResult ( AccessTokenResult
, AppRegistration , AppRegistration
, Account , Account
, AccountNotificationDate
, Application , Application
, Attachment , Attachment
, Client , Client
@ -146,11 +147,17 @@ type alias Notification =
} }
type alias AccountNotificationDate =
{ account : Account
, created_at : String
}
type alias NotificationAggregate = type alias NotificationAggregate =
{ id : Int { id : Int
, type_ : String , type_ : String
, status : Maybe Status , status : Maybe Status
, accounts : List Account , accounts : List AccountNotificationDate
, created_at : String , created_at : String
} }

View File

@ -9,8 +9,12 @@ module View.Common
, justifiedButtonGroup , justifiedButtonGroup
, loadMoreBtn , loadMoreBtn
, confirmView , confirmView
, formatDate
) )
import Date
import Date.Extra.Config.Config_en_au as DateEn
import Date.Extra.Format as DateFormat
import Html exposing (..) import Html exposing (..)
import Html.Attributes exposing (..) import Html.Attributes exposing (..)
import Html.Events 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"

View File

@ -55,28 +55,29 @@ filterNotifications filter notifications =
List.filter applyFilter notifications List.filter applyFilter notifications
notificationHeading : List Account -> String -> String -> Html Msg notificationHeading : List AccountNotificationDate -> String -> String -> Html Msg
notificationHeading accounts str iconType = notificationHeading accountsAndDate str iconType =
let let
( firstAccounts, finalStr ) = ( firstAccounts, finalStr ) =
case accounts of case accountsAndDate of
[ a1 ] -> [ a1 ] ->
( [ a1 ], str ) ( [ a1.account ], str )
[ a1, a2 ] -> [ a1, a2 ] ->
( [ a1, a2 ], str ) ( [ a1.account, a2.account ], str )
[ a1, a2, a3 ] -> [ a1, a2, a3 ] ->
( [ a1, a2, a3 ], str ) ( [ a1.account, a2.account, a3.account ], str )
a1 :: a2 :: a3 :: xs -> 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 in
div [ class "status-info" ] 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" ] <| , p [ class "status-info-text" ] <|
List.intersperse (text " ") List.intersperse (text " ")
[ Common.icon iconType [ Common.icon iconType
@ -106,10 +107,15 @@ notificationStatusView ( context, currentUser, status, { type_, accounts } ) =
notificationFollowView : CurrentUser -> NotificationAggregate -> Html Msg notificationFollowView : CurrentUser -> NotificationAggregate -> Html Msg
notificationFollowView currentUser { accounts } = notificationFollowView currentUser { accounts } =
let let
profileView account = profileView : AccountNotificationDate -> Html Msg
profileView { account, created_at } =
div [ class "status follow-profile" ] div [ class "status follow-profile" ]
[ Common.accountAvatarLink False account [ 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 [] , formatContent account.note []
|> div |> div
[ class "status-text" [ class "status-text"

View File

@ -5,9 +5,6 @@ module View.Status
, statusEntryView , statusEntryView
) )
import Date
import Date.Extra.Config.Config_en_au as DateEn
import Date.Extra.Format as DateFormat
import Html exposing (..) import Html exposing (..)
import Html.Attributes exposing (..) import Html.Attributes exposing (..)
import Html.Keyed as Keyed import Html.Keyed as Keyed
@ -108,13 +105,6 @@ statusActionsView status currentUser showApp =
_ -> _ ->
( baseBtnClasses, AddFavorite sourceStatus ) ( 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 in
div [ class "btn-group actions" ] div [ class "btn-group actions" ]
[ a [ a
@ -147,7 +137,7 @@ statusActionsView status currentUser showApp =
text "" text ""
, a , a
[ class baseBtnClasses, href (Maybe.withDefault "#" status.url), target "_blank" ] [ 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 , if showApp then
Common.appLink (baseBtnClasses ++ " applink") status.application Common.appLink (baseBtnClasses ++ " applink") status.application
else else