diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-05-05 19:36:15 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-05-05 19:36:15 +0900 |
commit | a8d2a73c771f188fc0fdc6351b4923af788317d5 (patch) | |
tree | b2795b93149f7c0ae3cd5005331b650a8eb6fd1e /lib/csapi/message_pagination.cpp | |
parent | da16225dfbec9b155c2c299757203f7676ac6ccf (diff) | |
parent | a63838235134b066c092ad98e1f18ff7991c91c1 (diff) | |
download | libquotient-a8d2a73c771f188fc0fdc6351b4923af788317d5.tar.gz libquotient-a8d2a73c771f188fc0fdc6351b4923af788317d5.zip |
Merge branch 'kitsune-gtad'
Diffstat (limited to 'lib/csapi/message_pagination.cpp')
-rw-r--r-- | lib/csapi/message_pagination.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/csapi/message_pagination.cpp b/lib/csapi/message_pagination.cpp new file mode 100644 index 00000000..f89ccd03 --- /dev/null +++ b/lib/csapi/message_pagination.cpp @@ -0,0 +1,76 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "message_pagination.h" + +#include "converters.h" + +#include <QtCore/QStringBuilder> + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +class GetRoomEventsJob::Private +{ + public: + QString begin; + QString end; + RoomEvents chunk; +}; + +BaseJob::Query queryToGetRoomEvents(const QString& from, const QString& to, const QString& dir, int limit, const QString& filter) +{ + BaseJob::Query _q; + _q.addQueryItem("from", from); + if (!to.isEmpty()) + _q.addQueryItem("to", to); + _q.addQueryItem("dir", dir); + _q.addQueryItem("limit", QString("%1").arg(limit)); + if (!filter.isEmpty()) + _q.addQueryItem("filter", filter); + return _q; +} + +QUrl GetRoomEventsJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& from, const QString& dir, const QString& to, int limit, const QString& filter) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/rooms/" % roomId % "/messages", + queryToGetRoomEvents(from, to, dir, limit, filter)); +} + +GetRoomEventsJob::GetRoomEventsJob(const QString& roomId, const QString& from, const QString& dir, const QString& to, int limit, const QString& filter) + : BaseJob(HttpVerb::Get, "GetRoomEventsJob", + basePath % "/rooms/" % roomId % "/messages", + queryToGetRoomEvents(from, to, dir, limit, filter)) + , d(new Private) +{ +} + +GetRoomEventsJob::~GetRoomEventsJob() = default; + +const QString& GetRoomEventsJob::begin() const +{ + return d->begin; +} + +const QString& GetRoomEventsJob::end() const +{ + return d->end; +} + +RoomEvents&& GetRoomEventsJob::chunk() +{ + return std::move(d->chunk); +} + +BaseJob::Status GetRoomEventsJob::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; +} + |