Skip to content

Commit

Permalink
feat(model/channel): support stage voice channels (#748)
Browse files Browse the repository at this point in the history
Support guild stage voice channels. This is denoted by channel type 13.
This is, in effect, a voice channel, but with a separate channel type to
mark that it has additional external capability.

This is a part of #746.

Approved-by: Cassandra McCarthy <[email protected]>
Merged-by: Vivian Hellyer <[email protected]>
Signed-off-by: Vivian Hellyer <[email protected]>
  • Loading branch information
zeylahellyer authored Apr 4, 2021
1 parent 76addc0 commit ab9f835
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
4 changes: 4 additions & 0 deletions model/src/channel/channel_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub enum ChannelType {
GuildCategory = 4,
GuildNews = 5,
GuildStore = 6,
GuildStageVoice = 13,
}

impl ChannelType {
Expand All @@ -20,6 +21,7 @@ impl ChannelType {
Self::Group => "Group",
Self::GuildCategory => "GuildCategory",
Self::GuildNews => "GuildNews",
Self::GuildStageVoice => "GuildStageVoice",
Self::GuildStore => "GuildStore",
Self::GuildText => "GuildText",
Self::GuildVoice => "GuildVoice",
Expand All @@ -42,13 +44,15 @@ mod tests {
serde_test::assert_tokens(&ChannelType::GuildCategory, &[Token::U8(4)]);
serde_test::assert_tokens(&ChannelType::GuildNews, &[Token::U8(5)]);
serde_test::assert_tokens(&ChannelType::GuildStore, &[Token::U8(6)]);
serde_test::assert_tokens(&ChannelType::GuildStageVoice, &[Token::U8(13)]);
}

#[test]
fn test_names() {
assert_eq!("Group", ChannelType::Group.name());
assert_eq!("GuildCategory", ChannelType::GuildCategory.name());
assert_eq!("GuildNews", ChannelType::GuildNews.name());
assert_eq!("GuildStageVoice", ChannelType::GuildStageVoice.name());
assert_eq!("GuildStore", ChannelType::GuildStore.name());
assert_eq!("GuildText", ChannelType::GuildText.name());
assert_eq!("GuildVoice", ChannelType::GuildVoice.name());
Expand Down
2 changes: 1 addition & 1 deletion model/src/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ impl<'de> Visitor<'de> for GuildChannelVisitor {
position,
})
}
ChannelType::GuildVoice => {
ChannelType::GuildVoice | ChannelType::GuildStageVoice => {
let bitrate = bitrate.ok_or_else(|| DeError::missing_field("bitrate"))?;
let user_limit = user_limit.ok_or_else(|| DeError::missing_field("user_limit"))?;

Expand Down
42 changes: 26 additions & 16 deletions model/src/channel/voice_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,22 @@ mod tests {

#[test]
fn test_voice_channel_complete() {
let value = VoiceChannel {
id: ChannelId(1),
bitrate: 124_000,
guild_id: Some(GuildId(2)),
kind: ChannelType::GuildVoice,
name: "foo".to_owned(),
permission_overwrites: Vec::new(),
parent_id: Some(ChannelId(3)),
position: 3,
user_limit: Some(7),
};
fn channel(kind: ChannelType) -> VoiceChannel {
VoiceChannel {
id: ChannelId(1),
bitrate: 124_000,
guild_id: Some(GuildId(2)),
kind,
name: "foo".to_owned(),
permission_overwrites: Vec::new(),
parent_id: Some(ChannelId(3)),
position: 3,
user_limit: Some(7),
}
}

serde_test::assert_tokens(
&value,
&[
fn tokens(kind: ChannelType) -> [Token; 27] {
[
Token::Struct {
name: "VoiceChannel",
len: 9,
Expand All @@ -104,7 +105,7 @@ mod tests {
Token::NewtypeStruct { name: "ChannelId" },
Token::Str("1"),
Token::Str("type"),
Token::U8(2),
Token::U8(kind as u8),
Token::Str("name"),
Token::Str("foo"),
Token::Str("parent_id"),
Expand All @@ -120,7 +121,16 @@ mod tests {
Token::Some,
Token::U64(7),
Token::StructEnd,
],
]
}

serde_test::assert_tokens(
&channel(ChannelType::GuildVoice),
&tokens(ChannelType::GuildVoice),
);
serde_test::assert_tokens(
&channel(ChannelType::GuildStageVoice),
&tokens(ChannelType::GuildStageVoice),
);
}
}

0 comments on commit ab9f835

Please sign in to comment.