aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/peeking_events.cpp
blob: 53f2d280d75d32bb7970a64c470afd5c61067468 (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
/******************************************************************************
 * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
 */

#include "peeking_events.h"

#include "converters.h"

#include <QtCore/QStringBuilder>

using namespace QMatrixClient;

static const auto basePath = QStringLiteral("/_matrix/client/r0");

class PeekEventsJob::Private
{
    public:
        QString begin;
        QString end;
        RoomEvents chunk;
};

BaseJob::Query queryToPeekEvents(const QString& from, Omittable<int> timeout, const QString& roomId)
{
    BaseJob::Query _q;
    addToQuery<IfNotEmpty>(_q, "from", from);
    addToQuery<IfNotEmpty>(_q, "timeout", timeout);
    addToQuery<IfNotEmpty>(_q, "room_id", roomId);
    return _q;
}

QUrl PeekEventsJob::makeRequestUrl(QUrl baseUrl, const QString& from, Omittable<int> timeout, const QString& roomId)
{
    return BaseJob::makeRequestUrl(std::move(baseUrl),
            basePath % "/events",
            queryToPeekEvents(from, timeout, roomId));
}

PeekEventsJob::PeekEventsJob(const QString& from, Omittable<int> timeout, const QString& roomId)
    : BaseJob(HttpVerb::Get, "PeekEventsJob",
        basePath % "/events",
        queryToPeekEvents(from, timeout, roomId))
    , d(new Private)
{
}

PeekEventsJob::~PeekEventsJob() = default;

const QString& PeekEventsJob::begin() const
{
    return d->begin;
}

const QString& PeekEventsJob::end() const
{
    return d->end;
}

RoomEvents&& PeekEventsJob::chunk()
{
    return std::move(d->chunk);
}

BaseJob::Status PeekEventsJob::parseJson(const QJsonDocument& data)
{
    auto json = data.object();
    d->begin = fromJson<QString>(json.value("start"));
    d->end = fromJson<QString>(json.value("end"));
    d->chunk = fromJson<RoomEvents>(json.value("chunk"));
    return Success;
}