1
0
Fork 0
tooty/src/View/Account.elm

267 lines
9.9 KiB
Elm

module View.Account
exposing
( accountFollowView
, accountTimelineView
, accountView
)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Html.Keyed as Keyed
import Html.Lazy as Lazy
import List.Extra exposing (find)
import Mastodon.Helper
import Mastodon.Model exposing (..)
import Types exposing (..)
import View.Common as Common
import View.Events exposing (..)
import View.Status exposing (statusEntryView)
import View.Formatter exposing (formatContent)
type alias CurrentUser =
Account
type alias CurrentUserRelation =
Maybe Relationship
accountCounterLink : String -> Int -> (Account -> Msg) -> Account -> Html Msg
accountCounterLink label count tagger account =
a
[ href ""
, class "col-md-4"
, onClickWithPreventAndStop <| tagger account
]
[ text label
, br [] []
, text <| toString count
]
followButton : CurrentUser -> CurrentUserRelation -> Account -> Html Msg
followButton currentUser relationship account =
if Mastodon.Helper.sameAccount account currentUser then
text ""
else
let
( followEvent, btnClasses, iconName, tooltip ) =
case relationship of
Nothing ->
( NoOp
, "btn btn-default btn-follow btn-disabled"
, "question-sign"
, "Unknown relationship"
)
Just relationship ->
if relationship.following then
( UnfollowAccount account
, "btn btn-default btn-follow btn-primary"
, "eye-close"
, "Unfollow"
)
else
( FollowAccount account
, "btn btn-default btn-follow"
, "eye-open"
, "Follow"
)
in
button [ class btnClasses, title tooltip, onClick followEvent ]
[ Common.icon iconName ]
followView : CurrentUser -> Maybe Relationship -> Account -> Html Msg
followView currentUser relationship account =
div [ class "follow-entry" ]
[ Common.accountAvatarLink False account
, div [ class "userinfo" ]
[ strong []
[ a
[ href account.url
, onClickWithPreventAndStop <| LoadAccount account.id
]
[ text <|
if account.display_name /= "" then
account.display_name
else
account.username
]
]
, br [] []
, text <| "@" ++ account.acct
]
, muteButton currentUser relationship account
, followButton currentUser relationship account
]
muteButton : CurrentUser -> CurrentUserRelation -> Account -> Html Msg
muteButton currentUser relationship account =
if Mastodon.Helper.sameAccount account currentUser then
text ""
else
let
( muteEvent, btnClasses, iconName, tooltip ) =
case relationship of
Nothing ->
( NoOp
, "btn btn-default btn-mute btn-disabled"
, "question-sign"
, "Unknown relationship"
)
Just relationship ->
if relationship.muting then
( Unmute account
, "btn btn-default btn-mute btn-primary"
, "volume-up"
, "Unmute"
)
else
( Mute account
, "btn btn-default btn-mute"
, "volume-off"
, "Mute"
)
in
button [ class btnClasses, title tooltip, onClick muteEvent ]
[ Common.icon iconName ]
blockButton : CurrentUser -> CurrentUserRelation -> Account -> Html Msg
blockButton currentUser relationship account =
if Mastodon.Helper.sameAccount account currentUser then
text ""
else
let
( blockEvent, btnClasses, iconName, tooltip ) =
case relationship of
Nothing ->
( NoOp
, "btn btn-default btn-block btn-disabled"
, "question-sign"
, "Unknown relationship"
)
Just relationship ->
if relationship.blocking then
( Unblock account
, "btn btn-default btn-block btn-primary"
, "ok-circle"
, "Unblock"
)
else
( Block account
, "btn btn-default btn-block"
, "ban-circle"
, "Block"
)
in
button [ class btnClasses, title tooltip, onClick blockEvent ]
[ Common.icon iconName ]
accountFollowView :
CurrentUser
-> Timeline Account
-> List Relationship
-> CurrentUserRelation
-> Account
-> Html Msg
accountFollowView currentUser timeline relationships relationship account =
let
keyedEntry account =
( toString account.id
, li [ class "list-group-item status" ]
[ followView
currentUser
(find (\r -> r.id == account.id) relationships)
account
]
)
entries =
List.map keyedEntry timeline.entries
in
accountView currentUser account relationship <|
Keyed.ul [ class "list-group" ] <|
(entries ++ [ ( "load-more", Common.loadMoreBtn timeline ) ])
accountTimelineView : CurrentUser -> Timeline Status -> CurrentUserRelation -> Account -> Html Msg
accountTimelineView currentUser timeline relationship account =
let
keyedEntry status =
( toString status.id
, Lazy.lazy (statusEntryView "account" "status" currentUser) status
)
entries =
List.map keyedEntry timeline.entries
in
accountView currentUser account relationship <|
Keyed.ul [ id timeline.id, class "list-group" ] <|
(entries ++ [ ( "load-more", Common.loadMoreBtn timeline ) ])
accountView : CurrentUser -> Account -> CurrentUserRelation -> Html Msg -> Html Msg
accountView currentUser account relationship panelContent =
let
{ statuses_count, following_count, followers_count } =
account
in
div [ class "col-md-3 column" ]
[ div [ class "panel panel-default" ]
[ Common.closeablePanelheading "account" "user" "Account" CloseAccount
, div [ id "account", class "timeline" ]
[ div
[ class "account-detail"
, style [ ( "background-image", "url('" ++ account.header ++ "')" ) ]
]
[ div [ class "opacity-layer" ]
[ followButton currentUser relationship account
, muteButton currentUser relationship account
, blockButton currentUser relationship account
, Common.accountAvatarLink True account
, span [ class "account-display-name" ] [ text account.display_name ]
, span [ class "account-username" ]
[ Common.accountLink True account
, case relationship of
Just relationship ->
span []
[ if relationship.followed_by then
span [ class "badge followed-by" ] [ text "Follows you" ]
else
text ""
, text " "
, if relationship.muting then
span [ class "badge muting" ] [ text "Muted" ]
else
text ""
, text " "
, if relationship.blocking then
span [ class "badge blocking" ] [ text "Blocked" ]
else
text ""
]
Nothing ->
text ""
]
, span [ class "account-note" ] (formatContent account.note [])
]
]
, div [ class "row account-infos" ]
[ accountCounterLink "Statuses" statuses_count ViewAccountStatuses account
, accountCounterLink "Following" following_count ViewAccountFollowing account
, accountCounterLink "Followers" followers_count ViewAccountFollowers account
]
, panelContent
]
]
]