Skip to content

Commit 4b806ab

Browse files
solomon-bTristanCacqueray
authored andcommitted
Adds createWithSession
1 parent e634a09 commit 4b806ab

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

+27
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ module Network.Matrix.Client
2323
LoginResponse (..),
2424
getTokenFromEnv,
2525
createSession,
26+
createWithSession,
27+
createWithSessionIO,
2628
login,
2729
loginToken,
2830
logout,
@@ -31,6 +33,7 @@ module Network.Matrix.Client
3133
MatrixM,
3234
MatrixIO,
3335
runMatrixM,
36+
runMatrixIO,
3437
MatrixError (..),
3538
retry,
3639
retryWithLog,
@@ -180,6 +183,7 @@ import Network.Matrix.Internal
180183
mkRequest',
181184
retry,
182185
retryWithLog,
186+
runMatrixIO,
183187
runMatrixM,
184188
)
185189
import Network.Matrix.Room
@@ -238,6 +242,29 @@ createSession ::
238242
IO ClientSession
239243
createSession baseUrl' token' = ClientSession baseUrl' token' <$> mkManager
240244

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 ::
259+
-- | The matrix client-server base url, e.g. "https://matrix.org"
260+
T.Text ->
261+
-- | The user token
262+
MatrixToken ->
263+
-- | The matrix action to perform
264+
MatrixIO a ->
265+
IO (Either MatrixError a)
266+
createWithSessionIO = createWithSession
267+
241268
mkRequest :: MonadIO m => Bool -> T.Text -> MatrixM m HTTP.Request
242269
mkRequest auth path = do
243270
ClientSession {..} <- ask

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ runMatrixM session = flip runReaderT session . runExceptT . unMatrixM
194194
-- | Run Matrix actions in 'IO'.
195195
runMatrixIO :: ClientSession -> MatrixM IO a -> IO (Either MatrixError a)
196196
runMatrixIO = runMatrixM
197-
197+
198198
-- | Retry a network action
199199
retryWithLog ::
200200
(MonadMask m, MonadIO m) =>

0 commit comments

Comments
 (0)