mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-23 15:01:45 +01:00
NonPrivate* -> Public*
ChatKind::NonPrivate -> ChatKind::Public ChatNonPrivate -> ChatPublic NonPrivateChatKind -> PublicChatKind NonPrivateChatChannel -> PublicChatChannel NonPrivateChatGroup -> PublicChatGroup NonPrivateChatSupergroup -> PublicChatSupergroup
This commit is contained in:
parent
9b36d46c47
commit
cc37f9ff3c
2 changed files with 27 additions and 29 deletions
|
@ -28,18 +28,18 @@ pub struct Chat {
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum ChatKind {
|
pub enum ChatKind {
|
||||||
NonPrivate(ChatNonPrivate),
|
Public(ChatPublic),
|
||||||
Private(ChatPrivate),
|
Private(ChatPrivate),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[serde_with_macros::skip_serializing_none]
|
#[serde_with_macros::skip_serializing_none]
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct ChatNonPrivate {
|
pub struct ChatPublic {
|
||||||
/// A title, for supergroups, channels and group chats.
|
/// A title, for supergroups, channels and group chats.
|
||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
|
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub kind: NonPrivateChatKind,
|
pub kind: PublicChatKind,
|
||||||
|
|
||||||
/// A description, for groups, supergroups and channel chats. Returned
|
/// A description, for groups, supergroups and channel chats. Returned
|
||||||
/// only in [`Bot::get_chat`].
|
/// only in [`Bot::get_chat`].
|
||||||
|
@ -90,22 +90,22 @@ pub struct ChatPrivate {
|
||||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
pub enum NonPrivateChatKind {
|
pub enum PublicChatKind {
|
||||||
Channel(NonPrivateChatChannel),
|
Channel(PublicChatChannel),
|
||||||
Group(NonPrivateChatGroup),
|
Group(PublicChatGroup),
|
||||||
Supergroup(NonPrivateChatSupergroup),
|
Supergroup(PublicChatSupergroup),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[serde_with_macros::skip_serializing_none]
|
#[serde_with_macros::skip_serializing_none]
|
||||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct NonPrivateChatChannel {
|
pub struct PublicChatChannel {
|
||||||
/// A username, for private chats, supergroups and channels if available.
|
/// A username, for private chats, supergroups and channels if available.
|
||||||
pub username: Option<String>,
|
pub username: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[serde_with_macros::skip_serializing_none]
|
#[serde_with_macros::skip_serializing_none]
|
||||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct NonPrivateChatGroup {
|
pub struct PublicChatGroup {
|
||||||
/// A default chat member permissions, for groups and supergroups. Returned
|
/// A default chat member permissions, for groups and supergroups. Returned
|
||||||
/// only from [`Bot::get_chat`].
|
/// only from [`Bot::get_chat`].
|
||||||
///
|
///
|
||||||
|
@ -115,7 +115,7 @@ pub struct NonPrivateChatGroup {
|
||||||
|
|
||||||
#[serde_with_macros::skip_serializing_none]
|
#[serde_with_macros::skip_serializing_none]
|
||||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct NonPrivateChatSupergroup {
|
pub struct PublicChatSupergroup {
|
||||||
/// A username, for private chats, supergroups and channels if
|
/// A username, for private chats, supergroups and channels if
|
||||||
/// available.
|
/// available.
|
||||||
pub username: Option<String>,
|
pub username: Option<String>,
|
||||||
|
@ -182,17 +182,16 @@ impl Chat {
|
||||||
pub fn is_group(&self) -> bool {
|
pub fn is_group(&self) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
self.kind,
|
self.kind,
|
||||||
ChatKind::NonPrivate(ChatNonPrivate {
|
ChatKind::Public(ChatPublic {
|
||||||
kind: NonPrivateChatKind::Group(_),
|
kind: PublicChatKind::Group(_), ..
|
||||||
..
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
pub fn is_supergroup(&self) -> bool {
|
pub fn is_supergroup(&self) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
self.kind,
|
self.kind,
|
||||||
ChatKind::NonPrivate(ChatNonPrivate {
|
ChatKind::Public(ChatPublic {
|
||||||
kind: NonPrivateChatKind::Supergroup(_),
|
kind: PublicChatKind::Supergroup(_),
|
||||||
..
|
..
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -200,8 +199,8 @@ impl Chat {
|
||||||
pub fn is_channel(&self) -> bool {
|
pub fn is_channel(&self) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
self.kind,
|
self.kind,
|
||||||
ChatKind::NonPrivate(ChatNonPrivate {
|
ChatKind::Public(ChatPublic {
|
||||||
kind: NonPrivateChatKind::Channel(_),
|
kind: PublicChatKind::Channel(_),
|
||||||
..
|
..
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -222,9 +221,9 @@ mod tests {
|
||||||
fn channel_de() {
|
fn channel_de() {
|
||||||
let expected = Chat {
|
let expected = Chat {
|
||||||
id: -1,
|
id: -1,
|
||||||
kind: ChatKind::NonPrivate(ChatNonPrivate {
|
kind: ChatKind::Public(ChatPublic {
|
||||||
title: None,
|
title: None,
|
||||||
kind: NonPrivateChatKind::Channel(NonPrivateChatChannel {
|
kind: PublicChatKind::Channel(PublicChatChannel {
|
||||||
username: Some("channelname".into()),
|
username: Some("channelname".into()),
|
||||||
}),
|
}),
|
||||||
description: None,
|
description: None,
|
||||||
|
|
|
@ -3,12 +3,11 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::types::{
|
use crate::types::{
|
||||||
chat::{ChatKind, NonPrivateChatKind},
|
chat::{ChatKind, PublicChatKind},
|
||||||
Animation, Audio, Chat, ChatNonPrivate, Contact, Document, Game,
|
Animation, Audio, Chat, ChatPublic, Contact, Document, Game,
|
||||||
InlineKeyboardMarkup, Invoice, Location, MessageEntity,
|
InlineKeyboardMarkup, Invoice, Location, MessageEntity, PassportData,
|
||||||
NonPrivateChatChannel, NonPrivateChatSupergroup, PassportData, PhotoSize,
|
PhotoSize, Poll, PublicChatChannel, PublicChatSupergroup, Sticker,
|
||||||
Poll, Sticker, SuccessfulPayment, True, User, Venue, Video, VideoNote,
|
SuccessfulPayment, True, User, Venue, Video, VideoNote, Voice,
|
||||||
Voice,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// This object represents a message.
|
/// This object represents a message.
|
||||||
|
@ -924,16 +923,16 @@ mod getters {
|
||||||
impl Message {
|
impl Message {
|
||||||
pub fn url(&self) -> Option<reqwest::Url> {
|
pub fn url(&self) -> Option<reqwest::Url> {
|
||||||
match &self.chat.kind {
|
match &self.chat.kind {
|
||||||
ChatKind::NonPrivate(ChatNonPrivate {
|
ChatKind::Public(ChatPublic {
|
||||||
kind:
|
kind:
|
||||||
NonPrivateChatKind::Channel(NonPrivateChatChannel {
|
PublicChatKind::Channel(PublicChatChannel {
|
||||||
username: Some(username),
|
username: Some(username),
|
||||||
}),
|
}),
|
||||||
..
|
..
|
||||||
})
|
})
|
||||||
| ChatKind::NonPrivate(ChatNonPrivate {
|
| ChatKind::Public(ChatPublic {
|
||||||
kind:
|
kind:
|
||||||
NonPrivateChatKind::Supergroup(NonPrivateChatSupergroup {
|
PublicChatKind::Supergroup(PublicChatSupergroup {
|
||||||
username: Some(username),
|
username: Some(username),
|
||||||
..
|
..
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in a new issue