Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(model, cache): add support for voice messages #2196

Merged
merged 2 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(model): add support for voice messages
  • Loading branch information
suneettipirneni committed Apr 15, 2023
commit ec92ddd783fe479f91231c0ea7e866e4d2e999c1
3 changes: 1 addition & 2 deletions twilight-cache-inmemory/src/model/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl CachedMessageInteraction {
/// Represents a cached [`Message`].
///
/// [`Message`]: twilight_model::channel::Message
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct CachedMessage {
activity: Option<MessageActivity>,
application: Option<MessageApplication>,
Expand Down Expand Up @@ -399,7 +399,6 @@ mod tests {
assert_impl_all!(
CachedMessage: Clone,
Debug,
Eq,
From<Message>,
PartialEq,
Send,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::collections::hash_map::HashMap;
///
/// [`ApplicationCommand`]: crate::application::interaction::InteractionType::ApplicationCommand
/// [Discord Docs/Resolved Data Structure]: https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-resolved-data-structure
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct CommandInteractionDataResolved {
/// Map of resolved attachments.
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
Expand Down Expand Up @@ -130,11 +130,13 @@ mod tests {
ephemeral: true,
filename: "rainbow_dash.png".to_owned(),
description: None,
duration_secs: None,
height: Some(2674),
id: Id::new(400),
proxy_url: "https://proxy.example.com/rainbow_dash.png".to_owned(),
size: 13370,
url: "https://example.com/rainbow_dash.png".to_owned(),
waveform: None,
width: Some(1337),
},
)])
Expand Down
22 changes: 17 additions & 5 deletions twilight-model/src/channel/attachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
suneettipirneni marked this conversation as resolved.
Show resolved Hide resolved
pub struct Attachment {
/// Attachment's [media type].
///
Expand All @@ -17,6 +17,9 @@ pub struct Attachment {
/// available as long as the message itself exists.
#[serde(default, skip_serializing_if = "is_false")]
pub ephemeral: bool,
/// The duration of the audio file (currently for voice messages).
itohatweb marked this conversation as resolved.
Show resolved Hide resolved
#[serde(skip_serializing_if = "Option::is_none")]
pub duration_secs: Option<f64>,
pub filename: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
Expand All @@ -26,6 +29,9 @@ pub struct Attachment {
pub proxy_url: String,
pub size: u64,
pub url: String,
/// Base64 encoded bytearray representing a sampled waveform (currently for voice messages).
#[serde(skip_serializing_if = "Option::is_none")]
pub waveform: Option<String>,
suneettipirneni marked this conversation as resolved.
Show resolved Hide resolved
#[serde(skip_serializing_if = "Option::is_none")]
pub width: Option<u64>,
}
Expand All @@ -37,7 +43,7 @@ mod tests {
use serde::{Deserialize, Serialize};
use serde_test::Token;
use static_assertions::{assert_fields, assert_impl_all};
use std::{fmt::Debug, hash::Hash};
use std::fmt::Debug;

assert_fields!(
Attachment: content_type,
Expand All @@ -55,8 +61,6 @@ mod tests {
Attachment: Clone,
Debug,
Deserialize<'static>,
Eq,
Hash,
PartialEq,
Serialize
);
Expand All @@ -68,11 +72,13 @@ mod tests {
ephemeral: false,
filename: "a.png".to_owned(),
description: Some("a image".to_owned()),
duration_secs: Some(3.2),
height: Some(184),
id: Id::new(700_000_000_000_000_000),
proxy_url: "https://cdn.example.com/1.png".to_owned(),
size: 13_593,
url: "https://example.com/1.png".to_owned(),
waveform: Some(String::from("waveform")),
width: Some(184),
};

Expand All @@ -81,11 +87,14 @@ mod tests {
&[
Token::Struct {
name: "Attachment",
len: 9,
len: 11,
},
Token::Str("content_type"),
Token::Some,
Token::Str("image/png"),
Token::Str("duration_secs"),
Token::Some,
Token::F64(3.2),
Token::Str("filename"),
Token::Str("a.png"),
Token::Str("description"),
Expand All @@ -103,6 +112,9 @@ mod tests {
Token::U64(13_593),
Token::Str("url"),
Token::Str("https://example.com/1.png"),
Token::Str("waveform"),
Token::Some,
Token::Str("waveform"),
Token::Str("width"),
Token::Some,
Token::U64(184),
Expand Down
2 changes: 2 additions & 0 deletions twilight-model/src/channel/message/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ bitflags! {
const FAILED_TO_MENTION_SOME_ROLES_IN_THREAD = 1 << 8;
/// This message will not trigger push and desktop notifications.
const SUPPRESS_NOTIFICATIONS = 1 << 12;
/// This message is a voice message.
const IS_VOICE_MESSAGE = 1 << 13;
}
}

Expand Down
2 changes: 1 addition & 1 deletion twilight-model/src/channel/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use crate::{
use serde::{Deserialize, Serialize};

/// Text message sent in a [`Channel`].
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Message {
/// Present with Rich Presence-related chat embeds.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::channel::Message;
use serde::{Deserialize, Serialize};
use std::ops::{Deref, DerefMut};

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct MessageCreate(pub Message);

impl Deref for MessageCreate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct MessageUpdate {
/// List of attachments.
///
Expand Down
2 changes: 2 additions & 0 deletions twilight-model/src/guild/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ bitflags! {
const VIEW_CREATOR_MONETIZATION_ANALYTICS = 1 << 41;
/// Allows for using soundboard in a voice channel
const USE_SOUNDBOARD = 1 << 42;
/// Allows sending voice messages
const SEND_VOICE_MESSAGES = 1 << 46;
}
}

Expand Down