Add "typing people wrapper"

This commit is contained in:
Danila Fedorin 2018-12-13 16:28:13 -08:00
parent 5627168d20
commit 56878533f4
2 changed files with 25 additions and 2 deletions

View File

@ -269,11 +269,19 @@ uniqueByRecursive f l s = case l of
uniqueBy : (a -> comparable) -> List a -> List a uniqueBy : (a -> comparable) -> List a -> List a
uniqueBy f l = uniqueByRecursive f l Set.empty uniqueBy f l = uniqueByRecursive f l Set.empty
findFirst : (a -> Bool) -> List a -> Maybe a
findFirst cond l = case l of
x::xs -> if cond x then Just x else findFirst cond xs
[] -> Nothing
findLast : (a -> Bool) -> List a -> Maybe a
findLast cond l = findFirst cond <| List.reverse l
findFirstBy : (a -> comparable) -> (a -> Bool) -> List a -> Maybe a findFirstBy : (a -> comparable) -> (a -> Bool) -> List a -> Maybe a
findFirstBy sortFunction cond l = List.head <| List.sortBy sortFunction <| List.filter cond l findFirstBy sortFunction cond l = findFirst cond <| List.sortBy sortFunction l
findLastBy : (a -> comparable) -> (a -> Bool) -> List a -> Maybe a findLastBy : (a -> comparable) -> (a -> Bool) -> List a -> Maybe a
findLastBy sortFunction cond l = List.head <| List.reverse <| List.sortBy sortFunction <| List.filter cond l findLastBy sortFunction cond l = findLast cond <| List.sortBy sortFunction l
findFirstEvent : ({ a | originServerTs : Int } -> Bool) -> List { a | originServerTs : Int } -> Maybe { a | originServerTs : Int } findFirstEvent : ({ a | originServerTs : Int } -> Bool) -> List { a | originServerTs : Int } -> Maybe { a | originServerTs : Int }
findFirstEvent = findFirstBy .originServerTs findFirstEvent = findFirstBy .originServerTs
@ -407,6 +415,13 @@ joinedRoomsEvents s =
<| Maybe.andThen .join s.rooms <| Maybe.andThen .join s.rooms
-- Business Logic: User Extraction -- Business Logic: User Extraction
roomTypingUsers : JoinedRoom -> List Username
roomTypingUsers jr = Maybe.withDefault []
<| Maybe.andThen (Result.toMaybe << Decode.decodeValue (Decode.field "user_ids" (list string)))
<| Maybe.map .content
<| Maybe.andThen (findLast (((==) "m.typing") << .type_))
<| Maybe.andThen .events jr.ephemeral
roomsUsers : SyncResponse -> List Username roomsUsers : SyncResponse -> List Username
roomsUsers s = roomsUsers s =
let let

View File

@ -86,6 +86,13 @@ joinedRoomView m roomId jr =
events = Maybe.withDefault [] <| Maybe.andThen .events jr.timeline events = Maybe.withDefault [] <| Maybe.andThen .events jr.timeline
renderedEvents = List.filterMap (eventView m) events renderedEvents = List.filterMap (eventView m) events
eventWrapper = eventWrapperView m renderedEvents eventWrapper = eventWrapperView m renderedEvents
typing = List.map (displayName m) <| roomTypingUsers jr
typingText = String.join ", " typing
typingSuffix = case List.length typing of
0 -> ""
1 -> " is typing..."
_ -> " are typing..."
typingWrapper = div [ class "typing-wrapper" ] [ text <| typingText ++ typingSuffix ]
messageInput = div [ class "message-wrapper" ] messageInput = div [ class "message-wrapper" ]
[ input [ input
[ type_ "text" [ type_ "text"
@ -98,6 +105,7 @@ joinedRoomView m roomId jr =
div [ class "room-wrapper" ] div [ class "room-wrapper" ]
[ h2 [] [ text <| Maybe.withDefault "<No Name>" <| roomName jr ] [ h2 [] [ text <| Maybe.withDefault "<No Name>" <| roomName jr ]
, eventWrapper , eventWrapper
, typingWrapper
, messageInput , messageInput
] ]