Compare commits

..

2 Commits

Author SHA1 Message Date
7122d9e567 Put uniqueBy back in sync 2019-09-02 01:50:53 -07:00
207f6ab3be Remove dependency on model in message list 2019-09-02 01:10:28 -07:00
2 changed files with 34 additions and 33 deletions

View File

@ -328,10 +328,10 @@ mergeEvents : List Event -> List Event -> List Event
mergeEvents l1 l2 = l1 ++ l2 mergeEvents l1 l2 = l1 ++ l2
mergeStateEvents : List StateEvent -> List StateEvent -> List StateEvent mergeStateEvents : List StateEvent -> List StateEvent -> List StateEvent
mergeStateEvents l1 l2 = l1 ++ l2 mergeStateEvents l1 l2 = uniqueBy .eventId <| l1 ++ l2
mergeRoomEvents : List RoomEvent -> List RoomEvent -> List RoomEvent mergeRoomEvents : List RoomEvent -> List RoomEvent -> List RoomEvent
mergeRoomEvents l1 l2 = l1 ++ l2 mergeRoomEvents l1 l2 = uniqueBy .eventId <| l1 ++ l2
mergeStrippedStates : List StrippedState -> List StrippedState -> List StrippedState mergeStrippedStates : List StrippedState -> List StrippedState -> List StrippedState
mergeStrippedStates l1 l2 = l1 ++ l2 mergeStrippedStates l1 l2 = l1 ++ l2

View File

