1
0
Fork 0

Show pinned statuses

This commit is contained in:
Ryan Fox 2021-01-12 06:08:43 +00:00
parent 487adc9d1f
commit 2f227355b8
Signed by: flewkey
GPG Key ID: 94F56ADFD848851E
9 changed files with 58 additions and 7 deletions

View File

@ -10,6 +10,7 @@ module Command
, loadAccount , loadAccount
, loadAccountFollowers , loadAccountFollowers
, loadAccountFollowing , loadAccountFollowing
, loadAccountPins
, loadHomeTimeline , loadHomeTimeline
, loadLocalTimeline , loadLocalTimeline
, loadGlobalTimeline , loadGlobalTimeline
@ -186,6 +187,20 @@ loadAccount client accountId =
Cmd.none Cmd.none
loadAccountPins : Maybe Client -> String -> Maybe String -> Cmd Msg
loadAccountPins client accountId url =
case client of
Just client ->
HttpBuilder.get (Maybe.withDefault (ApiUrl.accountTimeline accountId) url)
|> withClient client
|> withBodyDecoder (Decode.list statusDecoder)
|> withQueryParams [ ( "pinned", "true" ) ]
|> send (MastodonEvent << AccountPins (url /= Nothing))
Nothing ->
Cmd.none
loadAccountFollowers : Maybe Client -> String -> Maybe String -> Cmd Msg loadAccountFollowers : Maybe Client -> String -> Maybe String -> Cmd Msg
loadAccountFollowers client accountId url = loadAccountFollowers client accountId url =
case client of case client of

View File

@ -253,6 +253,7 @@ statusDecoder =
|> Pipe.required "uri" Decode.string |> Pipe.required "uri" Decode.string
|> Pipe.required "url" (Decode.nullable Decode.string) |> Pipe.required "url" (Decode.nullable Decode.string)
|> Pipe.required "visibility" Decode.string |> Pipe.required "visibility" Decode.string
|> Pipe.optional "pinned" Decode.bool False -- Not a real value, used to show pinned indicator
webSocketEventDecoder : Decode.Decoder WebSocketMessage webSocketEventDecoder : Decode.Decoder WebSocketMessage

View File

@ -260,6 +260,7 @@ type alias Status =
, uri : String , uri : String
, url : Maybe String , url : Maybe String
, visibility : String , visibility : String
, pinned : Bool -- Not a real value, used to show pinned indicator
} }

View File

