diff --git a/src/Mastodon/Decoder.elm b/src/Mastodon/Decoder.elm index e84142b..edd2431 100644 --- a/src/Mastodon/Decoder.elm +++ b/src/Mastodon/Decoder.elm @@ -329,6 +329,7 @@ statusDecoder = , voted = False , options = [] } + |> Pipe.optional "emojis" (Decode.list emojiDecoder) [] |> Pipe.optional "pinned" Decode.bool False -- Not a real value, used to show pinned indicator diff --git a/src/Mastodon/Model.elm b/src/Mastodon/Model.elm index 29f6e14..f53a08d 100644 --- a/src/Mastodon/Model.elm +++ b/src/Mastodon/Model.elm @@ -314,6 +314,7 @@ type alias Status = , visibility : String , pleroma : Maybe Pleroma , poll : Poll + , emojis : List Emoji , pinned : Bool -- Not a real value, used to show pinned indicator } diff --git a/src/View/Account.elm b/src/View/Account.elm index b51c94c..8de07e5 100644 --- a/src/View/Account.elm +++ b/src/View/Account.elm @@ -50,7 +50,7 @@ movedIndicator account = , span [ class "acct" ] [ text <| "@" ++ account.moved.acct ] ] , div [ class "status-text" ] - ( formatContent account.moved.note [] ) + ( formatContent account.moved.note [] [] ) ] ] ] @@ -314,7 +314,7 @@ makeField field = [ dt [ title field.name ] [ text field.name ] , dd [ title (textContent field.value) , class dd_class ] - (checkmark :: (formatContent field.value [])) + (checkmark :: (formatContent field.value [] [])) ] fields : CurrentAccountView -> Account -> Html Msg @@ -396,7 +396,7 @@ accountView subView currentUser accountInfo = else text "" ] - , span [ class "account-note" ] (formatContent account.note []) + , span [ class "account-note" ] (formatContent account.note [] []) ] ] , fields subView account diff --git a/src/View/Draft.elm b/src/View/Draft.elm index 5e4995e..669dd5b 100644 --- a/src/View/Draft.elm +++ b/src/View/Draft.elm @@ -85,7 +85,7 @@ currentUserView currentUser = , text ")" ] ] - , p [ class "status-text" ] <| formatContent currentUser.note [] + , p [ class "status-text" ] <| formatContent currentUser.note [] [] ] Nothing -> diff --git a/src/View/Formatter.elm b/src/View/Formatter.elm index 70603cd..d7b090e 100644 --- a/src/View/Formatter.elm +++ b/src/View/Formatter.elm @@ -13,14 +13,14 @@ import Types exposing (..) import View.Events exposing (..) -formatContent : String -> List Mention -> List (Html Msg) -formatContent content mentions = +formatContent : String -> List Mention -> List Emoji -> List (Html Msg) +formatContent content mentions emojis = content |> replace " ?" " ?" |> replace " !" " !" |> replace " :" " :" |> HtmlParser.parse - |> toVirtualDom mentions + |> toVirtualDom mentions emojis textContent : String -> String @@ -30,9 +30,9 @@ textContent html = {-| Converts nodes to virtual dom nodes. -} -toVirtualDom : List Mention -> List HtmlParser.Node -> List (Html Msg) -toVirtualDom mentions nodes = - List.map (toVirtualDomEach mentions) nodes +toVirtualDom : List Mention -> List Emoji-> List HtmlParser.Node -> List (Html Msg) +toVirtualDom mentions emojis nodes = + List.map (toVirtualDomEach mentions emojis) nodes replaceHref : String -> List ( String, String ) -> List (Attribute Msg) @@ -48,21 +48,21 @@ createLinkNode attrs children mentions = Just mention -> Html.node "a" (replaceHref ("#account/" ++ mention.id) attrs) - (toVirtualDom mentions children) + (toVirtualDom mentions [] children) Nothing -> case getHashtagForLink attrs of Just hashtag -> Html.node "a" (replaceHref ("#hashtag/" ++ hashtag) attrs) - (toVirtualDom mentions children) + (toVirtualDom mentions [] children) Nothing -> Html.node "a" ((List.map toAttribute attrs) ++ [ onClickWithStop NoOp, target "_blank" ] ) - (toVirtualDom mentions children) + (toVirtualDom mentions [] children) getHrefLink : List ( String, String ) -> Maybe String @@ -103,22 +103,27 @@ getMentionForLink attrs mentions = Nothing -toVirtualDomEach : List Mention -> HtmlParser.Node -> Html Msg -toVirtualDomEach mentions node = +toVirtualDomEach : List Mention -> List Emoji -> HtmlParser.Node -> Html Msg +toVirtualDomEach mentions emoji node = case node of HtmlParser.Element "a" attrs children -> createLinkNode attrs children mentions HtmlParser.Element name attrs children -> - Html.node name (List.map toAttribute attrs) (toVirtualDom mentions children) + Html.node name (List.map toAttribute attrs) (toVirtualDom mentions emoji children) HtmlParser.Text s -> - Elmoji.text_ s + handleEmoji s emoji HtmlParser.Comment _ -> text "" +handleEmoji : String -> List Emoji -> Html Msg +handleEmoji s emoji = + Elmoji.text_ s -- todo + + toAttribute : ( String, String ) -> Attribute msg toAttribute ( name, value ) = attribute name value diff --git a/src/View/NewFile b/src/View/NewFile new file mode 100644 index 0000000..e69de29 diff --git a/src/View/Notification.elm b/src/View/Notification.elm index 94fbbf6..eae15e4 100644 --- a/src/View/Notification.elm +++ b/src/View/Notification.elm @@ -116,7 +116,7 @@ notificationFollowView currentUser { type_, accounts } = , span [ class "btn-sm follow-profile-date" ] [ Common.icon "time", text <| Common.formatDate created_at ] ] - , formatContent account.note [] + , formatContent account.note [] [] |> div [ class "status-text" , onClick <| Navigate ("#account/" ++ account.id) diff --git a/src/View/Search.elm b/src/View/Search.elm index 4fd8b6a..36341ac 100644 --- a/src/View/Search.elm +++ b/src/View/Search.elm @@ -17,7 +17,7 @@ accountListView accounts = li [ class "list-group-item status follow-profile" ] [ Common.accountAvatarLink False account , div [ class "username" ] [ Common.accountLinkLarge False account ] - , formatContent account.note [] + , formatContent account.note [] [] |> div [ class "status-text" , onClick <| Navigate ("#account/" ++ account.id) diff --git a/src/View/Status.elm b/src/View/Status.elm index fc1073a..8f259d1 100644 --- a/src/View/Status.elm +++ b/src/View/Status.elm @@ -250,7 +250,7 @@ statusContentView context status = "" -> div [ class "status-text" ] [ mentionsView status.mentions - , div [] <| formatContent status.content status.mentions + , div [] <| formatContent status.content status.mentions status.emojis , pollView status , attachmentListView context status , quoteView status @@ -263,13 +263,12 @@ statusContentView context status = "spoiler" ++ extractStatusId status.id ++ context in div [ class "status-text spoiled" ] - [ div [ class "spoiler" ] - [ text status.spoiler_text ] + [ div [ class "spoiler" ] <| formatContent status.spoiler_text status.mentions status.emojis , input [ onClickWithStop NoOp, type_ "checkbox", id statusId, class "spoiler-toggler" ] [] , label [ onClickWithStop NoOp, for statusId ] [ text "Reveal content" ] , div [ class "spoiled-content" ] [ mentionsView status.mentions - , div [] <| formatContent status.content status.mentions + , div [] <| formatContent status.content status.mentions status.emojis , pollView status , attachmentListView context status , quoteView status