libQuotient
A Qt library for building matrix clients
Loading...
Searching...
No Matches
uri.h
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: 2020 Kitsune Ral <kitsune-ral@users.sf.net>
2
// SPDX-License-Identifier: LGPL-2.1-or-later
3
4
#
pragma
once
5
6
#
include
"quotient_common.h"
7
8
#
include
<
QtCore
/
QUrl
>
9
#
include
<
QtCore
/
QUrlQuery
>
10
11
namespace
Quotient
{
12
13
/*! \brief A wrapper around a Matrix URI or identifier
14
*
15
* This class encapsulates a Matrix resource identifier, passed in either of
16
* 3 forms: a plain Matrix identifier (sigil, localpart, serverpart or, for
17
* modern event ids, sigil and base64 hash); an MSC2312 URI (aka matrix: URI);
18
* or a matrix.to URL. The input can be either encoded (serverparts with
19
* punycode, the rest with percent-encoding) or unencoded (in this case it is
20
* the caller's responsibility to resolve all possible ambiguities).
21
*
22
* The class provides functions to check the validity of the identifier,
23
* its type, and obtain components, also in either unencoded (for displaying)
24
* or encoded (for APIs) form.
25
*/
26
class
QUOTIENT_API
Uri
:
private
QUrl
{
27
Q_GADGET
28
QML_ELEMENT
29
public
:
30
enum
Type
:
char
{
31
Invalid
=
char
(-1),
32
Empty
= 0x0,
33
UserId
=
'@'
,
34
RoomId
=
'!'
,
35
RoomAlias
=
'#'
,
36
Group
=
'+'
,
37
BareEventId
=
'$'
,
// https://github.com/matrix-org/matrix-doc/pull/2644
38
NonMatrix
=
':'
39
};
40
Q_ENUM
(
Type
)
41
enum
SecondaryType
:
char
{
NoSecondaryId
= 0x0,
EventId
=
'$'
};
42
Q_ENUM
(
SecondaryType
)
43
44
enum
UriForm
:
short
{
CanonicalUri
,
MatrixToUri
};
45
Q_ENUM
(
UriForm
)
46
47
/// Construct an empty Matrix URI
48
Uri
() =
default
;
49
/*! \brief Decode a user input string to a Matrix identifier
50
*
51
* Accepts plain Matrix ids, MSC2312 URIs (aka matrix: URIs) and
52
* matrix.to URLs. In case of URIs/URLs, it uses QUrl's TolerantMode
53
* parser to decode common mistakes/irregularities (see QUrl documentation
54
* for more details).
55
*/
56
Uri
(
const
QString
&
uriOrId
);
57
58
/// Construct a Matrix URI from components
59
explicit
Uri
(
QByteArray
primaryId
,
QByteArray
secondaryId
= {},
60
QString
query
= {});
61
/// Construct a Matrix URI from matrix.to or MSC2312 (matrix:) URI
62
explicit
Uri
(
QUrl
url
);
63
64
static
Uri
fromUserInput
(
const
QString
&
uriOrId
);
65
static
Uri
fromUrl
(
QUrl
url
);
66
67
/// Get the primary type of the Matrix URI (user id, room id or alias)
68
/*! Note that this does not include an event as a separate type, since
69
* events can only be addressed inside of rooms, which, in turn, are
70
* addressed either by id or alias. If you need to check whether the URI
71
* is specifically an event URI, use secondaryType() instead.
72
*/
73
Q_INVOKABLE
Type
type
()
const
;
74
Q_INVOKABLE
SecondaryType
secondaryType
()
const
;
75
Q_INVOKABLE
QUrl
toUrl
(
UriForm
form
=
CanonicalUri
)
const
;
76
Q_INVOKABLE
QString
primaryId
()
const
;
77
Q_INVOKABLE
QString
secondaryId
()
const
;
78
Q_INVOKABLE
QString
action
()
const
;
79
Q_INVOKABLE
void
setAction
(
const
QString
&
newAction
);
80
Q_INVOKABLE
QStringList
viaServers
()
const
;
81
Q_INVOKABLE
bool
isValid
()
const
;
82
using
QUrl
::
path
,
QUrl
::
query
,
QUrl
::
fragment
;
83
using
QUrl
::
isEmpty
,
QUrl
::
toDisplayString
;
84
85
private
:
86
Type
primaryType_
=
Empty
;
87
};
88
89
}
Quotient::Uri
A wrapper around a Matrix URI or identifier.
Definition
uri.h:26
Quotient
Definition
accountregistry.h:13
QUOTIENT_API
#define QUOTIENT_API
Definition
quotient_export.h:22
Quotient
uri.h
Generated by
1.9.8