Skip to main content

twilight_model/channel/message/component/
unfurled_media.rs

1use bitflags::bitflags;
2use serde::{Deserialize, Deserializer, Serialize, Serializer};
3
4/// Unfurled media item for use in components.
5#[derive(Clone, Debug, Eq, Hash, PartialEq, Deserialize, Serialize)]
6pub struct UnfurledMediaItem {
7    /// Results of Discord's content scanning, if the media item has been
8    /// scanned.
9    #[serde(skip_serializing_if = "Option::is_none")]
10    pub content_scan_metadata: Option<ContentScanMetadata>,
11    /// The media type of the content. This field is ignored and provided by the
12    /// API as part of the response.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub content_type: Option<String>,
15    /// The height of the media item. This field is ignored and provided by the
16    /// API as part of the response.
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub height: Option<Option<u32>>,
19    /// The proxied url of the media item. This field is ignored and provided
20    /// by the API as part of the response.
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub proxy_url: Option<String>,
23    /// Supports arbitrary urls and `attachment://<filename>` references.
24    pub url: String,
25    /// The width of the media item. This field is ignored and provided by the
26    /// API as part of the response.
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub width: Option<Option<u32>>,
29}
30
31/// Results of Discord's content scanning, if the media item has been
32/// scanned.
33#[derive(Clone, Debug, Eq, Hash, PartialEq, Deserialize, Serialize)]
34pub struct ContentScanMetadata {
35    /// Content scan metadata flags combined as a bitfield.
36    pub flags: ContentScanMetadataFlags,
37}
38
39bitflags! {
40    /// Content scan metadata flags.
41    #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
42    pub struct ContentScanMetadataFlags: u64 {
43        /// This media was flagged as explicit by Discord's content scanning.
44        const IS_EXPLICIT_CONTENT = 1 << 0;
45        /// This media was flagged as gore by Discord's content scanning.
46        const IS_GORE_CONTENT = 1 << 1;
47        /// This media was flagged as self-harm by Discord's content scanning.
48        const IS_SELF_HARM_CONTENT = 1 << 2;
49    }
50}
51
52impl<'de> Deserialize<'de> for ContentScanMetadataFlags {
53    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
54        Ok(Self::from_bits_retain(u64::deserialize(deserializer)?))
55    }
56}
57
58impl Serialize for ContentScanMetadataFlags {
59    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
60    where
61        S: Serializer,
62    {
63        serializer.serialize_u64(self.bits())
64    }
65}