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 , tracker = Nothing
} }
userData : ApiUrl -> ApiToken -> Username -> Cmd Msg getUserData : ApiUrl -> ApiToken -> Username -> Cmd Msg
userData apiUrl token username = request getUserData apiUrl token username = request
{ method = "GET" { method = "GET"
, headers = authenticatedHeaders token , headers = authenticatedHeaders token
, url = (fullClientUrl apiUrl) ++ "/profile/" ++ username , url = (fullClientUrl apiUrl) ++ "/profile/" ++ username

View File

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

View File

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

View File

@ -142,8 +142,8 @@ getRoomName ad ud rid rd =
(_, Just d) -> getDisplayName ud d (_, Just d) -> getDisplayName ud d
_ -> rid _ -> rid
getRoomNotificationCount : RoomData -> (Int, Int) getNotificationCount : RoomData -> (Int, Int)
getRoomNotificationCount rd = getNotificationCount rd =
( Maybe.withDefault 0 rd.unreadNotifications.notificationCount ( Maybe.withDefault 0 rd.unreadNotifications.notificationCount
, Maybe.withDefault 0 rd.unreadNotifications.highlightCount , Maybe.withDefault 0 rd.unreadNotifications.highlightCount
) )
@ -153,7 +153,7 @@ getTotalNotificationCount =
let let
sumTuples (x1, y1) (x2, y2) = (x1+x2, y1+y2) sumTuples (x1, y1) (x2, y2) = (x1+x2, y1+y2)
in in
Dict.foldl (\_ -> sumTuples << getRoomNotificationCount) (0, 0) Dict.foldl (\_ -> sumTuples << getNotificationCount) (0, 0)
getTotalNotificationCountString : OpenRooms -> Maybe String getTotalNotificationCountString : OpenRooms -> Maybe String
getTotalNotificationCountString or = 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 : Dict String UserData -> RoomId -> RoomData -> ApiUrl -> Username -> Dict Int (RoomId, SendingMessage) -> Html Msg
lazyMessagesView ud rid rd au lu snd = lazyMessagesView ud rid rd au lu snd =
let let
roomReceived = receivedMessagesRoom rd roomReceived = getReceivedMessages rd
roomSending = sendingMessagesRoom rid snd roomSending = getSendingMessages rid snd
renderedMessages = List.map (userMessagesView ud au) renderedMessages = List.map (userMessagesView ud au)
<| mergeMessages lu <| groupMessages lu
<| roomReceived ++ roomSending <| roomReceived ++ roomSending
in in
messagesWrapperView rid renderedMessages messagesWrapperView rid renderedMessages