1#pragma once
2
3/// @file
4/// @brief An ephemeral event describing the presence of a user.
5
6#if __has_include(<nlohmann/json_fwd.hpp>)
7#include <nlohmann/json_fwd.hpp>
8#else
9#include <nlohmann/json.hpp>
10#endif
11
12#include <optional>
13#include <string>
14#include <string_view>
15
16namespace mtx {
17//! Presence specific types.
18namespace presence {
19//! The current presence state.
20enum PresenceState
21{
22 online, //!< The user is online.
23 offline, //!< The user is offline.
24 unavailable, //!< The user is online, but currently not available.
25};
26
27std::string
28to_string(PresenceState state);
29PresenceState
30from_string(std::string_view str);
31}
32
33namespace events {
34namespace presence {
35//! The `m.presence` ephemeral event.
36struct Presence
37{
38 std::string avatar_url; //! The current avatar URL for this user, if any.
39 std::string displayname; //! The current display name for this user, if any.
40 uint64_t
41 last_active_ago; //! The last time since this used performed some action, in milliseconds.
42 mtx::presence::PresenceState presence; //! Required. The presence state for this user. One
43 //! of: ["online", "offline", "unavailable"]
44 bool currently_active; //! Whether the user is currently active
45 std::string status_msg; //! An optional description to accompany the presence.
46
47 friend void from_json(const nlohmann::json &obj, Presence &presence);
48 friend void to_json(nlohmann::json &obj, const Presence &presence);
49};
50}
51}
52}
53