Skip to content

Commit 40b4132

Browse files
Adds createSessionWithManager
Change-Id: I64106c117ca5f7dc3832f6e731e67d5b4dcbafb6
1 parent 0c28c59 commit 40b4132

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

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

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ module Network.Matrix.Client
2323
LoginResponse (..),
2424
getTokenFromEnv,
2525
createSession,
26-
createWithSession,
27-
createWithSessionIO,
26+
createSessionWithManager,
2827
login,
2928
loginToken,
29+
loginTokenWithManager,
3030
logout,
3131

3232
-- * API
@@ -214,8 +214,13 @@ login = fmap (fmap fst) . loginToken
214214
-- | 'loginToken' allows you to generate a session token and recover the Matrix auth token.
215215
loginToken :: LoginCredentials -> IO (Either MatrixError (ClientSession, MatrixToken))
216216
loginToken cred = do
217-
req <- mkLoginRequest cred
218217
manager <- mkManager
218+
loginTokenWithManager manager cred
219+
220+
-- | 'loginTokenWithManager' allows you to generate a session token with a custom http manager and recover the Matrix auth token.
221+
loginTokenWithManager :: HTTP.Manager -> LoginCredentials -> IO (Either MatrixError (ClientSession, MatrixToken))
222+
loginTokenWithManager manager cred = do
223+
req <- mkLoginRequest cred
219224
resp <- doRequest' manager req
220225
pure $ case resp of
221226
Left e -> Left e
@@ -242,28 +247,16 @@ createSession ::
242247
IO ClientSession
243248
createSession baseUrl' token' = ClientSession baseUrl' token' <$> mkManager
244249

245-
createWithSession ::
246-
MonadIO m =>
247-
-- | The matrix client-server base url, e.g. "https://matrix.org"
248-
T.Text ->
249-
-- | The user token
250-
MatrixToken ->
251-
-- | The matrix action to perform
252-
MatrixM m a ->
253-
m (Either MatrixError a)
254-
createWithSession baseUrl' token' action = do
255-
session <- liftIO $ createSession baseUrl' token'
256-
runMatrixM session action
257-
258-
createWithSessionIO ::
250+
-- | 'createSession' creates the session record.
251+
createSessionWithManager ::
259252
-- | The matrix client-server base url, e.g. "https://matrix.org"
260253
T.Text ->
261254
-- | The user token
262255
MatrixToken ->
263-
-- | The matrix action to perform
264-
MatrixIO a ->
265-
IO (Either MatrixError a)
266-
createWithSessionIO = createWithSession
256+
-- | A 'http-client' Manager
257+
HTTP.Manager ->
258+
ClientSession
259+
createSessionWithManager = ClientSession
267260

268261
mkRequest :: MonadIO m => Bool -> T.Text -> MatrixM m HTTP.Request
269262
mkRequest auth path = do

0 commit comments

Comments
 (0)