Skip to content

Commit

Permalink
Deprecate Channel::is_nsfw (serenity-rs#2791)
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev authored Mar 11, 2024
1 parent 2534b60 commit 2951d98
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 45 deletions.
6 changes: 2 additions & 4 deletions src/model/channel/guild_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,13 +664,11 @@ impl GuildChannel {
}

/// Determines if the channel is NSFW.
///
/// Only [text channels][`ChannelType::Text`] are taken into consideration as being NSFW.
/// [voice channels][`ChannelType::Voice`] are never NSFW.
#[inline]
#[must_use]
#[deprecated = "Use the GuildChannel::nsfw field"]
pub fn is_nsfw(&self) -> bool {
self.kind == ChannelType::Text && self.nsfw
self.nsfw
}

/// Gets a message from the channel.
Expand Down
40 changes: 2 additions & 38 deletions src/model/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ impl Channel {
#[inline]
#[must_use]
#[cfg(feature = "model")]
#[deprecated = "Use the GuildChannel::nsfw field, as PrivateChannel is never NSFW"]
pub fn is_nsfw(&self) -> bool {
match self {
#[allow(deprecated)]
Self::Guild(channel) => channel.is_nsfw(),
Self::Private(_) => false,
}
Expand Down Expand Up @@ -481,44 +483,6 @@ pub struct ThreadsData {
pub has_more: bool,
}

#[cfg(test)]
mod test {
#[cfg(all(feature = "model", feature = "utils"))]
mod model_utils {
use crate::model::prelude::*;

#[test]
fn nsfw_checks() {
let mut channel = GuildChannel::default();
assert!(!channel.is_nsfw());
channel.kind = ChannelType::Voice;
assert!(!channel.is_nsfw());

channel.kind = ChannelType::Text;
channel.name = "nsfw-".to_string();
assert!(!channel.is_nsfw());

channel.name = "nsfw".to_string();
assert!(!channel.is_nsfw());
channel.kind = ChannelType::Voice;
assert!(!channel.is_nsfw());
channel.kind = ChannelType::Text;

channel.name = "nsf".to_string();
channel.nsfw = true;
assert!(channel.is_nsfw());
channel.nsfw = false;
assert!(!channel.is_nsfw());

let channel = Channel::Guild(channel);
assert!(!channel.is_nsfw());

let private_channel = PrivateChannel::default();
assert!(!private_channel.is_nsfw());
}
}
}

/// An object that specifies the emoji to use for Forum related emoji parameters.
///
/// See [Discord](https://discord.com/developers/docs/resources/channel#default-reaction-object)
Expand Down
4 changes: 1 addition & 3 deletions src/model/channel/private_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,10 @@ impl PrivateChannel {
}

/// Determines if the channel is NSFW.
///
/// **Note**: This method is for consistency. This will always return `false`, due to DMs not
/// being considered NSFW.
#[inline]
#[must_use]
#[allow(clippy::unused_self)]
#[deprecated = "This always returns false"]
pub fn is_nsfw(&self) -> bool {
false
}
Expand Down

0 comments on commit 2951d98

Please sign in to comment.