Add new fields of TBA7.0 to the ChatFullInfo

This commit is contained in:
Сырцев Вадим Игоревич 2024-07-16 15:08:12 +03:00 committed by Andrey Brusnik
parent 7dc7047ea1
commit 83d9e6c6b7
No known key found for this signature in database
GPG key ID: D33232F28CFF442C
4 changed files with 45 additions and 30 deletions

View file

@ -108,13 +108,6 @@ pub struct ChatPrivate {
/// A last name of the other party in a private chat.
pub last_name: Option<String>,
/// Custom emoji identifier of emoji status of the other party in a private
/// chat. Returned only in [`GetChat`].
///
/// [`GetChat`]: crate::payloads::GetChat
// FIXME: CustomEmojiId
pub emoji_status_custom_emoji_id: Option<String>,
/// Bio of the other party in a private chat. Returned only in [`GetChat`].
///
/// [`GetChat`]: crate::payloads::GetChat
@ -539,7 +532,6 @@ mod serde_helper {
bio: Option<String>,
has_private_forwards: Option<True>,
has_restricted_voice_and_video_messages: Option<True>,
emoji_status_custom_emoji_id: Option<String>,
}
impl From<ChatPrivate> for super::ChatPrivate {
@ -552,7 +544,6 @@ mod serde_helper {
bio,
has_private_forwards,
has_restricted_voice_and_video_messages,
emoji_status_custom_emoji_id,
}: ChatPrivate,
) -> Self {
Self {
@ -562,7 +553,6 @@ mod serde_helper {
bio,
has_private_forwards,
has_restricted_voice_and_video_messages,
emoji_status_custom_emoji_id,
}
}
}
@ -576,7 +566,6 @@ mod serde_helper {
bio,
has_private_forwards,
has_restricted_voice_and_video_messages,
emoji_status_custom_emoji_id,
}: super::ChatPrivate,
) -> Self {
Self {
@ -587,7 +576,6 @@ mod serde_helper {
bio,
has_private_forwards,
has_restricted_voice_and_video_messages,
emoji_status_custom_emoji_id,
}
}
}
@ -618,7 +606,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 },
chat_full_info: ChatFullInfo::default(),
};
let actual = from_str(r#"{"id":-1,"type":"channel","username":"channel_name"}"#).unwrap();
assert_eq!(expected, actual);
@ -636,14 +624,13 @@ mod tests {
bio: None,
has_private_forwards: None,
has_restricted_voice_and_video_messages: None,
emoji_status_custom_emoji_id: None
}),
photo: None,
pinned_message: None,
message_auto_delete_time: None,
has_hidden_members: false,
has_aggressive_anti_spam_enabled: false,
chat_full_info: ChatFullInfo { emoji_status_expiration_date: None }
chat_full_info: ChatFullInfo::default()
},
from_str(r#"{"id":0,"type":"private","username":"username","first_name":"Anon"}"#)
.unwrap()
@ -661,14 +648,13 @@ mod tests {
bio: None,
has_private_forwards: None,
has_restricted_voice_and_video_messages: None,
emoji_status_custom_emoji_id: None,
}),
photo: None,
pinned_message: None,
message_auto_delete_time: None,
has_hidden_members: false,
has_aggressive_anti_spam_enabled: false,
chat_full_info: ChatFullInfo { emoji_status_expiration_date: None },
chat_full_info: ChatFullInfo::default(),
};
let json = to_string(&chat).unwrap();

View file

@ -4,12 +4,43 @@ 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::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Default, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ChatFullInfo {
/// Identifier of the accent color for the chat name and backgrounds of the
/// chat photo, reply header, and link preview. See [accent colors] for more
/// details.
///
/// [accent colors]: https://core.telegram.org/bots/api#accent-colors
pub accent_color_id: Option<u8>,
/// Custom emoji identifier of the emoji chosen by the chat for the reply
/// header and link preview background
// FIXME: CustomEmojiId
pub background_custom_emoji_id: Option<String>,
/// Identifier of the accent color for the chat's profile background. See
/// [profile accent colors] for more details.
///
/// [profile accent colors]: https://core.telegram.org/bots/api#profile-accent-colors
pub profile_accent_color_id: Option<u8>,
/// Custom emoji identifier of the emoji chosen by the chat for its profile
/// background
// FIXME: CustomEmojiId
pub profile_background_custom_emoji_id: Option<String>,
/// Custom emoji identifier of emoji status of the other party in a private
/// chat. Returned only in [`GetChat`].
///
/// [`GetChat`]: crate::payloads::GetChat
// FIXME: CustomEmojiId
pub emoji_status_custom_emoji_id: Option<String>,
/// Expiration date of the emoji status of the chat or the other party in a
/// private chat, in Unix time, if any
#[serde(default, with = "crate::types::serde_opt_date_from_unix_timestamp")]
pub emoji_status_expiration_date: Option<DateTime<Utc>>,
/// True, if new chat members will have access to old messages; available
/// only to chat administrators. Returned only in [`GetChat`].
///
/// [`GetChat`]: crate::payloads::GetChat
#[serde(default)]
pub has_visible_history: bool,
}
#[cfg(test)]
@ -18,18 +49,18 @@ mod tests {
#[test]
fn test_chat_full_info_de() {
assert_eq!(
serde_json::from_str::<ChatFullInfo>("{}").unwrap(),
ChatFullInfo { emoji_status_expiration_date: None }
);
assert_eq!(serde_json::from_str::<ChatFullInfo>("{}").unwrap(), ChatFullInfo::default());
assert_eq!(
serde_json::from_str::<ChatFullInfo>(
r#"{
"emoji_status_expiration_date": 1720708004
}"#
"emoji_status_expiration_date": 1720708004
}"#
)
.unwrap(),
ChatFullInfo { emoji_status_expiration_date: DateTime::from_timestamp(1720708004, 0) }
ChatFullInfo {
emoji_status_expiration_date: DateTime::from_timestamp(1720708004, 0),
..ChatFullInfo::default()
}
);
}
}

View file

@ -1775,7 +1775,6 @@ mod tests {
last_name: Some("Власов".to_string()),
username: Some("aka_dude".to_string()),
bio: None,
emoji_status_custom_emoji_id: None,
has_private_forwards: None,
has_restricted_voice_and_video_messages: None
}),
@ -1784,7 +1783,7 @@ mod tests {
pinned_message: None,
message_auto_delete_time: None,
has_hidden_members: false,
chat_full_info: ChatFullInfo { emoji_status_expiration_date: None }
chat_full_info: ChatFullInfo::default()
},
kind: MessageKind::ChatShared(MessageChatShared {
chat_shared: ChatShared { request_id: 348349, chat_id: ChatId(384939) }
@ -2017,7 +2016,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 },
chat_full_info: ChatFullInfo::default(),
};
assert!(message.from().unwrap().is_anonymous());

View file

@ -435,14 +435,13 @@ mod test {
bio: None,
has_private_forwards: None,
has_restricted_voice_and_video_messages: None,
emoji_status_custom_emoji_id: None,
}),
photo: None,
pinned_message: None,
message_auto_delete_time: None,
has_hidden_members: false,
has_aggressive_anti_spam_enabled: false,
chat_full_info: ChatFullInfo { emoji_status_expiration_date: None },
chat_full_info: ChatFullInfo::default(),
},
kind: MessageKind::Common(MessageCommon {
from: Some(User {