1
0
Fork 0

Prepare for emoji support

This commit is contained in:
Ryan Fox 2022-03-26 23:07:04 -07:00
parent b30c66356a
commit 51b1fa2b17
Signed by: flewkey
GPG Key ID: 94F56ADFD848851E
9 changed files with 29 additions and 23 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -85,7 +85,7 @@ currentUserView currentUser =
, text ")"
]
]
, p [ class "status-text" ] <| formatContent currentUser.note []
, p [ class "status-text" ] <| formatContent currentUser.note [] []
]
Nothing ->

View File

@ -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 " ?" "&#160;?"
|> replace " !" "&#160;!"
|> replace " :" "&#160;:"
|> 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

0
src/View/NewFile Normal file
View File

View File

@ -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)

View File

@ -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)

View File

@ -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