diff --git a/src/Internal/Api/Snackbar.elm b/src/Internal/Api/Snackbar.elm index 85b8be1..d298d3c 100644 --- a/src/Internal/Api/Snackbar.elm +++ b/src/Internal/Api/Snackbar.elm @@ -1,6 +1,7 @@ module Internal.Api.Snackbar exposing (..) -{-| The snackbar module helps wraps relevant credentials, access tokens, refresh tokens and more around internal types. +{-| The snackbar module helps wraps relevant credentials, access tokens, +refresh tokens and more around internal types. Vault, Room and Event types don't need access to API tokens, but a user may way to redact an event, leave a room or reject an invite. @@ -14,6 +15,7 @@ without needing to update every data type whenever any of the tokens change. import Dict exposing (Dict) import Internal.Api.Versions.V1.Versions as V +import Internal.Config.DefaultSettings as DS import Internal.Tools.LoginValues as Login exposing (AccessToken(..)) import Task exposing (Task) @@ -27,9 +29,14 @@ type Snackbar a vu , homeserver : String , transactionOffset : Int , vs : Maybe V.Versions + , settings : Settings } +type alias Settings = + { syncTimeout : Int } + + accessToken : Snackbar a vu -> AccessToken accessToken (Snackbar { access }) = access @@ -92,6 +99,9 @@ init data = , failedTasks = Dict.empty , failedTasksOffset = 0 , homeserver = data.baseUrl + , settings = + { syncTimeout = DS.syncTimeout + } , transactionOffset = 0 , vs = Nothing } @@ -105,6 +115,7 @@ map f (Snackbar data) = , failedTasks = data.failedTasks , failedTasksOffset = 0 , homeserver = data.homeserver + , settings = data.settings , transactionOffset = data.transactionOffset , vs = data.vs } @@ -135,6 +146,11 @@ setTransactionOffset i (Snackbar data) = Snackbar { data | transactionOffset = max (data.transactionOffset + 1) (i + 1) } +updateSettings : (Settings -> Settings) -> Snackbar a vu -> Snackbar a vu +updateSettings f (Snackbar ({ settings } as data)) = + Snackbar { data | settings = f settings } + + userId : Snackbar a vu -> Maybe String userId (Snackbar { access }) = Login.getUserId access diff --git a/src/Internal/Config/DefaultSettings.elm b/src/Internal/Config/DefaultSettings.elm index dee906e..a383e48 100644 --- a/src/Internal/Config/DefaultSettings.elm +++ b/src/Internal/Config/DefaultSettings.elm @@ -33,3 +33,10 @@ supportedVersions = defaultDeviceName : String defaultDeviceName = "Elm Matrix SDK (v" ++ currentVersion ++ ")" + + +{-| The amount of seconds that the Matrix Vault should wait for a response from the Matrix homeserver. +-} +syncTimeout : Int +syncTimeout = + 10 diff --git a/src/Matrix/Room.elm b/src/Matrix/Room.elm index 1c9bcac..eebf837 100644 --- a/src/Matrix/Room.elm +++ b/src/Matrix/Room.elm @@ -68,9 +68,7 @@ allowed for every room admin. import Internal.Api.VaultUpdate exposing (VaultUpdate) import Internal.Event as Event import Internal.Room as Internal -import Internal.Tools.Exceptions as X import Json.Decode as D -import Task exposing (Task) {-| A room represents a channel of communication within a Matrix home server. diff --git a/src/Matrix/Settings.elm b/src/Matrix/Settings.elm new file mode 100644 index 0000000..f72e94d --- /dev/null +++ b/src/Matrix/Settings.elm @@ -0,0 +1,27 @@ +module Matrix.Settings exposing (..) +{-| There are a lot of settings that you can change! + +These settings change how the Vault interacts with the Matrix API. +You can adjust these values for performance reasons, for customizability, benchmarking, +or maybe just because you like it. :) + +It is common to set all settings in the `init` function, but you can adjust all settings on the fly. +-} + +import Internal.Vault exposing (Vault) + +{-| When your Matrix client synchronizes with the homeserver, the homeserver often +responds quite quickly, giving all the information that you need. + +Sometimes, the homeserver has nothing new to report, and instead makes you wait for a response. +This is called long-polling, and it's the homeserver waiting for an update to give to you. +Long-polling is very useful! + +This setting sets a limit on how long the long-polling should last. It is smart +to make this equal to the interval at which you run the `sync` function. + +**Default:** 10 (seconds) +-} +syncTimeout : Int -> Vault -> Vault +syncTimeout timeout = + Internal.Vault.settings \data -> { data | syncTimeout = timeout } \ No newline at end of file