From 3b6b147b69d9628518f5942e91d0c62affb36434 Mon Sep 17 00:00:00 2001 From: RustemB Date: Thu, 19 Sep 2019 00:22:58 +0500 Subject: [PATCH] getChat --- src/core/requests/get_chat.rs | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/core/requests/get_chat.rs diff --git a/src/core/requests/get_chat.rs b/src/core/requests/get_chat.rs new file mode 100644 index 00000000..eecf2711 --- /dev/null +++ b/src/core/requests/get_chat.rs @@ -0,0 +1,43 @@ +use crate::core::requests::{ChatId, RequestContext, RequestFuture, ResponseResult, Request}; +use crate::core::types::Chat; +use crate::core::network; + +/// Use this method to get up to date information about the chat +/// (current name of the user for one-on-one conversations, +/// current username of a user, group or channel, etc.). +/// Returns a Chat object on success. +#[derive(Debug, Clone, Serialize)] +pub struct GetChat<'a> { + #[serde(skip_serializing)] + ctx: RequestContext<'a>, + /// Unique identifier for the target chat or username + /// of the target supergroup or channel (in the format @channelusername) + chat_id: ChatId, +} + + +impl<'a> Request<'a> for GetChat<'a> { + type ReturnValue = Chat; + + fn send(self) -> RequestFuture<'a, ResponseResult> { + Box::pin(async move { + network::request_json( + &self.ctx.client, + &self.ctx.token, + "getChat", + &self, + ).await + }) + } +} + + +impl<'a> GetChat<'a>{ + pub fn chat_id(mut self, chat_id: T) -> Self + where + T: Into, + { + self.chat_id = chat_id.into(); + self + } +}