2017-05-02 02:27:01 -04:00
|
|
|
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 (..)
|
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
|
|
|
|
|
|
|
|
|
|
|
|
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-disabled"
|
|
|
|
, "question-sign"
|
|
|
|
, "Unknown relationship"
|
|
|
|
)
|
|
|
|
|
|
|
|
Just relationship ->
|
|
|
|
if relationship.following then
|
|
|
|
( UnfollowAccount account.id
|
|
|
|
, "btn btn-default btn-primary"
|
|
|
|
, "eye-close"
|
|
|
|
, "Unfollow"
|
|
|
|
)
|
|
|
|
else
|
|
|
|
( FollowAccount account.id
|
|
|
|
, "btn btn-default"
|
|
|
|
, "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
|
|
|
|
[ href account.url
|
|
|
|
, onClickWithPreventAndStop <| LoadAccount account.id
|
|
|
|
]
|
|
|
|
[ text <|
|
|
|
|
if account.display_name /= "" then
|
|
|
|
account.display_name
|
|
|
|
else
|
|
|
|
account.username
|
|
|
|
]
|
|
|
|
]
|
|
|
|
, br [] []
|
|
|
|
, text <| "@" ++ account.acct
|
|
|
|
]
|
|
|
|
, followButton currentUser relationship account
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
accountFollowView :
|
|
|
|
CurrentUser
|
|
|
|
-> List Account
|
|
|
|
-> List Relationship
|
|
|
|
-> CurrentUserRelation
|
|
|
|
-> Account
|
|
|
|
-> Html Msg
|
|
|
|
accountFollowView currentUser accounts 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
|
|
|
|
]
|
|
|
|
)
|
|
|
|
in
|
|
|
|
accountView currentUser account relationship <|
|
|
|
|
Keyed.ul [ class "list-group" ] <|
|
|
|
|
List.map keyedEntry accounts
|
|
|
|
|
|
|
|
|
2017-05-05 17:35:54 -04:00
|
|
|
accountTimelineView : CurrentUser -> Timeline Status -> CurrentUserRelation -> Account -> Html Msg
|
2017-05-05 11:26:49 -04:00
|
|
|
accountTimelineView currentUser timeline relationship account =
|
2017-05-02 02:27:01 -04:00
|
|
|
let
|
|
|
|
keyedEntry status =
|
|
|
|
( toString 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-05 17:35:54 -04:00
|
|
|
List.map keyedEntry timeline.entries
|
2017-05-02 02:27:01 -04:00
|
|
|
in
|
|
|
|
accountView currentUser account relationship <|
|
2017-05-05 11:26:49 -04:00
|
|
|
Keyed.ul [ id timeline.id, class "list-group" ] <|
|
|
|
|
(entries ++ [ ( "load-more", Common.loadMoreBtn timeline ) ])
|
2017-05-02 02:27:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2017-05-03 09:08:10 -04:00
|
|
|
, Common.accountAvatarLink True account
|
2017-05-02 02:27:01 -04:00
|
|
|
, span [ class "account-display-name" ] [ text account.display_name ]
|
2017-05-03 09:08:10 -04:00
|
|
|
, span [ class "account-username" ] [ Common.accountLink True account ]
|
2017-05-02 02:27:01 -04:00
|
|
|
, 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
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|