Skip to content

Commit f28ac46

Browse files
authored
Add message_snapshots on Message (#3092)
Fixes #2995, item 2
1 parent bceffa2 commit f28ac46

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/model/channel/message.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ pub struct Message {
106106
pub flags: Option<MessageFlags>,
107107
/// The message that was replied to using this message.
108108
pub referenced_message: Option<Box<Message>>, // Boxed to avoid recursion
109+
/// An array of message snapshots, known as forwarded messages.
110+
#[serde(default, deserialize_with = "deserialize_snapshots")]
111+
pub message_snapshots: Vec<MessageSnapshot>,
109112
#[cfg_attr(not(ignore_serenity_deprecated), deprecated = "Use interaction_metadata")]
110113
pub interaction: Option<Box<MessageInteraction>>,
111114
/// Sent if the message is a response to an [`Interaction`].
@@ -1190,6 +1193,47 @@ pub struct ChannelMention {
11901193
pub name: String,
11911194
}
11921195

1196+
/// [Discord docs](https://discord.com/developers/docs/resources/message#message-snapshot-structure)
1197+
///
1198+
/// For field documentation, see [`Message`].
1199+
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
1200+
#[derive(Clone, Debug, Serialize, Deserialize)]
1201+
#[non_exhaustive]
1202+
pub struct MessageSnapshot {
1203+
pub content: String,
1204+
pub timestamp: Timestamp,
1205+
pub edited_timestamp: Option<Timestamp>,
1206+
pub mentions: Vec<User>,
1207+
#[serde(default)]
1208+
pub mention_roles: Vec<RoleId>,
1209+
pub attachments: Vec<Attachment>,
1210+
pub embeds: Vec<Embed>,
1211+
#[serde(rename = "type")]
1212+
pub kind: MessageType,
1213+
pub flags: Option<MessageFlags>,
1214+
#[serde(default)]
1215+
pub components: Vec<ActionRow>,
1216+
#[serde(default)]
1217+
pub sticker_items: Vec<StickerItem>,
1218+
}
1219+
1220+
/// Custom deserialization function to handle the nested "message" field
1221+
fn deserialize_snapshots<'de, D>(deserializer: D) -> Result<Vec<MessageSnapshot>, D::Error>
1222+
where
1223+
D: Deserializer<'de>,
1224+
{
1225+
#[derive(Deserialize)]
1226+
struct MessageSnapshotWrapper {
1227+
pub message: MessageSnapshot,
1228+
}
1229+
1230+
let snapshots: Vec<MessageSnapshotWrapper> = Deserialize::deserialize(deserializer)?;
1231+
1232+
let result = snapshots.into_iter().map(|wrapper| wrapper.message).collect();
1233+
1234+
Ok(result)
1235+
}
1236+
11931237
bitflags! {
11941238
/// Describes extra features of the message.
11951239
///

0 commit comments

Comments
 (0)