Add settings to Vault type
parent
f5f5c14e10
commit
2cb21dc102
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 }
|
Loading…
Reference in New Issue