2017-05-02 02:27:01 -04:00
|
|
|
module View.Notification exposing (notificationListView)
|
|
|
|
|
|
|
|
import Html exposing (..)
|
|
|
|
import Html.Attributes exposing (..)
|
|
|
|
import Html.Events exposing (..)
|
|
|
|
import Html.Keyed as Keyed
|
|
|
|
import Html.Lazy as Lazy
|
|
|
|
import Mastodon.Model exposing (..)
|
|
|
|
import Types exposing (..)
|
|
|
|
import View.Common as Common
|
|
|
|
import View.Events exposing (..)
|
|
|
|
import View.Formatter exposing (formatContent)
|
|
|
|
import View.Status exposing (statusActionsView, statusView)
|
|
|
|
|
|
|
|
|
|
|
|
type alias CurrentUser =
|
|
|
|
Account
|
|
|
|
|
|
|
|
|
|
|
|
filterNotifications : NotificationFilter -> List NotificationAggregate -> List NotificationAggregate
|
|
|
|
filterNotifications filter notifications =
|
|
|
|
let
|
2017-05-13 07:57:44 -04:00
|
|
|
applyFilter { type_, status } =
|
|
|
|
let
|
|
|
|
visibility =
|
|
|
|
case status of
|
|
|
|
Just status ->
|
|
|
|
status.visibility
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
""
|
|
|
|
in
|
|
|
|
case filter of
|
|
|
|
NotificationAll ->
|
|
|
|
True
|
|
|
|
|
|
|
|
NotificationOnlyMentions ->
|
|
|
|
type_ == "mention" && visibility /= "direct"
|
|
|
|
|
|
|
|
NotificationOnlyDirect ->
|
|
|
|
type_ == "mention" && visibility == "direct"
|
|
|
|
|
|
|
|
NotificationOnlyBoosts ->
|
|
|
|
type_ == "reblog"
|
|
|
|
|
|
|
|
NotificationOnlyFavourites ->
|
|
|
|
type_ == "favourite"
|
|
|
|
|
|
|
|
NotificationOnlyFollows ->
|
2021-01-12 16:06:13 -05:00
|
|
|
type_ == "follow" || type_ == "follow_request"
|
2017-05-02 02:27:01 -04:00
|
|
|
in
|
|
|
|
if filter == NotificationAll then
|
|
|
|
notifications
|
|
|
|
else
|
|
|
|
List.filter applyFilter notifications
|
|
|
|
|
|
|
|
|
2017-06-01 06:01:13 -04:00
|
|
|
notificationHeading : List AccountNotificationDate -> String -> String -> Html Msg
|
|
|
|
notificationHeading accountsAndDate str iconType =
|
2017-05-14 04:30:59 -04:00
|
|
|
let
|
|
|
|
( firstAccounts, finalStr ) =
|
2017-06-01 06:01:13 -04:00
|
|
|
case accountsAndDate of
|
2017-05-14 04:30:59 -04:00
|
|
|
[ a1 ] ->
|
2017-06-01 06:01:13 -04:00
|
|
|
( [ a1.account ], str )
|
2017-05-14 04:30:59 -04:00
|
|
|
|
|
|
|
[ a1, a2 ] ->
|
2017-06-01 06:01:13 -04:00
|
|
|
( [ a1.account, a2.account ], str )
|
2017-05-14 04:30:59 -04:00
|
|
|
|
|
|
|
[ a1, a2, a3 ] ->
|
2017-06-01 06:01:13 -04:00
|
|
|
( [ a1.account, a2.account, a3.account ], str )
|
2017-05-14 04:30:59 -04:00
|
|
|
|
|
|
|
a1 :: a2 :: a3 :: xs ->
|
2017-06-01 06:01:13 -04:00
|
|
|
( [ a1.account, a2.account, a3.account ], " and " ++ (toString <| List.length xs) ++ " others " ++ str )
|
2017-05-14 04:30:59 -04:00
|
|
|
|
|
|
|
_ ->
|
|
|
|
( [], "" )
|
|
|
|
in
|
|
|
|
div [ class "status-info" ]
|
2017-06-01 06:01:13 -04:00
|
|
|
[ div [ class "avatars" ] <|
|
|
|
|
List.map (Common.accountAvatarLink False) (List.map .account accountsAndDate)
|
2017-05-14 04:30:59 -04:00
|
|
|
, p [ class "status-info-text" ] <|
|
|
|
|
List.intersperse (text " ")
|
|
|
|
[ Common.icon iconType
|
2021-01-10 17:09:11 -05:00
|
|
|
, span [] <| List.intersperse (text ", ") (List.map (Common.accountLinkSmall False) firstAccounts)
|
2017-05-14 04:30:59 -04:00
|
|
|
, text finalStr
|
|
|
|
]
|
|
|
|
]
|
2017-05-02 02:27:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
notificationStatusView : ( String, CurrentUser, Status, NotificationAggregate ) -> Html Msg
|
|
|
|
notificationStatusView ( context, currentUser, status, { type_, accounts } ) =
|
|
|
|
div [ class <| "notification " ++ type_ ]
|
|
|
|
[ case type_ of
|
|
|
|
"reblog" ->
|
|
|
|
notificationHeading accounts "boosted your toot" "fire"
|
|
|
|
|
|
|
|
"favourite" ->
|
|
|
|
notificationHeading accounts "favourited your toot" "star"
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
text ""
|
2021-01-15 15:13:24 -05:00
|
|
|
, Lazy.lazy3 statusView context status True
|
2017-05-22 18:25:28 -04:00
|
|
|
, Lazy.lazy3 statusActionsView status currentUser False
|
2017-05-02 02:27:01 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
notificationFollowView : CurrentUser -> NotificationAggregate -> Html Msg
|
2021-01-12 16:06:13 -05:00
|
|
|
notificationFollowView currentUser { type_, accounts } =
|
2017-05-02 02:27:01 -04:00
|
|
|
let
|
2017-06-01 06:01:13 -04:00
|
|
|
profileView : AccountNotificationDate -> Html Msg
|
|
|
|
profileView { account, created_at } =
|
2017-05-02 02:27:01 -04:00
|
|
|
div [ class "status follow-profile" ]
|
2017-05-03 09:08:10 -04:00
|
|
|
[ Common.accountAvatarLink False account
|
2017-06-01 06:01:13 -04:00
|
|
|
, div [ class "username" ]
|
2021-01-11 19:12:13 -05:00
|
|
|
[ Common.accountLinkLarge False account
|
2017-06-01 06:01:13 -04:00
|
|
|
, span [ class "btn-sm follow-profile-date" ]
|
|
|
|
[ Common.icon "time", text <| Common.formatDate created_at ]
|
|
|
|
]
|
2017-05-30 18:27:30 -04:00
|
|
|
, formatContent account.note []
|
|
|
|
|> div
|
|
|
|
[ class "status-text"
|
2017-11-29 08:06:08 -05:00
|
|
|
, onClick <| Navigate ("#account/" ++ account.id)
|
2017-05-30 18:27:30 -04:00
|
|
|
]
|
2017-05-02 02:27:01 -04:00
|
|
|
]
|
2021-01-12 16:06:13 -05:00
|
|
|
|
|
|
|
message =
|
|
|
|
if type_ == "follow_request" then
|
|
|
|
"sent you a follow request"
|
|
|
|
else
|
|
|
|
"started following you"
|
2017-05-02 02:27:01 -04:00
|
|
|
in
|
|
|
|
div [ class "notification follow" ]
|
2021-01-12 16:06:13 -05:00
|
|
|
[ notificationHeading accounts message "user"
|
2017-05-14 04:30:59 -04:00
|
|
|
, div [ class "" ] <| List.map profileView (List.take 3 accounts)
|
2017-05-02 02:27:01 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
notificationEntryView : CurrentUser -> NotificationAggregate -> Html Msg
|
|
|
|
notificationEntryView currentUser notification =
|
|
|
|
li [ class "list-group-item" ]
|
|
|
|
[ case notification.status of
|
|
|
|
Just status ->
|
|
|
|
Lazy.lazy notificationStatusView ( "notification", currentUser, status, notification )
|
|
|
|
|
|
|
|
Nothing ->
|
|
|
|
notificationFollowView currentUser notification
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
notificationFilterView : NotificationFilter -> Html Msg
|
|
|
|
notificationFilterView filter =
|
|
|
|
let
|
|
|
|
filterBtn tooltip iconName event =
|
|
|
|
button
|
|
|
|
[ class <|
|
|
|
|
if filter == event then
|
2017-05-02 11:36:10 -04:00
|
|
|
"btn btn-primary active"
|
2017-05-02 02:27:01 -04:00
|
|
|
else
|
|
|
|
"btn btn-default"
|
|
|
|
, title tooltip
|
|
|
|
, onClick <| FilterNotifications event
|
|
|
|
]
|
|
|
|
[ Common.icon iconName ]
|
|
|
|
in
|
2017-05-14 05:30:38 -04:00
|
|
|
Common.justifiedButtonGroup "column-menu notification-filters"
|
2017-05-02 02:27:01 -04:00
|
|
|
[ filterBtn "All notifications" "asterisk" NotificationAll
|
|
|
|
, filterBtn "Mentions" "share-alt" NotificationOnlyMentions
|
2017-05-13 07:57:44 -04:00
|
|
|
, filterBtn "Direct" "envelope" NotificationOnlyDirect
|
2017-05-02 02:27:01 -04:00
|
|
|
, filterBtn "Boosts" "fire" NotificationOnlyBoosts
|
|
|
|
, filterBtn "Favorites" "star" NotificationOnlyFavourites
|
|
|
|
, filterBtn "Follows" "user" NotificationOnlyFollows
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2017-05-05 17:35:54 -04:00
|
|
|
notificationListView : CurrentUser -> NotificationFilter -> Timeline NotificationAggregate -> Html Msg
|
2017-05-02 02:27:01 -04:00
|
|
|
notificationListView currentUser filter notifications =
|
|
|
|
let
|
|
|
|
keyedEntry notification =
|
2017-11-29 08:06:08 -05:00
|
|
|
( notification.id
|
2017-05-02 02:27:01 -04:00
|
|
|
, Lazy.lazy2 notificationEntryView currentUser notification
|
|
|
|
)
|
2017-05-05 17:35:54 -04:00
|
|
|
|
|
|
|
entries =
|
|
|
|
notifications.entries
|
|
|
|
|> filterNotifications filter
|
|
|
|
|> List.map keyedEntry
|
2017-05-02 02:27:01 -04:00
|
|
|
in
|
|
|
|
div [ class "col-md-3 column" ]
|
|
|
|
[ div [ class "panel panel-default notifications-panel" ]
|
|
|
|
[ a
|
|
|
|
[ href "", onClickWithPreventAndStop <| ScrollColumn ScrollTop "notifications" ]
|
|
|
|
[ div [ class "panel-heading" ] [ Common.icon "bell", text "Notifications" ] ]
|
|
|
|
, notificationFilterView filter
|
|
|
|
, Keyed.ul [ id "notifications", class "list-group timeline" ] <|
|
2017-05-05 17:35:54 -04:00
|
|
|
(entries ++ [ ( "load-more", Common.loadMoreBtn notifications ) ])
|
2017-05-02 02:27:01 -04:00
|
|
|
]
|
|
|
|
]
|