From 2393ea6a1c43f2e7ac7bcb5d7fb4915cec09f2e3 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 26 Jan 2018 20:53:01 +0900 Subject: Connection class cleanup createRoom and createUser renamed to roomFactory and userFactory (because createRoom will mean a different thing); unneeded #include moved to the cpp file. --- connection.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'connection.h') diff --git a/connection.h b/connection.h index 79d7d658..b9aa328b 100644 --- a/connection.h +++ b/connection.h @@ -18,7 +18,6 @@ #pragma once -#include "jobs/generated/leaving.h" #include "joinstate.h" #include @@ -39,6 +38,7 @@ namespace QMatrixClient class SyncData; class RoomMessagesJob; class PostReceiptJob; + class ForgetRoomJob; class MediaThumbnailJob; class JoinRoomJob; class UploadContentJob; @@ -145,7 +145,7 @@ namespace QMatrixClient template static void setRoomType() { - createRoom = + roomFactory = [](Connection* c, const QString& id, JoinState joinState) { return new T(c, id, joinState); }; } @@ -153,7 +153,7 @@ namespace QMatrixClient template static void setUserType() { - createUser = + userFactory = [](Connection* c, const QString& id) { return new T(id, c); }; } @@ -186,15 +186,15 @@ namespace QMatrixClient int requestedHeight) const; // QIODevice* should already be open - virtual UploadContentJob* uploadContent(QIODevice* contentSource, + UploadContentJob* uploadContent(QIODevice* contentSource, const QString& filename = {}, const QString& contentType = {}) const; - virtual UploadContentJob* uploadFile(const QString& fileName, - const QString& contentType = {}); - virtual GetContentJob* getContent(const QString& mediaId) const; + UploadContentJob* uploadFile(const QString& fileName, + const QString& contentType = {}); + GetContentJob* getContent(const QString& mediaId) const; GetContentJob* getContent(const QUrl& url) const; // If localFilename is empty, a temporary file will be created - virtual DownloadFileJob* downloadFile(const QUrl& url, + DownloadFileJob* downloadFile(const QUrl& url, const QString& localFilename = {}) const; virtual JoinRoomJob* joinRoom(const QString& roomAlias); @@ -310,7 +310,7 @@ namespace QMatrixClient * the server; in particular, does not automatically create rooms * on the server. * @return a pointer to a Room object with the specified id; nullptr - * if roomId is empty if createRoom() failed to create a Room object. + * if roomId is empty if roomFactory() failed to create a Room object. */ Room* provideRoom(const QString& roomId, JoinState joinState); @@ -340,7 +340,7 @@ namespace QMatrixClient const QString& initialDeviceName, const QString& deviceId = {}); - static room_factory_t createRoom; - static user_factory_t createUser; + static room_factory_t roomFactory; + static user_factory_t userFactory; }; } // namespace QMatrixClient -- cgit v1.2.3 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.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'connection.h') 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 From fcb0342410beaacc84c59813a1a7b6195c6abf7f Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 30 Jan 2018 15:13:35 +0900 Subject: Connection: more Q_PROPERTYs, newUser signal --- connection.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'connection.h') diff --git a/connection.h b/connection.h index 47f8e4de..792ed126 100644 --- a/connection.h +++ b/connection.h @@ -52,6 +52,11 @@ namespace QMatrixClient /** Whether or not the rooms state should be cached locally * \sa loadState(), saveState() */ + Q_PROPERTY(User* localUser READ user CONSTANT) + Q_PROPERTY(QString localUserId READ userId CONSTANT) + Q_PROPERTY(QString deviceId READ deviceId CONSTANT) + Q_PROPERTY(QByteArray accessToken READ accessToken CONSTANT) + Q_PROPERTY(QUrl homeserver READ homeserver WRITE setHomeserver NOTIFY homeserverChanged) Q_PROPERTY(bool cacheState READ cacheState WRITE setCacheState NOTIFY cacheStateChanged) public: using room_factory_t = @@ -83,14 +88,14 @@ namespace QMatrixClient // FIXME: Convert Q_INVOKABLEs to Q_PROPERTIES // (breaks back-compatibility) - Q_INVOKABLE QUrl homeserver() const; + QUrl homeserver() const; Q_INVOKABLE User* user(const QString& userId); - Q_INVOKABLE User* user(); - Q_INVOKABLE QString userId() const; - Q_INVOKABLE QString deviceId() const; + User* user(); + QString userId() const; + QString deviceId() const; /** @deprecated Use accessToken() instead. */ Q_INVOKABLE QString token() const; - Q_INVOKABLE QByteArray accessToken() const; + QByteArray accessToken() const; Q_INVOKABLE SyncJob* syncJob() const; Q_INVOKABLE int millisToReconnect() const; @@ -257,6 +262,8 @@ namespace QMatrixClient void syncDone(); void syncError(QString error); + void newUser(User* user); + /** * \group Signals emitted on room transitions * @@ -364,3 +371,4 @@ namespace QMatrixClient static user_factory_t userFactory; }; } // namespace QMatrixClient +Q_DECLARE_METATYPE(QMatrixClient::Connection*) -- cgit v1.2.3 From 038471e340c51f36f612fbb19d8a2b60a9923973 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 30 Jan 2018 15:35:06 +0900 Subject: Connection: expose the list of users; use an ordered map It's still an open question whether it's better to store a separate sorted index of users, next to an unsorted one; but a sorted list of users is of much more use in GUI than an unsorted one. --- connection.h | 1 + 1 file changed, 1 insertion(+) (limited to 'connection.h') diff --git a/connection.h b/connection.h index 792ed126..2f7c38b3 100644 --- a/connection.h +++ b/connection.h @@ -71,6 +71,7 @@ namespace QMatrixClient virtual ~Connection(); QHash, Room*> roomMap() const; + QMap users() const; /** Sends /forget to the server and also deletes room locally. * This method is in Connection, not in Room, since it's a -- cgit v1.2.3