Matrix users are identified by their unique ID. In the Matrix API, this is a string that looks as follows:
Types.User
The User type represents a Matrix user.
It contains information like:
It does NOT contain information like:
You can get all that information by looking it up in the Vault.
Note: Please do not store this user type as a variable in your model! You should always maintain a single source of truth in Elm, and the User type contains various credentials and API tokens that might expire if you don't update them from the Vault.
If you need to remember specific users, you can best compare their identifying string using toString or you can use get with the Vault to get the user type.
toString : User -> String
Get the uniquely identifying string for this user. Since the strings are case-sensitive, you can run a simple string comparison to compare usernames.
Sometimes, you are more interested in the username itself. These functions can help you decipher, disambiguate and categorize users based on their username.
localpart : User -> String
The localpart is the user's unique username. Every homeserver has their own username registry, so you might occasionally find distinct users with the same localpart.
The localpart is often used as a user's name in a room if they haven't set up a custom name.
See the following examples:
localpart (get vault "@alice:example.org") -- "alice"
localpart (get vault "@bob:127.0.0.1") -- "bob"
localpart (get vault "@charlie:[2001:db8::]") -- "charlie"
domain : User -> String
The domain is the name of the server that the user connects to. Server names are case-sensitive, so if the strings are equal, the users are on the same server!
As a result, you can use the user domain for:
See the following examples:
domain (get vault "@alice:example.org") -- "example.org"
domain (get vault "@bob:127.0.0.1") -- "127.0.0.1"
domain (get vault "@charlie:[2001:db8::]") -- "[2001:db8::]"
get : Types.Vault -> String -> Maybe User
Get a specific user by their unique identifier.
The Vault is needed as an input because the User
type also stores various
credentials needed to talk to the Matrix API.
get vault "@alice:example.org" -- Just (User "alice" "example.org")
get vault "@bob:127.0.0.1" -- Just (User "bob" "127.0.0.1")
get vault "@charlie:[2001:db8::]" -- Just (User "charlie" "2001:db8::")
get vault "@evil:#mp#ss#bl#.c#m" -- Nothing
get vault "" -- Nothing