From eada897471ff84b9d0eeb353726e0acbeb1ceee4 Mon Sep 17 00:00:00 2001 From: nextel Date: Thu, 12 Sep 2019 16:00:58 +0300 Subject: [PATCH 1/9] add stop message live location handler --- src/core/requests/mod.rs | 1 + .../requests/stop_message_live_location.rs | 90 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 src/core/requests/stop_message_live_location.rs diff --git a/src/core/requests/mod.rs b/src/core/requests/mod.rs index 1876db11..c951f54c 100644 --- a/src/core/requests/mod.rs +++ b/src/core/requests/mod.rs @@ -96,3 +96,4 @@ pub mod send_media_group; pub mod send_audio; pub mod send_location; pub mod edit_message_live_location; +pub mod stop_message_live_location; \ No newline at end of file diff --git a/src/core/requests/stop_message_live_location.rs b/src/core/requests/stop_message_live_location.rs new file mode 100644 index 00000000..9f1fd027 --- /dev/null +++ b/src/core/requests/stop_message_live_location.rs @@ -0,0 +1,90 @@ +use std::path::Path; + +use crate::core::{ + network, + requests::{ + ChatId, form_builder::FormBuilder, Request, RequestContext, + RequestFuture, ResponseResult, + }, + types::{InlineKeyboardMarkup, Message, ParseMode}, +}; + +/// Use this method to stop updating a live location message before live_period +/// expires. On success, if the message was sent by the bot, the sent Message is +/// returned, otherwise True is returned. +#[derive(Debug, Clone, Serialize)] +struct StopMessageLiveLocation<'a> { + ctx: RequestContext<'a>, + /// Required if inline_message_id is not specified. Unique identifier for + /// the target chat or username of the target channel (in the format + /// @channelusername) + chat_id: Option, + /// Required if inline_message_id is not specified. Identifier of the + /// message with live location to stop + message_id: Option, + /// Required if chat_id and message_id are not specified. Identifier of the + /// inline message + inline_message_id: Option, + /// A JSON-serialized object InlineKeyboardMarkup for a new inline + /// keyboard. + reply_markup: Option, +} + +impl<'a> Request<'a> for StopMessageLiveLocation<'a> { + type ReturnValue = Message; + + fn send(self) -> RequestFuture<'a, ResponseResult> { + Box::pin(async move { + network::request_json( + &self.ctx.client, + &self.ctx.token, + "stopMessageLiveLocation", + &self, + ) + .await + }) + } +} + +impl<'a> StopMessageLiveLocation<'a> { + fn new( + ctx: RequestContext<'a>, + chat_id: ChatId, + ) -> Self { + Self { + ctx, + chat_id: None, + message_id: None, + inline_message_id: None, + reply_markup: None, + } + } + + pub fn chat_id(mut self, chat_id: T) -> Self + where T: Into + { + self.chat_id = chat_id.into(); + self + } + + pub fn message_id(mut self, message_id: T) -> Self + where T: Into + { + self.message_id = Some(message_id.into()); + self + } + + pub fn inline_message_id(mut self, inline_message_id: T) -> Self + where T: Into + { + self.inline_message_id = Some(inline_message_id.into()); + self + } + + pub fn reply_markup(mut self, reply_markup: T) -> Self + where T: Into + { + self.inline_message_id = Some(reply_markup.into()); + self + } +} \ No newline at end of file From 1c40479f872decdd6d7d9218be6b4901c39c3234 Mon Sep 17 00:00:00 2001 From: nextel Date: Thu, 12 Sep 2019 18:11:50 +0300 Subject: [PATCH 2/9] add serde tags to optional fields --- src/core/requests/stop_message_live_location.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/requests/stop_message_live_location.rs b/src/core/requests/stop_message_live_location.rs index 9f1fd027..9c92e4f0 100644 --- a/src/core/requests/stop_message_live_location.rs +++ b/src/core/requests/stop_message_live_location.rs @@ -18,15 +18,19 @@ struct StopMessageLiveLocation<'a> { /// Required if inline_message_id is not specified. Unique identifier for /// the target chat or username of the target channel (in the format /// @channelusername) + #[serde(skip_serializing_if="Option::is_none")] chat_id: Option, /// Required if inline_message_id is not specified. Identifier of the /// message with live location to stop + #[serde(skip_serializing_if="Option::is_none")] message_id: Option, /// Required if chat_id and message_id are not specified. Identifier of the /// inline message + #[serde(skip_serializing_if="Option::is_none")] inline_message_id: Option, /// A JSON-serialized object InlineKeyboardMarkup for a new inline /// keyboard. + #[serde(skip_serializing_if="Option::is_none")] reply_markup: Option, } From b831cd3f1cd099dfdef5001740b95a5ad7320273 Mon Sep 17 00:00:00 2001 From: Mishko torop'izhko Date: Thu, 12 Sep 2019 18:29:15 +0300 Subject: [PATCH 3/9] Update src/core/requests/mod.rs Co-Authored-By: Waffle Lapkin --- src/core/requests/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/requests/mod.rs b/src/core/requests/mod.rs index c951f54c..a9b4cd61 100644 --- a/src/core/requests/mod.rs +++ b/src/core/requests/mod.rs @@ -96,4 +96,4 @@ pub mod send_media_group; pub mod send_audio; pub mod send_location; pub mod edit_message_live_location; -pub mod stop_message_live_location; \ No newline at end of file +pub mod stop_message_live_location; From f37e41361ffda974492a68d9b18c8fa73de4a1b5 Mon Sep 17 00:00:00 2001 From: Mishko torop'izhko Date: Thu, 12 Sep 2019 18:29:37 +0300 Subject: [PATCH 4/9] Update src/core/requests/stop_message_live_location.rs Co-Authored-By: Waffle Lapkin --- src/core/requests/stop_message_live_location.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/requests/stop_message_live_location.rs b/src/core/requests/stop_message_live_location.rs index 9c92e4f0..fb3b209c 100644 --- a/src/core/requests/stop_message_live_location.rs +++ b/src/core/requests/stop_message_live_location.rs @@ -45,7 +45,7 @@ impl<'a> Request<'a> for StopMessageLiveLocation<'a> { "stopMessageLiveLocation", &self, ) - .await + .await }) } } @@ -91,4 +91,4 @@ impl<'a> StopMessageLiveLocation<'a> { self.inline_message_id = Some(reply_markup.into()); self } -} \ No newline at end of file +} From 33dd80d49d59df5d1c7cc0edff1c8dbd0f6abf3d Mon Sep 17 00:00:00 2001 From: Mishko torop'izhko Date: Thu, 12 Sep 2019 18:30:59 +0300 Subject: [PATCH 5/9] Update src/core/requests/stop_message_live_location.rs Co-Authored-By: Waffle Lapkin --- src/core/requests/stop_message_live_location.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/requests/stop_message_live_location.rs b/src/core/requests/stop_message_live_location.rs index fb3b209c..c45c4080 100644 --- a/src/core/requests/stop_message_live_location.rs +++ b/src/core/requests/stop_message_live_location.rs @@ -65,7 +65,7 @@ impl<'a> StopMessageLiveLocation<'a> { } pub fn chat_id(mut self, chat_id: T) -> Self - where T: Into + where T: Into { self.chat_id = chat_id.into(); self From 8bc6d7b13f03a4b27dfd5b094b8feb74cc210c96 Mon Sep 17 00:00:00 2001 From: Mishko torop'izhko Date: Thu, 12 Sep 2019 18:31:11 +0300 Subject: [PATCH 6/9] Update src/core/requests/stop_message_live_location.rs Co-Authored-By: Waffle Lapkin --- src/core/requests/stop_message_live_location.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/requests/stop_message_live_location.rs b/src/core/requests/stop_message_live_location.rs index c45c4080..20220c88 100644 --- a/src/core/requests/stop_message_live_location.rs +++ b/src/core/requests/stop_message_live_location.rs @@ -86,7 +86,7 @@ impl<'a> StopMessageLiveLocation<'a> { } pub fn reply_markup(mut self, reply_markup: T) -> Self - where T: Into + where T: Into { self.inline_message_id = Some(reply_markup.into()); self From 3df77cc356a8ecb876ba6c62ec1fa73a7dc7f632 Mon Sep 17 00:00:00 2001 From: Mishko torop'izhko Date: Thu, 12 Sep 2019 18:31:35 +0300 Subject: [PATCH 7/9] Update src/core/requests/stop_message_live_location.rs Co-Authored-By: Waffle Lapkin --- src/core/requests/stop_message_live_location.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/requests/stop_message_live_location.rs b/src/core/requests/stop_message_live_location.rs index 20220c88..01643f59 100644 --- a/src/core/requests/stop_message_live_location.rs +++ b/src/core/requests/stop_message_live_location.rs @@ -72,7 +72,7 @@ impl<'a> StopMessageLiveLocation<'a> { } pub fn message_id(mut self, message_id: T) -> Self - where T: Into + where T: Into { self.message_id = Some(message_id.into()); self From 5b8166a9d8c59b3e0f9e2278455bce1868a3ee0b Mon Sep 17 00:00:00 2001 From: Mishko torop'izhko Date: Thu, 12 Sep 2019 18:31:53 +0300 Subject: [PATCH 8/9] Update src/core/requests/stop_message_live_location.rs Co-Authored-By: Waffle Lapkin --- src/core/requests/stop_message_live_location.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/requests/stop_message_live_location.rs b/src/core/requests/stop_message_live_location.rs index 01643f59..05760227 100644 --- a/src/core/requests/stop_message_live_location.rs +++ b/src/core/requests/stop_message_live_location.rs @@ -79,7 +79,7 @@ impl<'a> StopMessageLiveLocation<'a> { } pub fn inline_message_id(mut self, inline_message_id: T) -> Self - where T: Into + where T: Into { self.inline_message_id = Some(inline_message_id.into()); self From 40321467dd4579187efff027249d90169790a30f Mon Sep 17 00:00:00 2001 From: nextel Date: Thu, 12 Sep 2019 18:33:35 +0300 Subject: [PATCH 9/9] fix review mistakes --- src/core/requests/stop_message_live_location.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/core/requests/stop_message_live_location.rs b/src/core/requests/stop_message_live_location.rs index 05760227..ee6777a6 100644 --- a/src/core/requests/stop_message_live_location.rs +++ b/src/core/requests/stop_message_live_location.rs @@ -19,19 +19,19 @@ struct StopMessageLiveLocation<'a> { /// the target chat or username of the target channel (in the format /// @channelusername) #[serde(skip_serializing_if="Option::is_none")] - chat_id: Option, + pub chat_id: Option, /// Required if inline_message_id is not specified. Identifier of the /// message with live location to stop #[serde(skip_serializing_if="Option::is_none")] - message_id: Option, + pub message_id: Option, /// Required if chat_id and message_id are not specified. Identifier of the /// inline message #[serde(skip_serializing_if="Option::is_none")] - inline_message_id: Option, + pub inline_message_id: Option, /// A JSON-serialized object InlineKeyboardMarkup for a new inline /// keyboard. #[serde(skip_serializing_if="Option::is_none")] - reply_markup: Option, + pub reply_markup: Option, } impl<'a> Request<'a> for StopMessageLiveLocation<'a> { @@ -53,7 +53,6 @@ impl<'a> Request<'a> for StopMessageLiveLocation<'a> { impl<'a> StopMessageLiveLocation<'a> { fn new( ctx: RequestContext<'a>, - chat_id: ChatId, ) -> Self { Self { ctx,