Add support for m.notice and m.emote

This commit is contained in:
Danila Fedorin 2019-09-08 15:00:52 -07:00
parent 266c421223
commit 911e46c4c3
2 changed files with 36 additions and 14 deletions

View File

@ -238,42 +238,60 @@ userMessagesView ud apiUrl (u, ms) =
in in
tr [] tr []
[ td [] [ senderView ud u ] [ td [] [ senderView ud u ]
, td [] <| List.map wrap <| List.filterMap (messageView apiUrl) ms , td [] <| List.map wrap <| List.filterMap (messageView ud apiUrl) ms
] ]
messageView : ApiUrl -> Message -> Maybe (Html Msg) messageView : Dict String UserData -> ApiUrl -> Message -> Maybe (Html Msg)
messageView apiUrl msg = case msg of messageView ud apiUrl msg = case msg of
Sending t -> Just <| sendingMessageView t Sending t -> Just <| sendingMessageView t
Received re -> roomEventView apiUrl re Received re -> roomEventView ud apiUrl re
sendingMessageView : SendingMessage -> Html Msg sendingMessageView : SendingMessage -> Html Msg
sendingMessageView msg = case msg.body of sendingMessageView msg = case msg.body of
TextMessage t -> span [ class "sending"] [ text t ] TextMessage t -> span [ class "sending"] [ text t ]
roomEventView : ApiUrl -> RoomEvent -> Maybe (Html Msg) roomEventView : Dict String UserData -> ApiUrl -> RoomEvent -> Maybe (Html Msg)
roomEventView apiUrl re = roomEventView ud apiUrl re =
let let
msgtype = Decode.decodeValue (Decode.field "msgtype" Decode.string) re.content msgtype = Decode.decodeValue (Decode.field "msgtype" Decode.string) re.content
in in
case msgtype of case msgtype of
Ok "m.text" -> roomEventTextView re Ok "m.text" -> roomEventTextView re
Ok "m.notice" -> roomEventNoticeView re
Ok "m.emote" -> roomEventEmoteView ud re
Ok "m.image" -> roomEventImageView apiUrl re Ok "m.image" -> roomEventImageView apiUrl re
Ok "m.file" -> roomEventFileView apiUrl re Ok "m.file" -> roomEventFileView apiUrl re
Ok "m.video" -> roomEventVideoView apiUrl re Ok "m.video" -> roomEventVideoView apiUrl re
_ -> Nothing _ -> Nothing
roomEventTextView : RoomEvent -> Maybe (Html Msg) roomEventFormattedContent : RoomEvent -> Maybe (List (Html Msg))
roomEventTextView re = roomEventFormattedContent re = Maybe.map Html.Parser.Util.toVirtualDom
let
body = Decode.decodeValue (Decode.field "body" Decode.string) re.content
customHtml = Maybe.map Html.Parser.Util.toVirtualDom
<| Maybe.andThen (Result.toMaybe << Html.Parser.run ) <| Maybe.andThen (Result.toMaybe << Html.Parser.run )
<| Result.toMaybe <| Result.toMaybe
<| Decode.decodeValue (Decode.field "formatted_body" Decode.string) re.content <| Decode.decodeValue (Decode.field "formatted_body" Decode.string) re.content
roomEventContent : (List (Html Msg) -> Html Msg) -> RoomEvent -> Maybe (Html Msg)
roomEventContent f re =
let
body = Decode.decodeValue (Decode.field "body" Decode.string) re.content
customHtml = roomEventFormattedContent re
in in
case customHtml of case customHtml of
Just c -> Just <| div [] c Just c -> Just <| f c
Nothing -> Maybe.map (p [] << List.singleton << text) <| Result.toMaybe body Nothing -> Maybe.map (f << List.singleton << text) <| Result.toMaybe body
roomEventEmoteView : Dict String UserData -> RoomEvent -> Maybe (Html Msg)
roomEventEmoteView ud re =
let
emoteText = "* " ++ displayName ud re.sender ++ " "
in
roomEventContent (\cs -> span [] (text emoteText :: cs)) re
roomEventNoticeView : RoomEvent -> Maybe (Html Msg)
roomEventNoticeView = roomEventContent (span [ class "message-notice" ])
roomEventTextView : RoomEvent -> Maybe (Html Msg)
roomEventTextView = roomEventContent (span [])
roomEventImageView : ApiUrl -> RoomEvent -> Maybe (Html Msg) roomEventImageView : ApiUrl -> RoomEvent -> Maybe (Html Msg)
roomEventImageView apiUrl re = roomEventImageView apiUrl re =

View File

@ -333,6 +333,10 @@ a.file-wrapper {
} }
} }
.message-notice {
text-transform: uppercase;
}
/** /**
* Icons * Icons