Skip to content

Commit fc998a9

Browse files
schoettlTristanCacqueray
authored andcommitted
Refactor
1 parent 722034f commit fc998a9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

matrix-client/src/Network/Matrix/Client.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ mkRequest ClientSession {..} = mkRequest' baseUrl token
226226
doRequest :: FromJSON a => ClientSession -> HTTP.Request -> MatrixIO a
227227
doRequest ClientSession {..} = doRequest' manager
228228

229+
doRequestExpectEmptyResponse :: ClientSession -> String -> HTTP.Request -> MatrixIO ()
230+
doRequestExpectEmptyResponse sess apiName request = fmap (ensureEmptyObject apiName) <$> doRequest sess request
231+
229232
-- | 'getTokenOwner' gets information about the owner of a given access token.
230233
getTokenOwner :: ClientSession -> MatrixIO UserID
231234
getTokenOwner session =
@@ -631,10 +634,10 @@ inviteToRoom :: ClientSession -> RoomID -> UserID -> Maybe T.Text -> MatrixIO ()
631634
inviteToRoom session (RoomID rid) (UserID uid) reason = do
632635
request <- mkRequest session True $ "/_matrix/client/v3/rooms/" <> rid <> "/invite"
633636
let body = object $ [("user_id", toJSON uid)] <> catMaybes [fmap (("reason",) . toJSON) reason]
634-
fmap (ensureEmptyObject "invite") <$> (doRequest session $
637+
doRequestExpectEmptyResponse session "invite" $
635638
request { HTTP.method = "POST"
636639
, HTTP.requestBody = HTTP.RequestBodyLBS $ encode body
637-
})
640+
}
638641

639642
-- | Note that this API takes either a room ID or alias, unlike 'joinRoomById'
640643
-- https://spec.matrix.org/v1.1/client-server-api/#post_matrixclientv3joinroomidoralias

0 commit comments

Comments
 (0)