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

#include "event_context.h"

#include "converters.h"

#include <QtCore/QStringBuilder>

using namespace QMatrixClient;

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

class GetEventContextJob::Private
{
    public:
        QString begin;
        QString end;
        RoomEvents eventsBefore;
        RoomEventPtr event;
        RoomEvents eventsAfter;
        StateEvents state;
};

BaseJob::Query queryToGetEventContext(Omittable<int> limit)
{
    BaseJob::Query _q;
    addParam<IfNotEmpty>(_q, QStringLiteral("limit"), limit);
    return _q;
}

QUrl GetEventContextJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& eventId, Omittable<int> limit)
{
    return BaseJob::makeRequestUrl(std::move(baseUrl),
            basePath % "/rooms/" % roomId % "/context/" % eventId,
            queryToGetEventContext(limit));
}

static const auto GetEventContextJobName = QStringLiteral("GetEventContextJob");

GetEventContextJob::GetEventContextJob(const QString& roomId, const QString& eventId, Omittable<int> limit)
    : BaseJob(HttpVerb::Get, GetEventContextJobName,
        basePath % "/rooms/" % roomId % "/context/" % eventId,
        queryToGetEventContext(limit))
    , d(new Private)
{
}

GetEventContextJob::~GetEventContextJob() = default;

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

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

RoomEvents&& GetEventContextJob::eventsBefore()
{
    return std::move(d->eventsBefore);
}

RoomEventPtr&& GetEventContextJob::event()
{
    return std::move(d->event);
}

RoomEvents&& GetEventContextJob::eventsAfter()
{
    return std::move(d->eventsAfter);
}

StateEvents&& GetEventContextJob::state()
{
    return std::move(d->state);
}

BaseJob::Status GetEventContextJob::parseJson(const QJsonDocument& data)
{
    auto json = data.object();
    fromJson(json.value("start"_ls), d->begin);
    fromJson(json.value("end"_ls), d->end);
    fromJson(json.value("events_before"_ls), d->eventsBefore);
    fromJson(json.value("event"_ls), d->event);
    fromJson(json.value("events_after"_ls), d->eventsAfter);
    fromJson(json.value("state"_ls), d->state);
    return Success;
}