aboutsummaryrefslogtreecommitdiff
path: root/jobs
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2017-03-08 20:22:44 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2017-03-08 20:30:27 +0900
commitde9448a65655451e1310947955dd6b341479dc23 (patch)
tree0879b1af22932751da48ef5b58d4e188a6a9f4ad /jobs
parentba5ca3c88a20926f2be06872f530d9da12d5a062 (diff)
downloadlibquotient-de9448a65655451e1310947955dd6b341479dc23.tar.gz
libquotient-de9448a65655451e1310947955dd6b341479dc23.zip
Connection::callApi<>, a factory for all API call jobs
This call (intended to only be used within the lib) creates a job object of the passed type and passes a ConnectionData pointer to its constructor. This allows to avoid making a switchboard of methods on Connection for the whole API, leaving only those that naturally belong there - e.g. joinRoom() or sync() - and moving, e.g., postMessage() to where it belongs - Room. PostMessageJob and RoomMessagesJob were updated along the way, to unbind from the Room class (which they really don't and won't need).
Diffstat (limited to 'jobs')
-rw-r--r--jobs/postmessagejob.cpp6
-rw-r--r--jobs/postmessagejob.h4
-rw-r--r--jobs/roommessagesjob.cpp9
-rw-r--r--jobs/roommessagesjob.h9
4 files changed, 14 insertions, 14 deletions
diff --git a/jobs/postmessagejob.cpp b/jobs/postmessagejob.cpp
index 9903bec6..a835cd9f 100644
--- a/jobs/postmessagejob.cpp
+++ b/jobs/postmessagejob.cpp
@@ -17,7 +17,6 @@
*/
#include "postmessagejob.h"
-#include "../room.h"
#include "../connectiondata.h"
#include <QtNetwork/QNetworkReply>
@@ -32,9 +31,10 @@ class PostMessageJob::Private
QString eventId; // unused yet
};
-PostMessageJob::PostMessageJob(ConnectionData* connection, Room* room, QString type, QString message)
+PostMessageJob::PostMessageJob(ConnectionData* connection, QString roomId,
+ QString type, QString message)
: BaseJob(connection, JobHttpType::PostJob, "PostMessageJob",
- QString("_matrix/client/r0/rooms/%1/send/m.room.message").arg(room->id()),
+ QString("_matrix/client/r0/rooms/%1/send/m.room.message").arg(roomId),
Query(),
Data({ { "msgtype", type }, { "body", message } }))
, d(new Private)
diff --git a/jobs/postmessagejob.h b/jobs/postmessagejob.h
index 2e1989fd..eba3da51 100644
--- a/jobs/postmessagejob.h
+++ b/jobs/postmessagejob.h
@@ -22,11 +22,11 @@
namespace QMatrixClient
{
- class Room;
class PostMessageJob: public BaseJob
{
public:
- PostMessageJob(ConnectionData* connection, Room* room, QString type, QString message);
+ PostMessageJob(ConnectionData* connection, QString roomId,
+ QString type, QString message);
virtual ~PostMessageJob();
//bool success();
diff --git a/jobs/roommessagesjob.cpp b/jobs/roommessagesjob.cpp
index 7a0bc756..fd972eaf 100644
--- a/jobs/roommessagesjob.cpp
+++ b/jobs/roommessagesjob.cpp
@@ -17,7 +17,7 @@
*/
#include "roommessagesjob.h"
-#include "../room.h"
+#include "../util.h"
#include <QtCore/QJsonArray>
@@ -32,12 +32,13 @@ class RoomMessagesJob::Private
QString end;
};
-RoomMessagesJob::RoomMessagesJob(ConnectionData* data, Room* room, QString from, FetchDirectory dir, int limit)
+RoomMessagesJob::RoomMessagesJob(ConnectionData* data, QString roomId,
+ QString from, int limit, FetchDirection dir)
: BaseJob(data, JobHttpType::GetJob, "RoomMessagesJob",
- QString("/_matrix/client/r0/rooms/%1/messages").arg(room->id()),
+ QString("/_matrix/client/r0/rooms/%1/messages").arg(roomId),
Query(
{ { "from", from }
- , { "dir", dir == FetchDirectory::Backwards ? "b" : "f" }
+ , { "dir", dir == FetchDirection::Backward ? "b" : "f" }
, { "limit", QString::number(limit) }
}))
, d(new Private)
diff --git a/jobs/roommessagesjob.h b/jobs/roommessagesjob.h
index fd6a131d..af7d65df 100644
--- a/jobs/roommessagesjob.h
+++ b/jobs/roommessagesjob.h
@@ -24,15 +24,14 @@
namespace QMatrixClient
{
- class Room;
-
- enum class FetchDirectory { Backwards, Forward };
+ enum class FetchDirection { Backward, Forward };
class RoomMessagesJob: public BaseJob
{
public:
- RoomMessagesJob(ConnectionData* data, Room* room, QString from,
- FetchDirectory dir = FetchDirectory::Backwards, int limit=10);
+ RoomMessagesJob(ConnectionData* data, QString roomId,
+ QString from, int limit = 10,
+ FetchDirection dir = FetchDirection::Backward);
virtual ~RoomMessagesJob();
Events releaseEvents();