aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/list_public_rooms.h
blob: 701a74f6c31a26a9ee7385ab3ba7855fa604e41b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/******************************************************************************
 * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
 */

#pragma once

#include "csapi/definitions/public_rooms_chunk.h"

#include "jobs/basejob.h"

namespace Quotient {

/*! \brief Gets the visibility of a room in the directory
 *
 * Gets the visibility of a given room on the server's public room directory.
 */
class QUOTIENT_API GetRoomVisibilityOnDirectoryJob : public BaseJob {
public:
    /*! \brief Gets the visibility of a room in the directory
     *
     * \param roomId
     *   The room ID.
     */
    explicit GetRoomVisibilityOnDirectoryJob(const QString& roomId);

    /*! \brief Construct a URL without creating a full-fledged job object
     *
     * This function can be used when a URL for GetRoomVisibilityOnDirectoryJob
     * is necessary but the job itself isn't.
     */
    static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId);

    // Result properties

    /// The visibility of the room in the directory.
    QString visibility() const
    {
        return loadFromJson<QString>("visibility"_ls);
    }
};

/*! \brief Sets the visibility of a room in the room directory
 *
 * Sets the visibility of a given room in the server's public room
 * directory.
 *
 * Servers may choose to implement additional access control checks
 * here, for instance that room visibility can only be changed by
 * the room creator or a server administrator.
 */
class QUOTIENT_API SetRoomVisibilityOnDirectoryJob : public BaseJob {
public:
    /*! \brief Sets the visibility of a room in the room directory
     *
     * \param roomId
     *   The room ID.
     *
     * \param visibility
     *   The new visibility setting for the room.
     *   Defaults to 'public'.
     */
    explicit SetRoomVisibilityOnDirectoryJob(const QString& roomId,
                                             const QString& visibility = {});
};

/*! \brief Lists the public rooms on the server.
 *
 * Lists the public rooms on the server.
 *
 * This API returns paginated responses. The rooms are ordered by the number
 * of joined members, with the largest rooms first.
 */
class QUOTIENT_API GetPublicRoomsJob : public BaseJob {
public:
    /*! \brief Lists the public rooms on the server.
     *
     * \param limit
     *   Limit the number of results returned.
     *
     * \param since
     *   A pagination token from a previous request, allowing clients to
     *   get the next (or previous) batch of rooms.
     *   The direction of pagination is specified solely by which token
     *   is supplied, rather than via an explicit flag.
     *
     * \param server
     *   The server to fetch the public room lists from. Defaults to the
     *   local server.
     */
    explicit GetPublicRoomsJob(Omittable<int> limit = none,
                               const QString& since = {},
                               const QString& server = {});

    /*! \brief Construct a URL without creating a full-fledged job object
     *
     * This function can be used when a URL for GetPublicRoomsJob
     * is necessary but the job itself isn't.
     */
    static QUrl makeRequestUrl(QUrl baseUrl, Omittable<int> limit = none,
                               const QString& since = {},
                               const QString& server = {});

    // Result properties

    /// A paginated chunk of public rooms.
    QVector<QJsonObject> chunk() const
    {
        return loadFromJson<QVector<QJsonObject>>("chunk"_ls);
    }

    /// A pagination token for the response. The absence of this token
    /// means there are no more results to fetch and the client should
    /// stop paginating.
    QString nextBatch() const { return loadFromJson<QString>("next_batch"_ls); }

    /// A pagination token that allows fetching previous results. The
    /// absence of this token means there are no results before this
    /// batch, i.e. this is the first batch.
    QString prevBatch() const { return loadFromJson<QString>("prev_batch"_ls); }

    /// An estimate on the total number of public rooms, if the
    /// server has an estimate.
    Omittable<int> totalRoomCountEstimate() const
    {
        return loadFromJson<Omittable<int>>("total_room_count_estimate"_ls);
    }
};

/*! \brief Lists the public rooms on the server with optional filter.
 *
 * Lists the public rooms on the server, with optional filter.
 *
 * This API returns paginated responses. The rooms are ordered by the number
 * of joined members, with the largest rooms first.
 */
class QUOTIENT_API QueryPublicRoomsJob : public BaseJob {
public:
    // Inner data structures

    /// Filter to apply to the results.
    struct Filter {
        /// A string to search for in the room metadata, e.g. name,
        /// topic, canonical alias etc. (Optional).
        QString genericSearchTerm;
    };

    // Construction/destruction

    /*! \brief Lists the public rooms on the server with optional filter.
     *
     * \param server
     *   The server to fetch the public room lists from. Defaults to the
     *   local server.
     *
     * \param limit
     *   Limit the number of results returned.
     *
     * \param since
     *   A pagination token from a previous request, allowing clients
     *   to get the next (or previous) batch of rooms.  The direction
     *   of pagination is specified solely by which token is supplied,
     *   rather than via an explicit flag.
     *
     * \param filter
     *   Filter to apply to the results.
     *
     * \param includeAllNetworks
     *   Whether or not to include all known networks/protocols from
     *   application services on the homeserver. Defaults to false.
     *
     * \param thirdPartyInstanceId
     *   The specific third party network/protocol to request from the
     *   homeserver. Can only be used if `include_all_networks` is false.
     */
    explicit QueryPublicRoomsJob(const QString& server = {},
                                 Omittable<int> limit = none,
                                 const QString& since = {},
                                 const Omittable<Filter>& filter = none,
                                 Omittable<bool> includeAllNetworks = none,
                                 const QString& thirdPartyInstanceId = {});

    // Result properties

    /// A paginated chunk of public rooms.
    QVector<QJsonObject> chunk() const
    {
        return loadFromJson<QVector<QJsonObject>>("chunk"_ls);
    }

    /// A pagination token for the response. The absence of this token
    /// means there are no more results to fetch and the client should
    /// stop paginating.
    QString nextBatch() const { return loadFromJson<QString>("next_batch"_ls); }

    /// A pagination token that allows fetching previous results. The
    /// absence of this token means there are no results before this
    /// batch, i.e. this is the first batch.
    QString prevBatch() const { return loadFromJson<QString>("prev_batch"_ls); }

    /// An estimate on the total number of public rooms, if the
    /// server has an estimate.
    Omittable<int> totalRoomCountEstimate() const
    {
        return loadFromJson<Omittable<int>>("total_room_count_estimate"_ls);
    }
};

template <>
struct JsonObjectConverter<QueryPublicRoomsJob::Filter> {
    static void dumpTo(QJsonObject& jo, const QueryPublicRoomsJob::Filter& pod)
    {
        addParam<IfNotEmpty>(jo, QStringLiteral("generic_search_term"),
                             pod.genericSearchTerm);
    }
};

} // namespace Quotient