aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/filter.h
blob: 9518a461a98df16a031f86a6f44836c3fbc4fbf0 (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
/******************************************************************************
 * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
 */

#pragma once

#include "csapi/definitions/sync_filter.h"

#include "jobs/basejob.h"

namespace Quotient {

/*! \brief Upload a new filter.
 *
 * Uploads a new filter definition to the homeserver.
 * Returns a filter ID that may be used in future requests to
 * restrict which events are returned to the client.
 */
class QUOTIENT_API DefineFilterJob : public BaseJob {
public:
    /*! \brief Upload a new filter.
     *
     * \param userId
     *   The id of the user uploading the filter. The access token must be
     * authorized to make requests for this user id.
     *
     * \param filter
     *   The filter to upload.
     */
    explicit DefineFilterJob(const QString& userId, const Filter& filter);

    // Result properties

    /// The ID of the filter that was created. Cannot start
    /// with a `{` as this character is used to determine
    /// if the filter provided is inline JSON or a previously
    /// declared filter by homeservers on some APIs.
    QString filterId() const { return loadFromJson<QString>("filter_id"_ls); }
};

/*! \brief Download a filter
 *
 */
class QUOTIENT_API GetFilterJob : public BaseJob {
public:
    /*! \brief Download a filter
     *
     * \param userId
     *   The user ID to download a filter for.
     *
     * \param filterId
     *   The filter ID to download.
     */
    explicit GetFilterJob(const QString& userId, const QString& filterId);

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

    // Result properties

    /// The filter definition.
    Filter filter() const { return fromJson<Filter>(jsonData()); }
};

} // namespace Quotient