libQuotient
A Qt library for building matrix clients
Quotient::Uri Class Reference

A wrapper around a Matrix URI or identifier. More...

#include <uri.h>

Inheritance diagram for Quotient::Uri:
Collaboration diagram for Quotient::Uri:

Public Types

enum  Type : char {
  Invalid = char(-1) , Empty = 0x0 , UserId = '@' , RoomId = '!' ,
  RoomAlias = '#' , Group = '+' , BareEventId = '$' , NonMatrix = ':'
}
 
enum  SecondaryType : char { NoSecondaryId = 0x0 , EventId = '$' }
 
enum  UriForm : short { CanonicalUri , MatrixToUri }
 

Public Member Functions

 Uri ()=default
 Construct an empty Matrix URI. More...
 
 Uri (const QString &uriOrId)
 Decode a user input string to a Matrix identifier. More...
 
 Uri (QByteArray primaryId, QByteArray secondaryId={}, QString query={})
 Construct a Matrix URI from components. More...
 
 Uri (QUrl url)
 Construct a Matrix URI from matrix.to or MSC2312 (matrix:) URI. More...
 
Q_INVOKABLE Type type () const
 Get the primary type of the Matrix URI (user id, room id or alias) More...
 
Q_INVOKABLE SecondaryType secondaryType () const
 
Q_INVOKABLE QUrl toUrl (UriForm form=CanonicalUri) const
 
Q_INVOKABLE QString primaryId () const
 
Q_INVOKABLE QString secondaryId () const
 
Q_INVOKABLE QString action () const
 
Q_INVOKABLE void setAction (const QString &newAction)
 
Q_INVOKABLE QStringList viaServers () const
 
Q_INVOKABLE bool isValid () const
 

Static Public Member Functions

static Uri fromUserInput (const QString &uriOrId)
 
static Uri fromUrl (QUrl url)
 

Detailed Description

A wrapper around a Matrix URI or identifier.

This class encapsulates a Matrix resource identifier, passed in either of 3 forms: a plain Matrix identifier (sigil, localpart, serverpart or, for modern event ids, sigil and base64 hash); an MSC2312 URI (aka matrix: URI); or a matrix.to URL. The input can be either encoded (serverparts with punycode, the rest with percent-encoding) or unencoded (in this case it is the caller's responsibility to resolve all possible ambiguities).

The class provides functions to check the validity of the identifier, its type, and obtain components, also in either unencoded (for displaying) or encoded (for APIs) form.

Definition at line 26 of file uri.h.

Member Enumeration Documentation

◆ SecondaryType

Enumerator
NoSecondaryId 
EventId 

Definition at line 40 of file uri.h.

◆ Type

enum Quotient::Uri::Type : char
Enumerator
Invalid 
Empty 
UserId 
RoomId 
RoomAlias 
Group 
BareEventId 
NonMatrix 

Definition at line 29 of file uri.h.

◆ UriForm

enum Quotient::Uri::UriForm : short
Enumerator
CanonicalUri 
MatrixToUri 

Definition at line 43 of file uri.h.

Constructor & Destructor Documentation

◆ Uri() [1/4]

Quotient::Uri::Uri ( )
default

Construct an empty Matrix URI.

◆ Uri() [2/4]

Quotient::Uri::Uri ( const QString &  uriOrId)

Decode a user input string to a Matrix identifier.

Accepts plain Matrix ids, MSC2312 URIs (aka matrix: URIs) and matrix.to URLs. In case of URIs/URLs, it uses QUrl's TolerantMode parser to decode common mistakes/irregularities (see QUrl documentation for more details).

◆ Uri() [3/4]

Quotient::Uri::Uri ( QByteArray  primaryId,
QByteArray  secondaryId = {},
QString  query = {} 
)
explicit

Construct a Matrix URI from components.

◆ Uri() [4/4]

Quotient::Uri::Uri ( QUrl  url)
explicit

Construct a Matrix URI from matrix.to or MSC2312 (matrix:) URI.

Member Function Documentation

◆ action()

Q_INVOKABLE QString Quotient::Uri::action ( ) const

◆ fromUrl()

static Uri Quotient::Uri::fromUrl ( QUrl  url)
static

◆ fromUserInput()

static Uri Quotient::Uri::fromUserInput ( const QString &  uriOrId)
static

◆ isValid()

Q_INVOKABLE bool Quotient::Uri::isValid ( ) const

◆ primaryId()

Q_INVOKABLE QString Quotient::Uri::primaryId ( ) const

◆ secondaryId()

Q_INVOKABLE QString Quotient::Uri::secondaryId ( ) const

◆ secondaryType()

Q_INVOKABLE SecondaryType Quotient::Uri::secondaryType ( ) const

◆ setAction()

Q_INVOKABLE void Quotient::Uri::setAction ( const QString &  newAction)

◆ toUrl()

Q_INVOKABLE QUrl Quotient::Uri::toUrl ( UriForm  form = CanonicalUri) const

◆ type()

Q_INVOKABLE Type Quotient::Uri::type ( ) const

Get the primary type of the Matrix URI (user id, room id or alias)

Note that this does not include an event as a separate type, since events can only be addressed inside of rooms, which, in turn, are addressed either by id or alias. If you need to check whether the URI is specifically an event URI, use secondaryType() instead.

◆ viaServers()

Q_INVOKABLE QStringList Quotient::Uri::viaServers ( ) const

The documentation for this class was generated from the following file: