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