Compare commits
2 Commits
63fcb22998
...
47a684b777
Author | SHA1 | Date | |
---|---|---|---|
47a684b777 | |||
5bd6124df2 |
|
@ -1,6 +1,6 @@
|
|||
module Scylla.Model exposing (..)
|
||||
import Scylla.Api exposing (..)
|
||||
import Scylla.Sync exposing (SyncResponse, HistoryResponse, JoinedRoom, senderName)
|
||||
import Scylla.Sync exposing (SyncResponse, HistoryResponse, JoinedRoom, senderName, roomName, roomJoinedUsers)
|
||||
import Scylla.Login exposing (LoginResponse, Username, Password)
|
||||
import Scylla.UserData exposing (UserData)
|
||||
import Scylla.Route exposing (Route(..), RoomId)
|
||||
|
@ -72,6 +72,25 @@ type Msg =
|
|||
displayName : Model -> Username -> String
|
||||
displayName m s = Maybe.withDefault (senderName s) <| Maybe.andThen .displayName <| Dict.get s m.userData
|
||||
|
||||
roomDisplayName : Model -> JoinedRoom -> String
|
||||
roomDisplayName m jr =
|
||||
let
|
||||
customName = roomName jr
|
||||
roomUsers = List.filter ((/=) m.loginUsername) <| roomJoinedUsers jr
|
||||
singleUserName = if List.length roomUsers == 1 then List.head roomUsers else Nothing
|
||||
singleUserDisplayName = Maybe.andThen
|
||||
(\u -> Maybe.andThen .displayName <| Dict.get u m.userData) singleUserName
|
||||
firstOption d os = case os of
|
||||
[] -> d
|
||||
((Just v)::_) -> v
|
||||
(Nothing::xs) -> firstOption d xs
|
||||
in
|
||||
firstOption "<No Name>"
|
||||
[ customName
|
||||
, singleUserDisplayName
|
||||
, singleUserName
|
||||
]
|
||||
|
||||
roomUrl : String -> String
|
||||
roomUrl s = Url.Builder.absolute [ "room", s ] []
|
||||
|
||||
|
|
|
@ -100,21 +100,16 @@ roomGroups jrs = groupBy (homeserver << Tuple.first) jrs
|
|||
homeserverView : Model -> String -> List (String, JoinedRoom) -> Html Msg
|
||||
homeserverView m hs rs =
|
||||
let
|
||||
roomList = div [ class "rooms-list" ] <| List.map (\(rid, r) -> roomListElementView m rid r) rs
|
||||
roomList = div [ class "rooms-list" ]
|
||||
<| List.map (\(rid, r) -> roomListElementView m rid r)
|
||||
<| List.sortBy (\(rid, r) -> roomDisplayName m r) rs
|
||||
in
|
||||
div [ class "homeserver-wrapper" ] [ h3 [] [ text hs ], roomList ]
|
||||
|
||||
roomListElementView : Model -> String -> JoinedRoom -> Html Msg
|
||||
roomListElementView m s jr =
|
||||
let
|
||||
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
|
||||
name = roomDisplayName m jr
|
||||
in
|
||||
div [ class "room-link-wrapper" ]
|
||||
[ a [ href <| roomUrl s ] [ text name ]
|
||||
|
@ -169,7 +164,7 @@ joinedRoomView m roomId rd =
|
|||
]
|
||||
in
|
||||
div [ class "room-wrapper" ]
|
||||
[ h2 [] [ text <| Maybe.withDefault "<No Name>" <| roomName rd.joinedRoom ]
|
||||
[ h2 [] [ text <| roomDisplayName m rd.joinedRoom ]
|
||||
, messagesWrapper
|
||||
, typingWrapper
|
||||
, messageInput
|
||||
|
|
Loading…
Reference in New Issue
Block a user