diff --git a/src/Scylla/Http.elm b/src/Scylla/Http.elm index a95bbfd..641fe0a 100644 --- a/src/Scylla/Http.elm +++ b/src/Scylla/Http.elm @@ -17,7 +17,7 @@ firstSyncFilter : Json.Decode.Value firstSyncFilter = object [ ("room", object [ ("state", object - [ ("types", list string [ "m.room.name" ]) + [ ("types", list string [ "m.room.name", "m.room.member" ]) ]) ]) ] diff --git a/src/Scylla/Sync.elm b/src/Scylla/Sync.elm index e084dbc..ba54d77 100644 --- a/src/Scylla/Sync.elm +++ b/src/Scylla/Sync.elm @@ -547,3 +547,14 @@ roomTypingUsers jr = Maybe.withDefault [] -- Business Logic: Users allUsers : SyncResponse -> List Username 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 diff --git a/src/Scylla/Views.elm b/src/Scylla/Views.elm index e39a5fa..9d4be09 100644 --- a/src/Scylla/Views.elm +++ b/src/Scylla/Views.elm @@ -86,7 +86,7 @@ roomListView m = groups = roomGroups <| Dict.toList rooms homeserverList = div [ class "homeservers-list" ] - <| List.map (\(k, v) -> homeserverView k v) + <| List.map (\(k, v) -> homeserverView m k v) <| Dict.toList groups in div [ class "rooms-wrapper" ] @@ -97,17 +97,24 @@ roomListView m = roomGroups : List (String, JoinedRoom) -> Dict String (List (String, JoinedRoom)) roomGroups jrs = groupBy (homeserver << Tuple.first) jrs -homeserverView : String -> List (String, JoinedRoom) -> Html Msg -homeserverView hs rs = +homeserverView : Model -> String -> List (String, JoinedRoom) -> Html Msg +homeserverView m hs rs = 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 div [ class "homeserver-wrapper" ] [ h3 [] [ text hs ], roomList ] -roomListElementView : String -> JoinedRoom -> Html Msg -roomListElementView s jr = +roomListElementView : Model -> String -> JoinedRoom -> Html Msg +roomListElementView m s jr = let - name = Maybe.withDefault "" <| 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 "" maybeRoomName in div [ class "room-link-wrapper" ] [ a [ href <| roomUrl s ] [ text name ]