From c9ace4f4037577846085fa6805a2918c5a2e745b Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 2 Jul 2018 18:24:09 +0900 Subject: Support ignoring users Closes #215. --- lib/connection.h | 62 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 8 deletions(-) (limited to 'lib/connection.h') diff --git a/lib/connection.h b/lib/connection.h index a1662449..b2bfdce3 100644 --- a/lib/connection.h +++ b/lib/connection.h @@ -20,6 +20,7 @@ #include "csapi/create_room.h" #include "joinstate.h" +#include "events/accountdataevents.h" #include #include @@ -32,7 +33,6 @@ namespace QMatrixClient { class Room; class User; - class RoomEvent; class ConnectionData; class SyncJob; @@ -46,7 +46,6 @@ namespace QMatrixClient class GetContentJob; class DownloadFileJob; class SendToDeviceJob; - class Event; /** Enumeration with flags defining the network job running policy * So far only background/foreground flags are available. @@ -74,10 +73,7 @@ namespace QMatrixClient std::function; using DirectChatsMap = QMultiHash; - - using AccountDataMap = std::conditional_t< - QT_VERSION >= QT_VERSION_CHECK(5, 5, 0), - QVariantHash, QVariantMap>; + using IgnoredUsersList = IgnoredUsersEvent::content_type; using UsersToDevicesToEvents = std::unordered_map + const typename EventT::content_type accountData() const + { + if (const auto& eventPtr = accountData(EventT::matrixTypeId())) + return eventPtr->content(); + return {}; + } + + /** Get account data as a JSON object + * This returns the content part of the account data event + * of the given type. Direct chats map cannot be retrieved using + * this method _yet_; use directChats() instead. + */ + Q_INVOKABLE QJsonObject accountDataJson(const QString& type) const; + + /** Set a generic account data event of the given type */ + void setAccountData(EventPtr&& event); + + Q_INVOKABLE void setAccountData(const QString& type, + const QJsonObject& content); /** Get all Invited and Joined rooms grouped by tag * \return a hashmap from tag name to a vector of room pointers, @@ -154,6 +176,27 @@ namespace QMatrixClient */ QList directChatUsers(const Room* room) const; + /** Check whether a particular user is in the ignore list */ + bool isIgnored(const User* user) const; + + /** Get the whole list of ignored users */ + IgnoredUsersList ignoredUsers() const; + + /** Add the user to the ignore list + * The change signal is emitted synchronously, without waiting + * to complete synchronisation with the server. + * + * \sa ignoredUsersListChanged + */ + void addToIgnoredUsers(const User* user); + + /** Remove the user from the ignore list + * Similar to adding, the change signal is emitted synchronously. + * + * \sa ignoredUsersListChanged + */ + void removeFromIgnoredUsers(const User* user); + /** Get the full list of users known to this account */ QMap users() const; @@ -516,6 +559,9 @@ namespace QMatrixClient void directChatsListChanged(DirectChatsMap additions, DirectChatsMap removals); + void ignoredUsersListChanged(IgnoredUsersList additions, + IgnoredUsersList removals); + void cacheStateChanged(); protected: -- cgit v1.2.3