1 | #pragma once |
2 | |
3 | /// @file |
4 | /// @brief A widget in account data or a room |
5 | |
6 | #include <map> |
7 | |
8 | #if __has_include(<nlohmann/json_fwd.hpp>) |
9 | #include <nlohmann/json_fwd.hpp> |
10 | #else |
11 | #include <nlohmann/json.hpp> |
12 | #endif |
13 | |
14 | namespace mtx { |
15 | namespace events { |
16 | namespace state { |
17 | //! Content of the `m.widget` event. |
18 | /// |
19 | /// https://github.com/matrix-org/matrix-doc/issues/1236 |
20 | struct Widget |
21 | { |
22 | //! Required. The type of widget. This is used to determine which widgets can be grouped |
23 | //! together on the UI (e.g multiple grafana graphs together). |
24 | std::string type; |
25 | |
26 | //! Required. The URL of the widget. All widget-enabled matrix clients need to transform this |
27 | //! URL into a final URL which they will perform an HTTP GET to. All substituted values are |
28 | //! url-encoded. |
29 | std::string url; |
30 | |
31 | //! Optional. A human-readable string which can be displayed instead of, or in addition to, the |
32 | //! embedded `<iframe>`. |
33 | std::string name; |
34 | |
35 | //! Unique id |
36 | std::string id; |
37 | |
38 | //! Optional (unless required by a widget type below). Arbitrary key/value pairs. |
39 | std::map<std::string, std::string> data; |
40 | |
41 | //! This flag is used to denote whether the client should display a placeholder / loading |
42 | //! spinner while waiting for the widget content to return a loaded event. |
43 | bool waitForIframeLoad = true; |
44 | |
45 | //! The creatorUserID field is required. It is used to identify the user that added the widget |
46 | //! instance (as opposed to the user that last modified the widget instance, as given by the |
47 | //! 'sender' field on the m.widgets event). |
48 | std::string creatorUserId; |
49 | |
50 | friend void from_json(const nlohmann::json &obj, Widget &create); |
51 | friend void to_json(nlohmann::json &obj, const Widget &create); |
52 | }; |
53 | |
54 | } // namespace state |
55 | } // namespace events |
56 | } // namespace mtx |
57 | |