diff --git a/CHANGELOG.md b/CHANGELOG.md index cd4ef396..57c44cbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,8 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `Me::username` and `Deref` implementation for `Me` ([#197][pr197]) - `Me::{mention, tme_url}` ([#197][pr197]) - `AllowedUpdate::ChatJoinRequest` ([#201][pr201]) -- `ChatId::{is_user, is_group, is_channel, to_bare}` functions and `BareChatId` type [#198][pr198] - +- `ChatId::{is_user, is_group, is_channel_or_supergroup}` functions [#198][pr198] [pr197]: https://github.com/teloxide/teloxide-core/pull/197 [pr198]: https://github.com/teloxide/teloxide-core/pull/198 diff --git a/src/adaptors/throttle.rs b/src/adaptors/throttle.rs index 7d75ec7f..4e10be25 100644 --- a/src/adaptors/throttle.rs +++ b/src/adaptors/throttle.rs @@ -645,7 +645,7 @@ enum ChatIdHash { impl ChatIdHash { fn is_channel(&self) -> bool { match self { - &Self::Id(id) => id.is_channel(), + &Self::Id(id) => id.is_channel_or_supergroup(), Self::ChannelUsernameHash(_) => true, } } diff --git a/src/types/chat_id.rs b/src/types/chat_id.rs index e4951727..cca06e41 100644 --- a/src/types/chat_id.rs +++ b/src/types/chat_id.rs @@ -22,9 +22,10 @@ pub struct ChatId(pub i64); /// /// `BareChatId` can be created by [`ChatId::to_bare`]. #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub enum BareChatId { +pub(crate) enum BareChatId { User(UserId), Group(u64), + /// Note: supergroups are considered channels. Channel(u64), } @@ -42,16 +43,14 @@ impl ChatId { } /// Returns `true` if this is an id of a channel. - /// - /// Note: supergroup is considered a channel. - pub fn is_channel(self) -> bool { + pub fn is_channel_or_supergroup(self) -> bool { matches!(self.to_bare(), BareChatId::Channel(_)) } /// Converts this id to "bare" MTProto peer id. /// /// See [`BareChatId`] for more. - pub fn to_bare(self) -> BareChatId { + pub(crate) fn to_bare(self) -> BareChatId { use BareChatId::*; match self.0 { @@ -73,7 +72,8 @@ impl From for ChatId { impl BareChatId { /// Converts bare chat id back to normal bot API [`ChatId`]. - pub fn to_bot_api(self) -> ChatId { + #[allow(unused)] + pub(crate) fn to_bot_api(self) -> ChatId { use BareChatId::*; match self { @@ -146,7 +146,6 @@ mod tests { 1666111087, 1 << 20, (1 << 35) | 123456, - (1 << 40) - 1, ]; // rust 2021 when :( diff --git a/src/types/recipient.rs b/src/types/recipient.rs index e7a29672..469aac97 100644 --- a/src/types/recipient.rs +++ b/src/types/recipient.rs @@ -19,16 +19,6 @@ pub enum Recipient { ChannelUsername(String), } -impl Recipient { - #[allow(unused)] - pub(crate) fn is_channel(&self) -> bool { - match self { - Recipient::Id(id) => id.is_channel(), - Recipient::ChannelUsername(_) => true, - } - } -} - impl From for Recipient { fn from(id: UserId) -> Self { Self::Id(id.into())