Rename some functions to be more clear

This commit is contained in:
Danila Fedorin 2019-09-12 15:56:21 -07:00
parent 71e0b3f64e
commit c594d9858f
5 changed files with 21 additions and 21 deletions

View File

@ -138,8 +138,8 @@ login apiUrl username password = request
, tracker = Nothing
}
userData : ApiUrl -> ApiToken -> Username -> Cmd Msg
userData apiUrl token username = request
getUserData : ApiUrl -> ApiToken -> Username -> Cmd Msg
getUserData apiUrl token username = request
{ method = "GET"
, headers = authenticatedHeaders token
, url = (fullClientUrl apiUrl) ++ "/profile/" ++ username

View File

@ -16,13 +16,13 @@ type Message
= Sending SendingMessage
| Received MessageEvent
messageUsername : Username -> Message -> Username
messageUsername u msg = case msg of
getUsername : Username -> Message -> Username
getUsername u msg = case msg of
Sending _ -> u
Received re -> re.sender
mergeMessages : Username -> List Message -> List (Username, List Message)
mergeMessages du xs =
groupMessages : Username -> List Message -> List (Username, List Message)
groupMessages du xs =
let
initialState = (Nothing, [], [])
appendNamed mu ms msl = case mu of
@ -30,19 +30,19 @@ mergeMessages du xs =
Nothing -> msl
foldFunction msg (pu, ms, msl) =
let
nu = Just <| messageUsername du msg
nu = Just <| getUsername du msg
in
if pu == nu then (pu, ms ++ [msg], msl) else (nu, [msg], appendNamed pu ms msl)
(fmu, fms, fmsl) = List.foldl foldFunction initialState xs
in
appendNamed fmu fms fmsl
receivedMessagesRoom : RoomData -> List Message
receivedMessagesRoom rd = rd.messages
getReceivedMessages : RoomData -> List Message
getReceivedMessages rd = rd.messages
|> List.filter (\e -> e.type_ == "m.room.message")
|> List.map Received
sendingMessagesRoom : RoomId -> Dict Int (RoomId, SendingMessage) -> List Message
sendingMessagesRoom rid ms = List.map (\(tid, (_, sm)) -> Sending sm)
getSendingMessages : RoomId -> Dict Int (RoomId, SendingMessage) -> List Message
getSendingMessages rid ms = List.map (\(tid, (_, sm)) -> Sending sm)
<| List.filter (\(_, (nrid, _)) -> nrid == rid)
<| Dict.toList ms

View File

@ -13,13 +13,13 @@ type alias Notification =
port sendNotificationPort : Notification -> Cmd msg
port onNotificationClickPort : (String -> msg) -> Sub msg
notificationText : MessageEvent -> String
notificationText re = case (Decode.decodeValue (field "msgtype" string) re.content) of
getText : MessageEvent -> String
getText re = case (Decode.decodeValue (field "msgtype" string) re.content) of
Ok "m.text" -> Result.withDefault "" <| (Decode.decodeValue (field "body" string) re.content)
_ -> ""
joinedRoomNotificationEvents : SyncResponse -> List (String, MessageEvent)
joinedRoomNotificationEvents s =
getNotificationEvents : SyncResponse -> List (String, MessageEvent)
getNotificationEvents s =
let
applyPair k = List.map (\v -> (k, v))
in

View File

@ -142,8 +142,8 @@ getRoomName ad ud rid rd =
(_, Just d) -> getDisplayName ud d
_ -> rid
getRoomNotificationCount : RoomData -> (Int, Int)
getRoomNotificationCount rd =
getNotificationCount : RoomData -> (Int, Int)
getNotificationCount rd =
( Maybe.withDefault 0 rd.unreadNotifications.notificationCount
, Maybe.withDefault 0 rd.unreadNotifications.highlightCount
)
@ -153,7 +153,7 @@ getTotalNotificationCount =
let
sumTuples (x1, y1) (x2, y2) = (x1+x2, y1+y2)
in
Dict.foldl (\_ -> sumTuples << getRoomNotificationCount) (0, 0)
Dict.foldl (\_ -> sumTuples << getNotificationCount) (0, 0)
getTotalNotificationCountString : OpenRooms -> Maybe String
getTotalNotificationCountString or =

View File

@ -191,10 +191,10 @@ joinedRoomView m roomId rd =
lazyMessagesView : Dict String UserData -> RoomId -> RoomData -> ApiUrl -> Username -> Dict Int (RoomId, SendingMessage) -> Html Msg
lazyMessagesView ud rid rd au lu snd =
let
roomReceived = receivedMessagesRoom rd
roomSending = sendingMessagesRoom rid snd
roomReceived = getReceivedMessages rd
roomSending = getSendingMessages rid snd
renderedMessages = List.map (userMessagesView ud au)
<| mergeMessages lu
<| groupMessages lu
<| roomReceived ++ roomSending
in
messagesWrapperView rid renderedMessages