Compare commits
No commits in common. "7c7e05d42a9fbf582538cefe16239cfdcd78c2bd" and "a53fca33266b67a344d9328b8cda2430f9ecd827" have entirely different histories.
7c7e05d42a
...
a53fca3326
4
elm.json
4
elm.json
|
@ -6,18 +6,14 @@
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"exposed-modules": [
|
"exposed-modules": [
|
||||||
"Matrix",
|
"Matrix",
|
||||||
"Internal.Config.Default",
|
|
||||||
"Internal.Config.Text",
|
|
||||||
"Internal.Tools.Hashdict",
|
"Internal.Tools.Hashdict",
|
||||||
"Internal.Tools.Iddict",
|
"Internal.Tools.Iddict",
|
||||||
"Internal.Tools.Timestamp",
|
|
||||||
"Internal.Tools.VersionControl"
|
"Internal.Tools.VersionControl"
|
||||||
],
|
],
|
||||||
"elm-version": "0.19.0 <= v < 0.20.0",
|
"elm-version": "0.19.0 <= v < 0.20.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"elm/core": "1.0.0 <= v < 2.0.0",
|
"elm/core": "1.0.0 <= v < 2.0.0",
|
||||||
"elm/json": "1.0.0 <= v < 2.0.0",
|
"elm/json": "1.0.0 <= v < 2.0.0",
|
||||||
"elm/time": "1.0.0 <= v < 2.0.0",
|
|
||||||
"miniBill/elm-fast-dict": "1.0.0 <= v < 2.0.0"
|
"miniBill/elm-fast-dict": "1.0.0 <= v < 2.0.0"
|
||||||
},
|
},
|
||||||
"test-dependencies": {}
|
"test-dependencies": {}
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
module Internal.Config.Default exposing
|
|
||||||
( currentVersion, deviceName
|
|
||||||
, syncTime
|
|
||||||
)
|
|
||||||
|
|
||||||
{-| This module hosts all default settings and configurations that the Vault
|
|
||||||
will assume until overriden by the user.
|
|
||||||
|
|
||||||
|
|
||||||
## Version management
|
|
||||||
|
|
||||||
@docs currentVersion, deviceName
|
|
||||||
|
|
||||||
|
|
||||||
## Communication config
|
|
||||||
|
|
||||||
@docs syncTime
|
|
||||||
|
|
||||||
-}
|
|
||||||
|
|
||||||
|
|
||||||
{-| The version that is being communicated to the user
|
|
||||||
-}
|
|
||||||
currentVersion : String
|
|
||||||
currentVersion =
|
|
||||||
"beta 1.0.0"
|
|
||||||
|
|
||||||
|
|
||||||
{-| 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.
|
|
||||||
|
|
||||||
-}
|
|
||||||
deviceName : String
|
|
||||||
deviceName =
|
|
||||||
"Elm SDK (" ++ currentVersion ++ ")"
|
|
||||||
|
|
||||||
|
|
||||||
{-| 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 refuces 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.
|
|
||||||
|
|
||||||
-}
|
|
||||||
syncTime : Int
|
|
||||||
syncTime =
|
|
||||||
30 * 1000
|
|
|
@ -1,108 +0,0 @@
|
||||||
module Internal.Config.Text exposing
|
|
||||||
( versionsFoundLocally, versionsReceived, versionsFailedToDecode
|
|
||||||
, accessTokenFoundLocally, accessTokenExpired, accessTokenInvalid
|
|
||||||
, unsupportedVersionForEndpoint
|
|
||||||
)
|
|
||||||
|
|
||||||
{-| Throughout the Elm SDK, there are lots of pieces of text being used for
|
|
||||||
various purposes. Some of these are:
|
|
||||||
|
|
||||||
- To log on what is happening during an API call.
|
|
||||||
- To fail with custom decoder errors.
|
|
||||||
- To describe custom values in a human readable format.
|
|
||||||
|
|
||||||
All magic values of text are gathered in this module, to form a monolithic
|
|
||||||
source of text. This allows people to learn more about the Elm SDK, and it
|
|
||||||
|
|
||||||
|
|
||||||
## API Versions
|
|
||||||
|
|
||||||
Messages sent as API logs while the Elm SDK is figuring out how modern the
|
|
||||||
homeserver is and how it can best communicate.
|
|
||||||
|
|
||||||
@docs versionsFoundLocally, versionsReceived, versionsFailedToDecode
|
|
||||||
|
|
||||||
|
|
||||||
## API Authentication
|
|
||||||
|
|
||||||
Messages sent as API logs during the authentication phase of the API
|
|
||||||
interaction.
|
|
||||||
|
|
||||||
@docs accessTokenFoundLocally, accessTokenExpired, accessTokenInvalid
|
|
||||||
|
|
||||||
offers room for translation, re-wording and refactors.
|
|
||||||
|
|
||||||
|
|
||||||
## API miscellaneous messages
|
|
||||||
|
|
||||||
Messages sent as API logs during communication with the API.
|
|
||||||
|
|
||||||
@docs unsupportedVersionForEndpoint
|
|
||||||
|
|
||||||
-}
|
|
||||||
|
|
||||||
|
|
||||||
{-| Logs when the Matrix API returns that an access token is no longer valid.
|
|
||||||
-}
|
|
||||||
accessTokenExpired : String
|
|
||||||
accessTokenExpired =
|
|
||||||
"Matrix API reports access token as no longer valid"
|
|
||||||
|
|
||||||
|
|
||||||
{-| Logs when the Vault has an access token that is still (locally) considered
|
|
||||||
valid.
|
|
||||||
-}
|
|
||||||
accessTokenFoundLocally : String
|
|
||||||
accessTokenFoundLocally =
|
|
||||||
"Found locally cached access token"
|
|
||||||
|
|
||||||
|
|
||||||
{-| Logs when the Matrix API rejects an access token without explicitly
|
|
||||||
mentioning a reason.
|
|
||||||
-}
|
|
||||||
accessTokenInvalid : String
|
|
||||||
accessTokenInvalid =
|
|
||||||
"Matrix API rejected access token as invalid"
|
|
||||||
|
|
||||||
|
|
||||||
{-| The Matrix homeserver can specify how it wishes to communicate, and the Elm
|
|
||||||
SDK aims to communicate accordingly. This may fail in some scenarios, however,
|
|
||||||
in which case it will throw this error.
|
|
||||||
|
|
||||||
Most of the time, the error is caused by one of two options:
|
|
||||||
|
|
||||||
1. The homeserver is very archaic and does not (yet) support API endpoints that
|
|
||||||
are nowadays considered mature.
|
|
||||||
|
|
||||||
2. The homeserver is much more modern than the Elm SDK and either uses
|
|
||||||
exclusively API endpoints that the Elm SDK doesn't (yet) support, or it uses
|
|
||||||
spec versions that aren't considered "official" Matrix spec versions and
|
|
||||||
were designed by a third party.
|
|
||||||
|
|
||||||
-}
|
|
||||||
unsupportedVersionForEndpoint : String
|
|
||||||
unsupportedVersionForEndpoint =
|
|
||||||
"This Matrix homeserver and the Elm SDK do not share a common spec version for this endpoint"
|
|
||||||
|
|
||||||
|
|
||||||
{-| Occasionally, the Matrix homeserver fails to communicate how it is best
|
|
||||||
communicated with. Most of the time, this means that the homeserver is somehow
|
|
||||||
unreachable or some gateway error has occured.
|
|
||||||
-}
|
|
||||||
versionsFailedToDecode : String
|
|
||||||
versionsFailedToDecode =
|
|
||||||
"Matrix API returned an invalid version list"
|
|
||||||
|
|
||||||
|
|
||||||
{-| Logs when the Vault remembers how to communicate with the Matrix homeserver
|
|
||||||
-}
|
|
||||||
versionsFoundLocally : String
|
|
||||||
versionsFoundLocally =
|
|
||||||
"Found locally cached version list"
|
|
||||||
|
|
||||||
|
|
||||||
{-| Logs when the Matrix API has returned how to best communicate with them
|
|
||||||
-}
|
|
||||||
versionsReceived : String
|
|
||||||
versionsReceived =
|
|
||||||
"Matrix API returned a version list"
|
|
|
@ -1,43 +0,0 @@
|
||||||
module Internal.Tools.Timestamp exposing
|
|
||||||
( Timestamp
|
|
||||||
, encode, decoder
|
|
||||||
)
|
|
||||||
|
|
||||||
{-| The Timestamp module is a simplification of the Timetsamp as delivered by
|
|
||||||
elm/time. This module offers ways to work with the timestamp in meaningful ways.
|
|
||||||
|
|
||||||
|
|
||||||
## Timetstamp
|
|
||||||
|
|
||||||
@docs Timestamp
|
|
||||||
|
|
||||||
|
|
||||||
## JSON coders
|
|
||||||
|
|
||||||
@docs encode, decoder
|
|
||||||
|
|
||||||
-}
|
|
||||||
|
|
||||||
import Json.Decode as D
|
|
||||||
import Json.Encode as E
|
|
||||||
import Time
|
|
||||||
|
|
||||||
|
|
||||||
{-| The Timetstamp data type representing a moment in time.
|
|
||||||
-}
|
|
||||||
type alias Timestamp =
|
|
||||||
Time.Posix
|
|
||||||
|
|
||||||
|
|
||||||
{-| Encode a timestamp into a JSON value.
|
|
||||||
-}
|
|
||||||
encode : Timestamp -> E.Value
|
|
||||||
encode =
|
|
||||||
Time.posixToMillis >> E.int
|
|
||||||
|
|
||||||
|
|
||||||
{-| Decode a timestamp from a JSON value.
|
|
||||||
-}
|
|
||||||
decoder : D.Decoder Timestamp
|
|
||||||
decoder =
|
|
||||||
D.map Time.millisToPosix D.int
|
|
Loading…
Reference in New Issue