libQuotient
A Qt library for building matrix clients
peeking_events.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 Listen on the event stream of a particular room.
11 //!
12 //! This will listen for new events related to a particular room and return
13 //! them to the caller. This will block until an event is received, or until
14 //! the `timeout` is reached.
15 //!
16 //! This API is the same as the normal `/events` endpoint, but can be
17 //! called by users who have not joined the room.
18 //!
19 //! Note that the normal `/events` endpoint has been deprecated. This
20 //! API will also be deprecated at some point, but its replacement is not
21 //! yet known.
22 class QUOTIENT_API PeekEventsJob : public BaseJob {
23 public:
24  //! \param from
25  //! The token to stream from. This token is either from a previous
26  //! request to this API or from the initial sync API.
27  //!
28  //! \param timeout
29  //! The maximum time in milliseconds to wait for an event.
30  //!
31  //! \param roomId
32  //! The room ID for which events should be returned.
33  explicit PeekEventsJob(const QString& from = {}, std::optional<int> timeout = std::nullopt,
34  const QString& roomId = {});
35 
36  //! \brief Construct a URL without creating a full-fledged job object
37  //!
38  //! This function can be used when a URL for PeekEventsJob
39  //! is necessary but the job itself isn't.
40  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& from = {},
41  std::optional<int> timeout = std::nullopt,
42  const QString& roomId = {});
43 
44  // Result properties
45 
46  //! A token which correlates to the first value in `chunk`. This
47  //! is usually the same token supplied to `from=`.
48  QString begin() const { return loadFromJson<QString>("start"_L1); }
49 
50  //! A token which correlates to the last value in `chunk`. This
51  //! token should be used in the next request to `/events`.
52  QString end() const { return loadFromJson<QString>("end"_L1); }
53 
54  //! An array of events.
55  RoomEvents chunk() { return takeFromJson<RoomEvents>("chunk"_L1); }
56 
57  struct Response {
58  //! A token which correlates to the first value in `chunk`. This
59  //! is usually the same token supplied to `from=`.
60  QString begin{};
61 
62  //! A token which correlates to the last value in `chunk`. This
63  //! token should be used in the next request to `/events`.
64  QString end{};
65 
66  //! An array of events.
67  RoomEvents chunk{};
68  };
69 };
70 
71 template <std::derived_from<PeekEventsJob> JobT>
72 constexpr inline auto doCollectResponse<JobT> =
73  [](JobT* j) -> PeekEventsJob::Response { return { j->begin(), j->end(), j->chunk() }; };
74 
75 } // namespace Quotient