ruma_events/
image_pack.rs1use std::collections::{BTreeMap, BTreeSet};
6
7use ruma_common::{serde::StringEnum, OwnedMxcUri, OwnedRoomId};
8use ruma_macros::EventContent;
9use serde::{Deserialize, Serialize};
10
11use crate::{room::ImageInfo, PrivOwnedStr};
12
13#[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)]
18#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
19#[ruma_event(type = "im.ponies.room_emotes", kind = State, state_key_type = String)]
20pub struct RoomImagePackEventContent {
21 pub images: BTreeMap<String, PackImage>,
25
26 #[serde(skip_serializing_if = "Option::is_none")]
28 pub pack: Option<PackInfo>,
29}
30
31impl RoomImagePackEventContent {
32 pub fn new(images: BTreeMap<String, PackImage>) -> Self {
34 Self { images, pack: None }
35 }
36}
37
38#[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)]
41#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
42#[ruma_event(type = "im.ponies.user_emotes", kind = GlobalAccountData)]
43pub struct AccountImagePackEventContent {
44 pub images: BTreeMap<String, PackImage>,
48
49 #[serde(skip_serializing_if = "Option::is_none")]
51 pub pack: Option<PackInfo>,
52}
53
54impl AccountImagePackEventContent {
55 pub fn new(images: BTreeMap<String, PackImage>) -> Self {
57 Self { images, pack: None }
58 }
59}
60
61#[derive(Clone, Debug, Deserialize, Serialize)]
63#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
64pub struct PackImage {
65 pub url: OwnedMxcUri,
67
68 #[serde(skip_serializing_if = "Option::is_none")]
73 pub body: Option<String>,
74
75 #[serde(skip_serializing_if = "Option::is_none")]
77 pub info: Option<ImageInfo>,
78
79 #[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
81 pub usage: BTreeSet<PackUsage>,
82}
83
84impl PackImage {
85 pub fn new(url: OwnedMxcUri) -> Self {
87 Self { url, body: None, info: None, usage: BTreeSet::new() }
88 }
89}
90
91#[derive(Clone, Debug, Default, Deserialize, Serialize)]
93#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
94pub struct PackInfo {
95 #[serde(skip_serializing_if = "Option::is_none")]
100 pub display_name: Option<String>,
101
102 #[serde(skip_serializing_if = "Option::is_none")]
107 pub avatar_url: Option<OwnedMxcUri>,
108
109 #[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
111 pub usage: BTreeSet<PackUsage>,
112
113 #[serde(skip_serializing_if = "Option::is_none")]
115 pub attribution: Option<String>,
116}
117
118impl PackInfo {
119 pub fn new() -> Self {
121 Self::default()
122 }
123}
124
125#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
127#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, StringEnum)]
128#[ruma_enum(rename_all = "snake_case")]
129#[non_exhaustive]
130pub enum PackUsage {
131 Emoticon,
133
134 Sticker,
136
137 #[doc(hidden)]
138 _Custom(PrivOwnedStr),
139}
140
141#[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)]
144#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
145#[ruma_event(type = "im.ponies.emote_rooms", kind = GlobalAccountData)]
146pub struct ImagePackRoomsEventContent {
147 pub rooms: BTreeMap<OwnedRoomId, BTreeMap<String, ImagePackRoomContent>>,
149}
150
151impl ImagePackRoomsEventContent {
152 pub fn new(rooms: BTreeMap<OwnedRoomId, BTreeMap<String, ImagePackRoomContent>>) -> Self {
155 Self { rooms }
156 }
157}
158
159#[derive(Clone, Debug, Default, Deserialize, Serialize)]
161#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
162pub struct ImagePackRoomContent {}
163
164impl ImagePackRoomContent {
165 pub fn new() -> Self {
167 Self {}
168 }
169}