From 096fbd4ed4033bbf770769b50ed709862c369281 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 26 Jan 2018 20:54:13 +0900 Subject: Connection::createRoom and Connection::createDirectChat --- connection.cpp | 21 +++++++++++++++++++++ connection.h | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+) 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& invites, const QString& presetName, + bool isDirect, bool guestsCanJoin, + const QVector& initialState, + const QVector& invite3pids, + const QJsonObject creationContent) +{ + return callApi( + 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 @@ -58,6 +59,8 @@ namespace QMatrixClient using user_factory_t = std::function; + 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& invites, const QString& presetName = {}, bool isDirect = false, + bool guestsCanJoin = false, + const QVector& initialState = {}, + const QVector& 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. -- cgit v1.2.3