aboutsummaryrefslogtreecommitdiff
path: root/jobs
diff options
context:
space:
mode:
authorKitsune Ral <KitsuneRal@users.noreply.github.com>2016-04-05 20:46:45 +0300
committerKitsune Ral <KitsuneRal@users.noreply.github.com>2016-04-05 20:46:45 +0300
commit7abdc7ec386776602758d84edc6b583d6dad4ecd (patch)
tree247b6affaa7828e5122f1c338dd35a729cc4ee19 /jobs
downloadlibquotient-7abdc7ec386776602758d84edc6b583d6dad4ecd.tar.gz
libquotient-7abdc7ec386776602758d84edc6b583d6dad4ecd.zip
Imported the current source tree from Quaternion/lib.
Diffstat (limited to 'jobs')
-rw-r--r--jobs/basejob.cpp146
-rw-r--r--jobs/basejob.h76
-rw-r--r--jobs/checkauthmethods.cpp63
-rw-r--r--jobs/checkauthmethods.h47
-rw-r--r--jobs/geteventsjob.cpp96
-rw-r--r--jobs/geteventsjob.h49
-rw-r--r--jobs/initialsyncjob.cpp117
-rw-r--r--jobs/initialsyncjob.h53
-rw-r--r--jobs/joinroomjob.cpp71
-rw-r--r--jobs/joinroomjob.h46
-rw-r--r--jobs/leaveroomjob.cpp50
-rw-r--r--jobs/leaveroomjob.h44
-rw-r--r--jobs/mediathumbnailjob.cpp88
-rw-r--r--jobs/mediathumbnailjob.h53
-rw-r--r--jobs/passwordlogin.cpp96
-rw-r--r--jobs/passwordlogin.h50
-rw-r--r--jobs/postmessagejob.cpp74
-rw-r--r--jobs/postmessagejob.h47
-rw-r--r--jobs/postreceiptjob.cpp52
-rw-r--r--jobs/postreceiptjob.h43
-rw-r--r--jobs/roommembersjob.cpp70
-rw-r--r--jobs/roommembersjob.h47
-rw-r--r--jobs/roommessagesjob.cpp95
-rw-r--r--jobs/roommessagesjob.h52
-rw-r--r--jobs/syncjob.cpp176
-rw-r--r--jobs/syncjob.h75
26 files changed, 1876 insertions, 0 deletions
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp
new file mode 100644
index 00000000..b7e1b718
--- /dev/null
+++ b/jobs/basejob.cpp
@@ -0,0 +1,146 @@
+/******************************************************************************
+ * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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 "basejob.h"
+
+#include <QtNetwork/QNetworkAccessManager>
+#include <QtNetwork/QNetworkReply>
+#include <QtNetwork/QNetworkRequest>
+#include <QtCore/QTimer>
+
+#include "../connectiondata.h"
+
+using namespace QMatrixClient;
+
+class BaseJob::Private
+{
+ public:
+ Private(ConnectionData* c, JobHttpType t, bool nt)
+ : connection(c), reply(0), type(t), needsToken(nt) {}
+
+ ConnectionData* connection;
+ QNetworkReply* reply;
+ JobHttpType type;
+ bool needsToken;
+};
+
+BaseJob::BaseJob(ConnectionData* connection, JobHttpType type, bool needsToken)
+ : d(new Private(connection, type, needsToken))
+{
+}
+
+BaseJob::~BaseJob()
+{
+ if( d->reply )
+ d->reply->deleteLater();
+ delete d;
+}
+
+ConnectionData* BaseJob::connection() const
+{
+ return d->connection;
+}
+
+QJsonObject BaseJob::data()
+{
+ return QJsonObject();
+}
+
+QUrlQuery BaseJob::query()
+{
+ return QUrlQuery();
+}
+
+void BaseJob::parseJson(const QJsonDocument& data)
+{
+}
+
+void BaseJob::start()
+{
+ QUrl url = d->connection->baseUrl();
+ url.setPath( url.path() + "/" + apiPath() );
+ QUrlQuery query = this->query();
+ if( d->needsToken )
+ query.addQueryItem("access_token", connection()->token());
+ url.setQuery(query);
+ QNetworkRequest req = QNetworkRequest(url);
+ req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
+ req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);\
+ req.setMaximumRedirectsAllowed(10);
+#endif
+ QJsonDocument data = QJsonDocument(this->data());
+ switch( d->type )
+ {
+ case JobHttpType::GetJob:
+ d->reply = d->connection->nam()->get(req);
+ break;
+ case JobHttpType::PostJob:
+ d->reply = d->connection->nam()->post(req, data.toJson());
+ break;
+ case JobHttpType::PutJob:
+ d->reply = d->connection->nam()->put(req, data.toJson());
+ break;
+ }
+ connect( d->reply, &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)
+{
+ setError( errorCode );
+ setErrorText( errorString );
+ emitResult();
+}
+
+QNetworkReply* BaseJob::networkReply() const
+{
+ return d->reply;
+}
+
+// void BaseJob::networkError(QNetworkReply::NetworkError code)
+// {
+// fail( KJob::UserDefinedError+1, d->reply->errorString() );
+// }
+
+void BaseJob::gotReply()
+{
+ if( d->reply->error() != QNetworkReply::NoError )
+ {
+ qDebug() << "NetworkError!!!";
+ fail( NetworkError, d->reply->errorString() );
+ return;
+ }
+ QJsonParseError error;
+ QJsonDocument data = QJsonDocument::fromJson(d->reply->readAll(), &error);
+ if( error.error != QJsonParseError::NoError )
+ {
+ fail( JsonParseError, error.errorString() );
+ return;
+ }
+ parseJson(data);
+}
+
+void BaseJob::timeout()
+{
+ qDebug() << "Timeout!";
+ if( d->reply->isRunning() )
+ d->reply->abort();
+}
diff --git a/jobs/basejob.h b/jobs/basejob.h
new file mode 100644
index 00000000..88911ca1
--- /dev/null
+++ b/jobs/basejob.h
@@ -0,0 +1,76 @@
+/******************************************************************************
+ * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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
+ */
+
+#ifndef QMATRIXCLIENT_BASEJOB_H
+#define QMATRIXCLIENT_BASEJOB_H
+
+#ifdef USING_SYSTEM_KCOREADDONS
+#include <KCoreAddons/KJob>
+#else
+#include "kjob.h"
+#endif // KCOREADDONS_FOUND
+
+#include <QtCore/QJsonDocument>
+#include <QtCore/QJsonObject>
+#include <QtCore/QUrlQuery>
+#include <QtNetwork/QNetworkReply>
+
+namespace QMatrixClient
+{
+ class ConnectionData;
+
+ enum class JobHttpType { GetJob, PutJob, PostJob };
+
+ class BaseJob: public KJob
+ {
+ Q_OBJECT
+ public:
+ BaseJob(ConnectionData* connection, JobHttpType type, bool needsToken=true);
+ virtual ~BaseJob();
+
+ void start() override;
+
+ enum ErrorCode { NetworkError = KJob::UserDefinedError, JsonParseError, UserDefinedError };
+
+ protected:
+ ConnectionData* connection() const;
+
+ // to implement
+ virtual QString apiPath()=0;
+ virtual QUrlQuery query();
+ virtual QJsonObject data();
+ virtual void parseJson(const QJsonDocument& data);
+
+ void fail( int errorCode, QString errorString );
+ QNetworkReply* networkReply() const;
+
+
+ protected slots:
+ virtual void gotReply();
+ void timeout();
+
+ //void networkError(QNetworkReply::NetworkError code);
+
+
+ private:
+ class Private;
+ Private* d;
+ };
+}
+
+#endif // QMATRIXCLIENT_BASEJOB_H
diff --git a/jobs/checkauthmethods.cpp b/jobs/checkauthmethods.cpp
new file mode 100644
index 00000000..18b5f9a5
--- /dev/null
+++ b/jobs/checkauthmethods.cpp
@@ -0,0 +1,63 @@
+/******************************************************************************
+ * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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 "checkauthmethods.h"
+
+#include <QtNetwork/QNetworkAccessManager>
+#include <QtNetwork/QNetworkReply>
+#include <QtCore/QJsonDocument>
+#include <QtCore/QJsonObject>
+#include <QtCore/QJsonParseError>
+
+#include "../connectiondata.h"
+
+using namespace QMatrixClient;
+
+class CheckAuthMethods::Private
+{
+ public:
+ Private() {}
+
+ QString session;
+};
+
+CheckAuthMethods::CheckAuthMethods(ConnectionData* connection)
+ : BaseJob(connection, JobHttpType::GetJob, false)
+ , d(new Private)
+{
+}
+
+CheckAuthMethods::~CheckAuthMethods()
+{
+ delete d;
+}
+
+QString CheckAuthMethods::session()
+{
+ return d->session;
+}
+
+QString CheckAuthMethods::apiPath()
+{
+ return "_matrix/client/r0/login";
+}
+
+void CheckAuthMethods::parseJson(const QJsonDocument& data)
+{
+ // TODO
+} \ No newline at end of file
diff --git a/jobs/checkauthmethods.h b/jobs/checkauthmethods.h
new file mode 100644
index 00000000..2c9ab61a
--- /dev/null
+++ b/jobs/checkauthmethods.h
@@ -0,0 +1,47 @@
+/******************************************************************************
+ * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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
+ */
+
+#ifndef QMATRIXCLIENT_CHECKAUTHMETHODS_H
+#define QMATRIXCLIENT_CHECKAUTHMETHODS_H
+
+#include "basejob.h"
+
+namespace QMatrixClient
+{
+ class ConnectionData;
+
+ class CheckAuthMethods : public BaseJob
+ {
+ Q_OBJECT
+ public:
+ CheckAuthMethods(ConnectionData* connection);
+ virtual ~CheckAuthMethods();
+
+ QString session();
+
+ protected:
+ QString apiPath();
+ void parseJson(const QJsonDocument& data);
+
+ private:
+ class Private;
+ Private* d;
+ };
+}
+
+#endif // QMATRIXCLIENT_CHECKAUTHMETHODS_H \ No newline at end of file
diff --git a/jobs/geteventsjob.cpp b/jobs/geteventsjob.cpp
new file mode 100644
index 00000000..748a0189
--- /dev/null
+++ b/jobs/geteventsjob.cpp
@@ -0,0 +1,96 @@
+/******************************************************************************
+ * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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 "geteventsjob.h"
+
+#include <QtCore/QJsonDocument>
+#include <QtCore/QJsonObject>
+#include <QtCore/QJsonValue>
+#include <QtCore/QJsonArray>
+#include <QtCore/QDebug>
+
+#include <QtNetwork/QNetworkReply>
+
+#include "../room.h"
+#include "../connectiondata.h"
+#include "../events/event.h"
+
+using namespace QMatrixClient;
+
+class GetEventsJob::Private
+{
+ public:
+ Private() {}
+
+ QList<Event*> events;
+ QString from;
+};
+
+GetEventsJob::GetEventsJob(ConnectionData* connection, QString from)
+ : BaseJob(connection, JobHttpType::GetJob)
+ , d(new Private)
+{
+ if( from.isEmpty() )
+ from = connection->lastEvent();
+ d->from = from;
+}
+
+GetEventsJob::~GetEventsJob()
+{
+ delete d;
+}
+
+QList< Event* > GetEventsJob::events()
+{
+ return d->events;
+}
+
+QString GetEventsJob::apiPath()
+{
+ return "_matrix/client/r0/events";
+}
+
+QUrlQuery GetEventsJob::query()
+{
+ QUrlQuery query;
+ query.addQueryItem("from", d->from);
+ return query;
+}
+
+void GetEventsJob::parseJson(const QJsonDocument& data)
+{
+ QJsonObject json = data.object();
+ if( !json.contains("chunk") || !json.value("chunk").isArray() )
+ {
+ fail( BaseJob::UserDefinedError, "Couldn't find chunk" );
+ return;
+ }
+ QJsonArray chunk = json.value("chunk").toArray();
+// qDebug() << chunk;
+ for( const QJsonValue& val: chunk )
+ {
+ QJsonObject eventObj = val.toObject();
+ Event* event = Event::fromJson(eventObj);
+ if( event )
+ {
+ d->events.append(event);
+ }
+ }
+ connection()->setLastEvent( json.value("end").toString() );
+ emitResult();
+} \ No newline at end of file
diff --git a/jobs/geteventsjob.h b/jobs/geteventsjob.h
new file mode 100644
index 00000000..d2eb75eb
--- /dev/null
+++ b/jobs/geteventsjob.h
@@ -0,0 +1,49 @@
+/******************************************************************************
+ * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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
+ */
+
+#ifndef QMATRIXCLIENT_GETEVENTSJOB_H
+#define QMATRIXCLIENT_GETEVENTSJOB_H
+
+#include "basejob.h"
+
+namespace QMatrixClient
+{
+ class ConnectionData;
+ class Room;
+ class Event;
+ class GetEventsJob: public BaseJob
+ {
+ Q_OBJECT
+ public:
+ GetEventsJob(ConnectionData* connection, QString from=QString());
+ virtual ~GetEventsJob();
+
+ QList<Event*> events();
+
+ protected:
+ QString apiPath();
+ QUrlQuery query();
+ void parseJson(const QJsonDocument& data);
+
+ private:
+ class Private;
+ Private* d;
+ };
+}
+
+#endif // QMATRIXCLIENT_GETEVENTSJOB_H \ No newline at end of file
diff --git a/jobs/initialsyncjob.cpp b/jobs/initialsyncjob.cpp
new file mode 100644
index 00000000..9512e0ea
--- /dev/null
+++ b/jobs/initialsyncjob.cpp
@@ -0,0 +1,117 @@
+/******************************************************************************
+ * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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 "initialsyncjob.h"
+
+#include <QtNetwork/QNetworkAccessManager>
+#include <QtNetwork/QNetworkReply>
+#include <QtCore/QUrlQuery>
+#include <QtCore/QJsonDocument>
+#include <QtCore/QJsonObject>
+#include <QtCore/QJsonArray>
+#include <QtCore/QJsonValue>
+
+#include "../connectiondata.h"
+#include "../room.h"
+#include "../state.h"
+#include "../events/event.h"
+
+using namespace QMatrixClient;
+
+class InitialSyncJob::Private
+{
+ public:
+ Private() {}
+
+ QList<Event*> events;
+ QList<State*> initialState;
+};
+
+InitialSyncJob::InitialSyncJob(ConnectionData* connection)
+ : BaseJob(connection, JobHttpType::GetJob)
+ , d(new Private)
+{
+}
+
+InitialSyncJob::~InitialSyncJob()
+{
+ delete d;
+}
+
+QList< Event* > InitialSyncJob::events()
+{
+ return d->events;
+}
+
+QList< State* > InitialSyncJob::initialState()
+{
+ return d->initialState;
+}
+
+QString InitialSyncJob::apiPath()
+{
+ return "_matrix/client/r0/initialSync";
+}
+
+QUrlQuery InitialSyncJob::query()
+{
+ QUrlQuery query;
+ query.addQueryItem("limit", "200");
+ return query;
+}
+
+void InitialSyncJob::parseJson(const QJsonDocument& data)
+{
+ QJsonObject json = data.object();
+ if( !json.contains("rooms") || !json.value("rooms").isArray() )
+ {
+ fail( KJob::UserDefinedError+2, "Didn't find rooms" );
+ qDebug() << json;
+ return;
+ }
+ QJsonArray array = json.value("rooms").toArray();
+ for( const QJsonValue& val : array )
+ {
+ if( !val.isObject() )
+ {
+ qWarning() << "Strange: " << val;
+ continue;
+ }
+ QJsonObject obj = val.toObject();
+ QJsonObject messages = obj.value("messages").toObject();
+ QJsonArray chunk = messages.value("chunk").toArray();
+ for( const QJsonValue& val: chunk )
+ {
+ Event* event = Event::fromJson(val.toObject());
+ if( event )
+ d->events.append( event );
+ }
+ QJsonArray state = obj.value("state").toArray();
+ for( const QJsonValue& val: state )
+ {
+// qDebug() << val.toObject();
+ State* state = State::fromJson(val.toObject());
+ if( state )
+ d->initialState.append( state );
+ }
+ }
+ connection()->setLastEvent( json.value("end").toString() );
+ qDebug() << connection()->lastEvent();
+ emitResult();
+}
+
diff --git a/jobs/initialsyncjob.h b/jobs/initialsyncjob.h
new file mode 100644
index 00000000..188522c1
--- /dev/null
+++ b/jobs/initialsyncjob.h
@@ -0,0 +1,53 @@
+/******************************************************************************
+ * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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
+ */
+
+#ifndef QMATRIXCLIENT_INITIALSYNCJOB_H
+#define QMATRIXCLIENT_INITIALSYNCJOB_H
+
+#include "basejob.h"
+
+#include "lib/room.h"
+
+namespace QMatrixClient
+{
+ class ConnectionData;
+ class Event;
+ class State;
+
+ class InitialSyncJob: public BaseJob
+ {
+ Q_OBJECT
+ public:
+ InitialSyncJob(ConnectionData* connection);
+ virtual ~InitialSyncJob();
+
+ QList<Event*> events();
+ QList<State*> initialState();
+
+ protected:
+ QString apiPath();
+ QUrlQuery query();
+ void parseJson(const QJsonDocument& data);
+
+ private:
+ class Private;
+ Private* d;
+ };
+}
+
+#endif // QMATRIXCLIENT_INITIALSYNCJOB_H \ No newline at end of file
diff --git a/jobs/joinroomjob.cpp b/jobs/joinroomjob.cpp
new file mode 100644
index 00000000..85a331fa
--- /dev/null
+++ b/jobs/joinroomjob.cpp
@@ -0,0 +1,71 @@
+/******************************************************************************
+ * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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 "joinroomjob.h"
+
+#include <QtCore/QJsonObject>
+#include <QtNetwork/QNetworkReply>
+
+#include "../connectiondata.h"
+
+using namespace QMatrixClient;
+
+class JoinRoomJob::Private
+{
+ public:
+ QString roomId;
+ QString roomAlias;
+};
+
+JoinRoomJob::JoinRoomJob(ConnectionData* data, QString roomAlias)
+ : BaseJob(data, JobHttpType::PostJob)
+ , d(new Private)
+{
+ d->roomAlias = roomAlias;
+}
+
+JoinRoomJob::~JoinRoomJob()
+{
+ delete d;
+}
+
+QString JoinRoomJob::roomId()
+{
+ return d->roomId;
+}
+
+QString JoinRoomJob::apiPath()
+{
+ return QString("_matrix/client/r0/join/%1").arg(d->roomAlias);
+}
+
+void JoinRoomJob::parseJson(const QJsonDocument& data)
+{
+ QJsonObject json = data.object();
+ if( !json.contains("room_id") )
+ {
+ fail( BaseJob::UserDefinedError, "Something went wrong..." );
+ qDebug() << data;
+ return;
+ }
+ else
+ {
+ d->roomId = json.value("room_id").toString();
+ }
+ emitResult();
+}
diff --git a/jobs/joinroomjob.h b/jobs/joinroomjob.h
new file mode 100644
index 00000000..8f4059f2
--- /dev/null
+++ b/jobs/joinroomjob.h
@@ -0,0 +1,46 @@
+/******************************************************************************
+ * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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
+ */
+
+#ifndef QMATRIXCLIENT_JOINROOMJOB_H
+#define QMATRIXCLIENT_JOINROOMJOB_H
+
+#include "basejob.h"
+
+namespace QMatrixClient
+{
+ class ConnectionData;
+
+ class JoinRoomJob: public BaseJob
+ {
+ public:
+ JoinRoomJob(ConnectionData* data, QString roomAlias);
+ virtual ~JoinRoomJob();
+
+ QString roomId();
+
+ protected:
+ QString apiPath();
+ void parseJson(const QJsonDocument& data);
+
+ private:
+ class Private;
+ Private* d;
+ };
+}
+
+#endif // QMATRIXCLIENT_JOINROOMJOB_H \ No newline at end of file
diff --git a/jobs/leaveroomjob.cpp b/jobs/leaveroomjob.cpp
new file mode 100644
index 00000000..1adab31f
--- /dev/null
+++ b/jobs/leaveroomjob.cpp
@@ -0,0 +1,50 @@
+/******************************************************************************
+ * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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 "leaveroomjob.h"
+
+#include <QtNetwork/QNetworkReply>
+
+#include "../room.h"
+#include "../connectiondata.h"
+
+using namespace QMatrixClient;
+
+class LeaveRoomJob::Private
+{
+ public:
+ Private(Room* r) : room(r) {}
+
+ Room* room;
+};
+
+LeaveRoomJob::LeaveRoomJob(ConnectionData* data, Room* room)
+ : BaseJob(data, JobHttpType::PostJob)
+ , d(new Private(room))
+{
+}
+
+LeaveRoomJob::~LeaveRoomJob()
+{
+ delete d;
+}
+
+QString LeaveRoomJob::apiPath()
+{
+ return QString("_matrix/client/r0/rooms/%1/leave").arg(d->room->id());
+}
diff --git a/jobs/leaveroomjob.h b/jobs/leaveroomjob.h
new file mode 100644
index 00000000..535c44b8
--- /dev/null
+++ b/jobs/leaveroomjob.h
@@ -0,0 +1,44 @@
+/******************************************************************************
+ * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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
+ */
+
+#ifndef QMATRIXCLIENT_LEAVEROOMJOB_H
+#define QMATRIXCLIENT_LEAVEROOMJOB_H
+
+#include "basejob.h"
+
+namespace QMatrixClient
+{
+ class ConnectionData;
+ class Room;
+
+ class LeaveRoomJob: public BaseJob
+ {
+ public:
+ LeaveRoomJob(ConnectionData* data, Room* room);
+ virtual ~LeaveRoomJob();
+
+ protected:
+ QString apiPath();
+
+ private:
+ class Private;
+ Private* d;
+ };
+}
+
+#endif // QMATRIXCLIENT_LEAVEROOMJOB_H \ No newline at end of file
diff --git a/jobs/mediathumbnailjob.cpp b/jobs/mediathumbnailjob.cpp
new file mode 100644
index 00000000..02d9bbd9
--- /dev/null
+++ b/jobs/mediathumbnailjob.cpp
@@ -0,0 +1,88 @@
+/******************************************************************************
+ * Copyright (C) 2016 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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 "mediathumbnailjob.h"
+
+#include <QtCore/QDebug>
+
+using namespace QMatrixClient;
+
+class MediaThumbnailJob::Private
+{
+ public:
+ QUrl url;
+ QPixmap thumbnail;
+ int requestedHeight;
+ int requestedWidth;
+ ThumbnailType thumbnailType;
+};
+
+MediaThumbnailJob::MediaThumbnailJob(ConnectionData* data, QUrl url, int requestedWidth, int requestedHeight,
+ ThumbnailType thumbnailType)
+ : BaseJob(data, JobHttpType::GetJob)
+ , d(new Private)
+{
+ d->url = url;
+ d->requestedHeight = requestedHeight;
+ d->requestedWidth = requestedWidth;
+ d->thumbnailType = thumbnailType;
+}
+
+MediaThumbnailJob::~MediaThumbnailJob()
+{
+ delete d;
+}
+
+QPixmap MediaThumbnailJob::thumbnail()
+{
+ return d->thumbnail;
+}
+
+QString MediaThumbnailJob::apiPath()
+{
+ return QString("/_matrix/media/v1/thumbnail/%1/%2").arg(d->url.host()).arg(d->url.path());
+}
+
+QUrlQuery MediaThumbnailJob::query()
+{
+ QUrlQuery query;
+ query.addQueryItem("width", QString::number(d->requestedWidth));
+ query.addQueryItem("height", QString::number(d->requestedHeight));
+ if( d->thumbnailType == ThumbnailType::Scale )
+ query.addQueryItem("method", "scale");
+ else
+ query.addQueryItem("method", "crop");
+ return query;
+}
+
+void MediaThumbnailJob::gotReply()
+{
+ if( networkReply()->error() != QNetworkReply::NoError )
+ {
+ qDebug() << "NetworkError!!!";
+ qDebug() << networkReply()->errorString();
+ fail( NetworkError, networkReply()->errorString() );
+ return;
+ }
+
+ if( !d->thumbnail.loadFromData( networkReply()->readAll() ) )
+ {
+ qDebug() << "MediaThumbnailJob: could not read image data";
+ }
+ emitResult();
+}
diff --git a/jobs/mediathumbnailjob.h b/jobs/mediathumbnailjob.h
new file mode 100644
index 00000000..85dc8251
--- /dev/null
+++ b/jobs/mediathumbnailjob.h
@@ -0,0 +1,53 @@
+/******************************************************************************
+ * Copyright (C) 2016 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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
+ */
+
+#ifndef QMATRIXCLIENT_MEDIATHUMBNAILJOB_H
+#define QMATRIXCLIENT_MEDIATHUMBNAILJOB_H
+
+#include "basejob.h"
+
+#include <QtGui/QPixmap>
+
+namespace QMatrixClient
+{
+ enum class ThumbnailType {Crop, Scale};
+
+ class MediaThumbnailJob: public BaseJob
+ {
+ Q_OBJECT
+ public:
+ MediaThumbnailJob(ConnectionData* data, QUrl url, int requestedWidth, int requestedHeight,
+ ThumbnailType thumbnailType=ThumbnailType::Scale);
+ virtual ~MediaThumbnailJob();
+
+ QPixmap thumbnail();
+
+ protected:
+ QString apiPath() override;
+ QUrlQuery query() override;
+
+ protected slots:
+ void gotReply() override;
+
+ private:
+ class Private;
+ Private* d;
+ };
+}
+
+#endif // QMATRIXCLIENT_MEDIATHUMBNAILJOB_H \ No newline at end of file
diff --git a/jobs/passwordlogin.cpp b/jobs/passwordlogin.cpp
new file mode 100644
index 00000000..d989815f
--- /dev/null
+++ b/jobs/passwordlogin.cpp
@@ -0,0 +1,96 @@
+/******************************************************************************
+ * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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 "passwordlogin.h"
+
+#include <QtCore/QJsonDocument>
+#include <QtCore/QJsonObject>
+#include <QtNetwork/QNetworkReply>
+
+#include "../connectiondata.h"
+
+using namespace QMatrixClient;
+
+class PasswordLogin::Private
+{
+ public:
+ Private() {}
+
+ QString user;
+ QString password;
+ QString returned_id;
+ QString returned_server;
+ QString returned_token;
+};
+
+PasswordLogin::PasswordLogin(ConnectionData* connection, QString user, QString password)
+ : BaseJob(connection, JobHttpType::PostJob, false)
+ , d(new Private)
+{
+ d->user = user;
+ d->password = password;
+}
+
+PasswordLogin::~PasswordLogin()
+{
+ delete d;
+}
+
+QString PasswordLogin::token()
+{
+ return d->returned_token;
+}
+
+QString PasswordLogin::id()
+{
+ return d->returned_id;
+}
+
+QString PasswordLogin::server()
+{
+ return d->returned_server;
+}
+
+QString PasswordLogin::apiPath()
+{
+ return "_matrix/client/r0/login";
+}
+
+QJsonObject PasswordLogin::data()
+{
+ QJsonObject json;
+ json.insert("type", "m.login.password");
+ json.insert("user", d->user);
+ json.insert("password", d->password);
+ return json;
+}
+
+void 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" );
+ }
+ d->returned_token = json.value("access_token").toString();
+ qDebug() << d->returned_token;
+ d->returned_server = json.value("home_server").toString();
+ d->returned_id = json.value("user_id").toString();
+ connection()->setToken(d->returned_token);
+ emitResult();
+}
diff --git a/jobs/passwordlogin.h b/jobs/passwordlogin.h
new file mode 100644
index 00000000..19df118e
--- /dev/null
+++ b/jobs/passwordlogin.h
@@ -0,0 +1,50 @@
+/******************************************************************************
+ * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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
+ */
+
+#ifndef QMATRIXCLIENT_PASSWORDLOGIN_H
+#define QMATRIXCLIENT_PASSWORDLOGIN_H
+
+#include "basejob.h"
+
+namespace QMatrixClient
+{
+ class ConnectionData;
+
+ class PasswordLogin : public BaseJob
+ {
+ Q_OBJECT
+ public:
+ PasswordLogin(ConnectionData* connection, QString user, QString password);
+ virtual ~PasswordLogin();
+
+ QString token();
+ QString id();
+ QString server();
+
+ protected:
+ QString apiPath();
+ QJsonObject data();
+ void parseJson(const QJsonDocument& data);
+
+ private:
+ class Private;
+ Private* d;
+ };
+}
+
+#endif // QMATRIXCLIENT_PASSWORDLOGIN_H \ No newline at end of file
diff --git a/jobs/postmessagejob.cpp b/jobs/postmessagejob.cpp
new file mode 100644
index 00000000..67c79669
--- /dev/null
+++ b/jobs/postmessagejob.cpp
@@ -0,0 +1,74 @@
+/******************************************************************************
+ * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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 "postmessagejob.h"
+#include "../room.h"
+#include "../connectiondata.h"
+
+#include <QtNetwork/QNetworkReply>
+
+using namespace QMatrixClient;
+
+class PostMessageJob::Private
+{
+ public:
+ Private() {}
+
+ QString type;
+ QString message;
+ Room* room;
+};
+
+PostMessageJob::PostMessageJob(ConnectionData* connection, Room* room, QString type, QString message)
+ : BaseJob(connection, JobHttpType::PostJob)
+ , d(new Private)
+{
+ d->type = type;
+ d->message = message;
+ d->room = room;
+}
+
+PostMessageJob::~PostMessageJob()
+{
+ delete d;
+}
+
+QString PostMessageJob::apiPath()
+{
+ return QString("_matrix/client/r0/rooms/%1/send/m.room.message").arg(d->room->id());
+}
+
+QJsonObject PostMessageJob::data()
+{
+ QJsonObject json;
+ json.insert("msgtype", d->type);
+ json.insert("body", d->message);
+ return json;
+}
+
+void PostMessageJob::parseJson(const QJsonDocument& data)
+{
+ QJsonObject json = data.object();
+ if( !json.contains("event_id") )
+ {
+ fail( BaseJob::UserDefinedError, "Something went wrong..." );
+ qDebug() << data;
+ return;
+ }
+ emitResult();
+} \ No newline at end of file
diff --git a/jobs/postmessagejob.h b/jobs/postmessagejob.h
new file mode 100644
index 00000000..7f40534e
--- /dev/null
+++ b/jobs/postmessagejob.h
@@ -0,0 +1,47 @@
+/******************************************************************************
+ * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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
+ */
+
+#ifndef QMATRIXCLIENT_POSTMESSAGEJOB_H
+#define QMATRIXCLIENT_POSTMESSAGEJOB_H
+
+#include "basejob.h"
+
+namespace QMatrixClient
+{
+ class Room;
+ class PostMessageJob: public BaseJob
+ {
+ Q_OBJECT
+ public:
+ PostMessageJob(ConnectionData* connection, Room* room, QString type, QString message);
+ virtual ~PostMessageJob();
+
+ //bool success();
+
+ protected:
+ QString apiPath();
+ QJsonObject data();
+ void parseJson(const QJsonDocument& data);
+
+ private:
+ class Private;
+ Private* d;
+ };
+}
+
+#endif // QMATRIXCLIENT_POSTMESSAGEJOB_H \ No newline at end of file
diff --git a/jobs/postreceiptjob.cpp b/jobs/postreceiptjob.cpp
new file mode 100644
index 00000000..c26186e8
--- /dev/null
+++ b/jobs/postreceiptjob.cpp
@@ -0,0 +1,52 @@
+/******************************************************************************
+ * Copyright (C) 2016 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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 "postreceiptjob.h"
+#include "../room.h"
+#include "../connectiondata.h"
+
+#include <QtNetwork/QNetworkReply>
+
+using namespace QMatrixClient;
+
+class PostReceiptJob::Private
+{
+ public:
+ Private() {}
+
+ QString roomId;
+ QString eventId;
+};
+
+PostReceiptJob::PostReceiptJob(ConnectionData* connection, QString roomId, QString eventId)
+ : BaseJob(connection, JobHttpType::PostJob)
+ , d(new Private)
+{
+ d->roomId = roomId;
+ d->eventId = eventId;
+}
+
+PostReceiptJob::~PostReceiptJob()
+{
+ delete d;
+}
+
+QString PostReceiptJob::apiPath()
+{
+ return QString("/_matrix/client/r0/rooms/%1/receipt/m.read/%2").arg(d->roomId).arg(d->eventId);
+}
diff --git a/jobs/postreceiptjob.h b/jobs/postreceiptjob.h
new file mode 100644
index 00000000..2767fa9a
--- /dev/null
+++ b/jobs/postreceiptjob.h
@@ -0,0 +1,43 @@
+/******************************************************************************
+ * Copyright (C) 2016 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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
+ */
+
+#ifndef QMATRIXCLIENT_POSTRECEIPTJOB_H
+#define QMATRIXCLIENT_POSTRECEIPTJOB_H
+
+#include "basejob.h"
+
+namespace QMatrixClient
+{
+ class Room;
+ class PostReceiptJob: public BaseJob
+ {
+ Q_OBJECT
+ public:
+ PostReceiptJob(ConnectionData* connection, QString roomId, QString eventId);
+ virtual ~PostReceiptJob();
+
+ protected:
+ QString apiPath();
+
+ private:
+ class Private;
+ Private* d;
+ };
+}
+
+#endif // QMATRIXCLIENT_POSTRECEIPTJOB_H
diff --git a/jobs/roommembersjob.cpp b/jobs/roommembersjob.cpp
new file mode 100644
index 00000000..e12bc6c4
--- /dev/null
+++ b/jobs/roommembersjob.cpp
@@ -0,0 +1,70 @@
+/******************************************************************************
+ * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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 "roommembersjob.h"
+
+#include <QtCore/QJsonObject>
+#include <QtCore/QJsonArray>
+
+#include "../room.h"
+#include "../state.h"
+
+using namespace QMatrixClient;
+
+class RoomMembersJob::Private
+{
+ public:
+ Room* room;
+ QList<State*> states;
+};
+
+RoomMembersJob::RoomMembersJob(ConnectionData* data, Room* room)
+ : BaseJob(data, JobHttpType::GetJob)
+ , d(new Private)
+{
+ d->room = room;
+}
+
+RoomMembersJob::~RoomMembersJob()
+{
+ delete d;
+}
+
+QList< State* > RoomMembersJob::states()
+{
+ return d->states;
+}
+
+QString RoomMembersJob::apiPath()
+{
+ return QString("_matrix/client/r0/rooms/%1/members").arg(d->room->id());
+}
+
+void RoomMembersJob::parseJson(const QJsonDocument& data)
+{
+ QJsonObject obj = data.object();
+ QJsonArray chunk = obj.value("chunk").toArray();
+ for( const QJsonValue& val : chunk )
+ {
+ State* state = State::fromJson(val.toObject());
+ if( state )
+ d->states.append(state);
+ }
+ qDebug() << "States: " << d->states.count();
+ emitResult();
+} \ No newline at end of file
diff --git a/jobs/roommembersjob.h b/jobs/roommembersjob.h
new file mode 100644
index 00000000..0349aa02
--- /dev/null
+++ b/jobs/roommembersjob.h
@@ -0,0 +1,47 @@
+/******************************************************************************
+ * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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
+ */
+
+#ifndef QMATRIXCLIENT_ROOMMEMBERSJOB_H
+#define QMATRIXCLIENT_ROOMMEMBERSJOB_H
+
+#include "basejob.h"
+
+namespace QMatrixClient
+{
+ class ConnectionData;
+ class Room;
+ class State;
+ class RoomMembersJob: public BaseJob
+ {
+ public:
+ RoomMembersJob(ConnectionData* data, Room* room);
+ virtual ~RoomMembersJob();
+
+ QList<State*> states();
+
+ protected:
+ virtual QString apiPath();
+ virtual void parseJson(const QJsonDocument& data);
+
+ private:
+ class Private;
+ Private* d;
+ };
+}
+
+#endif // QMATRIXCLIENT_ROOMMEMBERSJOB_H \ No newline at end of file
diff --git a/jobs/roommessagesjob.cpp b/jobs/roommessagesjob.cpp
new file mode 100644
index 00000000..fc3f5f1e
--- /dev/null
+++ b/jobs/roommessagesjob.cpp
@@ -0,0 +1,95 @@
+/******************************************************************************
+ * Copyright (C) 2016 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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 "roommessagesjob.h"
+#include "../room.h"
+#include "../events/event.h"
+
+#include <QtCore/QJsonObject>
+#include <QtCore/QJsonArray>
+
+using namespace QMatrixClient;
+
+class RoomMessagesJob::Private
+{
+ public:
+ Private() {}
+
+ Room* room;
+ QString from;
+ FetchDirectory dir;
+ int limit;
+
+ QList<Event*> events;
+ QString end;
+};
+
+RoomMessagesJob::RoomMessagesJob(ConnectionData* data, Room* room, QString from, FetchDirectory dir, int limit)
+ : BaseJob(data, JobHttpType::GetJob)
+{
+ d = new Private();
+ d->room = room;
+ d->from = from;
+ d->dir = dir;
+ d->limit = limit;
+}
+
+RoomMessagesJob::~RoomMessagesJob()
+{
+ delete d;
+}
+
+QList<Event*> RoomMessagesJob::events()
+{
+ return d->events;
+}
+
+QString RoomMessagesJob::end()
+{
+ return d->end;
+}
+
+QString RoomMessagesJob::apiPath()
+{
+ return QString("/_matrix/client/r0/rooms/%1/messages").arg(d->room->id());
+}
+
+QUrlQuery RoomMessagesJob::query()
+{
+ QUrlQuery query;
+ query.addQueryItem("from", d->from);
+ if( d->dir == FetchDirectory::Backwards )
+ query.addQueryItem("dir", "b");
+ else
+ query.addQueryItem("dir", "f");
+ query.addQueryItem("limit", QString::number(d->limit));
+ return query;
+}
+
+void RoomMessagesJob::parseJson(const QJsonDocument& data)
+{
+ QJsonObject obj = data.object();
+ QJsonArray chunk = obj.value("chunk").toArray();
+ for( const QJsonValue& val: chunk )
+ {
+ Event* event = Event::fromJson(val.toObject());
+ d->events.append(event);
+ }
+ d->end = obj.value("end").toString();
+ emitResult();
+} \ No newline at end of file
diff --git a/jobs/roommessagesjob.h b/jobs/roommessagesjob.h
new file mode 100644
index 00000000..2a12ac08
--- /dev/null
+++ b/jobs/roommessagesjob.h
@@ -0,0 +1,52 @@
+/******************************************************************************
+ * Copyright (C) 2016 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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
+ */
+
+#ifndef QMATRIXCLIENT_ROOMMESSAGESJOB_H
+#define QMATRIXCLIENT_ROOMMESSAGESJOB_H
+
+#include "basejob.h"
+
+namespace QMatrixClient
+{
+ class Room;
+ class Event;
+
+ enum class FetchDirectory { Backwards, Forward };
+
+ class RoomMessagesJob: public BaseJob
+ {
+ Q_OBJECT
+ public:
+ RoomMessagesJob(ConnectionData* data, Room* room, QString from, FetchDirectory dir = FetchDirectory::Backwards, int limit=10);
+ virtual ~RoomMessagesJob();
+
+ QList<Event*> events();
+ QString end();
+
+ protected:
+ QString apiPath();
+ QUrlQuery query();
+ void parseJson(const QJsonDocument& data);
+
+ private:
+ class Private;
+ Private* d;
+ };
+}
+
+#endif // QMATRIXCLIENT_ROOMMESSAGESJOB_H \ No newline at end of file
diff --git a/jobs/syncjob.cpp b/jobs/syncjob.cpp
new file mode 100644
index 00000000..cd60e2c1
--- /dev/null
+++ b/jobs/syncjob.cpp
@@ -0,0 +1,176 @@
+/******************************************************************************
+ * Copyright (C) 2016 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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 "syncjob.h"
+
+#include <QtCore/QJsonDocument>
+#include <QtCore/QJsonObject>
+#include <QtCore/QJsonValue>
+#include <QtCore/QJsonArray>
+#include <QtCore/QDebug>
+
+#include <QtNetwork/QNetworkReply>
+
+#include "../room.h"
+#include "../connectiondata.h"
+#include "../events/event.h"
+
+using namespace QMatrixClient;
+
+class SyncJob::Private
+{
+ public:
+ QString since;
+ QString filter;
+ bool fullState;
+ QString presence;
+ int timeout;
+ QString nextBatch;
+
+ QList<SyncRoomData> roomData;
+
+ void parseEvents(QString roomId, const QJsonObject& room, JoinState joinState);
+};
+
+SyncJob::SyncJob(ConnectionData* connection, QString since)
+ : BaseJob(connection, JobHttpType::GetJob)
+ , d(new Private)
+{
+ d->since = since;
+ d->fullState = false;
+ d->timeout = -1;
+}
+
+SyncJob::~SyncJob()
+{
+ delete d;
+}
+
+void SyncJob::setFilter(QString filter)
+{
+ d->filter = filter;
+}
+
+void SyncJob::setFullState(bool full)
+{
+ d->fullState = full;
+}
+
+void SyncJob::setPresence(QString presence)
+{
+ d->presence = presence;
+}
+
+void SyncJob::setTimeout(int timeout)
+{
+ d->timeout = timeout;
+}
+
+QString SyncJob::nextBatch() const
+{
+ return d->nextBatch;
+}
+
+QList<SyncRoomData> SyncJob::roomData() const
+{
+ return d->roomData;
+}
+
+QString SyncJob::apiPath()
+{
+ return "_matrix/client/r0/sync";
+}
+
+QUrlQuery SyncJob::query()
+{
+ QUrlQuery query;
+ if( !d->filter.isEmpty() )
+ query.addQueryItem("filter", d->filter);
+ if( d->fullState )
+ query.addQueryItem("full_state", "true");
+ if( !d->presence.isEmpty() )
+ query.addQueryItem("set_presence", d->presence);
+ if( d->timeout >= 0 )
+ query.addQueryItem("timeout", QString::number(d->timeout));
+ if( !d->since.isEmpty() )
+ query.addQueryItem("since", d->since);
+ return query;
+}
+
+void SyncJob::parseJson(const QJsonDocument& data)
+{
+ QJsonObject json = data.object();
+ d->nextBatch = json.value("next_batch").toString();
+ // TODO: presence
+ // TODO: account_data
+ QJsonObject rooms = json.value("rooms").toObject();
+
+ QJsonObject joinRooms = rooms.value("join").toObject();
+ for( const QString& roomId: joinRooms.keys() )
+ {
+ d->parseEvents(roomId, joinRooms.value(roomId).toObject(), JoinState::Join);
+ }
+
+ QJsonObject inviteRooms = rooms.value("invite").toObject();
+ for( const QString& roomId: inviteRooms.keys() )
+ {
+ d->parseEvents(roomId, inviteRooms.value(roomId).toObject(), JoinState::Invite);
+ }
+
+ QJsonObject leaveRooms = rooms.value("leave").toObject();
+ for( const QString& roomId: leaveRooms.keys() )
+ {
+ d->parseEvents(roomId, leaveRooms.value(roomId).toObject(), JoinState::Leave);
+ }
+ emitResult();
+}
+
+SyncRoomData::SyncRoomData(QString roomId_, const QJsonObject& room_, JoinState joinState_)
+ : roomId(roomId_), joinState(joinState_)
+{
+ const QList<QPair<QString, QList<Event *> *> > eventLists = {
+ { "state", &state },
+ { "timeline", &timeline },
+ { "ephemeral", &ephemeral },
+ { "account_data", &accountData }
+ };
+
+ for (auto elist: eventLists) {
+ QJsonArray array = room_.value(elist.first).toObject().value("events").toArray();
+ for( QJsonValue val: array )
+ {
+ if ( Event* event = Event::fromJson(val.toObject()) )
+ elist.second->append(event);
+ }
+ }
+
+ QJsonObject timeline = room_.value("timeline").toObject();
+ timelineLimited = timeline.value("limited").toBool();
+ timelinePrevBatch = timeline.value("prev_batch").toString();
+
+ QJsonObject unread = room_.value("unread_notifications").toObject();
+ highlightCount = unread.value("highlight_count").toInt();
+ notificationCount = unread.value("notification_count").toInt();
+ qDebug() << "Highlights: " << highlightCount << " Notifications:" << notificationCount;
+}
+
+void SyncJob::Private::parseEvents(QString roomId, const QJsonObject& room, JoinState joinState)
+{
+ roomData.append(SyncRoomData{roomId, room, joinState});
+}
+
diff --git a/jobs/syncjob.h b/jobs/syncjob.h
new file mode 100644
index 00000000..507d46eb
--- /dev/null
+++ b/jobs/syncjob.h
@@ -0,0 +1,75 @@
+/******************************************************************************
+ * Copyright (C) 2016 Felix Rohrbach <kde@fxrh.de>
+ *
+ * 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
+ */
+
+#ifndef QMATRIXCLIENT_SYNCJOB_H
+#define QMATRIXCLIENT_SYNCJOB_H
+
+#include "basejob.h"
+
+#include "../joinstate.h"
+
+namespace QMatrixClient
+{
+ class Event;
+
+ class SyncRoomData
+ {
+ public:
+ QString roomId;
+ JoinState joinState;
+ QList<Event*> state;
+ QList<Event*> timeline;
+ QList<Event*> ephemeral;
+ QList<Event*> accountData;
+
+ bool timelineLimited;
+ QString timelinePrevBatch;
+ int highlightCount;
+ int notificationCount;
+
+ SyncRoomData(QString roomId_, const QJsonObject& room_, JoinState joinState_);
+ };
+
+ class ConnectionData;
+ class SyncJob: public BaseJob
+ {
+ Q_OBJECT
+ public:
+ SyncJob(ConnectionData* connection, QString since=QString());
+ virtual ~SyncJob();
+
+ void setFilter(QString filter);
+ void setFullState(bool full);
+ void setPresence(QString presence);
+ void setTimeout(int timeout);
+
+ QList<SyncRoomData> roomData() const;
+ QString nextBatch() const;
+
+ protected:
+ QString apiPath();
+ QUrlQuery query();
+ void parseJson(const QJsonDocument& data);
+
+ private:
+ class Private;
+ Private* d;
+ };
+}
+
+#endif // QMATRIXCLIENT_GETEVENTSJOB_H