From e708f7197a88410dfc76eb1e0054817ac6665cac Mon Sep 17 00:00:00 2001 From: Ryan Fox Date: Sat, 16 Jan 2021 04:53:12 +0000 Subject: [PATCH] Add moved account indicator --- public/style.css | 8 +++++++ src/Mastodon/Decoder.elm | 28 +++++++++++++++++++++++ src/Mastodon/Model.elm | 17 ++++++++++++++ src/View/Account.elm | 49 ++++++++++++++++++++++++++++++++++++++-- 4 files changed, 100 insertions(+), 2 deletions(-) diff --git a/public/style.css b/public/style.css index 5a34f2a..7f15b78 100644 --- a/public/style.css +++ b/public/style.css @@ -667,6 +667,14 @@ input.form-control[type=file] { } /* Account rules */ +.account-notice { + padding: 8px 12px; +} + +.inactive .account-detail, .inactive account-fields, .inactive .account-infos { + opacity: 0.5; +} + .account-detail { position: relative; text-align: center; diff --git a/src/Mastodon/Decoder.elm b/src/Mastodon/Decoder.elm index cfeb401..53e82d0 100644 --- a/src/Mastodon/Decoder.elm +++ b/src/Mastodon/Decoder.elm @@ -3,6 +3,7 @@ module Mastodon.Decoder ( appRegistrationDecoder , accessTokenDecoder , accountDecoder + , accountMovedDecoder , attachmentDecoder , contextDecoder , decodeWebSocketMessage @@ -104,6 +105,33 @@ accountDecoder = } |> Pipe.optional "emojis" (Decode.list emojiDecoder) [] |> Pipe.optional "fields" (Decode.list fieldDecoder) [] + |> Pipe.optional "moved" accountMovedDecoder + { acct = "" + , avatar = "" + , display_name = "" + , header = "" + , id = "" + , locked = False + , bot = False + , username = "" + , url = "" + , note = "" + } + + +accountMovedDecoder : Decode.Decoder AccountMoved +accountMovedDecoder = + Pipe.decode AccountMoved + |> Pipe.required "acct" Decode.string + |> Pipe.optional "avatar" Decode.string "" + |> Pipe.optional "display_name" Decode.string "" + |> Pipe.optional "header" Decode.string "" + |> Pipe.required "id" idDecoder + |> Pipe.optional "locked" Decode.bool False + |> Pipe.optional "bot" Decode.bool False + |> Pipe.required "username" Decode.string + |> Pipe.required "url" Decode.string + |> Pipe.optional "note" Decode.string "" applicationDecoder : Decode.Decoder Application diff --git a/src/Mastodon/Model.elm b/src/Mastodon/Model.elm index dd1c519..69ca275 100644 --- a/src/Mastodon/Model.elm +++ b/src/Mastodon/Model.elm @@ -3,6 +3,7 @@ module Mastodon.Model ( AccessTokenResult , AppRegistration , Account + , AccountMoved , AccountNotificationDate , Application , Attachment @@ -122,6 +123,22 @@ type alias Account = , source : Source , emojis : List Emoji , fields : List Field + , moved : AccountMoved + } + + +type alias AccountMoved = + -- Minimal account to avoid recursive type alias + { acct : String + , avatar : String + , display_name : String + , header : String + , id : AccountId + , locked : Bool + , bot : Bool + , username : String + , url : String + , note : String } diff --git a/src/View/Account.elm b/src/View/Account.elm index c2df6c0..0944834 100644 --- a/src/View/Account.elm +++ b/src/View/Account.elm @@ -22,6 +22,42 @@ type alias CurrentUserRelation = Maybe Relationship +movedIndicator : Account -> Html Msg +movedIndicator account = + let + displayName account = + if account.display_name == "" then + account.username + else + account.display_name + in + if account.moved.id /= "" then + div [ class "account-notice" ] + [ p [] + [ Common.icon "briefcase" + , text <| " " ++ displayName account + , text " has moved to:" + ] + , div [ class "status" ] + [ a + [ href + <| "#account/" ++ account.moved.id + ] + [ img [ class "avatar", src account.moved.avatar ] [] + , div [ class "username" ] + [ text <| displayName account.moved + , br [] [] + , span [ class "acct" ] [ text <| "@" ++ account.moved.acct ] + ] + , div [ class "status-text" ] + ( formatContent account.moved.note [] ) + ] + ] + ] + else + text "" + + followButton : CurrentUser -> CurrentUserRelation -> Account -> Html Msg followButton currentUser relationship account = if Mastodon.Helper.sameAccount account currentUser then @@ -290,8 +326,17 @@ accountView subView currentUser accountInfo = div [ class "col-md-3 column" ] [ div [ class "panel panel-default" ] [ Common.closeablePanelheading "account" "user" "Account" - , div [ id "account", class "timeline" ] - [ div + , div + [ id "account" + , class + <| "timeline" ++ + if account.moved.id /= "" then + " inactive" + else + "" + ] + [ movedIndicator account + , div [ class "account-detail" , style [ ( "background-image", "url('" ++ account.header ++ "')" ), ( "background-position", "center" ),