mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
Add the ChatFullInfo chat as part of the Chat struct
This commit is contained in:
parent
6b97f72d12
commit
24cfdf3991
5 changed files with 27 additions and 4 deletions
|
@ -13,6 +13,7 @@ pub use callback_query::*;
|
||||||
pub use chat::*;
|
pub use chat::*;
|
||||||
pub use chat_action::*;
|
pub use chat_action::*;
|
||||||
pub use chat_administrator_rights::*;
|
pub use chat_administrator_rights::*;
|
||||||
|
pub use chat_full_info::*;
|
||||||
pub use chat_invite_link::*;
|
pub use chat_invite_link::*;
|
||||||
pub use chat_join_request::*;
|
pub use chat_join_request::*;
|
||||||
pub use chat_location::*;
|
pub use chat_location::*;
|
||||||
|
@ -142,6 +143,7 @@ mod callback_query;
|
||||||
mod chat;
|
mod chat;
|
||||||
mod chat_action;
|
mod chat_action;
|
||||||
mod chat_administrator_rights;
|
mod chat_administrator_rights;
|
||||||
|
mod chat_full_info;
|
||||||
mod chat_invite_link;
|
mod chat_invite_link;
|
||||||
mod chat_join_request;
|
mod chat_join_request;
|
||||||
mod chat_location;
|
mod chat_location;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::types::{
|
use crate::types::{
|
||||||
ChatId, ChatLocation, ChatPermissions, ChatPhoto, Message, Seconds, True, User,
|
ChatFullInfo, ChatId, ChatLocation, ChatPermissions, ChatPhoto, Message, Seconds, True, User,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// This object represents a chat.
|
/// This object represents a chat.
|
||||||
|
@ -47,6 +47,9 @@ pub struct Chat {
|
||||||
/// [`GetChat`]: crate::payloads::GetChat
|
/// [`GetChat`]: crate::payloads::GetChat
|
||||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||||
pub has_aggressive_anti_spam_enabled: bool,
|
pub has_aggressive_anti_spam_enabled: bool,
|
||||||
|
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub chat_full_info: ChatFullInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[serde_with_macros::skip_serializing_none]
|
#[serde_with_macros::skip_serializing_none]
|
||||||
|
@ -615,6 +618,7 @@ mod tests {
|
||||||
message_auto_delete_time: None,
|
message_auto_delete_time: None,
|
||||||
has_hidden_members: false,
|
has_hidden_members: false,
|
||||||
has_aggressive_anti_spam_enabled: false,
|
has_aggressive_anti_spam_enabled: false,
|
||||||
|
chat_full_info: ChatFullInfo { emoji_status_expiration_date: None },
|
||||||
};
|
};
|
||||||
let actual = from_str(r#"{"id":-1,"type":"channel","username":"channel_name"}"#).unwrap();
|
let actual = from_str(r#"{"id":-1,"type":"channel","username":"channel_name"}"#).unwrap();
|
||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
|
@ -639,6 +643,7 @@ mod tests {
|
||||||
message_auto_delete_time: None,
|
message_auto_delete_time: None,
|
||||||
has_hidden_members: false,
|
has_hidden_members: false,
|
||||||
has_aggressive_anti_spam_enabled: false,
|
has_aggressive_anti_spam_enabled: false,
|
||||||
|
chat_full_info: ChatFullInfo { emoji_status_expiration_date: None }
|
||||||
},
|
},
|
||||||
from_str(r#"{"id":0,"type":"private","username":"username","first_name":"Anon"}"#)
|
from_str(r#"{"id":0,"type":"private","username":"username","first_name":"Anon"}"#)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -663,6 +668,7 @@ mod tests {
|
||||||
message_auto_delete_time: None,
|
message_auto_delete_time: None,
|
||||||
has_hidden_members: false,
|
has_hidden_members: false,
|
||||||
has_aggressive_anti_spam_enabled: false,
|
has_aggressive_anti_spam_enabled: false,
|
||||||
|
chat_full_info: ChatFullInfo { emoji_status_expiration_date: None },
|
||||||
};
|
};
|
||||||
|
|
||||||
let json = to_string(&chat).unwrap();
|
let json = to_string(&chat).unwrap();
|
||||||
|
|
12
crates/teloxide-core/src/types/chat_full_info.rs
Normal file
12
crates/teloxide-core/src/types/chat_full_info.rs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
// TODO: in the TBA7.3 the Chat will be splitted into Chat and ChatInfo
|
||||||
|
// Currently it's just a container for the some fields of the Chat struct
|
||||||
|
#[serde_with_macros::skip_serializing_none]
|
||||||
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
pub struct ChatFullInfo {
|
||||||
|
// FIXME: better type for the unix timestamp?
|
||||||
|
/// Expiration date of the emoji status of the chat or the other party in a
|
||||||
|
/// private chat, in Unix time, if any
|
||||||
|
pub emoji_status_expiration_date: Option<i64>,
|
||||||
|
}
|
|
@ -1783,7 +1783,8 @@ mod tests {
|
||||||
has_aggressive_anti_spam_enabled: false,
|
has_aggressive_anti_spam_enabled: false,
|
||||||
pinned_message: None,
|
pinned_message: None,
|
||||||
message_auto_delete_time: None,
|
message_auto_delete_time: None,
|
||||||
has_hidden_members: false
|
has_hidden_members: false,
|
||||||
|
chat_full_info: ChatFullInfo { emoji_status_expiration_date: None }
|
||||||
},
|
},
|
||||||
kind: MessageKind::ChatShared(MessageChatShared {
|
kind: MessageKind::ChatShared(MessageChatShared {
|
||||||
chat_shared: ChatShared { request_id: 348349, chat_id: ChatId(384939) }
|
chat_shared: ChatShared { request_id: 348349, chat_id: ChatId(384939) }
|
||||||
|
@ -2016,6 +2017,7 @@ mod tests {
|
||||||
pinned_message: None,
|
pinned_message: None,
|
||||||
has_hidden_members: false,
|
has_hidden_members: false,
|
||||||
has_aggressive_anti_spam_enabled: false,
|
has_aggressive_anti_spam_enabled: false,
|
||||||
|
chat_full_info: ChatFullInfo { emoji_status_expiration_date: None },
|
||||||
};
|
};
|
||||||
|
|
||||||
assert!(message.from().unwrap().is_anonymous());
|
assert!(message.from().unwrap().is_anonymous());
|
||||||
|
|
|
@ -385,8 +385,8 @@ fn empty_error() -> UpdateKind {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::types::{
|
use crate::types::{
|
||||||
Chat, ChatId, ChatKind, ChatPrivate, MediaKind, MediaText, Message, MessageCommon,
|
Chat, ChatFullInfo, ChatId, ChatKind, ChatPrivate, MediaKind, MediaText, Message,
|
||||||
MessageId, MessageKind, Update, UpdateId, UpdateKind, User, UserId,
|
MessageCommon, MessageId, MessageKind, Update, UpdateId, UpdateKind, User, UserId,
|
||||||
};
|
};
|
||||||
|
|
||||||
use chrono::DateTime;
|
use chrono::DateTime;
|
||||||
|
@ -442,6 +442,7 @@ mod test {
|
||||||
message_auto_delete_time: None,
|
message_auto_delete_time: None,
|
||||||
has_hidden_members: false,
|
has_hidden_members: false,
|
||||||
has_aggressive_anti_spam_enabled: false,
|
has_aggressive_anti_spam_enabled: false,
|
||||||
|
chat_full_info: ChatFullInfo { emoji_status_expiration_date: None },
|
||||||
},
|
},
|
||||||
kind: MessageKind::Common(MessageCommon {
|
kind: MessageKind::Common(MessageCommon {
|
||||||
from: Some(User {
|
from: Some(User {
|
||||||
|
|
Loading…
Reference in a new issue