@ -6,6 +6,7 @@ import Scylla.Fnv as Fnv
import Scylla.Room exposing (..) import Scylla.Room exposing (..)
import Scylla.Messages exposing (..) import Scylla.Messages exposing (..)
import Scylla.Login exposing (Username) import Scylla.Login exposing (Username)
import Scylla.UserData exposing (UserData)
import Scylla.Http exposing (fullMediaUrl) import Scylla.Http exposing (fullMediaUrl)
import Scylla.Api exposing (ApiUrl) import Scylla.Api exposing (ApiUrl)
import Html.Parser import Html.Parser
@ -159,7 +160,7 @@ loginView m = div [ class "login-wrapper" ]
joinedRoomView : Model -> RoomId -> RoomData -> Html Msg joinedRoomView : Model -> RoomId -> RoomData -> Html Msg
joinedRoomView m roomId rd = joinedRoomView m roomId rd =
let let
renderedMessages = List.map (userMessagesView m) <| mergeMessages m.loginUsername <| extractMessages rd renderedMessages = List.map (userMessagesView m.userData m.apiUrl) <| mergeMessages m.loginUsername <| extractMessages rd
messagesWrapper = messagesWrapperView m roomId renderedMessages messagesWrapper = messagesWrapperView m roomId renderedMessages
typing = List.map (displayName m.userData) <| roomTypingUsers rd.joinedRoom typing = List.map (displayName m.userData) <| roomTypingUsers rd.joinedRoom
typingText = String.join ", " typing typingText = String.join ", " typing
@ -213,43 +214,43 @@ messagesWrapperView m rid es = div [ class "messages-wrapper", id "messages-wrap
, table [ class "messages-table" ] es , table [ class "messages-table" ] es
] ]
senderView : Model -> Username -> Html Msg senderView : Dict String UserData -> Username -> Html Msg
senderView m s = senderView ud s =
span [ style "color" <| stringColor s, class "sender-wrapper" ] [ text <| displayName m.userData s ] span [ style "color" <| stringColor s, class "sender-wrapper" ] [ text <| displayName ud s ]
userMessagesView : Model -> (Username, List Message) -> Html Msg userMessagesView : Dict String UserData -> ApiUrl -> (Username, List Message) -> Html Msg
userMessagesView m (u, ms) = userMessagesView ud apiUrl (u, ms) =
let let
wrap h = div [ class "message" ] [ h ] wrap h = div [ class "message" ] [ h ]
in in
tr [] tr []
[ td [] [ senderView m u ] [ td [] [ senderView ud u ]
, td [] <| List.map wrap <| List.filterMap (messageView m) ms , td [] <| List.map wrap <| List.filterMap (messageView apiUrl) ms
] ]
messageView : Model -> Message -> Maybe (Html Msg) messageView : ApiUrl -> Message -> Maybe (Html Msg)
messageView m msg = case msg of messageView apiUrl msg = case msg of
Sending t -> Just <| sendingMessageView m t Sending t -> Just <| sendingMessageView t
Received re -> roomEventView m re Received re -> roomEventView apiUrl re
sendingMessageView : Model -> SendingMessage -> Html Msg sendingMessageView : SendingMessage -> Html Msg
sendingMessageView m 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 : Model -> RoomEvent -> Maybe (Html Msg) roomEventView : ApiUrl -> RoomEvent -> Maybe (Html Msg)
roomEventView m re = roomEventView 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 m re Ok "m.text" -> roomEventTextView re
Ok "m.image" -> roomEventImageView m re Ok "m.image" -> roomEventImageView apiUrl re
Ok "m.file" -> roomEventFileView m re Ok "m.file" -> roomEventFileView apiUrl re
Ok "m.video" -> roomEventVideoView m re Ok "m.video" -> roomEventVideoView apiUrl re
_ -> Nothing _ -> Nothing
roomEventTextView : Model -> RoomEvent -> Maybe (Html Msg) roomEventTextView : RoomEvent -> Maybe (Html Msg)
roomEventTextView m re = roomEventTextView re =
let let
body = Decode.decodeValue (Decode.field "body" Decode.string) re.content body = Decode.decodeValue (Decode.field "body" Decode.string) re.content
customHtml = Maybe.map Html.Parser.Util.toVirtualDom customHtml = Maybe.map Html.Parser.Util.toVirtualDom
@ -261,27 +262,27 @@ roomEventTextView m re =
Just c -> Just <| div [] c Just c -> Just <| div [] c
Nothing -> Maybe.map (p [] << List.singleton << text) <| Result.toMaybe body Nothing -> Maybe.map (p [] << List.singleton << text) <| Result.toMaybe body
roomEventImageView : Model -> RoomEvent -> Maybe (Html Msg) roomEventImageView : ApiUrl -> RoomEvent -> Maybe (Html Msg)
roomEventImageView m re = roomEventImageView apiUrl re =
let let
body = Decode.decodeValue (Decode.field "url" Decode.string) re.content body = Decode.decodeValue (Decode.field "url" Decode.string) re.content
in in
Maybe.map (\s -> img [ class "message-image", src s ] []) Maybe.map (\s -> img [ class "message-image", src s ] [])
<| Maybe.map (contentRepositoryDownloadUrl m.apiUrl) <| Maybe.map (contentRepositoryDownloadUrl apiUrl)
<| Result.toMaybe body <| Result.toMaybe body
roomEventFileView : Model -> RoomEvent -> Maybe (Html Msg) roomEventFileView : ApiUrl -> RoomEvent -> Maybe (Html Msg)
roomEventFileView m re = roomEventFileView apiUrl re =
let let
decoder = Decode.map2 (\l r -> (l, r)) (Decode.field "url" Decode.string) (Decode.field "body" Decode.string) decoder = Decode.map2 (\l r -> (l, r)) (Decode.field "url" Decode.string) (Decode.field "body" Decode.string)
fileData = Decode.decodeValue decoder re.content fileData = Decode.decodeValue decoder re.content
in in
Maybe.map (\(url, name) -> a [ href url, class "file-wrapper" ] [ iconView "file", text name ]) Maybe.map (\(url, name) -> a [ href url, class "file-wrapper" ] [ iconView "file", text name ])
<| Maybe.map (\(url, name) -> (contentRepositoryDownloadUrl m.apiUrl url, name)) <| Maybe.map (\(url, name) -> (contentRepositoryDownloadUrl apiUrl url, name))
<| Result.toMaybe fileData <| Result.toMaybe fileData
roomEventVideoView : Model -> RoomEvent -> Maybe (Html Msg) roomEventVideoView : ApiUrl -> RoomEvent -> Maybe (Html Msg)
roomEventVideoView m re = roomEventVideoView apiUrl re =
let let
decoder = Decode.map2 (\l r -> (l, r)) decoder = Decode.map2 (\l r -> (l, r))
(Decode.field "url" Decode.string) (Decode.field "url" Decode.string)
@ -289,5 +290,5 @@ roomEventVideoView m re =
videoData = Decode.decodeValue decoder re.content videoData = Decode.decodeValue decoder re.content
in in
Maybe.map (\(url, t) -> video [ controls True ] [ source [ src url, type_ t ] [] ]) Maybe.map (\(url, t) -> video [ controls True ] [ source [ src url, type_ t ] [] ])
<| Maybe.map (\(url, type_) -> (contentRepositoryDownloadUrl m.apiUrl url, type_)) <| Maybe.map (\(url, type_) -> (contentRepositoryDownloadUrl apiUrl url, type_))
<| Result.toMaybe videoData <| Result.toMaybe videoData