Skip to content

Commit

Permalink
Adds createWithSession
Browse files Browse the repository at this point in the history
  • Loading branch information
solomon-b authored and TristanCacqueray committed Feb 13, 2022
1 parent e634a09 commit 4b806ab
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions matrix-client/src/Network/Matrix/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module Network.Matrix.Client
LoginResponse (..),
getTokenFromEnv,
createSession,
createWithSession,
createWithSessionIO,
login,
loginToken,
logout,
Expand All @@ -31,6 +33,7 @@ module Network.Matrix.Client
MatrixM,
MatrixIO,
runMatrixM,
runMatrixIO,
MatrixError (..),
retry,
retryWithLog,
Expand Down Expand Up @@ -180,6 +183,7 @@ import Network.Matrix.Internal
mkRequest',
retry,
retryWithLog,
runMatrixIO,
runMatrixM,
)
import Network.Matrix.Room
Expand Down Expand Up @@ -238,6 +242,29 @@ createSession ::
IO ClientSession
createSession baseUrl' token' = ClientSession baseUrl' token' <$> mkManager

createWithSession ::
MonadIO m =>
-- | The matrix client-server base url, e.g. "https://matrix.org"
T.Text ->
-- | The user token
MatrixToken ->
-- | The matrix action to perform
MatrixM m a ->
m (Either MatrixError a)
createWithSession baseUrl' token' action = do
session <- liftIO $ createSession baseUrl' token'
runMatrixM session action

createWithSessionIO ::
-- | The matrix client-server base url, e.g. "https://matrix.org"
T.Text ->
-- | The user token
MatrixToken ->
-- | The matrix action to perform
MatrixIO a ->
IO (Either MatrixError a)
createWithSessionIO = createWithSession

mkRequest :: MonadIO m => Bool -> T.Text -> MatrixM m HTTP.Request
mkRequest auth path = do
ClientSession {..} <- ask
Expand Down
2 changes: 1 addition & 1 deletion matrix-client/src/Network/Matrix/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ runMatrixM session = flip runReaderT session . runExceptT . unMatrixM
-- | Run Matrix actions in 'IO'.
runMatrixIO :: ClientSession -> MatrixM IO a -> IO (Either MatrixError a)
runMatrixIO = runMatrixM

-- | Retry a network action
retryWithLog ::
(MonadMask m, MonadIO m) =>
Expand Down

0 comments on commit 4b806ab

Please sign in to comment.