1
0
Fork 0

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;
}
.follow-profile-date {
font-weight: normal;
}
.follow-profile-date > .glyphicon {
margin-right: 5px;
}
/* Thread */
.thread-target {

View File

@ -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 :: _ ->

View File

@ -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
}

View File

@ -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"

View File

@ -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"

View File

@ -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