noordstar/elm-matrix-sdk-beta/3.6.0

NOTE: the latest version is 3.6.1

Matrix

Matrix SDK

This library forms a mere basis from which an entire functional SDK is developed for the Matrix protocol.

It is generally quite unusual to regularly publish iterative beta versions on the public registry, but it is also generally quite unusual to exclusively support a monolithic public registry. (:

Vault

type alias Vault =
Vault

The Vault type stores all relevant information about the Matrix API.

If you make sure that the data type stays up-to-date, you can use it to explore the latest information about an account.

fromUserId : String -> Maybe Vault

Use a fully-fledged Matrix ID to connect.

case Matrix.fromUserId "@alice:example.org" of
    Just vault ->
        "We got a vault!"


    Nothing ->
        "Invalid username"
{ username : String
, host : String
, port_ : Maybe Int
}
-> Vault

Using a username and an address, create a Vault.

The username can either be the localpart or the full Matrix ID. For example, you can either insert alice or @alice:example.org.

Keeping the Vault up-to-date

type alias VaultUpdate =
VaultUpdate

The VaultUpdate type is the central type that keeps the Vault up-to-date.

update : VaultUpdate -> Vault -> Vault

Using new VaultUpdate information, update the Vault accordingly.

This allows us to change our perception of the Matrix environment: has anyone sent a new message? Did someone send us an invite for a new room?

sync : (VaultUpdate -> msg) -> Vault -> Cmd msg

Synchronize the Vault with the Matrix API.

Effectively, this task asks the Matrix API to provide the latest information, which will be returned as your VaultUpdate.

VaultUpdate
-> List
{ channel : String
, content : String
}

The VaultUpdate is a complex type that helps update the Vault. However, it also contains a human output!

Using this function, you can get a human output that describes everything that the VaultUpdate has to tell the Vault.

The channel field describes the context of the log, allowing you to filter further. For example:

  • debug is a comprehensive channel describing everything the Elm runtime has executed.
  • warn contains warnings that aren't breaking, but relevant.
  • securityWarn warns about potential security issues or potential attacks.
  • error has errors that were encountered.
  • caughtError has errors that were dealt with successfully.

Exploring the Vault

rooms : Vault -> List Room

Get a list of all the rooms that the user has joined.

fromRoomId : String -> Vault -> Maybe Room

Get a room based on its room ID, if the user is a member of that room.

invites : Vault -> List Invite

Get a list of all invites that the user has received.

fromInviteId : String -> Vault -> Maybe Invite

Get a specific invite to a given room Id.

Account data

getAccountData : String -> Vault -> Maybe Value

Get global account data.

{ content : Value
, eventType : String
, room : Vault
, toMsg : VaultUpdate -> msg
}
-> Cmd msg

Set global account data.

Debugging

addAccessToken : String -> Vault -> Vault

Adds a custom access token to the Vault. This can be done if no password is provided or known.

{ reason : Maybe String
, roomId : String
, toMsg : VaultUpdate -> msg
, vault : Vault
}
-> Cmd msg

Leave a room. This stops a user from participating in a room.

If the user was already in the room, they will no longer be able to see new events in the room. If the room requires an invite to join, they will need to be re-invited before they can re-join.

If the user was invited to the room, but had not joined, this call serves to reject the invite.

The user will still be allowed to retrieve history from the room which they were previously allowed to see.

{ content : Value
, eventType : String
, roomId : String
, toMsg : VaultUpdate -> msg
, transactionId : String
, vault : Vault
}
-> Cmd msg

Send a message event to a room.

This function can be used in a scenario where the user does not want to sync the client, or is unable to. This function doesn't check whether the given room exists and the user is able to send a message to, and instead just sends the request to the Matrix API.

The fields stand for the following:

  • content is the JSON object that is sent to the Matrix room.
  • eventType is the event type that is sent to the Matrix room.
  • roomId is the Matrix room ID.
  • toMsg is the msg type that is returned after the message has been sent.
  • transactionId is a unique identifier that helps the Matrix server distringuish messages. If you send the same message with the same transactionId, the server promises to register it only once.
  • vault is the Matrix Vault that contains all the latest and most relevant information.
whoAmI : (VaultUpdate -> msg) -> Vault -> Cmd msg

Get personal information about the vault, such as the user id, the device id or other vital information.

When the vault logs in, it will automatically know this information. However, if you plug in an access token, the vault might not know. If you wish to ensure that such information is available, you can use this function to download that information.