2017-05-29 10:28:01 -04:00
|
|
|
module View.Account exposing (accountView)
|
2017-05-02 02:27:01 -04:00
|
|
|
|
|
|
|
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)
|
2017-11-29 08:06:08 -05:00
|
|
|
import Mastodon.Helper exposing (extractStatusId)
|
2017-05-02 02:27:01 -04:00
|
|
|
import Mastodon.Model exposing (..)
|
|
|
|
import Types exposing (..)
|
|
|
|
import View.Common as Common
|
2017-05-05 13:20:07 -04:00
|
|
|
import View.Status exposing (statusEntryView)
|
2017-05-02 02:27:01 -04:00
|
|
|
import View.Formatter exposing (formatContent)
|
|
|
|
|
|
|
|
|
|
|
|
type alias CurrentUser =
|
|
|
|
Account
|
|
|
|
|
|
|
|
|
|
|
|
type alias CurrentUserRelation =
|
|
|
|
Maybe Relationship
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2017-05-25 17:07:17 -04:00
|
|
|
, "btn btn-default btn-follow btn-disabled"
|
2017-05-02 02:27:01 -04:00
|
|
|
, "question-sign"
|
|
|
|
, "Unknown relationship"
|
|
|
|
)
|
|
|
|
|
|
|
|
Just relationship ->
|
|
|
|
if relationship.following then
|
2017-05-25 04:25:43 -04:00
|
|
|
( UnfollowAccount account
|
2017-05-25 17:07:17 -04:00
|
|
|
, "btn btn-default btn-follow btn-primary"
|
2017-05-02 02:27:01 -04:00
|
|
|
, "eye-close"
|
|
|
|
, "Unfollow"
|
|
|
|
)
|
|
|
|
else
|
2017-05-25 04:25:43 -04:00
|
|
|
( FollowAccount account
|
2017-05-25 17:07:17 -04:00
|
|
|
, "btn btn-default btn-follow"
|
2017-05-02 02:27:01 -04:00
|
|
|
, "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" ]
|
2017-05-03 09:08:10 -04:00
|
|
|
[ Common.accountAvatarLink False account
|
2017-05-02 02:27:01 -04:00
|
|
|
, div [ class "userinfo" ]
|
|
|
|
[ strong []
|
|
|
|
[ a
|
2017-11-29 08:06:08 -05:00
|
|
|
[ href <| "#account/" ++ account.id ]
|
2017-05-02 02:27:01 -04:00
|
|
|
[ text <|
|
|
|
|
if account.display_name /= "" then
|
|
|
|
account.display_name
|
|
|
|
else
|
|
|
|
account.username
|
|
|
|
]
|
|
|
|
]
|
|
|
|
, br [] []
|
|
|
|
, text <| "@" ++ account.acct
|
|
|
|
]
|
2017-05-25 17:07:17 -04:00
|
|
|
, muteButton currentUser relationship account
|
2017-05-02 02:27:01 -04:00
|
|
|
, followButton currentUser relationship account
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2017-05-25 17:07:17 -04:00
|
|
|
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 ]
|
|
|
|
|
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
accountFollowView : CurrentAccountView -> CurrentUser -> AccountInfo -> Html Msg
|
|
|
|
accountFollowView view currentUser accountInfo =
|
2017-05-02 02:27:01 -04:00
|
|
|
let
|
|
|
|
keyedEntry account =
|
2017-11-29 08:06:08 -05:00
|
|
|
( account.id
|
2017-05-02 02:27:01 -04:00
|
|
|
, li [ class "list-group-item status" ]
|
|
|
|
[ followView
|
|
|
|
currentUser
|
2017-05-29 10:28:01 -04:00
|
|
|
(find (\r -> r.id == account.id) accountInfo.relationships)
|
2017-05-02 02:27:01 -04:00
|
|
|
account
|
|
|
|
]
|
|
|
|
)
|
2017-05-08 06:22:20 -04:00
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
timeline =
|
|
|
|
if view == AccountFollowersView then
|
|
|
|
accountInfo.followers
|
|
|
|
else
|
|
|
|
accountInfo.following
|
|
|
|
|
2017-05-08 06:22:20 -04:00
|
|
|
entries =
|
|
|
|
List.map keyedEntry timeline.entries
|
2017-05-02 02:27:01 -04:00
|
|
|
in
|
2017-05-29 10:28:01 -04:00
|
|
|
case accountInfo.account of
|
|
|
|
Just account ->
|
|
|
|
Keyed.ul [ class "list-group" ] <|
|
|
|
|
(entries ++ [ ( "load-more", Common.loadMoreBtn timeline ) ])
|
2017-05-02 02:27:01 -04:00
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
Nothing ->
|
|
|
|
text ""
|
2017-05-02 02:27:01 -04:00
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
|
|
|
|
accountTimelineView : CurrentUser -> AccountInfo -> Html Msg
|
|
|
|
accountTimelineView currentUser accountInfo =
|
2017-05-02 02:27:01 -04:00
|
|
|
let
|
|
|
|
keyedEntry status =
|
2017-11-29 08:06:08 -05:00
|
|
|
( extractStatusId status.id
|
2017-05-05 13:20:07 -04:00
|
|
|
, Lazy.lazy (statusEntryView "account" "status" currentUser) status
|
2017-05-02 02:27:01 -04:00
|
|
|
)
|
2017-05-05 11:26:49 -04:00
|
|
|
|
|
|
|
entries =
|
2017-05-29 10:28:01 -04:00
|
|
|
List.map keyedEntry accountInfo.timeline.entries
|
2017-05-02 02:27:01 -04:00
|
|
|
in
|
2017-05-29 10:28:01 -04:00
|
|
|
case accountInfo.account of
|
|
|
|
Just account ->
|
|
|
|
Keyed.ul [ id accountInfo.timeline.id, class "list-group" ] <|
|
|
|
|
(entries ++ [ ( "load-more", Common.loadMoreBtn accountInfo.timeline ) ])
|
2017-05-02 02:27:01 -04:00
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
Nothing ->
|
|
|
|
text ""
|
2017-05-02 02:27:01 -04:00
|
|
|
|
2017-05-29 10:28:01 -04:00
|
|
|
|
|
|
|
counterLink : String -> String -> Int -> Bool -> Html Msg
|
|
|
|
counterLink href_ label count active =
|
|
|
|
a
|
|
|
|
[ href href_
|
|
|
|
, class <|
|
|
|
|
"col-md-4"
|
|
|
|
++ (if active then
|
|
|
|
" active"
|
|
|
|
else
|
|
|
|
""
|
|
|
|
)
|
|
|
|
]
|
|
|
|
[ text label
|
|
|
|
, br [] []
|
|
|
|
, text <| toString count
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
counterLinks : CurrentAccountView -> Account -> Html Msg
|
|
|
|
counterLinks subView account =
|
2017-05-02 02:27:01 -04:00
|
|
|
let
|
|
|
|
{ statuses_count, following_count, followers_count } =
|
|
|
|
account
|
|
|
|
in
|
2017-05-29 10:28:01 -04:00
|
|
|
div [ class "row account-infos" ]
|
|
|
|
[ counterLink
|
2017-11-29 08:06:08 -05:00
|
|
|
("#account/" ++ account.id)
|
2017-05-29 10:28:01 -04:00
|
|
|
"Statuses"
|
|
|
|
statuses_count
|
|
|
|
(subView == AccountStatusesView)
|
|
|
|
, counterLink
|
2017-11-29 08:06:08 -05:00
|
|
|
("#account/" ++ account.id ++ "/following")
|
2017-05-29 10:28:01 -04:00
|
|
|
"Following"
|
|
|
|
following_count
|
|
|
|
(subView == AccountFollowingView)
|
|
|
|
, counterLink
|
2017-11-29 08:06:08 -05:00
|
|
|
("#account/" ++ account.id ++ "/followers")
|
2017-05-29 10:28:01 -04:00
|
|
|
"Followers"
|
|
|
|
followers_count
|
|
|
|
(subView == AccountFollowersView)
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
accountView : CurrentAccountView -> CurrentUser -> AccountInfo -> Html Msg
|
|
|
|
accountView subView currentUser accountInfo =
|
|
|
|
case accountInfo.account of
|
|
|
|
Nothing ->
|
|
|
|
text ""
|
|
|
|
|
|
|
|
Just account ->
|
|
|
|
div [ class "col-md-3 column" ]
|
|
|
|
[ div [ class "panel panel-default" ]
|
|
|
|
[ Common.closeablePanelheading "account" "user" "Account"
|
|
|
|
, div [ id "account", class "timeline" ]
|
|
|
|
[ div
|
|
|
|
[ class "account-detail"
|
2021-01-10 16:35:14 -05:00
|
|
|
, style [ ( "background-image", "url('" ++ account.header ++ "')" ),
|
|
|
|
( "background-position", "center" ),
|
|
|
|
( "background-size", "cover" ) ]
|
2017-05-29 10:28:01 -04:00
|
|
|
]
|
|
|
|
[ div [ class "opacity-layer" ]
|
|
|
|
[ followButton currentUser accountInfo.relationship account
|
|
|
|
, muteButton currentUser accountInfo.relationship account
|
|
|
|
, blockButton currentUser accountInfo.relationship account
|
|
|
|
, Common.accountAvatarLink True account
|
2021-01-10 14:23:49 -05:00
|
|
|
, span [ class "account-display-name" ] [ text (if account.display_name=="" then account.username else account.display_name) ]
|
2017-05-29 10:28:01 -04:00
|
|
|
, span [ class "account-username" ]
|
|
|
|
[ Common.accountLink True account
|
|
|
|
, case accountInfo.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 [])
|
2017-05-05 18:06:32 -04:00
|
|
|
]
|
2017-05-02 02:27:01 -04:00
|
|
|
]
|
2017-05-29 10:28:01 -04:00
|
|
|
, counterLinks subView account
|
|
|
|
, case subView of
|
|
|
|
AccountStatusesView ->
|
|
|
|
accountTimelineView currentUser accountInfo
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
accountFollowView subView currentUser accountInfo
|
2017-05-02 02:27:01 -04:00
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|