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
7
8#include <QtCore/QUrl>
9#include <QtCore/QUrlQuery>
10
11namespace 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 */
26class QUOTIENT_API Uri : private QUrl {
29public:
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 };
41 enum SecondaryType : char { NoSecondaryId = 0x0, EventId = '$' };
43
44 enum UriForm : short { CanonicalUri, MatrixToUri };
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 */
57
58 /// Construct a Matrix URI from components
60 QString query = {});
61 /// Construct a Matrix URI from matrix.to or MSC2312 (matrix:) URI
62 explicit Uri(QUrl url);
63
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 */
81 Q_INVOKABLE bool isValid() const;
82 using QUrl::path, QUrl::query, QUrl::fragment;
84
85private:
87};
88
89}
A wrapper around a Matrix URI or identifier.
Definition uri.h:26
#define QUOTIENT_API