Skip to content

Commit

Permalink
Manage null preview_url
Browse files Browse the repository at this point in the history
In attachmements, the preview_url can be null when the attachment type
is audio.
  • Loading branch information
vjousse committed Dec 18, 2023
1 parent f106f9e commit c4c4e16
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/Mastodon/Decoder.elm
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ attachmentDecoder =
|> Pipe.required "type" Decode.string
|> Pipe.required "url" Decode.string
|> Pipe.optional "remote_url" Decode.string ""
|> Pipe.required "preview_url" Decode.string
|> Pipe.required "preview_url" (Decode.nullable Decode.string)
|> Pipe.required "text_url" (Decode.nullable Decode.string)
|> Pipe.required "description" (Decode.nullable Decode.string)

Expand Down
2 changes: 1 addition & 1 deletion src/Mastodon/Model.elm
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ type alias Attachment =
, type_ : String
, url : String
, remote_url : String
, preview_url : String
, preview_url : Maybe String
, text_url : Maybe String
, description : Maybe String
}
Expand Down
4 changes: 3 additions & 1 deletion src/View/Draft.elm
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,9 @@ draftAttachments attachments =
attachmentPreview attachment =
li
[ class "draft-attachment-entry"
, style "background" ("url(" ++ attachment.preview_url ++ ") center center / cover no-repeat")

--@TODO: manage other attachment types like audio. For the audio type, the preview_url can be null
, style "background" ("url(" ++ Maybe.withDefault "" attachment.preview_url ++ ") center center / cover no-repeat")
]
[ a
[ href ""
Expand Down
76 changes: 41 additions & 35 deletions src/View/Status.elm
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,50 @@ type alias CurrentUser =

attachmentPreview : String -> Maybe Bool -> List Attachment -> Attachment -> Html Msg
attachmentPreview context sensitive attachments ({ url, preview_url } as attachment) =
let
attId =
"att" ++ attachment.id ++ context
--@TODO: manage other attachment types like audio
case preview_url of
Just p_url ->
let
attId =
"att" ++ attachment.id ++ context

media =
a
[ href url
]
[ img
[ class "attachment-image"
, src preview_url
, alt <|
case attachment.description of
Just description ->
description

Nothing ->
""
, onClickWithPreventAndStop <|
ViewerEvent (OpenViewer attachments attachment)
media =
a
[ href url
]
[ img
[ class "attachment-image"
, src <| p_url
, alt <|
case attachment.description of
Just description ->
description

Nothing ->
""
, onClickWithPreventAndStop <|
ViewerEvent (OpenViewer attachments attachment)
]
[]
]
in
li [ class "attachment-entry" ] <|
if Maybe.withDefault False sensitive then
[ input [ type_ "radio", id attId ] []
, label [ for attId ]
[ text "Sensitive content"
, br [] []
, br [] []
, text "click to show image"
]
, media
]
[]
]
in
li [ class "attachment-entry" ] <|
if Maybe.withDefault False sensitive then
[ input [ type_ "radio", id attId ] []
, label [ for attId ]
[ text "Sensitive content"
, br [] []
, br [] []
, text "click to show image"
]
, media
]

else
[ media ]
else
[ media ]

Nothing ->
em [] [ text <| "Attachement type " ++ attachment.type_ ++ " not implemented." ]


attachmentListView : String -> Status -> Html Msg
Expand Down

0 comments on commit c4c4e16

Please sign in to comment.