aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-05-04 12:12:07 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-05-04 13:27:28 +0900
commit4cbe1a5fe9b0ae17e89425c3127db2af9b328320 (patch)
tree70e88c522a412d4502fcf439907304abe2990bdc
parent28a0d70164e2596d306521cd18d25c0e8c0b5336 (diff)
downloadlibquotient-4cbe1a5fe9b0ae17e89425c3127db2af9b328320.tar.gz
libquotient-4cbe1a5fe9b0ae17e89425c3127db2af9b328320.zip
Preempt job/setroomstatejob.* with jobs/generated/room_state.*
The template part (not exposed in the auto-generated class) goes to Room::Private::requestSetState(). Also, Room::setMemberState() to interface with User class.
-rw-r--r--CMakeLists.txt1
-rw-r--r--lib/jobs/generated/room_state.cpp70
-rw-r--r--lib/jobs/generated/room_state.h47
-rw-r--r--lib/jobs/setroomstatejob.cpp32
-rw-r--r--lib/jobs/setroomstatejob.h64
-rw-r--r--lib/room.cpp29
-rw-r--r--lib/room.h4
-rw-r--r--lib/user.cpp5
-rw-r--r--libqmatrixclient.pri2
9 files changed, 146 insertions, 108 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5da87063..96bca983 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -83,7 +83,6 @@ set(libqmatrixclient_SRCS
lib/jobs/basejob.cpp
lib/jobs/checkauthmethods.cpp
lib/jobs/sendeventjob.cpp
- lib/jobs/setroomstatejob.cpp
lib/jobs/syncjob.cpp
lib/jobs/mediathumbnailjob.cpp
lib/jobs/downloadfilejob.cpp
diff --git a/lib/jobs/generated/room_state.cpp b/lib/jobs/generated/room_state.cpp
new file mode 100644
index 00000000..39f36afb
--- /dev/null
+++ b/lib/jobs/generated/room_state.cpp
@@ -0,0 +1,70 @@
+/******************************************************************************
+ * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
+ */
+
+#include "room_state.h"
+
+#include "converters.h"
+
+#include <QtCore/QStringBuilder>
+
+using namespace QMatrixClient;
+
+static const auto basePath = QStringLiteral("/_matrix/client/r0");
+
+class SetRoomStateWithKeyJob::Private
+{
+ public:
+ QString eventId;
+};
+
+SetRoomStateWithKeyJob::SetRoomStateWithKeyJob(const QString& roomId, const QString& eventType, const QString& stateKey, const QJsonObject& body)
+ : BaseJob(HttpVerb::Put, "SetRoomStateWithKeyJob",
+ basePath % "/rooms/" % roomId % "/state/" % eventType % "/" % stateKey)
+ , d(new Private)
+{
+ setRequestData(Data(toJson(body)));
+}
+
+SetRoomStateWithKeyJob::~SetRoomStateWithKeyJob() = default;
+
+const QString& SetRoomStateWithKeyJob::eventId() const
+{
+ return d->eventId;
+}
+
+BaseJob::Status SetRoomStateWithKeyJob::parseJson(const QJsonDocument& data)
+{
+ auto json = data.object();
+ d->eventId = fromJson<QString>(json.value("event_id"));
+ return Success;
+}
+
+class SetRoomStateJob::Private
+{
+ public:
+ QString eventId;
+};
+
+SetRoomStateJob::SetRoomStateJob(const QString& roomId, const QString& eventType, const QJsonObject& body)
+ : BaseJob(HttpVerb::Put, "SetRoomStateJob",
+ basePath % "/rooms/" % roomId % "/state/" % eventType)
+ , d(new Private)
+{
+ setRequestData(Data(toJson(body)));
+}
+
+SetRoomStateJob::~SetRoomStateJob() = default;
+
+const QString& SetRoomStateJob::eventId() const
+{
+ return d->eventId;
+}
+
+BaseJob::Status SetRoomStateJob::parseJson(const QJsonDocument& data)
+{
+ auto json = data.object();
+ d->eventId = fromJson<QString>(json.value("event_id"));
+ return Success;
+}
+
diff --git a/lib/jobs/generated/room_state.h b/lib/jobs/generated/room_state.h
new file mode 100644
index 00000000..5d16b2a6
--- /dev/null
+++ b/lib/jobs/generated/room_state.h
@@ -0,0 +1,47 @@
+/******************************************************************************
+ * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
+ */
+
+#pragma once
+
+#include "../basejob.h"
+
+#include <QtCore/QJsonObject>
+
+
+namespace QMatrixClient
+{
+ // Operations
+
+ class SetRoomStateWithKeyJob : public BaseJob
+ {
+ public:
+ explicit SetRoomStateWithKeyJob(const QString& roomId, const QString& eventType, const QString& stateKey, const QJsonObject& body = {});
+ ~SetRoomStateWithKeyJob() override;
+
+ const QString& eventId() const;
+
+ protected:
+ Status parseJson(const QJsonDocument& data) override;
+
+ private:
+ class Private;
+ QScopedPointer<Private> d;
+ };
+
+ class SetRoomStateJob : public BaseJob
+ {
+ public:
+ explicit SetRoomStateJob(const QString& roomId, const QString& eventType, const QJsonObject& body = {});
+ ~SetRoomStateJob() override;
+
+ const QString& eventId() const;
+
+ protected:
+ Status parseJson(const QJsonDocument& data) override;
+
+ private:
+ class Private;
+ QScopedPointer<Private> d;
+ };
+} // namespace QMatrixClient
diff --git a/lib/jobs/setroomstatejob.cpp b/lib/jobs/setroomstatejob.cpp
deleted file mode 100644
index c2beb87b..00000000
--- a/lib/jobs/setroomstatejob.cpp
+++ /dev/null
@@ -1,32 +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 "setroomstatejob.h"
-
-using namespace QMatrixClient;
-
-BaseJob::Status SetRoomStateJob::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/lib/jobs/setroomstatejob.h b/lib/jobs/setroomstatejob.h
deleted file mode 100644
index 36047667..00000000
--- a/lib/jobs/setroomstatejob.h
+++ /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
- */
-
-#pragma once
-
-#include "basejob.h"
-
-#include "connectiondata.h"
-
-namespace QMatrixClient
-{
- class SetRoomStateJob: public BaseJob
- {
- public:
- /**
- * Constructs a job that sets a state using an arbitrary room event
- * with a state key.
- */
- template <typename EvT>
- SetRoomStateJob(const QString& roomId, const QString& stateKey,
- const EvT& event)
- : BaseJob(HttpVerb::Put, "SetRoomStateJob",
- QStringLiteral("_matrix/client/r0/rooms/%1/state/%2/%3")
- .arg(roomId, EvT::typeId(), stateKey),
- Query(),
- Data(event.toJson()))
- { }
- /**
- * Constructs a job that sets a state using an arbitrary room event
- * without a state key.
- */
- template <typename EvT>
- SetRoomStateJob(const QString& roomId, const EvT& event)
- : BaseJob(HttpVerb::Put, "SetRoomStateJob",
- QStringLiteral("_matrix/client/r0/rooms/%1/state/%2")
- .arg(roomId, EvT::typeId()),
- Query(),
- Data(event.toJson()))
- { }
-
- QString eventId() const { return _eventId; }
-
- protected:
- Status parseJson(const QJsonDocument& data) override;
-
- private:
- QString _eventId;
- };
-} // namespace QMatrixClient
diff --git a/lib/room.cpp b/lib/room.cpp
index f8f195e1..2ec5a591 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -26,7 +26,7 @@
#include "jobs/generated/redaction.h"
#include "jobs/generated/account-data.h"
#include "jobs/generated/message_pagination.h"
-#include "jobs/setroomstatejob.h"
+#include "jobs/generated/room_state.h"
#include "events/simplestateevents.h"
#include "events/roomavatarevent.h"
#include "events/roommemberevent.h"
@@ -199,6 +199,20 @@ class Room::Private
void markMessagesAsRead(rev_iter_t upToMarker);
+ template <typename EvT>
+ auto requestSetState(const QString& stateKey, const EvT& event)
+ {
+ return connection->callApi<SetRoomStateWithKeyJob>(
+ id, EvT::typeId(), stateKey, event.toJson());
+ }
+
+ template <typename EvT>
+ auto requestSetState(const EvT& event)
+ {
+ return connection->callApi<SetRoomStateJob>(
+ id, EvT::typeId(), event.toJson());
+ }
+
/**
* @brief Apply redaction to the timeline
*
@@ -1110,19 +1124,17 @@ void Room::postMessage(const RoomMessageEvent& event)
void Room::setName(const QString& newName)
{
- connection()->callApi<SetRoomStateJob>(id(), RoomNameEvent(newName));
+ d->requestSetState(RoomNameEvent(newName));
}
void Room::setCanonicalAlias(const QString& newAlias)
{
- connection()->callApi<SetRoomStateJob>(id(),
- RoomCanonicalAliasEvent(newAlias));
+ d->requestSetState(RoomCanonicalAliasEvent(newAlias));
}
void Room::setTopic(const QString& newTopic)
{
- RoomTopicEvent evt(newTopic);
- connection()->callApi<SetRoomStateJob>(id(), evt);
+ d->requestSetState(RoomTopicEvent(newTopic));
}
void Room::getPreviousContent(int limit)
@@ -1153,6 +1165,11 @@ LeaveRoomJob* Room::leaveRoom()
return connection()->callApi<LeaveRoomJob>(id());
}
+SetRoomStateWithKeyJob*Room::setMemberState(const QString& memberId, const RoomMemberEvent& event) const
+{
+ return d->requestSetState(memberId, event);
+}
+
void Room::kickMember(const QString& memberId, const QString& reason)
{
connection()->callApi<KickJob>(id(), memberId, reason);
diff --git a/lib/room.h b/lib/room.h
index 7b4b3578..0d629e20 100644
--- a/lib/room.h
+++ b/lib/room.h
@@ -32,10 +32,12 @@
namespace QMatrixClient
{
class Event;
+ class RoomMemberEvent;
class Connection;
class User;
class MemberSorter;
class LeaveRoomJob;
+ class SetRoomStateWithKeyJob;
class RedactEventJob;
class TimelineItem
@@ -344,6 +346,8 @@ namespace QMatrixClient
void inviteToRoom(const QString& memberId);
LeaveRoomJob* leaveRoom();
+ SetRoomStateWithKeyJob* setMemberState(
+ const QString& memberId, const RoomMemberEvent& event) const;
void kickMember(const QString& memberId, const QString& reason = {});
void ban(const QString& userId, const QString& reason = {});
void unban(const QString& userId);
diff --git a/lib/user.cpp b/lib/user.cpp
index 89e324f9..5c380424 100644
--- a/lib/user.cpp
+++ b/lib/user.cpp
@@ -23,7 +23,7 @@
#include "avatar.h"
#include "events/event.h"
#include "events/roommemberevent.h"
-#include "jobs/setroomstatejob.h"
+#include "jobs/generated/room_state.h"
#include "jobs/generated/profile.h"
#include "jobs/generated/content-repo.h"
@@ -277,8 +277,7 @@ void User::rename(const QString& newName, const Room* r)
"Attempt to rename a user that's not a room member");
MemberEventContent evtC;
evtC.displayName = newName;
- auto job = d->connection->callApi<SetRoomStateJob>(
- r->id(), id(), RoomMemberEvent(move(evtC)));
+ auto job = r->setMemberState(id(), RoomMemberEvent(move(evtC)));
connect(job, &BaseJob::success, this, [=] { updateName(newName, r); });
}
diff --git a/libqmatrixclient.pri b/libqmatrixclient.pri
index 39e153a2..3aa419bb 100644
--- a/libqmatrixclient.pri
+++ b/libqmatrixclient.pri
@@ -36,7 +36,6 @@ HEADERS += \
$$SRCPATH/jobs/postreceiptjob.h \
$$SRCPATH/jobs/syncjob.h \
$$SRCPATH/jobs/mediathumbnailjob.h \
- $$SRCPATH/jobs/setroomstatejob.h \
$$SRCPATH/jobs/downloadfilejob.h \
$$SRCPATH/jobs/postreadmarkersjob.h \
$$files($$SRCPATH/jobs/generated/*.h, false) \
@@ -67,7 +66,6 @@ SOURCES += \
$$SRCPATH/jobs/postreceiptjob.cpp \
$$SRCPATH/jobs/syncjob.cpp \
$$SRCPATH/jobs/mediathumbnailjob.cpp \
- $$SRCPATH/jobs/setroomstatejob.cpp \
$$SRCPATH/jobs/downloadfilejob.cpp \
$$files($$SRCPATH/jobs/generated/*.cpp, false) \
$$files($$SRCPATH/jobs/generated/definitions/*.cpp, false) \