libQuotient
A Qt library for building matrix clients
presence.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 Update this user's presence state.
10 //!
11 //! This API sets the given user's presence state. When setting the status,
12 //! the activity time is updated to reflect that activity; the client does
13 //! not need to specify the `last_active_ago` field. You cannot set the
14 //! presence state of another user.
15 class QUOTIENT_API SetPresenceJob : public BaseJob {
16 public:
17  //! \param userId
18  //! The user whose presence state to update.
19  //!
20  //! \param presence
21  //! The new presence state.
22  //!
23  //! \param statusMsg
24  //! The status message to attach to this state.
25  explicit SetPresenceJob(const QString& userId, const QString& presence,
26  const QString& statusMsg = {});
27 };
28 
29 //! \brief Get this user's presence state.
30 //!
31 //! Get the given user's presence state.
32 class QUOTIENT_API GetPresenceJob : public BaseJob {
33 public:
34  //! \param userId
35  //! The user whose presence state to get.
36  explicit GetPresenceJob(const QString& userId);
37 
38  //! \brief Construct a URL without creating a full-fledged job object
39  //!
40  //! This function can be used when a URL for GetPresenceJob
41  //! is necessary but the job itself isn't.
42  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& userId);
43 
44  // Result properties
45 
46  //! This user's presence.
47  QString presence() const { return loadFromJson<QString>("presence"_L1); }
48 
49  //! The length of time in milliseconds since an action was performed
50  //! by this user.
51  std::optional<int> lastActiveAgo() const
52  {
53  return loadFromJson<std::optional<int>>("last_active_ago"_L1);
54  }
55 
56  //! The state message for this user if one was set.
57  QString statusMsg() const { return loadFromJson<QString>("status_msg"_L1); }
58 
59  //! Whether the user is currently active
60  std::optional<bool> currentlyActive() const
61  {
62  return loadFromJson<std::optional<bool>>("currently_active"_L1);
63  }
64 
65  struct Response {
66  //! This user's presence.
67  QString presence{};
68 
69  //! The length of time in milliseconds since an action was performed
70  //! by this user.
71  std::optional<int> lastActiveAgo{};
72 
73  //! The state message for this user if one was set.
74  QString statusMsg{};
75 
76  //! Whether the user is currently active
77  std::optional<bool> currentlyActive{};
78  };
79 };
80 
81 template <std::derived_from<GetPresenceJob> JobT>
82 constexpr inline auto doCollectResponse<JobT> = [](JobT* j) -> GetPresenceJob::Response {
83  return { j->presence(), j->lastActiveAgo(), j->statusMsg(), j->currentlyActive() };
84 };
85 
86 } // namespace Quotient