libQuotient
A Qt library for building matrix clients
rooms.h
Go to the documentation of this file.
1 // THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
2 
3 #pragma once
4 
5 #include <Quotient/events/roomevent.h>
6 #include <Quotient/events/stateevent.h>
7 #include <Quotient/jobs/basejob.h>
8 
9 namespace Quotient {
10 
11 //! \brief Get a single event by event ID.
12 //!
13 //! Get a single event based on `roomId/eventId`. You must have permission to
14 //! retrieve this event e.g. by being a member in the room for this event.
15 class QUOTIENT_API GetOneRoomEventJob : public BaseJob {
16 public:
17  //! \param roomId
18  //! The ID of the room the event is in.
19  //!
20  //! \param eventId
21  //! The event ID to get.
22  explicit GetOneRoomEventJob(const QString& roomId, const QString& eventId);
23 
24  //! \brief Construct a URL without creating a full-fledged job object
25  //!
26  //! This function can be used when a URL for GetOneRoomEventJob
27  //! is necessary but the job itself isn't.
28  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& roomId,
29  const QString& eventId);
30 
31  // Result properties
32 
33  //! The full event.
34  RoomEventPtr event() { return fromJson<RoomEventPtr>(jsonData()); }
35 };
36 
37 inline auto collectResponse(GetOneRoomEventJob* job) { return job->event(); }
38 
39 //! \brief Get the state identified by the type and key.
40 //!
41 //! Looks up the contents of a state event in a room. If the user is
42 //! joined to the room then the state is taken from the current
43 //! state of the room. If the user has left the room then the state is
44 //! taken from the state of the room when they left.
45 class QUOTIENT_API GetRoomStateWithKeyJob : public BaseJob {
46 public:
47  //! \param roomId
48  //! The room to look up the state in.
49  //!
50  //! \param eventType
51  //! The type of state to look up.
52  //!
53  //! \param stateKey
54  //! The key of the state to look up. Defaults to an empty string. When
55  //! an empty string, the trailing slash on this endpoint is optional.
56  explicit GetRoomStateWithKeyJob(const QString& roomId, const QString& eventType,
57  const QString& stateKey);
58 
59  //! \brief Construct a URL without creating a full-fledged job object
60  //!
61  //! This function can be used when a URL for GetRoomStateWithKeyJob
62  //! is necessary but the job itself isn't.
63  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& roomId,
64  const QString& eventType, const QString& stateKey);
65 
66  // Result properties
67 
68  //! The content of the state event.
69  QJsonObject content() const { return fromJson<QJsonObject>(jsonData()); }
70 };
71 
72 inline auto collectResponse(const GetRoomStateWithKeyJob* job) { return job->content(); }
73 
74 //! \brief Get all state events in the current state of a room.
75 //!
76 //! Get the state events for the current state of a room.
77 class QUOTIENT_API GetRoomStateJob : public BaseJob {
78 public:
79  //! \param roomId
80  //! The room to look up the state for.
81  explicit GetRoomStateJob(const QString& roomId);
82 
83  //! \brief Construct a URL without creating a full-fledged job object
84  //!
85  //! This function can be used when a URL for GetRoomStateJob
86  //! is necessary but the job itself isn't.
87  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& roomId);
88 
89  // Result properties
90 
91  //! The current state of the room
92  StateEvents events() { return fromJson<StateEvents>(jsonData()); }
93 };
94 
95 inline auto collectResponse(GetRoomStateJob* job) { return job->events(); }
96 
97 //! \brief Get the m.room.member events for the room.
98 //!
99 //! Get the list of members for this room.
100 class QUOTIENT_API GetMembersByRoomJob : public BaseJob {
101 public:
102  //! \param roomId
103  //! The room to get the member events for.
104  //!
105  //! \param at
106  //! The point in time (pagination token) to return members for in the room.
107  //! This token can be obtained from a `prev_batch` token returned for
108  //! each room by the sync API. Defaults to the current state of the room,
109  //! as determined by the server.
110  //!
111  //! \param membership
112  //! The kind of membership to filter for. Defaults to no filtering if
113  //! unspecified. When specified alongside `not_membership`, the two
114  //! parameters create an 'or' condition: either the membership *is*
115  //! the same as `membership` **or** *is not* the same as `not_membership`.
116  //!
117  //! \param notMembership
118  //! The kind of membership to exclude from the results. Defaults to no
119  //! filtering if unspecified.
120  explicit GetMembersByRoomJob(const QString& roomId, const QString& at = {},
121  const QString& membership = {}, const QString& notMembership = {});
122 
123  //! \brief Construct a URL without creating a full-fledged job object
124  //!
125  //! This function can be used when a URL for GetMembersByRoomJob
126  //! is necessary but the job itself isn't.
127  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& roomId,
128  const QString& at = {}, const QString& membership = {},
129  const QString& notMembership = {});
130 
131  // Result properties
132 
133  StateEvents chunk() { return takeFromJson<StateEvents>("chunk"_L1); }
134 };
135 
136 inline auto collectResponse(GetMembersByRoomJob* job) { return job->chunk(); }
137 
138 //! \brief Gets the list of currently joined users and their profile data.
139 //!
140 //! This API returns a map of MXIDs to member info objects for members of the room. The current user
141 //! must be in the room for it to work, unless it is an Application Service in which case any of the
142 //! AS's users must be in the room. This API is primarily for Application Services and should be
143 //! faster to respond than `/members` as it can be implemented more efficiently on the server.
144 class QUOTIENT_API GetJoinedMembersByRoomJob : public BaseJob {
145 public:
146  // Inner data structures
147 
148  struct QUOTIENT_API RoomMember {
149  //! The display name of the user this object is representing.
150  QString displayName{};
151 
152  //! The avatar of the user this object is representing, as an [`mxc://`
153  //! URI](/client-server-api/#matrix-content-mxc-uris).
154  QUrl avatarUrl{};
155  };
156 
157  // Construction/destruction
158 
159  //! \param roomId
160  //! The room to get the members of.
161  explicit GetJoinedMembersByRoomJob(const QString& roomId);
162 
163  //! \brief Construct a URL without creating a full-fledged job object
164  //!
165  //! This function can be used when a URL for GetJoinedMembersByRoomJob
166  //! is necessary but the job itself isn't.
167  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& roomId);
168 
169  // Result properties
170 
171  //! A map from user ID to a RoomMember object.
172  QHash<UserId, RoomMember> joined() const
173  {
174  return loadFromJson<QHash<UserId, RoomMember>>("joined"_L1);
175  }
176 };
177 
178 inline auto collectResponse(const GetJoinedMembersByRoomJob* job) { return job->joined(); }
179 
180 template <>
181 struct QUOTIENT_API JsonObjectConverter<GetJoinedMembersByRoomJob::RoomMember> {
182  static void fillFrom(const QJsonObject& jo, GetJoinedMembersByRoomJob::RoomMember& result)
183  {
184  fillFromJson(jo.value("display_name"_L1), result.displayName);
185  fillFromJson(jo.value("avatar_url"_L1), result.avatarUrl);
186  }
187 };
188 
189 } // namespace Quotient