Add settings to Vault type

main
Bram van den Heuvel 2023-11-03 22:42:18 +01:00
parent f5f5c14e10
commit 2cb21dc102
4 changed files with 51 additions and 3 deletions

View File

@ -1,6 +1,7 @@
module Internal.Api.Snackbar exposing (..) 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, 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. 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 Dict exposing (Dict)
import Internal.Api.Versions.V1.Versions as V import Internal.Api.Versions.V1.Versions as V
import Internal.Config.DefaultSettings as DS
import Internal.Tools.LoginValues as Login exposing (AccessToken(..)) import Internal.Tools.LoginValues as Login exposing (AccessToken(..))
import Task exposing (Task) import Task exposing (Task)
@ -27,9 +29,14 @@ type Snackbar a vu
, homeserver : String , homeserver : String
, transactionOffset : Int , transactionOffset : Int
, vs : Maybe V.Versions , vs : Maybe V.Versions
, settings : Settings
} }
type alias Settings =
{ syncTimeout : Int }
accessToken : Snackbar a vu -> AccessToken accessToken : Snackbar a vu -> AccessToken
accessToken (Snackbar { access }) = accessToken (Snackbar { access }) =
access access
@ -92,6 +99,9 @@ init data =
, failedTasks = Dict.empty , failedTasks = Dict.empty
, failedTasksOffset = 0 , failedTasksOffset = 0
, homeserver = data.baseUrl , homeserver = data.baseUrl
, settings =
{ syncTimeout = DS.syncTimeout
}
, transactionOffset = 0 , transactionOffset = 0
, vs = Nothing , vs = Nothing
} }
@ -105,6 +115,7 @@ map f (Snackbar data) =
, failedTasks = data.failedTasks , failedTasks = data.failedTasks
, failedTasksOffset = 0 , failedTasksOffset = 0
, homeserver = data.homeserver , homeserver = data.homeserver
, settings = data.settings
, transactionOffset = data.transactionOffset , transactionOffset = data.transactionOffset
, vs = data.vs , vs = data.vs
} }
@ -135,6 +146,11 @@ setTransactionOffset i (Snackbar data) =
Snackbar { data | transactionOffset = max (data.transactionOffset + 1) (i + 1) } 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 a vu -> Maybe String
userId (Snackbar { access }) = userId (Snackbar { access }) =
Login.getUserId access Login.getUserId access

View File

@ -33,3 +33,10 @@ supportedVersions =
defaultDeviceName : String defaultDeviceName : String
defaultDeviceName = defaultDeviceName =
"Elm Matrix SDK (v" ++ currentVersion ++ ")" "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

View File

@ -68,9 +68,7 @@ allowed for every room admin.
import Internal.Api.VaultUpdate exposing (VaultUpdate) import Internal.Api.VaultUpdate exposing (VaultUpdate)
import Internal.Event as Event import Internal.Event as Event
import Internal.Room as Internal import Internal.Room as Internal
import Internal.Tools.Exceptions as X
import Json.Decode as D import Json.Decode as D
import Task exposing (Task)
{-| A room represents a channel of communication within a Matrix home server. {-| A room represents a channel of communication within a Matrix home server.

27
src/Matrix/Settings.elm Normal file
View File

@ -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 }