From 29f9482b74899c5a5de35c0dc3da158e3743dca7 Mon Sep 17 00:00:00 2001 From: Bram Date: Mon, 18 Dec 2023 01:32:57 +0100 Subject: [PATCH] Add public settings interface --- elm.json | 1 + src/Internal/Config/Default.elm | 2 +- src/Matrix/Settings.elm | 71 +++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/Matrix/Settings.elm diff --git a/elm.json b/elm.json index d50267e..befcf14 100644 --- a/elm.json +++ b/elm.json @@ -6,6 +6,7 @@ "version": "1.0.0", "exposed-modules": [ "Matrix", + "Matrix.Settings", "Internal.Config.Default", "Internal.Config.Text", "Internal.Tools.Decode", diff --git a/src/Internal/Config/Default.elm b/src/Internal/Config/Default.elm index d05dd7f..d51eec7 100644 --- a/src/Internal/Config/Default.elm +++ b/src/Internal/Config/Default.elm @@ -42,7 +42,7 @@ the Elm SDK tolerates being held on hold. - ↗️ A high value is good because it significantly reduces traffic between the user and the homeserver. - - ↘️ A low value is good because it refuces the risk of + - ↘️ A low value is good because it reduces the risk of the connection ending abruptly or unexpectedly. Nowadays, most libraries use 30 seconds as the standard, as does the Elm SDK. diff --git a/src/Matrix/Settings.elm b/src/Matrix/Settings.elm new file mode 100644 index 0000000..7703695 --- /dev/null +++ b/src/Matrix/Settings.elm @@ -0,0 +1,71 @@ +module Matrix.Settings exposing + ( getDeviceName, setDeviceName + , getSyncTime, setSyncTime + ) + +{-| The Matrix Vault has lots of configurable variables that you rarely want to +interact with. Usually, you configure these variables only when creating a new +Vault, or when a user explicitly changes one of their preferred settings. + + +## Device name + +The default device name that is being communicated with the Matrix API. + +This is mostly useful for users who are logged in with multiple sessions. They +will see device names like "Element for Android" or "Element on iOS". For the +Elm SDK, they will by default see the Elm SDK with its version included. If you +are writing a custom client, however, you are free to change this to something +more meaningful to the user. + +@docs getDeviceName, setDeviceName + + +## Sync time + +Whenever the Matrix API has nothing new to report, the Elm SDK is kept on +hold until something new happens. The `syncTime` indicates a timeout to how long +the Elm SDK tolerates being held on hold. + + - ↗️ A high value is good because it significantly reduces traffic between the + user and the homeserver. + - ↘️ A low value is good because it reduces the risk of + the connection ending abruptly or unexpectedly. + +Nowadays, most libraries use 30 seconds as the standard, as does the Elm SDK. +The value is in miliseconds, so it is set at 30,000. + +@docs getSyncTime, setSyncTime + +-} + +import Internal.Values.Envelope as Envelope +import Types exposing (Vault(..)) + + +{-| Determine the device name. +-} +getDeviceName : Vault -> String +getDeviceName (Vault vault) = + Envelope.extractSettings .deviceName vault + + +{-| Override the device name. +-} +setDeviceName : String -> Vault -> Vault +setDeviceName name (Vault vault) = + Vault <| Envelope.mapSettings (\s -> { s | deviceName = name }) vault + + +{-| Determine the sync timeout value. +-} +getSyncTime : Vault -> Int +getSyncTime (Vault vault) = + Envelope.extractSettings .syncTime vault + + +{-| Override the sync timeout value. +-} +setSyncTime : Int -> Vault -> Vault +setSyncTime time (Vault vault) = + Vault <| Envelope.mapSettings (\s -> { s | syncTime = time }) vault