@ -50,6 +50,7 @@ type MastodonMsg
| AccountFollowing Bool (MastodonResult (List Account)) | AccountFollowing Bool (MastodonResult (List Account))
| AccountBlocked Account (MastodonResult Relationship) | AccountBlocked Account (MastodonResult Relationship)
| AccountMuted Account (MastodonResult Relationship) | AccountMuted Account (MastodonResult Relationship)
| AccountPins Bool (MastodonResult (List Status))
| AccountReceived (MastodonResult Account) | AccountReceived (MastodonResult Account)
| AccountRelationship (MastodonResult (List Relationship)) | AccountRelationship (MastodonResult (List Relationship))
| AccountRelationships (MastodonResult (List Relationship)) | AccountRelationships (MastodonResult (List Relationship))
@ -135,6 +136,7 @@ type Msg
type alias AccountInfo = type alias AccountInfo =
{ account : Maybe Account { account : Maybe Account
, pins : List Status
, timeline : Timeline Status , timeline : Timeline Status
, followers : Timeline Account , followers : Timeline Account
, following : Timeline Account , following : Timeline Account

View File

@ -7,6 +7,7 @@ import Update.Timeline
empty : AccountInfo empty : AccountInfo
empty = empty =
{ account = Nothing { account = Nothing
, pins = []
, timeline = Update.Timeline.empty "account-timeline" , timeline = Update.Timeline.empty "account-timeline"
, followers = Update.Timeline.empty "account-followers" , followers = Update.Timeline.empty "account-followers"
, following = Update.Timeline.empty "account-following" , following = Update.Timeline.empty "account-following"

View File

@ -275,6 +275,20 @@ update msg ({ accountInfo, search } as model) =
Err error -> Err error ->
{ model | errors = addErrorNotification (errorText error) model } ! [] { model | errors = addErrorNotification (errorText error) model } ! []
AccountPins append result ->
case result of
Ok { decoded, links } ->
{ model
| accountInfo =
{ accountInfo
| pins = decoded
}
}
! []
Err error ->
{ model | errors = addErrorNotification (errorText error) model } ! []
AccountTimeline append result -> AccountTimeline append result ->
case result of case result of
Ok { decoded, links } -> Ok { decoded, links } ->

View File

@ -96,6 +96,7 @@ update ({ accountInfo } as model) =
, accountInfo = Update.AccountInfo.empty , accountInfo = Update.AccountInfo.empty
} }
! [ Command.loadAccount (List.head model.clients) accountId ! [ Command.loadAccount (List.head model.clients) accountId
, Command.loadAccountPins (List.head model.clients) accountId Nothing
, Command.loadAccountTimeline (List.head model.clients) accountId Nothing , Command.loadAccountTimeline (List.head model.clients) accountId Nothing
] ]

View File

@ -175,8 +175,8 @@ accountFollowView view currentUser accountInfo =
text "" text ""
accountTimelineView : CurrentUser -> AccountInfo -> Html Msg accountTimelineView : CurrentUser -> AccountInfo -> Bool -> Html Msg
accountTimelineView currentUser accountInfo = accountTimelineView currentUser accountInfo pins =
let let
keyedEntry status = keyedEntry status =
( extractStatusId status.id ( extractStatusId status.id
@ -185,11 +185,17 @@ accountTimelineView currentUser accountInfo =
entries = entries =
List.map keyedEntry accountInfo.timeline.entries List.map keyedEntry accountInfo.timeline.entries
setPin status =
{ status | pinned = True }
pins =
List.map keyedEntry (List.map setPin accountInfo.pins)
in in
case accountInfo.account of case accountInfo.account of
Just account -> Just account ->
Keyed.ul [ id accountInfo.timeline.id, class "list-group" ] <| Keyed.ul [ id accountInfo.timeline.id, class "list-group" ] <|
(entries ++ [ ( "load-more", Common.loadMoreBtn accountInfo.timeline ) ]) List.append pins (entries ++ [ ( "load-more", Common.loadMoreBtn accountInfo.timeline ) ])
Nothing -> Nothing ->
text "" text ""
@ -341,10 +347,10 @@ accountView subView currentUser accountInfo =
, counterLinks subView account , counterLinks subView account
, case subView of , case subView of
AccountStatusesView -> AccountStatusesView ->
accountTimelineView currentUser accountInfo accountTimelineView currentUser accountInfo True
AccountStatusesRepliesView -> AccountStatusesRepliesView ->
accountTimelineView currentUser accountInfo accountTimelineView currentUser accountInfo False
_ -> _ ->
accountFollowView subView currentUser accountInfo accountFollowView subView currentUser accountInfo

View File

@ -205,10 +205,19 @@ statusEntryView context className currentUser status =
statusView : String -> Status -> Html Msg statusView : String -> Status -> Html Msg
statusView context ({ account, content, media_attachments, reblog, mentions } as status) = statusView context ({ account, content, media_attachments, reblog, mentions, pinned } as status) =
let let
accountLinkAttributes = accountLinkAttributes =
[ href <| "#account/" ++ account.id ] [ href <| "#account/" ++ account.id ]
pin =
if pinned then
p [ class "status-info" ]
[ Common.icon "pushpin"
, text " Pinned status"
]
else
text ""
in in
case reblog of case reblog of
Just (Reblog reblog) -> Just (Reblog reblog) ->
@ -224,7 +233,8 @@ statusView context ({ account, content, media_attachments, reblog, mentions } as
Nothing -> Nothing ->
div [ class "status" ] div [ class "status" ]
[ Common.accountAvatarLink False account [ pin
, Common.accountAvatarLink False account
, div [ class "username" ] , div [ class "username" ]
[ a accountLinkAttributes [ a accountLinkAttributes
[ text (if account.display_name=="" then account.username else account.display_name) [ text (if account.display_name=="" then account.username else account.display_name)