diff --git a/public/style.css b/public/style.css index c137545..af4a60b 100644 --- a/public/style.css +++ b/public/style.css @@ -120,6 +120,10 @@ li.load-more { background: #493438; } +span.applink { + cursor: default; +} + .reblog > p:first-of-type, .notification > p:first-of-type { color: #999; diff --git a/src/Mastodon/Decoder.elm b/src/Mastodon/Decoder.elm index 93a54ec..1cfbcfe 100644 --- a/src/Mastodon/Decoder.elm +++ b/src/Mastodon/Decoder.elm @@ -59,6 +59,13 @@ accountDecoder = |> Pipe.required "username" Decode.string +applicationDecoder : Decode.Decoder Application +applicationDecoder = + Pipe.decode Application + |> Pipe.required "name" Decode.string + |> Pipe.required "website" (Decode.nullable Decode.string) + + attachmentDecoder : Decode.Decoder Attachment attachmentDecoder = Pipe.decode Attachment @@ -128,6 +135,7 @@ statusDecoder : Decode.Decoder Status statusDecoder = Pipe.decode Status |> Pipe.required "account" accountDecoder + |> Pipe.required "application" (Decode.nullable applicationDecoder) |> Pipe.required "content" Decode.string |> Pipe.required "created_at" Decode.string |> Pipe.optional "favourited" (Decode.nullable Decode.bool) Nothing diff --git a/src/Mastodon/Model.elm b/src/Mastodon/Model.elm index 5775177..deeab9d 100644 --- a/src/Mastodon/Model.elm +++ b/src/Mastodon/Model.elm @@ -3,6 +3,7 @@ module Mastodon.Model ( AccessTokenResult , AppRegistration , Account + , Application , Attachment , Client , Context @@ -90,6 +91,12 @@ type alias Account = } +type alias Application = + { name : String + , website : Maybe String + } + + type alias Attachment = -- type_: -- "image", "video", "gifv" { id : Int @@ -163,6 +170,7 @@ type alias Relationship = type alias Status = { account : Account + , application : Maybe Application , content : String , created_at : String , favourited : Maybe Bool diff --git a/src/View/Common.elm b/src/View/Common.elm index 37a13e3..f79c35e 100644 --- a/src/View/Common.elm +++ b/src/View/Common.elm @@ -3,6 +3,7 @@ module View.Common ( accountAvatar , accountAvatarLink , accountLink + , appLink , closeablePanelheading , icon , justifiedButtonGroup @@ -63,6 +64,21 @@ accountAvatarLink external account = [ accountAvatar avatarClass account ] +appLink : String -> Maybe Application -> Html Msg +appLink classes app = + case app of + Nothing -> + text "" + + Just { name, website } -> + case website of + Nothing -> + span [ class classes ] [ text name ] + + Just website -> + a [ href website, target "_blank", class classes ] [ text name ] + + closeablePanelheading : String -> String -> String -> Msg -> Html Msg closeablePanelheading context iconName label onClose = div [ class "panel-heading" ] diff --git a/src/View/Notification.elm b/src/View/Notification.elm index a8c5304..8216614 100644 --- a/src/View/Notification.elm +++ b/src/View/Notification.elm @@ -99,7 +99,7 @@ notificationStatusView ( context, currentUser, status, { type_, accounts } ) = _ -> text "" , Lazy.lazy2 statusView context status - , Lazy.lazy2 statusActionsView status currentUser + , Lazy.lazy3 statusActionsView status currentUser False ] diff --git a/src/View/Status.elm b/src/View/Status.elm index d9525e4..92fdab4 100644 --- a/src/View/Status.elm +++ b/src/View/Status.elm @@ -84,8 +84,8 @@ attachmentListView context { media_attachments, sensitive } = List.map (keyedEntry attachments) attachments -statusActionsView : Status -> CurrentUser -> Html Msg -statusActionsView status currentUser = +statusActionsView : Status -> CurrentUser -> Bool -> Html Msg +statusActionsView status currentUser showApp = let sourceStatus = Mastodon.Helper.extractReblog status @@ -119,8 +119,7 @@ statusActionsView status currentUser = div [ class "btn-group actions" ] [ a [ class baseBtnClasses - , onClickWithPreventAndStop <| - DraftEvent (UpdateReplyTo status) + , onClickWithPreventAndStop <| DraftEvent (UpdateReplyTo status) ] [ Common.icon "share-alt" ] , if status.visibility == "private" then @@ -131,20 +130,17 @@ statusActionsView status currentUser = [ span [ title "Direct" ] [ Common.icon "envelope" ] ] else a - [ class reblogClasses - , onClickWithPreventAndStop reblogEvent - ] + [ class reblogClasses, onClickWithPreventAndStop reblogEvent ] [ Common.icon "fire", text (toString sourceStatus.reblogs_count) ] , a - [ class favClasses - , onClickWithPreventAndStop favEvent - ] + [ class favClasses, onClickWithPreventAndStop favEvent ] [ Common.icon "star", text (toString sourceStatus.favourites_count) ] , if Mastodon.Helper.sameAccount sourceStatus.account currentUser then a [ class <| baseBtnClasses ++ " btn-delete" , href "" - , onClickWithPreventAndStop <| AskConfirm "Are you sure you want to delete this toot?" (DeleteStatus sourceStatus.id) NoOp + , onClickWithPreventAndStop <| + AskConfirm "Are you sure you want to delete this toot?" (DeleteStatus sourceStatus.id) NoOp ] [ Common.icon "trash" ] else @@ -152,6 +148,10 @@ statusActionsView status currentUser = , a [ class baseBtnClasses, href (Maybe.withDefault "#" status.url), target "_blank" ] [ Common.icon "time", formatDate ] + , if showApp then + Common.appLink (baseBtnClasses ++ " applink") status.application + else + text "" ] @@ -205,7 +205,7 @@ statusEntryView context className currentUser status = in li liAttributes [ Lazy.lazy2 statusView context status - , Lazy.lazy2 statusActionsView status currentUser + , Lazy.lazy3 statusActionsView status currentUser (className == "thread-target") ]