diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-02 18:24:09 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-04 21:34:54 +0900 |
commit | c9ace4f4037577846085fa6805a2918c5a2e745b (patch) | |
tree | e2714a724bd5c2ad7b0976ce2d48e5d192d20d8a /lib/connection.h | |
parent | b52f3998a454a18ad46d1f276052965b96cd2ca9 (diff) | |
download | libquotient-c9ace4f4037577846085fa6805a2918c5a2e745b.tar.gz libquotient-c9ace4f4037577846085fa6805a2918c5a2e745b.zip |
Support ignoring users
Closes #215.
Diffstat (limited to 'lib/connection.h')
-rw-r--r-- | lib/connection.h | 62 |
1 files changed, 54 insertions, 8 deletions
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 <QtCore/QObject> #include <QtCore/QUrl> @@ -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<User*(Connection*, const QString&)>; using DirectChatsMap = QMultiHash<const User*, QString>; - - 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<QString, @@ -101,11 +97,37 @@ namespace QMatrixClient bool hasAccountData(const QString& type) const; /** Get a generic account data event of the given type - * This returns a generic hashmap for any account data event + * This returns an account data event of the given type + * stored on the server. Direct chats map cannot be retrieved + * using this method _yet_; use directChats() instead. + */ + const EventPtr& accountData(const QString& type) const; + + /** Get a generic account data event of the given type + * This returns an account data event of the given type * stored on the server. Direct chats map cannot be retrieved * using this method _yet_; use directChats() instead. */ - AccountDataMap accountData(const QString& type) const; + template <typename EventT> + 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<const User*> 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<QString, User*> users() const; @@ -516,6 +559,9 @@ namespace QMatrixClient void directChatsListChanged(DirectChatsMap additions, DirectChatsMap removals); + void ignoredUsersListChanged(IgnoredUsersList additions, + IgnoredUsersList removals); + void cacheStateChanged(); protected: |