libQuotient
A Qt library for building matrix clients
room_event_by_timestamp.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/jobs/basejob.h>
6 
7 namespace Quotient {
8 
9 //! \brief Get the closest event ID to the given timestamp
10 //!
11 //! Get the ID of the event closest to the given timestamp, in the
12 //! direction specified by the `dir` parameter.
13 //!
14 //! If the server does not have all of the room history and does not have
15 //! an event suitably close to the requested timestamp, it can use the
16 //! corresponding [federation
17 //! endpoint](/server-server-api/#get_matrixfederationv1timestamp_to_eventroomid) to ask other
18 //! servers for a suitable event.
19 //!
20 //! After calling this endpoint, clients can call
21 //! [`/rooms/{roomId}/context/{eventId}`](#get_matrixclientv3roomsroomidcontexteventid)
22 //! to obtain a pagination token to retrieve the events around the returned event.
23 //!
24 //! The event returned by this endpoint could be an event that the client
25 //! cannot render, and so may need to paginate in order to locate an event
26 //! that it can display, which may end up being outside of the client's
27 //! suitable range. Clients can employ different strategies to display
28 //! something reasonable to the user. For example, the client could try
29 //! paginating in one direction for a while, while looking at the
30 //! timestamps of the events that it is paginating through, and if it
31 //! exceeds a certain difference from the target timestamp, it can try
32 //! paginating in the opposite direction. The client could also simply
33 //! paginate in one direction and inform the user that the closest event
34 //! found in that direction is outside of the expected range.
35 class QUOTIENT_API GetEventByTimestampJob : public BaseJob {
36 public:
37  //! \param roomId
38  //! The ID of the room to search
39  //!
40  //! \param ts
41  //! The timestamp to search from, as given in milliseconds
42  //! since the Unix epoch.
43  //!
44  //! \param dir
45  //! The direction in which to search. `f` for forwards, `b` for backwards.
46  explicit GetEventByTimestampJob(const QString& roomId, int ts, const QString& dir);
47 
48  //! \brief Construct a URL without creating a full-fledged job object
49  //!
50  //! This function can be used when a URL for GetEventByTimestampJob
51  //! is necessary but the job itself isn't.
52  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& roomId, int ts,
53  const QString& dir);
54 
55  // Result properties
56 
57  //! The ID of the event found
58  QString eventId() const { return loadFromJson<QString>("event_id"_L1); }
59 
60  //! The event's timestamp, in milliseconds since the Unix epoch.
61  //! This makes it easy to do a quick comparison to see if the
62  //! `event_id` fetched is too far out of range to be useful for your
63  //! use case.
64  int originServerTimestamp() const { return loadFromJson<int>("origin_server_ts"_L1); }
65 
66  struct Response {
67  //! The ID of the event found
68  QString eventId{};
69 
70  //! The event's timestamp, in milliseconds since the Unix epoch.
71  //! This makes it easy to do a quick comparison to see if the
72  //! `event_id` fetched is too far out of range to be useful for your
73  //! use case.
74  int originServerTimestamp{};
75  };
76 };
77 
78 template <std::derived_from<GetEventByTimestampJob> JobT>
79 constexpr inline auto doCollectResponse<JobT> = [](JobT* j) -> GetEventByTimestampJob::Response {
80  return { j->eventId(), j->originServerTimestamp() };
81 };
82 
83 } // namespace Quotient