| 1 | // SPDX-FileCopyrightText: 2016 Kitsune Ral <Kitsune-Ral@users.sf.net> |
| 2 | // SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 | |
| 4 | #include "syncjob.h" |
| 5 | |
| 6 | #include "../logging_categories_p.h" |
| 7 | |
| 8 | using namespace Quotient; |
| 9 | |
| 10 | static size_t jobId = 0; |
| 11 | |
| 12 | SyncJob::SyncJob(const QString& since, const QString& filter, int timeout, |
| 13 | const QString& presence) |
| 14 | : BaseJob(HttpVerb::Get, QStringLiteral("SyncJob-%1" ).arg(a: ++jobId), |
| 15 | "_matrix/client/r0/sync" ) |
| 16 | { |
| 17 | setLoggingCategory(SYNCJOB); |
| 18 | QUrlQuery query; |
| 19 | addParam<IfNotEmpty>(container&: query, QStringLiteral("filter" ), value: filter); |
| 20 | addParam<IfNotEmpty>(container&: query, QStringLiteral("set_presence" ), value: presence); |
| 21 | if (timeout >= 0) |
| 22 | query.addQueryItem(QStringLiteral("timeout" ), value: QString::number(timeout)); |
| 23 | addParam<IfNotEmpty>(container&: query, QStringLiteral("since" ), value: since); |
| 24 | setRequestQuery(query); |
| 25 | |
| 26 | setMaxRetries(std::numeric_limits<int>::max()); |
| 27 | } |
| 28 | |
| 29 | SyncJob::SyncJob(const QString& since, const Filter& filter, int timeout, |
| 30 | const QString& presence) |
| 31 | : SyncJob(since, |
| 32 | QString::fromUtf8(ba: QJsonDocument(toJson(pod: filter)).toJson(format: QJsonDocument::Compact)), |
| 33 | timeout, presence) |
| 34 | {} |
| 35 | |
| 36 | BaseJob::Status SyncJob::prepareResult() |
| 37 | { |
| 38 | d.parseJson(json: jsonData()); |
| 39 | if (Q_LIKELY(d.unresolvedRooms().isEmpty())) |
| 40 | return Success; |
| 41 | |
| 42 | Q_ASSERT(d.unresolvedRooms().isEmpty()); |
| 43 | qCCritical(MAIN).noquote() << "Rooms missing after processing sync " |
| 44 | "response, possibly a bug in SyncData: " |
| 45 | << d.unresolvedRooms().join(sep: u','); |
| 46 | return IncorrectResponse; |
| 47 | } |
| 48 | |