aboutsummaryrefslogtreecommitdiff
path: root/jobs
diff options
context:
space:
mode:
Diffstat (limited to 'jobs')
-rw-r--r--jobs/basejob.cpp170
-rw-r--r--jobs/basejob.h151
-rw-r--r--jobs/checkauthmethods.cpp3
-rw-r--r--jobs/checkauthmethods.h3
-rw-r--r--jobs/joinroomjob.cpp15
-rw-r--r--jobs/joinroomjob.h2
-rw-r--r--jobs/logoutjob.cpp35
-rw-r--r--jobs/logoutjob.h34
-rw-r--r--jobs/mediathumbnailjob.cpp14
-rw-r--r--jobs/mediathumbnailjob.h4
-rw-r--r--jobs/passwordlogin.cpp6
-rw-r--r--jobs/passwordlogin.h3
-rw-r--r--jobs/postmessagejob.cpp15
-rw-r--r--jobs/postmessagejob.h3
-rw-r--r--jobs/postreceiptjob.h1
-rw-r--r--jobs/roommembersjob.cpp8
-rw-r--r--jobs/roommembersjob.h4
-rw-r--r--jobs/roommessagesjob.cpp4
-rw-r--r--jobs/roommessagesjob.h3
-rw-r--r--jobs/syncjob.cpp8
-rw-r--r--jobs/syncjob.h5
21 files changed, 358 insertions, 133 deletions
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp
index 50c85048..e0dff287 100644
--- a/jobs/basejob.cpp
+++ b/jobs/basejob.cpp
@@ -19,48 +19,56 @@
#include "basejob.h"
#include <QtNetwork/QNetworkAccessManager>
-#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>
+#include <QtNetwork/QNetworkReply>
+#include <QtNetwork/QSslError>
#include <QtCore/QTimer>
#include "../connectiondata.h"
using namespace QMatrixClient;
+struct NetworkReplyDeleter : public QScopedPointerDeleteLater
+{
+ static inline void cleanup(QNetworkReply* reply)
+ {
+ if (reply && reply->isRunning())
+ reply->abort();
+ QScopedPointerDeleteLater::cleanup(reply);
+ }
+};
+
class BaseJob::Private
{
public:
Private(ConnectionData* c, JobHttpType t, bool nt)
- : connection(c), reply(nullptr), type(t), needsToken(nt) {}
+ : connection(c), type(t), needsToken(nt)
+ , reply(nullptr), status(NoError)
+ {}
ConnectionData* connection;
- QNetworkReply* reply;
JobHttpType type;
bool needsToken;
+
+ QScopedPointer<QNetworkReply, NetworkReplyDeleter> reply;
+ Status status;
};
+inline QDebug operator<<(QDebug dbg, BaseJob* j)
+{
+ return dbg << "Job" << j->objectName();
+}
+
BaseJob::BaseJob(ConnectionData* connection, JobHttpType type, QString name, bool needsToken)
: d(new Private(connection, type, needsToken))
{
- // Work around KJob inability to separate success and failure signals
- connect(this, &BaseJob::result, [this]() {
- if (error() == NoError)
- emit success(this);
- else
- emit failure(this);
- });
setObjectName(name);
+ qDebug() << this << "created";
}
BaseJob::~BaseJob()
{
- if( d->reply )
- {
- if( d->reply->isRunning() )
- d->reply->abort();
- d->reply->deleteLater();
- }
- delete d;
+ qDebug() << this << "destroyed";
}
ConnectionData* BaseJob::connection() const
@@ -78,10 +86,6 @@ QUrlQuery BaseJob::query() const
return QUrlQuery();
}
-void BaseJob::parseJson(const QJsonDocument& data)
-{
-}
-
void BaseJob::start()
{
QUrl url = d->connection->baseUrl();
@@ -100,63 +104,127 @@ void BaseJob::start()
switch( d->type )
{
case JobHttpType::GetJob:
- d->reply = d->connection->nam()->get(req);
+ d->reply.reset( d->connection->nam()->get(req) );
break;
case JobHttpType::PostJob:
- d->reply = d->connection->nam()->post(req, data.toJson());
+ d->reply.reset( d->connection->nam()->post(req, data.toJson()) );
break;
case JobHttpType::PutJob:
- d->reply = d->connection->nam()->put(req, data.toJson());
+ d->reply.reset( d->connection->nam()->put(req, data.toJson()) );
break;
}
- connect( d->reply, &QNetworkReply::sslErrors, this, &BaseJob::sslErrors );
- connect( d->reply, &QNetworkReply::finished, this, &BaseJob::gotReply );
+ connect( d->reply.data(), &QNetworkReply::sslErrors, this, &BaseJob::sslErrors );
+ connect( d->reply.data(), &QNetworkReply::finished, this, &BaseJob::gotReply );
QTimer::singleShot( 120*1000, this, SLOT(timeout()) );
// connect( d->reply, static_cast<void(QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error),
// this, &BaseJob::networkError ); // http://doc.qt.io/qt-5/qnetworkreply.html#error-1
}
-void BaseJob::fail(int errorCode, QString errorString)
+void BaseJob::gotReply()
{
- setError( errorCode );
- setErrorText( errorString );
- if( d->reply->isRunning() )
- d->reply->abort();
- qWarning() << "Job" << objectName() << "failed:" << errorString;
- emitResult();
+ setStatus(checkReply(d->reply.data()));
+ if (status().good())
+ setStatus(parseReply(d->reply->readAll()));
+
+ finishJob(true);
}
-QNetworkReply* BaseJob::networkReply() const
+BaseJob::Status BaseJob::checkReply(QNetworkReply* reply) const
{
- return d->reply;
+ switch( reply->error() )
+ {
+ case QNetworkReply::NoError:
+ return NoError;
+
+ case QNetworkReply::AuthenticationRequiredError:
+ case QNetworkReply::ContentAccessDenied:
+ case QNetworkReply::ContentOperationNotPermittedError:
+ return { ContentAccessError, reply->errorString() };
+
+ default:
+ return { NetworkError, reply->errorString() };
+ }
}
-// void BaseJob::networkError(QNetworkReply::NetworkError code)
-// {
-// fail( KJob::UserDefinedError+1, d->reply->errorString() );
-// }
+BaseJob::Status BaseJob::parseReply(QByteArray data)
+{
+ QJsonParseError error;
+ QJsonDocument json = QJsonDocument::fromJson(data, &error);
+ if( error.error == QJsonParseError::NoError )
+ return parseJson(json);
+ else
+ return { JsonParseError, error.errorString() };
+}
-void BaseJob::gotReply()
+BaseJob::Status BaseJob::parseJson(const QJsonDocument&)
+{
+ return Success;
+}
+
+void BaseJob::finishJob(bool emitResult)
{
- if( d->reply->error() != QNetworkReply::NoError )
+ if (!d->reply)
{
- qDebug() << "NetworkError:" << d->reply->error();
- fail( NetworkError, d->reply->errorString() );
- return;
+ qWarning() << this << "finishes with empty network reply";
}
- QJsonParseError error;
- QJsonDocument data = QJsonDocument::fromJson(d->reply->readAll(), &error);
- if( error.error != QJsonParseError::NoError )
+ else if (d->reply->isRunning())
+ {
+ qWarning() << this << "finishes without ready network reply";
+ d->reply->disconnect(this); // Ignore whatever comes from the reply
+ }
+
+ // Notify those that are interested in any completion of the job (including killing)
+ emit finished(this);
+
+ if (emitResult) {
+ emit result(this);
+ if (error())
+ emit failure(this);
+ else
+ emit success(this);
+ }
+
+ deleteLater();
+}
+
+BaseJob::Status BaseJob::status() const
+{
+ return d->status;
+}
+
+int BaseJob::error() const
+{
+ return d->status.code;
+}
+
+QString BaseJob::errorString() const
+{
+ return d->status.message;
+}
+
+void BaseJob::setStatus(Status s)
+{
+ d->status = s;
+ if (!s.good())
{
- fail( JsonParseError, error.errorString() );
- return;
+ qWarning() << this << "status" << s.code << ":" << s.message;
}
- parseJson(data);
+}
+
+void BaseJob::setStatus(int code, QString message)
+{
+ setStatus({ code, message });
+}
+
+void BaseJob::abandon()
+{
+ finishJob(false);
}
void BaseJob::timeout()
{
- fail( TimeoutError, "The job has timed out" );
+ setStatus( TimeoutError, "The job has timed out" );
+ finishJob(true);
}
void BaseJob::sslErrors(const QList<QSslError>& errors)
diff --git a/jobs/basejob.h b/jobs/basejob.h
index 98b7358b..07b1f1dd 100644
--- a/jobs/basejob.h
+++ b/jobs/basejob.h
@@ -19,16 +19,14 @@
#ifndef QMATRIXCLIENT_BASEJOB_H
#define QMATRIXCLIENT_BASEJOB_H
-#ifdef USING_SYSTEM_KCOREADDONS
-#include <KCoreAddons/KJob>
-#else
-#include "kjob.h"
-#endif // KCOREADDONS_FOUND
-
+#include <QtCore/QObject>
#include <QtCore/QJsonDocument>
#include <QtCore/QJsonObject>
#include <QtCore/QUrlQuery>
-#include <QtNetwork/QNetworkReply>
+#include <QtCore/QScopedPointer>
+
+class QNetworkReply;
+class QSslError;
namespace QMatrixClient
{
@@ -36,27 +34,104 @@ namespace QMatrixClient
enum class JobHttpType { GetJob, PutJob, PostJob };
- class BaseJob: public KJob
+ class BaseJob: public QObject
{
Q_OBJECT
public:
+ /* Just in case, the values are compatible with KJob
+ * (which BaseJob used to inherit from). */
+ enum StatusCode { NoError = 0 // To be compatible with Qt conventions
+ , Success = 0
+ , ErrorLevel = 100 // Errors have codes starting from this
+ , NetworkError = 100
+ , JsonParseError
+ , TimeoutError
+ , ContentAccessError
+ , UserDefinedError = 200
+ };
+
+ /**
+ * This structure stores the status of a server call job. The status consists
+ * of a code, that is described (but not delimited) by the respective enum,
+ * and a freeform message.
+ *
+ * To extend the list of error codes, define an (anonymous) enum
+ * along the lines of StatusCode, with additional values
+ * starting at UserDefinedError
+ */
+ class Status
+ {
+ public:
+ Status(StatusCode c) : code(c) { }
+ Status(int c, QString m) : code(c), message(m) { }
+
+ bool good() const { return code < ErrorLevel; }
+
+ int code;
+ QString message;
+ };
+
+ public:
BaseJob(ConnectionData* connection, JobHttpType type,
QString name, bool needsToken=true);
virtual ~BaseJob();
- void start() override;
+ void start();
+
+ /**
+ * Abandons the result of this job, arrived or unarrived.
+ *
+ * This aborts waiting for a reply from the server (if there was
+ * any pending) and deletes the job object. It is always done quietly
+ * (as opposed to KJob::kill() that can trigger emitting the result).
+ */
+ void abandon();
- enum ErrorCode { NetworkError = KJob::UserDefinedError,
- JsonParseError, TimeoutError, UserDefinedError };
+ Status status() const;
+ int error() const;
+ virtual QString errorString() const;
signals:
/**
- * Emitted together with KJob::result() but only if there's no error.
+ * Emitted when the job is finished, in any case. It is used to notify
+ * observers that the job is terminated and that progress can be hidden.
+ *
+ * This should not be emitted directly by subclasses;
+ * use emitResult() instead.
+ *
+ * In general, to be notified of a job's completion, client code
+ * should connect to success() and failure()
+ * rather than finished(), so that kill() is indeed quiet.
+ * However if you store a list of jobs and they might get killed
+ * silently, then you must connect to this instead of result(),
+ * to avoid dangling pointers in your list.
+ *
+ * @param job the job that emitted this signal
+ * @internal
+ *
+ * @see success, failure
+ */
+ void finished(BaseJob* job);
+
+ /**
+ * Emitted when the job is finished (except when killed).
+ *
+ * Use error to know if the job was finished with error.
+ *
+ * @param job the job that emitted this signal
+ *
+ * @see success, failure
+ */
+ void result(BaseJob* job);
+
+ /**
+ * Emitted together with result() but only if there's no error.
*/
void success(BaseJob*);
+
/**
- * Emitted together with KJob::result() if there's an error.
- * Same as result(), this won't be emitted in case of kill(Quietly).
+ * Emitted together with result() if there's an error.
+ * Same as result(), this won't be emitted in case of kill().
*/
void failure(BaseJob*);
@@ -67,23 +142,55 @@ namespace QMatrixClient
virtual QString apiPath() const = 0;
virtual QUrlQuery query() const;
virtual QJsonObject data() const;
- virtual void parseJson(const QJsonDocument& data);
-
- void fail( int errorCode, QString errorString );
- QNetworkReply* networkReply() const;
+ /**
+ * Used by gotReply() slot to check the received reply for general
+ * issues such as network errors or access denial.
+ * Returning anything except NoError/Success prevents
+ * further parseReply()/parseJson() invocation.
+ *
+ * @param reply the reply received from the server
+ * @return the result of checking the reply
+ *
+ * @see gotReply
+ */
+ virtual Status checkReply(QNetworkReply* reply) const;
+
+ /**
+ * Processes the reply. By default, parses the reply into
+ * a QJsonDocument and calls parseJson() if it's a valid JSON.
+ *
+ * @param data raw contents of a HTTP reply from the server (without headers)
+ *
+ * @see gotReply, parseJson
+ */
+ virtual Status parseReply(QByteArray data);
+
+ /**
+ * Processes the JSON document received from the Matrix server.
+ * By default returns succesful status without analysing the JSON.
+ *
+ * @param json valid JSON document received from the server
+ *
+ * @see parseReply
+ */
+ virtual Status parseJson(const QJsonDocument&);
+ void setStatus(Status s);
+ void setStatus(int code, QString message);
+
protected slots:
- virtual void gotReply();
void timeout();
void sslErrors(const QList<QSslError>& errors);
- //void networkError(QNetworkReply::NetworkError code);
-
+ private slots:
+ void gotReply();
private:
+ void finishJob(bool emitResult);
+
class Private;
- Private* d;
+ QScopedPointer<Private> d;
};
}
diff --git a/jobs/checkauthmethods.cpp b/jobs/checkauthmethods.cpp
index 55d8632a..c93bf802 100644
--- a/jobs/checkauthmethods.cpp
+++ b/jobs/checkauthmethods.cpp
@@ -57,7 +57,8 @@ QString CheckAuthMethods::apiPath() const
return "_matrix/client/r0/login";
}
-void CheckAuthMethods::parseJson(const QJsonDocument& data)
+BaseJob::Status CheckAuthMethods::parseJson(const QJsonDocument& data)
{
// TODO
+ return { BaseJob::StatusCode::UserDefinedError, "Not implemented" };
}
diff --git a/jobs/checkauthmethods.h b/jobs/checkauthmethods.h
index 197f7aa7..36eaa01a 100644
--- a/jobs/checkauthmethods.h
+++ b/jobs/checkauthmethods.h
@@ -27,7 +27,6 @@ namespace QMatrixClient
class CheckAuthMethods : public BaseJob
{
- Q_OBJECT
public:
CheckAuthMethods(ConnectionData* connection);
virtual ~CheckAuthMethods();
@@ -36,7 +35,7 @@ namespace QMatrixClient
protected:
QString apiPath() const override;
- void parseJson(const QJsonDocument& data) override;
+ Status parseJson(const QJsonDocument& data) override;
private:
class Private;
diff --git a/jobs/joinroomjob.cpp b/jobs/joinroomjob.cpp
index 799d4926..8848aa70 100644
--- a/jobs/joinroomjob.cpp
+++ b/jobs/joinroomjob.cpp
@@ -54,18 +54,15 @@ QString JoinRoomJob::apiPath() const
return QString("_matrix/client/r0/join/%1").arg(d->roomAlias);
}
-void JoinRoomJob::parseJson(const QJsonDocument& data)
+BaseJob::Status JoinRoomJob::parseJson(const QJsonDocument& data)
{
QJsonObject json = data.object();
- if( !json.contains("room_id") )
- {
- fail( BaseJob::UserDefinedError, "Something went wrong..." );
- qDebug() << data;
- return;
- }
- else
+ if( json.contains("room_id") )
{
d->roomId = json.value("room_id").toString();
+ return Success;
}
- emitResult();
+
+ qDebug() << data;
+ return { UserDefinedError, "No room_id in the JSON response" };
}
diff --git a/jobs/joinroomjob.h b/jobs/joinroomjob.h
index 1329ca56..a6f4af21 100644
--- a/jobs/joinroomjob.h
+++ b/jobs/joinroomjob.h
@@ -35,7 +35,7 @@ namespace QMatrixClient
protected:
QString apiPath() const override;
- void parseJson(const QJsonDocument& data) override;
+ Status parseJson(const QJsonDocument& data) override;
private:
class Private;
diff --git a/jobs/logoutjob.cpp b/jobs/logoutjob.cpp
new file mode 100644
index 00000000..88767e4c
--- /dev/null
+++ b/jobs/logoutjob.cpp
@@ -0,0 +1,35 @@
+/******************************************************************************
+ * Copyright (C) 2016 Kitsune Ral <kitsune-ral@users.sf.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "logoutjob.h"
+
+using namespace QMatrixClient;
+
+LogoutJob::LogoutJob(ConnectionData* connection)
+ : BaseJob(connection, JobHttpType::PostJob, "LogoutJob")
+{
+}
+
+LogoutJob::~LogoutJob()
+{
+}
+
+QString LogoutJob::apiPath() const
+{
+ return "/_matrix/client/r0/logout";
+}
diff --git a/jobs/logoutjob.h b/jobs/logoutjob.h
new file mode 100644
index 00000000..faa1e2cb
--- /dev/null
+++ b/jobs/logoutjob.h
@@ -0,0 +1,34 @@
+/******************************************************************************
+ * Copyright (C) 2016 Kitsune Ral <kitsune-ral@users.sf.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#pragma once
+
+#include "basejob.h"
+
+namespace QMatrixClient
+{
+ class LogoutJob: public BaseJob
+ {
+ public:
+ LogoutJob(ConnectionData* connection);
+ virtual ~LogoutJob();
+
+ protected:
+ QString apiPath() const override;
+ };
+}
diff --git a/jobs/mediathumbnailjob.cpp b/jobs/mediathumbnailjob.cpp
index 48ed0ffb..1e434fbc 100644
--- a/jobs/mediathumbnailjob.cpp
+++ b/jobs/mediathumbnailjob.cpp
@@ -70,19 +70,11 @@ QUrlQuery MediaThumbnailJob::query() const
return query;
}
-void MediaThumbnailJob::gotReply()
+BaseJob::Status MediaThumbnailJob::parseReply(QByteArray data)
{
- if( networkReply()->error() != QNetworkReply::NoError )
- {
- qDebug() << "NetworkError!!!";
- qDebug() << networkReply()->errorString();
- fail( NetworkError, networkReply()->errorString() );
- return;
- }
-
- if( !d->thumbnail.loadFromData( networkReply()->readAll() ) )
+ if( !d->thumbnail.loadFromData(data) )
{
qDebug() << "MediaThumbnailJob: could not read image data";
}
- emitResult();
+ return Success;
}
diff --git a/jobs/mediathumbnailjob.h b/jobs/mediathumbnailjob.h
index df7c1832..3babf845 100644
--- a/jobs/mediathumbnailjob.h
+++ b/jobs/mediathumbnailjob.h
@@ -29,7 +29,6 @@ namespace QMatrixClient
class MediaThumbnailJob: public BaseJob
{
- Q_OBJECT
public:
MediaThumbnailJob(ConnectionData* data, QUrl url, int requestedWidth, int requestedHeight,
ThumbnailType thumbnailType=ThumbnailType::Scale);
@@ -41,8 +40,7 @@ namespace QMatrixClient
QString apiPath() const override;
QUrlQuery query() const override;
- protected slots:
- void gotReply() override;
+ Status parseReply(QByteArray data) override;
private:
class Private;
diff --git a/jobs/passwordlogin.cpp b/jobs/passwordlogin.cpp
index 231dcce5..c85e4c13 100644
--- a/jobs/passwordlogin.cpp
+++ b/jobs/passwordlogin.cpp
@@ -80,15 +80,15 @@ QJsonObject PasswordLogin::data() const
return json;
}
-void PasswordLogin::parseJson(const QJsonDocument& data)
+BaseJob::Status PasswordLogin::parseJson(const QJsonDocument& data)
{
QJsonObject json = data.object();
if( !json.contains("access_token") || !json.contains("home_server") || !json.contains("user_id") )
{
- fail( BaseJob::UserDefinedError, "Unexpected data" );
+ return { UserDefinedError, "No expected data" };
}
d->returned_token = json.value("access_token").toString();
d->returned_server = json.value("home_server").toString();
d->returned_id = json.value("user_id").toString();
- emitResult();
+ return Success;
}
diff --git a/jobs/passwordlogin.h b/jobs/passwordlogin.h
index 5e93e74e..d7e42725 100644
--- a/jobs/passwordlogin.h
+++ b/jobs/passwordlogin.h
@@ -27,7 +27,6 @@ namespace QMatrixClient
class PasswordLogin : public BaseJob
{
- Q_OBJECT
public:
PasswordLogin(ConnectionData* connection, QString user, QString password);
virtual ~PasswordLogin();
@@ -39,7 +38,7 @@ namespace QMatrixClient
protected:
QString apiPath() const override;
QJsonObject data() const override;
- void parseJson(const QJsonDocument& data) override;
+ Status parseJson(const QJsonDocument& data) override;
private:
class Private;
diff --git a/jobs/postmessagejob.cpp b/jobs/postmessagejob.cpp
index cf9b94fd..0a38da62 100644
--- a/jobs/postmessagejob.cpp
+++ b/jobs/postmessagejob.cpp
@@ -61,14 +61,11 @@ QJsonObject PostMessageJob::data() const
return json;
}
-void PostMessageJob::parseJson(const QJsonDocument& data)
+BaseJob::Status PostMessageJob::parseJson(const QJsonDocument& data)
{
- QJsonObject json = data.object();
- if( !json.contains("event_id") )
- {
- fail( BaseJob::UserDefinedError, "Something went wrong..." );
- qDebug() << data;
- return;
- }
- emitResult();
+ if( data.object().contains("event_id") )
+ return Success;
+
+ qDebug() << data;
+ return { UserDefinedError, "No event_id in the JSON response" };
}
diff --git a/jobs/postmessagejob.h b/jobs/postmessagejob.h
index 1917ef25..73d72020 100644
--- a/jobs/postmessagejob.h
+++ b/jobs/postmessagejob.h
@@ -26,7 +26,6 @@ namespace QMatrixClient
class Room;
class PostMessageJob: public BaseJob
{
- Q_OBJECT
public:
PostMessageJob(ConnectionData* connection, Room* room, QString type, QString message);
virtual ~PostMessageJob();
@@ -36,7 +35,7 @@ namespace QMatrixClient
protected:
QString apiPath() const override;
QJsonObject data() const override;
- void parseJson(const QJsonDocument& data) override;
+ Status parseJson(const QJsonDocument& data) override;
private:
class Private;
diff --git a/jobs/postreceiptjob.h b/jobs/postreceiptjob.h
index c5224af5..15963bf7 100644
--- a/jobs/postreceiptjob.h
+++ b/jobs/postreceiptjob.h
@@ -26,7 +26,6 @@ namespace QMatrixClient
class Room;
class PostReceiptJob: public BaseJob
{
- Q_OBJECT
public:
PostReceiptJob(ConnectionData* connection, QString roomId, QString eventId);
virtual ~PostReceiptJob();
diff --git a/jobs/roommembersjob.cpp b/jobs/roommembersjob.cpp
index c16ba481..7fc44c63 100644
--- a/jobs/roommembersjob.cpp
+++ b/jobs/roommembersjob.cpp
@@ -20,6 +20,7 @@
#include <QtCore/QJsonObject>
#include <QtCore/QJsonArray>
+#include <QtCore/QDebug>
#include "../room.h"
#include "../state.h"
@@ -55,10 +56,9 @@ QString RoomMembersJob::apiPath() const
return QString("_matrix/client/r0/rooms/%1/members").arg(d->room->id());
}
-void RoomMembersJob::parseJson(const QJsonDocument& data)
+BaseJob::Status RoomMembersJob::parseJson(const QJsonDocument& data)
{
- QJsonObject obj = data.object();
- QJsonArray chunk = obj.value("chunk").toArray();
+ QJsonArray chunk = data.object().value("chunk").toArray();
for( const QJsonValue& val : chunk )
{
State* state = State::fromJson(val.toObject());
@@ -66,5 +66,5 @@ void RoomMembersJob::parseJson(const QJsonDocument& data)
d->states.append(state);
}
qDebug() << "States: " << d->states.count();
- emitResult();
+ return Success;
}
diff --git a/jobs/roommembersjob.h b/jobs/roommembersjob.h
index ffae4309..04803d67 100644
--- a/jobs/roommembersjob.h
+++ b/jobs/roommembersjob.h
@@ -35,8 +35,8 @@ namespace QMatrixClient
QList<State*> states();
protected:
- virtual QString apiPath() const override;
- virtual void parseJson(const QJsonDocument& data) override;
+ QString apiPath() const override;
+ Status parseJson(const QJsonDocument& data) override;
private:
class Private;
diff --git a/jobs/roommessagesjob.cpp b/jobs/roommessagesjob.cpp
index f1943d2c..ba075007 100644
--- a/jobs/roommessagesjob.cpp
+++ b/jobs/roommessagesjob.cpp
@@ -81,10 +81,10 @@ QUrlQuery RoomMessagesJob::query() const
return query;
}
-void RoomMessagesJob::parseJson(const QJsonDocument& data)
+BaseJob::Status RoomMessagesJob::parseJson(const QJsonDocument& data)
{
QJsonObject obj = data.object();
d->events = eventListFromJson(obj.value("chunk").toArray());
d->end = obj.value("end").toString();
- emitResult();
+ return Success;
}
diff --git a/jobs/roommessagesjob.h b/jobs/roommessagesjob.h
index 6160dc57..52a72f70 100644
--- a/jobs/roommessagesjob.h
+++ b/jobs/roommessagesjob.h
@@ -30,7 +30,6 @@ namespace QMatrixClient
class RoomMessagesJob: public BaseJob
{
- Q_OBJECT
public:
RoomMessagesJob(ConnectionData* data, Room* room, QString from, FetchDirectory dir = FetchDirectory::Backwards, int limit=10);
virtual ~RoomMessagesJob();
@@ -41,7 +40,7 @@ namespace QMatrixClient
protected:
QString apiPath() const override;
QUrlQuery query() const override;
- void parseJson(const QJsonDocument& data) override;
+ Status parseJson(const QJsonDocument& data) override;
private:
class Private;
diff --git a/jobs/syncjob.cpp b/jobs/syncjob.cpp
index 37f79298..3bd1f0c8 100644
--- a/jobs/syncjob.cpp
+++ b/jobs/syncjob.cpp
@@ -43,8 +43,10 @@ class SyncJob::Private
QList<SyncRoomData> roomData;
};
+static size_t jobId = 0;
+
SyncJob::SyncJob(ConnectionData* connection, QString since)
- : BaseJob(connection, JobHttpType::GetJob, "SyncJob")
+ : BaseJob(connection, JobHttpType::GetJob, QString("SyncJob-%1").arg(++jobId))
, d(new Private)
{
d->since = since;
@@ -108,7 +110,7 @@ QUrlQuery SyncJob::query() const
return query;
}
-void SyncJob::parseJson(const QJsonDocument& data)
+BaseJob::Status SyncJob::parseJson(const QJsonDocument& data)
{
QJsonObject json = data.object();
d->nextBatch = json.value("next_batch").toString();
@@ -132,7 +134,7 @@ void SyncJob::parseJson(const QJsonDocument& data)
}
}
- emitResult();
+ return Success;
}
void SyncRoomData::EventList::fromJson(const QJsonObject& roomContents)
diff --git a/jobs/syncjob.h b/jobs/syncjob.h
index 19dd4646..6e6b4f7c 100644
--- a/jobs/syncjob.h
+++ b/jobs/syncjob.h
@@ -58,7 +58,6 @@ namespace QMatrixClient
class ConnectionData;
class SyncJob: public BaseJob
{
- Q_OBJECT
public:
SyncJob(ConnectionData* connection, QString since=QString());
virtual ~SyncJob();
@@ -74,7 +73,7 @@ namespace QMatrixClient
protected:
QString apiPath() const override;
QUrlQuery query() const override;
- void parseJson(const QJsonDocument& data) override;
+ Status parseJson(const QJsonDocument& data) override;
private:
class Private;
@@ -82,4 +81,4 @@ namespace QMatrixClient
};
}
-#endif // QMATRIXCLIENT_GETEVENTSJOB_H
+#endif // QMATRIXCLIENT_SYNCJOB_H