Move the room name code into a separate function.
This commit is contained in:
parent
63fcb22998
commit
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 ] []
|
||||
|
||||
|
|
|
@ -107,14 +107,7 @@ homeserverView m hs rs =
|
|||
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 +162,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