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