mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-10 20:12:25 +01:00
added is_{private, group, supergroup, channel, chat} for type Chat
This commit is contained in:
parent
50c29227ce
commit
1aae70048e
1 changed files with 31 additions and 3 deletions
|
@ -1,8 +1,6 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::types::{ChatPermissions, ChatPhoto, Message};
|
||||||
types::{ChatPermissions, ChatPhoto, Message},
|
|
||||||
};
|
|
||||||
|
|
||||||
/// This object represents a chat.
|
/// This object represents a chat.
|
||||||
///
|
///
|
||||||
|
@ -158,6 +156,36 @@ where
|
||||||
des.deserialize_str(PrivateChatKindVisitor)
|
des.deserialize_str(PrivateChatKindVisitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Chat {
|
||||||
|
pub fn is_private(&self) -> bool {
|
||||||
|
match self.kind {
|
||||||
|
ChatKind::Private {..} => true,
|
||||||
|
_ => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn is_group(&self) -> bool {
|
||||||
|
match self.kind {
|
||||||
|
ChatKind::NonPrivate { kind: NonPrivateChatKind::Group {..}, .. } => true,
|
||||||
|
_ => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn is_supergroup(&self) -> bool {
|
||||||
|
match self.kind {
|
||||||
|
ChatKind::NonPrivate { kind: NonPrivateChatKind::Supergroup {..}, .. } => true,
|
||||||
|
_ => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn is_channel(&self) -> bool {
|
||||||
|
match self.kind {
|
||||||
|
ChatKind::NonPrivate { kind: NonPrivateChatKind::Channel {..}, .. } => true,
|
||||||
|
_ => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn is_chat(&self) -> bool {
|
||||||
|
self.is_private() || self.is_group() || self.is_supergroup()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use serde_json::from_str;
|
use serde_json::from_str;
|
||||||
|
|
Loading…
Reference in a new issue