From c594d9858f890c73eb4830a9bf1f89bbad92a062 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 12 Sep 2019 15:56:21 -0700 Subject: [PATCH] Rename some functions to be more clear --- src/Scylla/Http.elm | 4 ++-- src/Scylla/Messages.elm | 18 +++++++++--------- src/Scylla/Notification.elm | 8 ++++---- src/Scylla/Room.elm | 6 +++--- src/Scylla/Views.elm | 6 +++--- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Scylla/Http.elm b/src/Scylla/Http.elm index 912f287..3a699dc 100644 --- a/src/Scylla/Http.elm +++ b/src/Scylla/Http.elm @@ -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 diff --git a/src/Scylla/Messages.elm b/src/Scylla/Messages.elm index b722c67..6525138 100644 --- a/src/Scylla/Messages.elm +++ b/src/Scylla/Messages.elm @@ -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 diff --git a/src/Scylla/Notification.elm b/src/Scylla/Notification.elm index 8af3257..5c3edf0 100644 --- a/src/Scylla/Notification.elm +++ b/src/Scylla/Notification.elm @@ -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 diff --git a/src/Scylla/Room.elm b/src/Scylla/Room.elm index bc46196..2331320 100644 --- a/src/Scylla/Room.elm +++ b/src/Scylla/Room.elm @@ -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 = diff --git a/src/Scylla/Views.elm b/src/Scylla/Views.elm index 1b58e1e..9a9ad11 100644 --- a/src/Scylla/Views.elm +++ b/src/Scylla/Views.elm @@ -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