TBA 6.2: Chat and MessageEntity changes

This commit is contained in:
Maybe Waffle 2022-09-25 20:00:14 +04:00
parent 00165e64dc
commit c544dae94c
3 changed files with 30 additions and 4 deletions

View file

@ -99,6 +99,13 @@ pub struct ChatPrivate {
/// ///
/// [`GetChat`]: crate::payloads::GetChat /// [`GetChat`]: crate::payloads::GetChat
pub has_private_forwards: Option<True>, pub has_private_forwards: Option<True>,
/// `True`, if the privacy settings of the other party restrict sending
/// voice and video note messages in the private chat. Returned only in
/// [`GetChat`].
///
/// [`GetChat`]: crate::payloads::GetChat
pub has_restricted_voice_and_video_messages: Option<True>,
} }
#[serde_with_macros::skip_serializing_none] #[serde_with_macros::skip_serializing_none]
@ -492,6 +499,7 @@ mod serde_helper {
last_name: Option<String>, last_name: Option<String>,
bio: Option<String>, bio: Option<String>,
has_private_forwards: Option<True>, has_private_forwards: Option<True>,
has_restricted_voice_and_video_messages: Option<True>,
} }
impl From<ChatPrivate> for super::ChatPrivate { impl From<ChatPrivate> for super::ChatPrivate {
@ -503,6 +511,7 @@ mod serde_helper {
last_name, last_name,
bio, bio,
has_private_forwards, has_private_forwards,
has_restricted_voice_and_video_messages,
}: ChatPrivate, }: ChatPrivate,
) -> Self { ) -> Self {
Self { Self {
@ -511,6 +520,7 @@ mod serde_helper {
last_name, last_name,
bio, bio,
has_private_forwards, has_private_forwards,
has_restricted_voice_and_video_messages,
} }
} }
} }
@ -523,6 +533,7 @@ mod serde_helper {
last_name, last_name,
bio, bio,
has_private_forwards, has_private_forwards,
has_restricted_voice_and_video_messages,
}: super::ChatPrivate, }: super::ChatPrivate,
) -> Self { ) -> Self {
Self { Self {
@ -532,6 +543,7 @@ mod serde_helper {
last_name, last_name,
bio, bio,
has_private_forwards, has_private_forwards,
has_restricted_voice_and_video_messages,
} }
} }
} }
@ -576,6 +588,7 @@ mod tests {
last_name: None, last_name: None,
bio: None, bio: None,
has_private_forwards: None, has_private_forwards: None,
has_restricted_voice_and_video_messages: None,
}), }),
photo: None, photo: None,
pinned_message: None, pinned_message: None,
@ -596,6 +609,7 @@ mod tests {
last_name: None, last_name: None,
bio: None, bio: None,
has_private_forwards: None, has_private_forwards: None,
has_restricted_voice_and_video_messages: None,
}), }),
photo: None, photo: None,
pinned_message: None, pinned_message: None,

View file

@ -139,7 +139,7 @@ impl MessageEntity {
/// If you don't have a complete [`User`] value, please use /// If you don't have a complete [`User`] value, please use
/// [`MessageEntity::text_mention_id`] instead. /// [`MessageEntity::text_mention_id`] instead.
#[must_use] #[must_use]
pub fn text_mention(user: User, offset: usize, length: usize) -> Self { pub const fn text_mention(user: User, offset: usize, length: usize) -> Self {
Self { Self {
kind: MessageEntityKind::TextMention { user }, kind: MessageEntityKind::TextMention { user },
offset, offset,
@ -158,6 +158,16 @@ impl MessageEntity {
} }
} }
/// Create a message entity representing a custom emoji.
#[must_use]
pub const fn custom_emoji(custom_emoji_id: String, offset: usize, length: usize) -> Self {
Self {
kind: MessageEntityKind::CustomEmoji { custom_emoji_id },
offset,
length,
}
}
#[must_use] #[must_use]
pub fn kind(mut self, val: MessageEntityKind) -> Self { pub fn kind(mut self, val: MessageEntityKind) -> Self {
self.kind = val; self.kind = val;
@ -300,13 +310,14 @@ pub enum MessageEntityKind {
PhoneNumber, PhoneNumber,
Bold, Bold,
Italic, Italic,
Underline,
Strikethrough,
Spoiler,
Code, Code,
Pre { language: Option<String> }, Pre { language: Option<String> },
TextLink { url: reqwest::Url }, TextLink { url: reqwest::Url },
TextMention { user: User }, TextMention { user: User },
Underline, CustomEmoji { custom_emoji_id: String }, // FIXME(waffle): newtype this
Strikethrough,
Spoiler,
} }
#[cfg(test)] #[cfg(test)]

View file

@ -344,6 +344,7 @@ mod test {
last_name: None, last_name: None,
bio: None, bio: None,
has_private_forwards: None, has_private_forwards: None,
has_restricted_voice_and_video_messages: None,
}), }),
photo: None, photo: None,
pinned_message: None, pinned_message: None,