Display user names in private chats.

This commit is contained in:
Danila Fedorin 2019-05-15 20:27:06 -07:00
parent 0dda1068fb
commit 63fcb22998
3 changed files with 26 additions and 8 deletions

View File

@ -17,7 +17,7 @@ firstSyncFilter : Json.Decode.Value
firstSyncFilter = object firstSyncFilter = object
[ ("room", object [ ("room", object
[ ("state", object [ ("state", object
[ ("types", list string [ "m.room.name" ]) [ ("types", list string [ "m.room.name", "m.room.member" ])
]) ])
]) ])
] ]

View File

@ -547,3 +547,14 @@ roomTypingUsers jr = Maybe.withDefault []
-- Business Logic: Users -- Business Logic: Users
allUsers : SyncResponse -> List Username allUsers : SyncResponse -> List Username
allUsers s = uniqueBy (\u -> u) <| List.map .sender <| allTimelineEvents s allUsers s = uniqueBy (\u -> u) <| List.map .sender <| allTimelineEvents s
roomJoinedUsers : JoinedRoom -> List Username
roomJoinedUsers r =
let
contentDecoder = Decode.field "membership" Decode.string
isJoin e = Ok "join" == (Decode.decodeValue contentDecoder e.content)
in
List.map .sender
<| List.filter isJoin
<| List.filter (((==) "m.room.member") << .type_)
<| allRoomStateEvents r

View File

@ -86,7 +86,7 @@ roomListView m =
groups = roomGroups groups = roomGroups
<| Dict.toList rooms <| Dict.toList rooms
homeserverList = div [ class "homeservers-list" ] homeserverList = div [ class "homeservers-list" ]
<| List.map (\(k, v) -> homeserverView k v) <| List.map (\(k, v) -> homeserverView m k v)
<| Dict.toList groups <| Dict.toList groups
in in
div [ class "rooms-wrapper" ] div [ class "rooms-wrapper" ]
@ -97,17 +97,24 @@ roomListView m =
roomGroups : List (String, JoinedRoom) -> Dict String (List (String, JoinedRoom)) roomGroups : List (String, JoinedRoom) -> Dict String (List (String, JoinedRoom))
roomGroups jrs = groupBy (homeserver << Tuple.first) jrs roomGroups jrs = groupBy (homeserver << Tuple.first) jrs
homeserverView : String -> List (String, JoinedRoom) -> Html Msg homeserverView : Model -> String -> List (String, JoinedRoom) -> Html Msg
homeserverView hs rs = homeserverView m hs rs =
let let
roomList = div [ class "rooms-list" ] <| List.map (\(rid, r) -> roomListElementView rid r) rs roomList = div [ class "rooms-list" ] <| List.map (\(rid, r) -> roomListElementView m rid r) rs
in in
div [ class "homeserver-wrapper" ] [ h3 [] [ text hs ], roomList ] div [ class "homeserver-wrapper" ] [ h3 [] [ text hs ], roomList ]
roomListElementView : String -> JoinedRoom -> Html Msg roomListElementView : Model -> String -> JoinedRoom -> Html Msg
roomListElementView s jr = roomListElementView m s jr =
let let
name = Maybe.withDefault "<No Name>" <| roomName jr roomUsers = List.filter ((/=) m.loginUsername) <| roomJoinedUsers jr
privateChatName = case (List.length roomUsers) of
1 -> Maybe.andThen (\u -> Maybe.andThen .displayName <| Dict.get u m.userData) <| List.head roomUsers
_ -> Nothing
maybeRoomName = case roomName jr of
Just rn -> Just rn
Nothing -> privateChatName
name = Maybe.withDefault "<No Name>" maybeRoomName
in in
div [ class "room-link-wrapper" ] div [ class "room-link-wrapper" ]
[ a [ href <| roomUrl s ] [ text name ] [ a [ href <| roomUrl s ] [ text name ]