aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--connection.cpp21
-rw-r--r--connection.h20
2 files changed, 41 insertions, 0 deletions
diff --git a/connection.cpp b/connection.cpp
index 51a73e8d..00116c5f 100644
--- a/connection.cpp
+++ b/connection.cpp
@@ -386,6 +386,27 @@ DownloadFileJob* Connection::downloadFile(const QUrl& url,
return job;
}
+CreateRoomJob* Connection::createRoom(RoomVisibility visibility,
+ const QString& alias, const QString& name, const QString& topic,
+ const QVector<QString>& invites, const QString& presetName,
+ bool isDirect, bool guestsCanJoin,
+ const QVector<CreateRoomJob::StateEvent>& initialState,
+ const QVector<CreateRoomJob::Invite3pid>& invite3pids,
+ const QJsonObject creationContent)
+{
+ return callApi<CreateRoomJob>(
+ visibility == PublishRoom ? "public" : "private", alias, name,
+ topic, invites, invite3pids, creationContent, initialState,
+ presetName, isDirect, guestsCanJoin);
+}
+
+CreateRoomJob* Connection::createDirectChat(const QString& userId,
+ const QString& topic, const QString& name)
+{
+ return createRoom(UnpublishRoom, "", name, topic, {userId},
+ "trusted_private_chat", true);
+}
+
ForgetRoomJob* Connection::forgetRoom(const QString& id)
{
// To forget is hard :) First we should ensure the local user is not
diff --git a/connection.h b/connection.h
index b9aa328b..47f8e4de 100644
--- a/connection.h
+++ b/connection.h
@@ -18,6 +18,7 @@
#pragma once
+#include "jobs/generated/create_room.h"
#include "joinstate.h"
#include <QtCore/QObject>
@@ -58,6 +59,8 @@ namespace QMatrixClient
using user_factory_t =
std::function<User*(Connection*, const QString&)>;
+ enum RoomVisibility { PublishRoom, UnpublishRoom }; // FIXME: Should go inside CreateRoomJob
+
explicit Connection(QObject* parent = nullptr);
explicit Connection(const QUrl& server, QObject* parent = nullptr);
virtual ~Connection();
@@ -197,6 +200,23 @@ namespace QMatrixClient
DownloadFileJob* downloadFile(const QUrl& url,
const QString& localFilename = {}) const;
+ /**
+ * \brief Create a room (generic method)
+ * This method allows to customize room entirely to your liking,
+ * providing all the attributes the original CS API provides.
+ */
+ CreateRoomJob* createRoom(RoomVisibility visibility,
+ const QString& alias, const QString& name, const QString& topic,
+ const QVector<QString>& invites, const QString& presetName = {}, bool isDirect = false,
+ bool guestsCanJoin = false,
+ const QVector<CreateRoomJob::StateEvent>& initialState = {},
+ const QVector<CreateRoomJob::Invite3pid>& invite3pids = {},
+ const QJsonObject creationContent = {});
+
+ /** Create a direct chat with a single user, optional name and topic */
+ CreateRoomJob* createDirectChat(const QString& userId,
+ const QString& topic = {}, const QString& name = {});
+
virtual JoinRoomJob* joinRoom(const QString& roomAlias);
// Old API that will be abolished any time soon. DO NOT USE.