From e3235adf2f5a36b6ce044647134cb56750ee5319 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Sat, 18 Jan 2020 05:40:01 +0600 Subject: [PATCH] Fix UpdateKind --- src/network/download.rs | 12 +++++------- src/types/message_entity.rs | 10 ++++++---- src/types/update.rs | 19 ++++++++++++++++--- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/network/download.rs b/src/network/download.rs index 0e68414f..05f08f5d 100644 --- a/src/network/download.rs +++ b/src/network/download.rs @@ -39,13 +39,11 @@ pub async fn download_file_stream( .await? .error_for_status()?; - Ok(futures::stream::unfold(res, |mut res| { - async { - match res.chunk().await { - Err(err) => Some((Err(err), res)), - Ok(Some(c)) => Some((Ok(c), res)), - Ok(None) => None, - } + Ok(futures::stream::unfold(res, |mut res| async { + match res.chunk().await { + Err(err) => Some((Err(err), res)), + Ok(Some(c)) => Some((Ok(c), res)), + Ok(None) => None, } })) } diff --git a/src/types/message_entity.rs b/src/types/message_entity.rs index c87471d6..9a649176 100644 --- a/src/types/message_entity.rs +++ b/src/types/message_entity.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::types::{User, Message}; +use crate::types::{Message, User}; /// This object represents one special entity in a text message. For example, /// hashtags, usernames, URLs, etc. @@ -42,14 +42,16 @@ pub enum MessageEntityKind { impl MessageEntity { pub fn text_from(&self, message: &Message) -> Option { let text = message.text(); - Some(String::from(&text?[self.offset..self.offset+self.length])) + Some(String::from(&text?[self.offset..self.offset + self.length])) } } #[cfg(test)] mod tests { use super::*; - use crate::types::{Chat, ChatKind, MessageKind, Sender, ForwardKind, MediaKind}; + use crate::types::{ + Chat, ChatKind, ForwardKind, MediaKind, MessageKind, Sender, + }; #[test] fn recursive_kind() { @@ -111,7 +113,7 @@ mod tests { entities: vec![MessageEntity { kind: MessageEntityKind::Mention, offset: 3, - length: 3 + length: 3, }], }, reply_markup: None, diff --git a/src/types/update.rs b/src/types/update.rs index 3dfb2270..b740afe1 100644 --- a/src/types/update.rs +++ b/src/types/update.rs @@ -2,7 +2,10 @@ use serde::{Deserialize, Serialize}; -use crate::types::{CallbackQuery, ChosenInlineResult, InlineQuery, Message}; +use crate::types::{ + CallbackQuery, ChosenInlineResult, InlineQuery, Message, Poll, + PreCheckoutQuery, ShippingQuery, +}; /// This [object] represents an incoming update. /// @@ -57,7 +60,17 @@ pub enum UpdateKind { /// New incoming callback query. CallbackQuery(CallbackQuery), - // TODO: Add more variants + + /// New incoming shipping query. Only for invoices with flexible price. + ShippingQuery(ShippingQuery), + + /// New incoming pre-checkout query. Contains full information about + /// checkout. + PreCheckoutQuery(PreCheckoutQuery), + + /// New poll state. Bots receive only updates about stopped polls and + /// polls, which are sent by the bot. + Poll(Poll), } #[cfg(test)] @@ -92,7 +105,7 @@ mod test { } }"#; - let expected: Update = Update { + let expected = Update { id: 892_252_934, kind: UpdateKind::Message(Message { id: 6557,