aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/rooms.h
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2022-10-06 19:27:24 +0200
committern-peugnet <n.peugnet@free.fr>2022-10-06 19:27:24 +0200
commitd911b207f49e936b3e992200796110f0749ed150 (patch)
tree96d20ebb4d074a4c1755e21cb316a52d584daee3 /lib/csapi/rooms.h
parent8ad8a74152c5701b6ca1f9a00487ba9257a439b4 (diff)
parent56c2f2e2b809b9077393eb617828f33d144f5634 (diff)
downloadlibquotient-d911b207f49e936b3e992200796110f0749ed150.tar.gz
libquotient-d911b207f49e936b3e992200796110f0749ed150.zip
New upstream version 0.7.0
Diffstat (limited to 'lib/csapi/rooms.h')
-rw-r--r--lib/csapi/rooms.h434
1 files changed, 193 insertions, 241 deletions
diff --git a/lib/csapi/rooms.h b/lib/csapi/rooms.h
index 2366918b..7823a1b0 100644
--- a/lib/csapi/rooms.h
+++ b/lib/csapi/rooms.h
@@ -4,257 +4,209 @@
#pragma once
+#include "events/roomevent.h"
+#include "events/stateevent.h"
#include "jobs/basejob.h"
-#include "events/roommemberevent.h"
-#include "events/eventloader.h"
-#include <QtCore/QHash>
-#include "converters.h"
+namespace Quotient {
-namespace QMatrixClient
-{
- // Operations
-
- /// Get a single event by event ID.
- ///
- /// Get a single event based on ``roomId/eventId``. You must have permission to
- /// retrieve this event e.g. by being a member in the room for this event.
- class GetOneRoomEventJob : public BaseJob
- {
- public:
- /*! Get a single event by event ID.
- * \param roomId
- * The ID of the room the event is in.
- * \param eventId
- * The event ID to get.
- */
- explicit GetOneRoomEventJob(const QString& roomId, const QString& eventId);
-
- /*! Construct a URL without creating a full-fledged job object
- *
- * This function can be used when a URL for
- * GetOneRoomEventJob is necessary but the job
- * itself isn't.
- */
- static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& eventId);
-
- ~GetOneRoomEventJob() override;
-
- // Result properties
-
- /// The full event.
- EventPtr&& data();
-
- protected:
- Status parseJson(const QJsonDocument& data) override;
-
- private:
- class Private;
- QScopedPointer<Private> d;
- };
-
- /// Get the state identified by the type and key.
- ///
- /// Looks up the contents of a state event in a room. If the user is
- /// joined to the room then the state is taken from the current
- /// state of the room. If the user has left the room then the state is
- /// taken from the state of the room when they left.
- class GetRoomStateWithKeyJob : public BaseJob
- {
- public:
- /*! Get the state identified by the type and key.
- * \param roomId
- * The room to look up the state in.
- * \param eventType
- * The type of state to look up.
- * \param stateKey
- * The key of the state to look up.
- */
- explicit GetRoomStateWithKeyJob(const QString& roomId, const QString& eventType, const QString& stateKey);
-
- /*! Construct a URL without creating a full-fledged job object
- *
- * This function can be used when a URL for
- * GetRoomStateWithKeyJob is necessary but the job
- * itself isn't.
- */
- static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& eventType, const QString& stateKey);
-
- ~GetRoomStateWithKeyJob() override;
-
- // Result properties
-
- /// The content of the state event.
- StateEventPtr&& data();
-
- protected:
- Status parseJson(const QJsonDocument& data) override;
-
- private:
- class Private;
- QScopedPointer<Private> d;
- };
-
- /// Get the state identified by the type, with the empty state key.
- ///
- /// Looks up the contents of a state event in a room. If the user is
- /// joined to the room then the state is taken from the current
- /// state of the room. If the user has left the room then the state is
- /// taken from the state of the room when they left.
- ///
- /// This looks up the state event with the empty state key.
- class GetRoomStateByTypeJob : public BaseJob
- {
- public:
- /*! Get the state identified by the type, with the empty state key.
- * \param roomId
- * The room to look up the state in.
- * \param eventType
- * The type of state to look up.
- */
- explicit GetRoomStateByTypeJob(const QString& roomId, const QString& eventType);
-
- /*! Construct a URL without creating a full-fledged job object
- *
- * This function can be used when a URL for
- * GetRoomStateByTypeJob is necessary but the job
- * itself isn't.
- */
- static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& eventType);
-
- ~GetRoomStateByTypeJob() override;
-
- // Result properties
-
- /// The content of the state event.
- StateEventPtr&& data();
-
- protected:
- Status parseJson(const QJsonDocument& data) override;
+/*! \brief Get a single event by event ID.
+ *
+ * Get a single event based on `roomId/eventId`. You must have permission to
+ * retrieve this event e.g. by being a member in the room for this event.
+ */
+class QUOTIENT_API GetOneRoomEventJob : public BaseJob {
+public:
+ /*! \brief Get a single event by event ID.
+ *
+ * \param roomId
+ * The ID of the room the event is in.
+ *
+ * \param eventId
+ * The event ID to get.
+ */
+ explicit GetOneRoomEventJob(const QString& roomId, const QString& eventId);
+
+ /*! \brief Construct a URL without creating a full-fledged job object
+ *
+ * This function can be used when a URL for GetOneRoomEventJob
+ * is necessary but the job itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId,
+ const QString& eventId);
+
+ // Result properties
+
+ /// The full event.
+ RoomEventPtr event() { return fromJson<RoomEventPtr>(jsonData()); }
+};
+
+/*! \brief Get the state identified by the type and key.
+ *
+ * Looks up the contents of a state event in a room. If the user is
+ * joined to the room then the state is taken from the current
+ * state of the room. If the user has left the room then the state is
+ * taken from the state of the room when they left.
+ */
+class QUOTIENT_API GetRoomStateWithKeyJob : public BaseJob {
+public:
+ /*! \brief Get the state identified by the type and key.
+ *
+ * \param roomId
+ * The room to look up the state in.
+ *
+ * \param eventType
+ * The type of state to look up.
+ *
+ * \param stateKey
+ * The key of the state to look up. Defaults to an empty string. When
+ * an empty string, the trailing slash on this endpoint is optional.
+ */
+ explicit GetRoomStateWithKeyJob(const QString& roomId,
+ const QString& eventType,
+ const QString& stateKey);
+
+ /*! \brief Construct a URL without creating a full-fledged job object
+ *
+ * This function can be used when a URL for GetRoomStateWithKeyJob
+ * is necessary but the job itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId,
+ const QString& eventType,
+ const QString& stateKey);
+};
+
+/*! \brief Get all state events in the current state of a room.
+ *
+ * Get the state events for the current state of a room.
+ */
+class QUOTIENT_API GetRoomStateJob : public BaseJob {
+public:
+ /*! \brief Get all state events in the current state of a room.
+ *
+ * \param roomId
+ * The room to look up the state for.
+ */
+ explicit GetRoomStateJob(const QString& roomId);
+
+ /*! \brief Construct a URL without creating a full-fledged job object
+ *
+ * This function can be used when a URL for GetRoomStateJob
+ * is necessary but the job itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId);
+
+ // Result properties
+
+ /// The current state of the room
+ StateEvents events() { return fromJson<StateEvents>(jsonData()); }
+};
+
+/*! \brief Get the m.room.member events for the room.
+ *
+ * Get the list of members for this room.
+ */
+class QUOTIENT_API GetMembersByRoomJob : public BaseJob {
+public:
+ /*! \brief Get the m.room.member events for the room.
+ *
+ * \param roomId
+ * The room to get the member events for.
+ *
+ * \param at
+ * The point in time (pagination token) to return members for in the room.
+ * This token can be obtained from a `prev_batch` token returned for
+ * each room by the sync API. Defaults to the current state of the room,
+ * as determined by the server.
+ *
+ * \param membership
+ * The kind of membership to filter for. Defaults to no filtering if
+ * unspecified. When specified alongside `not_membership`, the two
+ * parameters create an 'or' condition: either the membership *is*
+ * the same as `membership` **or** *is not* the same as `not_membership`.
+ *
+ * \param notMembership
+ * The kind of membership to exclude from the results. Defaults to no
+ * filtering if unspecified.
+ */
+ explicit GetMembersByRoomJob(const QString& roomId, const QString& at = {},
+ const QString& membership = {},
+ const QString& notMembership = {});
+
+ /*! \brief Construct a URL without creating a full-fledged job object
+ *
+ * This function can be used when a URL for GetMembersByRoomJob
+ * is necessary but the job itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId,
+ const QString& at = {},
+ const QString& membership = {},
+ const QString& notMembership = {});
+
+ // Result properties
- private:
- class Private;
- QScopedPointer<Private> d;
+ /// Get the list of members for this room.
+ StateEvents chunk() { return takeFromJson<StateEvents>("chunk"_ls); }
+};
+
+/*! \brief Gets the list of currently joined users and their profile data.
+ *
+ * This API returns a map of MXIDs to member info objects for members of the
+ * room. The current user must be in the room for it to work, unless it is an
+ * Application Service in which case any of the AS's users must be in the room.
+ * This API is primarily for Application Services and should be faster to respond
+ * than `/members` as it can be implemented more efficiently on the server.
+ */
+class QUOTIENT_API GetJoinedMembersByRoomJob : public BaseJob {
+public:
+ // Inner data structures
+
+ /// This API returns a map of MXIDs to member info objects for members of
+ /// the room. The current user must be in the room for it to work, unless it
+ /// is an Application Service in which case any of the AS's users must be in
+ /// the room. This API is primarily for Application Services and should be
+ /// faster to respond than `/members` as it can be implemented more
+ /// efficiently on the server.
+ struct RoomMember {
+ /// The display name of the user this object is representing.
+ QString displayName;
+ /// The mxc avatar url of the user this object is representing.
+ QUrl avatarUrl;
};
- /// Get all state events in the current state of a room.
- ///
- /// Get the state events for the current state of a room.
- class GetRoomStateJob : public BaseJob
- {
- public:
- /*! Get all state events in the current state of a room.
- * \param roomId
- * The room to look up the state for.
- */
- explicit GetRoomStateJob(const QString& roomId);
-
- /*! Construct a URL without creating a full-fledged job object
- *
- * This function can be used when a URL for
- * GetRoomStateJob is necessary but the job
- * itself isn't.
- */
- static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId);
-
- ~GetRoomStateJob() override;
+ // Construction/destruction
- // Result properties
+ /*! \brief Gets the list of currently joined users and their profile data.
+ *
+ * \param roomId
+ * The room to get the members of.
+ */
+ explicit GetJoinedMembersByRoomJob(const QString& roomId);
- /// If the user is a member of the room this will be the
- /// current state of the room as a list of events. If the user
- /// has left the room then this will be the state of the room
- /// when they left as a list of events.
- StateEvents&& data();
+ /*! \brief Construct a URL without creating a full-fledged job object
+ *
+ * This function can be used when a URL for GetJoinedMembersByRoomJob
+ * is necessary but the job itself isn't.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId);
- protected:
- Status parseJson(const QJsonDocument& data) override;
+ // Result properties
- private:
- class Private;
- QScopedPointer<Private> d;
- };
-
- /// Get the m.room.member events for the room.
- ///
- /// Get the list of members for this room.
- class GetMembersByRoomJob : public BaseJob
+ /// A map from user ID to a RoomMember object.
+ QHash<QString, RoomMember> joined() const
{
- public:
- /*! Get the m.room.member events for the room.
- * \param roomId
- * The room to get the member events for.
- */
- explicit GetMembersByRoomJob(const QString& roomId);
-
- /*! Construct a URL without creating a full-fledged job object
- *
- * This function can be used when a URL for
- * GetMembersByRoomJob is necessary but the job
- * itself isn't.
- */
- static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId);
-
- ~GetMembersByRoomJob() override;
-
- // Result properties
-
- /// Get the list of members for this room.
- EventsArray<RoomMemberEvent>&& chunk();
-
- protected:
- Status parseJson(const QJsonDocument& data) override;
-
- private:
- class Private;
- QScopedPointer<Private> d;
- };
-
- /// Gets the list of currently joined users and their profile data.
- ///
- /// This API returns a map of MXIDs to member info objects for members of the room. The current user must be in the room for it to work, unless it is an Application Service in which case any of the AS's users must be in the room. This API is primarily for Application Services and should be faster to respond than ``/members`` as it can be implemented more efficiently on the server.
- class GetJoinedMembersByRoomJob : public BaseJob
+ return loadFromJson<QHash<QString, RoomMember>>("joined"_ls);
+ }
+};
+
+template <>
+struct JsonObjectConverter<GetJoinedMembersByRoomJob::RoomMember> {
+ static void fillFrom(const QJsonObject& jo,
+ GetJoinedMembersByRoomJob::RoomMember& result)
{
- public:
- // Inner data structures
-
- /// This API returns a map of MXIDs to member info objects for members of the room. The current user must be in the room for it to work, unless it is an Application Service in which case any of the AS's users must be in the room. This API is primarily for Application Services and should be faster to respond than ``/members`` as it can be implemented more efficiently on the server.
- struct RoomMember
- {
- /// The display name of the user this object is representing.
- QString displayName;
- /// The mxc avatar url of the user this object is representing.
- QString avatarUrl;
- };
-
- // Construction/destruction
-
- /*! Gets the list of currently joined users and their profile data.
- * \param roomId
- * The room to get the members of.
- */
- explicit GetJoinedMembersByRoomJob(const QString& roomId);
+ fromJson(jo.value("display_name"_ls), result.displayName);
+ fromJson(jo.value("avatar_url"_ls), result.avatarUrl);
+ }
+};
- /*! Construct a URL without creating a full-fledged job object
- *
- * This function can be used when a URL for
- * GetJoinedMembersByRoomJob is necessary but the job
- * itself isn't.
- */
- static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId);
-
- ~GetJoinedMembersByRoomJob() override;
-
- // Result properties
-
- /// A map from user ID to a RoomMember object.
- const QHash<QString, RoomMember>& joined() const;
-
- protected:
- Status parseJson(const QJsonDocument& data) override;
-
- private:
- class Private;
- QScopedPointer<Private> d;
- };
-} // namespace QMatrixClient
+} // namespace Quotient