libQuotient
A Qt library for building matrix clients
message_pagination.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/jobs/basejob.h>
7 
8 namespace Quotient {
9 
10 //! \brief Get a list of events for this room
11 //!
12 //! This API returns a list of message and state events for a room. It uses
13 //! pagination query parameters to paginate history in the room.
14 //!
15 //! *Note*: This endpoint supports lazy-loading of room member events. See
16 //! [Lazy-loading room members](/client-server-api/#lazy-loading-room-members) for more information.
17 class QUOTIENT_API GetRoomEventsJob : public BaseJob {
18 public:
19  //! \param roomId
20  //! The room to get events from.
21  //!
22  //! \param dir
23  //! The direction to return events from. If this is set to `f`, events
24  //! will be returned in chronological order starting at `from`. If it
25  //! is set to `b`, events will be returned in *reverse* chronological
26  //! order, again starting at `from`.
27  //!
28  //! \param from
29  //! The token to start returning events from. This token can be obtained
30  //! from a `prev_batch` or `next_batch` token returned by the `/sync` endpoint,
31  //! or from an `end` token returned by a previous request to this endpoint.
32  //!
33  //! This endpoint can also accept a value returned as a `start` token
34  //! by a previous request to this endpoint, though servers are not
35  //! required to support this. Clients should not rely on the behaviour.
36  //!
37  //! If it is not provided, the homeserver shall return a list of messages
38  //! from the first or last (per the value of the `dir` parameter) visible
39  //! event in the room history for the requesting user.
40  //!
41  //! \param to
42  //! The token to stop returning events at. This token can be obtained from
43  //! a `prev_batch` or `next_batch` token returned by the `/sync` endpoint,
44  //! or from an `end` token returned by a previous request to this endpoint.
45  //!
46  //! \param limit
47  //! The maximum number of events to return. Default: 10.
48  //!
49  //! \param filter
50  //! A JSON RoomEventFilter to filter returned events with.
51  explicit GetRoomEventsJob(const QString& roomId, const QString& dir, const QString& from = {},
52  const QString& to = {}, std::optional<int> limit = std::nullopt,
53  const QString& filter = {});
54 
55  //! \brief Construct a URL without creating a full-fledged job object
56  //!
57  //! This function can be used when a URL for GetRoomEventsJob
58  //! is necessary but the job itself isn't.
59  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& roomId,
60  const QString& dir, const QString& from = {}, const QString& to = {},
61  std::optional<int> limit = std::nullopt, const QString& filter = {});
62 
63  // Result properties
64 
65  //! A token corresponding to the start of `chunk`. This will be the same as
66  //! the value given in `from`.
67  QString begin() const { return loadFromJson<QString>("start"_L1); }
68 
69  //! A token corresponding to the end of `chunk`. This token can be passed
70  //! back to this endpoint to request further events.
71  //!
72  //! If no further events are available (either because we have
73  //! reached the start of the timeline, or because the user does
74  //! not have permission to see any more events), this property
75  //! is omitted from the response.
76  QString end() const { return loadFromJson<QString>("end"_L1); }
77 
78  //! A list of room events. The order depends on the `dir` parameter.
79  //! For `dir=b` events will be in reverse-chronological order,
80  //! for `dir=f` in chronological order. (The exact definition of `chronological`
81  //! is dependent on the server implementation.)
82  //!
83  //! Note that an empty `chunk` does not *necessarily* imply that no more events
84  //! are available. Clients should continue to paginate until no `end` property
85  //! is returned.
86  RoomEvents chunk() { return takeFromJson<RoomEvents>("chunk"_L1); }
87 
88  //! A list of state events relevant to showing the `chunk`. For example, if
89  //! `lazy_load_members` is enabled in the filter then this may contain
90  //! the membership events for the senders of events in the `chunk`.
91  //!
92  //! Unless `include_redundant_members` is `true`, the server
93  //! may remove membership events which would have already been
94  //! sent to the client in prior calls to this endpoint, assuming
95  //! the membership of those members has not changed.
96  RoomEvents state() { return takeFromJson<RoomEvents>("state"_L1); }
97 
98  struct Response {
99  //! A token corresponding to the start of `chunk`. This will be the same as
100  //! the value given in `from`.
101  QString begin{};
102 
103  //! A token corresponding to the end of `chunk`. This token can be passed
104  //! back to this endpoint to request further events.
105  //!
106  //! If no further events are available (either because we have
107  //! reached the start of the timeline, or because the user does
108  //! not have permission to see any more events), this property
109  //! is omitted from the response.
110  QString end{};
111 
112  //! A list of room events. The order depends on the `dir` parameter.
113  //! For `dir=b` events will be in reverse-chronological order,
114  //! for `dir=f` in chronological order. (The exact definition of `chronological`
115  //! is dependent on the server implementation.)
116  //!
117  //! Note that an empty `chunk` does not *necessarily* imply that no more events
118  //! are available. Clients should continue to paginate until no `end` property
119  //! is returned.
120  RoomEvents chunk{};
121 
122  //! A list of state events relevant to showing the `chunk`. For example, if
123  //! `lazy_load_members` is enabled in the filter then this may contain
124  //! the membership events for the senders of events in the `chunk`.
125  //!
126  //! Unless `include_redundant_members` is `true`, the server
127  //! may remove membership events which would have already been
128  //! sent to the client in prior calls to this endpoint, assuming
129  //! the membership of those members has not changed.
130  RoomEvents state{};
131  };
132 };
133 
134 template <std::derived_from<GetRoomEventsJob> JobT>
135 constexpr inline auto doCollectResponse<JobT> = [](JobT* j) -> GetRoomEventsJob::Response {
136  return { j->begin(), j->end(), j->chunk(), j->state() };
137 };
138 
139 } // namespace Quotient