libQuotient
A Qt library for building matrix clients
event_context.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 events and state around the specified event.
12 //!
13 //! This API returns a number of events that happened just before and
14 //! after the specified event. This allows clients to get the context
15 //! surrounding an event.
16 //!
17 //! *Note*: This endpoint supports lazy-loading of room member events. See
18 //! [Lazy-loading room members](/client-server-api/#lazy-loading-room-members) for more information.
19 class QUOTIENT_API GetEventContextJob : public BaseJob {
20 public:
21  //! \param roomId
22  //! The room to get events from.
23  //!
24  //! \param eventId
25  //! The event to get context around.
26  //!
27  //! \param limit
28  //! The maximum number of context events to return. The limit applies
29  //! to the sum of the `events_before` and `events_after` arrays. The
30  //! requested event ID is always returned in `event` even if `limit` is
31  //! 0. Defaults to 10.
32  //!
33  //! \param filter
34  //! A JSON `RoomEventFilter` to filter the returned events with. The
35  //! filter is only applied to `events_before`, `events_after`, and
36  //! `state`. It is not applied to the `event` itself. The filter may
37  //! be applied before or/and after the `limit` parameter - whichever the
38  //! homeserver prefers.
39  //!
40  //! See [Filtering](/client-server-api/#filtering) for more information.
41  explicit GetEventContextJob(const QString& roomId, const QString& eventId,
42  std::optional<int> limit = std::nullopt, const QString& filter = {});
43 
44  //! \brief Construct a URL without creating a full-fledged job object
45  //!
46  //! This function can be used when a URL for GetEventContextJob
47  //! is necessary but the job itself isn't.
48  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& roomId,
49  const QString& eventId, std::optional<int> limit = std::nullopt,
50  const QString& filter = {});
51 
52  // Result properties
53 
54  //! A token that can be used to paginate backwards with.
55  QString begin() const { return loadFromJson<QString>("start"_L1); }
56 
57  //! A token that can be used to paginate forwards with.
58  QString end() const { return loadFromJson<QString>("end"_L1); }
59 
60  //! A list of room events that happened just before the
61  //! requested event, in reverse-chronological order.
62  RoomEvents eventsBefore() { return takeFromJson<RoomEvents>("events_before"_L1); }
63 
64  //! Details of the requested event.
65  RoomEventPtr event() { return takeFromJson<RoomEventPtr>("event"_L1); }
66 
67  //! A list of room events that happened just after the
68  //! requested event, in chronological order.
69  RoomEvents eventsAfter() { return takeFromJson<RoomEvents>("events_after"_L1); }
70 
71  //! The state of the room at the last event returned.
72  StateEvents state() { return takeFromJson<StateEvents>("state"_L1); }
73 
74  struct Response {
75  //! A token that can be used to paginate backwards with.
76  QString begin{};
77 
78  //! A token that can be used to paginate forwards with.
79  QString end{};
80 
81  //! A list of room events that happened just before the
82  //! requested event, in reverse-chronological order.
83  RoomEvents eventsBefore{};
84 
85  //! Details of the requested event.
86  RoomEventPtr event{};
87 
88  //! A list of room events that happened just after the
89  //! requested event, in chronological order.
90  RoomEvents eventsAfter{};
91 
92  //! The state of the room at the last event returned.
93  StateEvents state{};
94  };
95 };
96 
97 template <std::derived_from<GetEventContextJob> JobT>
98 constexpr inline auto doCollectResponse<JobT> = [](JobT* j) -> GetEventContextJob::Response {
99  return { j->begin(), j->end(), j->eventsBefore(), j->event(), j->eventsAfter(), j->state() };
100 };
101 
102 } // namespace Quotient