mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-08 19:33:53 +01:00
Apply changes from the review
Make `BareChatId` internal.
This commit is contained in:
parent
fa189af463
commit
6318a7e730
4 changed files with 8 additions and 20 deletions
|
@ -14,8 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- `Me::username` and `Deref<Target = User>` 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
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<UserId> 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 :(
|
||||
|
|
|
@ -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<UserId> for Recipient {
|
||||
fn from(id: UserId) -> Self {
|
||||
Self::Id(id.into())
|
||||
|
|
Loading…
Reference in a new issue