1 | #pragma once |
2 | |
3 | /// @file |
4 | /// @brief Image packs from [MSC2545](https://github.com/matrix-org/matrix-doc/pull/2545) |
5 | |
6 | #include <bitset> |
7 | #include <cstdint> |
8 | #include <map> |
9 | #include <string> |
10 | |
11 | #if __has_include(<nlohmann/json_fwd.hpp>) |
12 | #include <nlohmann/json_fwd.hpp> |
13 | #else |
14 | #include <nlohmann/json.hpp> |
15 | #endif |
16 | |
17 | #include "mtx/events.hpp" |
18 | |
19 | namespace mtx { |
20 | namespace events { |
21 | |
22 | //! Custom emotes and stickers MSC |
23 | namespace msc2545 { |
24 | //! How a pack or image is intended to be used. |
25 | enum PackUsage : uint8_t |
26 | { |
27 | Sticker, |
28 | Emoji, |
29 | }; |
30 | |
31 | //! A single image in a pack |
32 | struct PackImage |
33 | { |
34 | //! The mxc uri of this image. |
35 | std::string url; |
36 | //! The body to be sent in a sticker. May be empty. |
37 | std::string body; |
38 | |
39 | //! Info as used in stickers about size, etc. |
40 | std::optional<mtx::common::ImageInfo> info; |
41 | |
42 | //! What the images are used for. Indexed by PackUsage |
43 | std::bitset<2> usage; |
44 | |
45 | //! If this overrides the pack level usage definition. |
46 | bool overrides_usage() const { return usage.any(); } |
47 | |
48 | //! If this can be used as an emoji/emojicon. |
49 | bool is_emoji() const { return usage.test(position: PackUsage::Emoji); } |
50 | //! If this can be used as a sticker. |
51 | bool is_sticker() const { return usage.test(position: PackUsage::Sticker); } |
52 | }; |
53 | |
54 | //! A pack of stickers and/or emoticons. |
55 | struct ImagePack |
56 | { |
57 | //! The stickers/emoticons in this pack. Indexed by slug. |
58 | std::map<std::string, PackImage> images; |
59 | |
60 | //! Information about an image pack. |
61 | struct PackDescription |
62 | { |
63 | //! The name of this pack to be presented to the user. |
64 | std::string display_name; |
65 | //! An optional avatar/preview of the pack. |
66 | std::string avatar_url; |
67 | //! Attribution for this pack, i.e. where it is from originally. |
68 | std::string attribution; |
69 | |
70 | //! What the images are used for. Indexed by PackUsage |
71 | std::bitset<2> usage; |
72 | |
73 | //! If this can be used as an emoji/emojicon. |
74 | bool is_emoji() const { return usage.none() || usage.test(position: PackUsage::Emoji); } |
75 | //! If this can be used as a sticker. |
76 | bool is_sticker() const { return usage.none() || usage.test(position: PackUsage::Sticker); } |
77 | }; |
78 | |
79 | //! Information about this pack |
80 | std::optional<PackDescription> pack; |
81 | |
82 | friend void from_json(const nlohmann::json &obj, ImagePack &content); |
83 | friend void to_json(nlohmann::json &obj, const ImagePack &content); |
84 | }; |
85 | |
86 | //! The image packs from rooms enabled by this user to be available globally. |
87 | struct ImagePackRooms |
88 | { |
89 | // A map from room_id to state key to an arbitrary object (which currently is unused). |
90 | std::map<std::string, std::map<std::string, std::string>> rooms; |
91 | |
92 | friend void from_json(const nlohmann::json &obj, ImagePackRooms &content); |
93 | friend void to_json(nlohmann::json &obj, const ImagePackRooms &content); |
94 | }; |
95 | |
96 | } // namespace msc2545 |
97 | } // namespace events |
98 | } // namespace mtx |
99 | |