aboutsummaryrefslogtreecommitdiff
path: root/jobs
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2017-06-22 16:38:29 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2017-06-27 19:44:14 +0900
commit749def2b983d2338272c0891d15de20df22e2eea (patch)
treea960df12d66c462d261ee84b55903f6cadc74ed8 /jobs
parent7d745dca7bdd328fd96acdf53f15f4a5cd7cf484 (diff)
downloadlibquotient-749def2b983d2338272c0891d15de20df22e2eea.tar.gz
libquotient-749def2b983d2338272c0891d15de20df22e2eea.zip
Enable sending RoomMessageEvents
1. PostMessageJob is now SendEventJob, which reflects two things: first, it's a PUT instead of a POST (POST for /send is not supported by the latest spec anyway), so that we could enable tracking transaction ids for local echo in the near future; second, it's no more just about messages, the job can support sending any room events (topic changes etc.). 2. Room::postMessage() now uses the new RoomMessageEvent API to send m.room.message events.
Diffstat (limited to 'jobs')
-rw-r--r--jobs/postmessagejob.cpp64
-rw-r--r--jobs/sendeventjob.cpp41
-rw-r--r--jobs/sendeventjob.h (renamed from jobs/postmessagejob.h)35
3 files changed, 64 insertions, 76 deletions
diff --git a/jobs/postmessagejob.cpp b/jobs/postmessagejob.cpp
deleted file mode 100644
index df30614c..00000000
--- a/jobs/postmessagejob.cpp
+++ /dev/null
@@ -1,64 +0,0 @@
-/******************************************************************************
- * 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 "util.h"
-
-using namespace QMatrixClient;
-
-class PostMessageJob::Private
-{
- public:
- QString eventId; // unused yet
-};
-
-PostMessageJob::PostMessageJob(const ConnectionData* connection,
- const QString& roomId, const QString& type,
- const QString& plainText)
- : BaseJob(connection, HttpVerb::Post, "PostMessageJob",
- QStringLiteral("_matrix/client/r0/rooms/%1/send/m.room.message").arg(roomId),
- Query(),
- Data({ { "msgtype", type }, { "body", plainText } }) )
- , d(new Private)
-{ }
-
-PostMessageJob::PostMessageJob(const ConnectionData* connection,
- const QString& roomId, const QString& type,
- const QString& plainText, const QString& richText)
- : BaseJob(connection, HttpVerb::Post, "PostMessageJob",
- QStringLiteral("_matrix/client/r0/rooms/%1/send/m.room.message").arg(roomId),
- Query(),
- Data({ { "msgtype", type }, { "body", plainText }
- , { "format", QStringLiteral("org.matrix.custom.html") }
- , { "formatted_body", richText } }) )
- , d(new Private)
-{ }
-
-PostMessageJob::~PostMessageJob()
-{
- delete d;
-}
-
-BaseJob::Status PostMessageJob::parseJson(const QJsonDocument& data)
-{
- if( data.object().contains("event_id") )
- return Success;
-
- qCDebug(JOBS) << data;
- return { UserDefinedError, "No event_id in the JSON response" };
-}
diff --git a/jobs/sendeventjob.cpp b/jobs/sendeventjob.cpp
new file mode 100644
index 00000000..f3c95fe8
--- /dev/null
+++ b/jobs/sendeventjob.cpp
@@ -0,0 +1,41 @@
+/******************************************************************************
+ * 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 "sendeventjob.h"
+
+#include "events/roommessageevent.h"
+
+using namespace QMatrixClient;
+
+SendEventJob::SendEventJob(const ConnectionData* connection,
+ const QString& roomId, const QString& type,
+ const QString& plainText)
+ : SendEventJob(connection, roomId,
+ new RoomMessageEvent(plainText, type))
+{ }
+
+BaseJob::Status SendEventJob::parseJson(const QJsonDocument& data)
+{
+ _eventId = data.object().value("event_id").toString();
+ if (!_eventId.isEmpty())
+ return Success;
+
+ qCDebug(JOBS) << data;
+ return { UserDefinedError, "No event_id in the JSON response" };
+}
+
diff --git a/jobs/postmessagejob.h b/jobs/sendeventjob.h
index f4ae809b..180fdd19 100644
--- a/jobs/postmessagejob.h
+++ b/jobs/sendeventjob.h
@@ -20,27 +20,38 @@
#include "basejob.h"
+#include "connectiondata.h"
+
namespace QMatrixClient
{
- class PostMessageJob: public BaseJob
+ class SendEventJob: public BaseJob
{
public:
- /** Constructs a plain text message job */
- PostMessageJob(const ConnectionData* connection, const QString& roomId,
- const QString& type, const QString& plainText);
- /** Constructs a rich text message job */
- PostMessageJob(const ConnectionData* connection, const QString& roomId,
- const QString& type, const QString& plainText,
- const QString& richText);
- virtual ~PostMessageJob();
+ /** Constructs a job that sends an arbitrary room event */
+ template <typename EvT>
+ SendEventJob(const ConnectionData* connection, const QString& roomId,
+ const EvT* event)
+ : BaseJob(connection, HttpVerb::Put, "SendEventJob",
+ QStringLiteral("_matrix/client/r0/rooms/%1/send/%2/%3")
+ .arg(roomId).arg(EvT::TypeId)
+ .arg(event->transactionId()),
+ Query(),
+ Data(event->toJson()))
+ { }
+
+ /**
+ * Constructs a plain text message job (for compatibility with
+ * the old PostMessageJob API).
+ */
+ SendEventJob(const ConnectionData* connection, const QString& roomId,
+ const QString& type, const QString& plainText);
- //bool success();
+ QString eventId() const { return _eventId; }
protected:
Status parseJson(const QJsonDocument& data) override;
private:
- class Private;
- Private* d;
+ QString _eventId;
};
} // namespace QMatrixClient