Add the ChatFullInfo chat as part of the Chat struct

This commit is contained in:
Сырцев Вадим Игоревич 2024-06-26 11:41:23 +03:00
parent 6b97f72d12
commit 24cfdf3991
5 changed files with 27 additions and 4 deletions

View file

@ -13,6 +13,7 @@ pub use callback_query::*;
pub use chat::*;
pub use chat_action::*;
pub use chat_administrator_rights::*;
pub use chat_full_info::*;
pub use chat_invite_link::*;
pub use chat_join_request::*;
pub use chat_location::*;
@ -142,6 +143,7 @@ mod callback_query;
mod chat;
mod chat_action;
mod chat_administrator_rights;
mod chat_full_info;
mod chat_invite_link;
mod chat_join_request;
mod chat_location;

View file

@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
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.
@ -47,6 +47,9 @@ pub struct Chat {
/// [`GetChat`]: crate::payloads::GetChat
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub has_aggressive_anti_spam_enabled: bool,
#[serde(flatten)]
pub chat_full_info: ChatFullInfo,
}
#[serde_with_macros::skip_serializing_none]
@ -615,6 +618,7 @@ mod tests {
message_auto_delete_time: None,
has_hidden_members: 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();
assert_eq!(expected, actual);
@ -639,6 +643,7 @@ mod tests {
message_auto_delete_time: None,
has_hidden_members: 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"}"#)
.unwrap()
@ -663,6 +668,7 @@ mod tests {
message_auto_delete_time: None,
has_hidden_members: false,
has_aggressive_anti_spam_enabled: false,
chat_full_info: ChatFullInfo { emoji_status_expiration_date: None },
};
let json = to_string(&chat).unwrap();

View 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>,
}

View file

@ -1783,7 +1783,8 @@ mod tests {
has_aggressive_anti_spam_enabled: false,
pinned_message: 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 {
chat_shared: ChatShared { request_id: 348349, chat_id: ChatId(384939) }
@ -2016,6 +2017,7 @@ mod tests {
pinned_message: None,
has_hidden_members: false,
has_aggressive_anti_spam_enabled: false,
chat_full_info: ChatFullInfo { emoji_status_expiration_date: None },
};
assert!(message.from().unwrap().is_anonymous());

View file

@ -385,8 +385,8 @@ fn empty_error() -> UpdateKind {
#[cfg(test)]
mod test {
use crate::types::{
Chat, ChatId, ChatKind, ChatPrivate, MediaKind, MediaText, Message, MessageCommon,
MessageId, MessageKind, Update, UpdateId, UpdateKind, User, UserId,
Chat, ChatFullInfo, ChatId, ChatKind, ChatPrivate, MediaKind, MediaText, Message,
MessageCommon, MessageId, MessageKind, Update, UpdateId, UpdateKind, User, UserId,
};
use chrono::DateTime;
@ -442,6 +442,7 @@ mod test {
message_auto_delete_time: None,
has_hidden_members: false,
has_aggressive_anti_spam_enabled: false,
chat_full_info: ChatFullInfo { emoji_status_expiration_date: None },
},
kind: MessageKind::Common(MessageCommon {
from: Some(User {