From 5099403fa6573e91f54eacb38cb0a48a453cd68b Mon Sep 17 00:00:00 2001 From: P0lunin Date: Wed, 11 Sep 2019 18:05:36 +0300 Subject: [PATCH] add method editMessageLiveLocation --- .../requests/edit_message_live_location.rs | 96 +++++++++++++++++++ src/core/requests/mod.rs | 1 + 2 files changed, 97 insertions(+) create mode 100644 src/core/requests/edit_message_live_location.rs diff --git a/src/core/requests/edit_message_live_location.rs b/src/core/requests/edit_message_live_location.rs new file mode 100644 index 00000000..a6208aee --- /dev/null +++ b/src/core/requests/edit_message_live_location.rs @@ -0,0 +1,96 @@ +use serde::Serialize; +use crate::core::requests::{RequestContext, ChatId, Request, RequestFuture, ResponseResult}; +use crate::core::types::Message; +use crate::core::network; + +#[derive(Debug, Clone, Serialize)] +/// Use this method to edit live location messages. A location can be edited +/// until its live_period expires or editing is explicitly disabled by a +/// call to [`stopMessageLiveLocation`]. On success, if the edited message +/// was sent by the bot, the edited [`Message`] is returned, otherwise True +/// is returned. +pub struct EditMessageLiveLocation<'a> { + #[serde(skip_serializing)] + ctx: RequestContext<'a>, + + #[serde(skip_serializing_if="Option::is_none")] + /// 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, + #[serde(skip_serializing_if="Option::is_none")] + /// Required if inline_message_id is not specified. Identifier of the + /// message to edit + message_id: Option, + #[serde(skip_serializing_if="Option::is_none")] + /// Required if chat_id and message_id are not specified. Identifier of + /// the inline message + inline_message_id: Option, + /// Latitude of new location + latitude: f64, + /// Longitude of new location + longitude: f64, + #[serde(skip_serializing_if="Option::is_none")] + /// A JSON-serialized object for a new inline keyboard. + reply_markup: Option<()> // TODO: add reply_markup +} + +impl<'a> Request<'a> for EditMessageLiveLocation<'a> { + type ReturnValue = Message; + + fn send(self) -> RequestFuture<'a, ResponseResult> { + Box::pin(async move { + network::request_json( + &self.ctx.client, + &self.ctx.token, + "editMessageLiveLocation", + &self + ).await + }) + } +} + +impl<'a> EditMessageLiveLocation<'a> { + pub(crate) fn new ( + ctx: RequestContext<'a>, + latitude: f64, + longitude: f64, + ) -> Self { + Self { + ctx, + chat_id: None, + message_id: None, + inline_message_id: None, + latitude, + longitude, + reply_markup: None + } + } + + pub fn chat_id>(mut self, chat_id: T) -> Self { + self.chat_id = Some(chat_id.into()); + self + } + + pub fn message_id>(mut self, message_id: T) -> Self { + 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 latitude>(mut self, latitude: T) -> Self { + self.latitude = latitude.into(); + self + } + + pub fn longitude>(mut self, longitude: T) -> Self { + self.longitude = longitude.into(); + self + } +} diff --git a/src/core/requests/mod.rs b/src/core/requests/mod.rs index f35ccd25..1876db11 100644 --- a/src/core/requests/mod.rs +++ b/src/core/requests/mod.rs @@ -95,3 +95,4 @@ pub mod send_photo; pub mod send_media_group; pub mod send_audio; pub mod send_location; +pub mod edit_message_live_location;