ruma_events/
image_pack.rsuse std::collections::{BTreeMap, BTreeSet};
use ruma_common::{serde::StringEnum, OwnedMxcUri, OwnedRoomId};
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use crate::{room::ImageInfo, PrivOwnedStr};
#[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)]
#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
#[ruma_event(type = "im.ponies.room_emotes", kind = State, state_key_type = String)]
pub struct RoomImagePackEventContent {
pub images: BTreeMap<String, PackImage>,
#[serde(skip_serializing_if = "Option::is_none")]
pub pack: Option<PackInfo>,
}
impl RoomImagePackEventContent {
pub fn new(images: BTreeMap<String, PackImage>) -> Self {
Self { images, pack: None }
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)]
#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
#[ruma_event(type = "im.ponies.user_emotes", kind = GlobalAccountData)]
pub struct AccountImagePackEventContent {
pub images: BTreeMap<String, PackImage>,
#[serde(skip_serializing_if = "Option::is_none")]
pub pack: Option<PackInfo>,
}
impl AccountImagePackEventContent {
pub fn new(images: BTreeMap<String, PackImage>) -> Self {
Self { images, pack: None }
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
pub struct PackImage {
pub url: OwnedMxcUri,
#[serde(skip_serializing_if = "Option::is_none")]
pub body: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub info: Option<ImageInfo>,
#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
pub usage: BTreeSet<PackUsage>,
}
impl PackImage {
pub fn new(url: OwnedMxcUri) -> Self {
Self { url, body: None, info: None, usage: BTreeSet::new() }
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
pub struct PackInfo {
#[serde(skip_serializing_if = "Option::is_none")]
pub display_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub avatar_url: Option<OwnedMxcUri>,
#[serde(default, skip_serializing_if = "BTreeSet::is_empty")]
pub usage: BTreeSet<PackUsage>,
#[serde(skip_serializing_if = "Option::is_none")]
pub attribution: Option<String>,
}
impl PackInfo {
pub fn new() -> Self {
Self::default()
}
}
#[doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/doc/string_enum.md"))]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, StringEnum)]
#[ruma_enum(rename_all = "snake_case")]
#[non_exhaustive]
pub enum PackUsage {
Emoticon,
Sticker,
#[doc(hidden)]
_Custom(PrivOwnedStr),
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)]
#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
#[ruma_event(type = "im.ponies.emote_rooms", kind = GlobalAccountData)]
pub struct ImagePackRoomsEventContent {
pub rooms: BTreeMap<OwnedRoomId, BTreeMap<String, ImagePackRoomContent>>,
}
impl ImagePackRoomsEventContent {
pub fn new(rooms: BTreeMap<OwnedRoomId, BTreeMap<String, ImagePackRoomContent>>) -> Self {
Self { rooms }
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
pub struct ImagePackRoomContent {}
impl ImagePackRoomContent {
pub fn new() -> Self {
Self {}
}
}