mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-24 23:57:38 +01:00
Merge pull request #31 from Mr-Andersen/dev
+request/PinChatMessage, +type/EncryptedPassportElement
This commit is contained in:
commit
bc5b43d68b
6 changed files with 112 additions and 131 deletions
|
@ -14,7 +14,8 @@ pub use self::{
|
||||||
forward_message::ForwardMessage, get_chat::GetChat, get_file::GetFile,
|
forward_message::ForwardMessage, get_chat::GetChat, get_file::GetFile,
|
||||||
get_me::GetMe, get_updates::GetUpdates,
|
get_me::GetMe, get_updates::GetUpdates,
|
||||||
get_user_profile_photos::GetUserProfilePhotos,
|
get_user_profile_photos::GetUserProfilePhotos,
|
||||||
kick_chat_member::KickChatMember, restrict_chat_member::RestrictChatMember,
|
kick_chat_member::KickChatMember, pin_chat_message::PinChatMessage,
|
||||||
|
restrict_chat_member::RestrictChatMember,
|
||||||
send_audio::SendAudio, send_chat_action::SendChatAction,
|
send_audio::SendAudio, send_chat_action::SendChatAction,
|
||||||
send_contact::SendContact, send_location::SendLocation,
|
send_contact::SendContact, send_location::SendLocation,
|
||||||
send_media_group::SendMediaGroup, send_message::SendMessage,
|
send_media_group::SendMediaGroup, send_message::SendMessage,
|
||||||
|
@ -89,6 +90,7 @@ mod get_me;
|
||||||
mod get_updates;
|
mod get_updates;
|
||||||
mod get_user_profile_photos;
|
mod get_user_profile_photos;
|
||||||
mod kick_chat_member;
|
mod kick_chat_member;
|
||||||
|
mod pin_chat_message;
|
||||||
mod restrict_chat_member;
|
mod restrict_chat_member;
|
||||||
mod send_audio;
|
mod send_audio;
|
||||||
mod send_chat_action;
|
mod send_chat_action;
|
||||||
|
|
47
src/requests/pin_chat_message.rs
Normal file
47
src/requests/pin_chat_message.rs
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
use crate::requests::{ChatId, RequestContext, RequestFuture, ResponseResult, Request};
|
||||||
|
use crate::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 PinChatMessage<'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)
|
||||||
|
pub chat_id: ChatId,
|
||||||
|
pub message_id: i32,
|
||||||
|
pub disable_notification: Option<bool>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> PinChatMessage<'a> {
|
||||||
|
pub(crate) fn new(
|
||||||
|
ctx: RequestContext<'a>, chat_id: ChatId, message_id: i32
|
||||||
|
) -> Self {
|
||||||
|
Self { ctx, chat_id, message_id, disable_notification: None }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn disable_notification<T>(mut self, val: T) -> Self
|
||||||
|
where T: Into<bool>
|
||||||
|
{
|
||||||
|
self.disable_notification = Some(val.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Request<'a> for PinChatMessage<'a> {
|
||||||
|
type ReturnValue = bool; // TODO: change to unit type True
|
||||||
|
|
||||||
|
fn send(self) -> RequestFuture<'a, ResponseResult<Self::ReturnValue>> {
|
||||||
|
Box::pin(async move {
|
||||||
|
network::request_json(
|
||||||
|
&self.ctx.client,
|
||||||
|
&self.ctx.token,
|
||||||
|
"pinChatMessage",
|
||||||
|
&self,
|
||||||
|
).await
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,75 +1,67 @@
|
||||||
use super::passport_file::PassportFile;
|
use super::passport_file::PassportFile;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||||
pub struct EncryptedPassportElement {
|
pub struct EncryptedPassportElement {
|
||||||
#[serde(rename = "type")]
|
pub hash: String,
|
||||||
pub element_type: ElementType,
|
#[serde(flatten)]
|
||||||
pub data: String,
|
pub kind: EncryptedPassportElementKind
|
||||||
pub phone_number: String,
|
|
||||||
pub email: String,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub files: Option<Vec<PassportFile>>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub front_size: Option<PassportFile>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub reverse_side: Option<PassportFile>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub selfie: Option<PassportFile>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub translation: Option<Vec<PassportFile>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum ElementType {
|
pub enum EncryptedPassportElementKind {
|
||||||
PersonalData,
|
PersonalDetails {
|
||||||
Passport,
|
data: String
|
||||||
DriverLicense,
|
},
|
||||||
IdentityCard,
|
Passport {
|
||||||
Address,
|
data: String,
|
||||||
UtilityBill,
|
front_side: PassportFile,
|
||||||
BankStatement,
|
selfie: PassportFile,
|
||||||
RentalAgreement,
|
translation: Option<Vec<PassportFile>>
|
||||||
PassportRegistration,
|
},
|
||||||
TemporaryRegistration,
|
DriverLicense {
|
||||||
PhoneNumber,
|
data: String,
|
||||||
Email,
|
front_side: PassportFile,
|
||||||
}
|
reverse_side: PassportFile,
|
||||||
|
selfie: PassportFile,
|
||||||
#[cfg(test)]
|
translation: Option<Vec<PassportFile>>
|
||||||
mod tests {
|
},
|
||||||
use super::super::{ElementType, EncryptedPassportElement, PassportFile};
|
IdentityCard {
|
||||||
#[test]
|
data: String,
|
||||||
fn must_serialize_encrypted_passport_element_to_json() {
|
front_side: PassportFile,
|
||||||
// given
|
reverse_side: PassportFile,
|
||||||
let expected_json = r#"
|
selfie: PassportFile,
|
||||||
{
|
translation: Option<Vec<PassportFile>>
|
||||||
"type":"passport_registration",
|
},
|
||||||
"data":"somedata",
|
InternalPassport {
|
||||||
"phone_number":"1313",
|
data: String,
|
||||||
"email":"someemail",
|
front_side: PassportFile,
|
||||||
"front_size":{"file_id":"someId","file_size":13,"file_date":13}
|
selfie: PassportFile,
|
||||||
}"#
|
translation: Option<Vec<PassportFile>>
|
||||||
.replace("\n", "")
|
},
|
||||||
.replace(" ", "");
|
Address {
|
||||||
|
data: String
|
||||||
let passport_element = EncryptedPassportElement {
|
},
|
||||||
element_type: ElementType::PassportRegistration,
|
UtilityBill {
|
||||||
data: "somedata".to_string(),
|
files: Vec<PassportFile>,
|
||||||
phone_number: "1313".to_string(),
|
translation: Option<Vec<PassportFile>>
|
||||||
email: "someemail".to_string(),
|
},
|
||||||
files: None,
|
BankStatement {
|
||||||
front_size: Some(PassportFile {
|
files: Vec<PassportFile>,
|
||||||
file_id: "someId".to_string(),
|
translation: Option<Vec<PassportFile>>
|
||||||
file_size: 13,
|
},
|
||||||
file_date: 13,
|
RentalAgreement {
|
||||||
}),
|
files: Vec<PassportFile>,
|
||||||
reverse_side: None,
|
translation: Option<Vec<PassportFile>>
|
||||||
selfie: None,
|
},
|
||||||
translation: None,
|
PassportRegistration {
|
||||||
};
|
files: Vec<PassportFile>,
|
||||||
|
translation: Option<Vec<PassportFile>>
|
||||||
let actual_json = serde_json::to_string(&passport_element).unwrap();
|
},
|
||||||
assert_eq!(actual_json, expected_json)
|
TemporaryRegistration {
|
||||||
}
|
files: Vec<PassportFile>,
|
||||||
|
translation: Option<Vec<PassportFile>>
|
||||||
|
},
|
||||||
|
PhoneNumber { phone_number: String },
|
||||||
|
Email { email: String }
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub struct Message {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Message {
|
impl Message {
|
||||||
fn text(&self) -> Option<&str> {
|
pub fn text(&self) -> Option<&str> {
|
||||||
if let MessageKind::Common {
|
if let MessageKind::Common {
|
||||||
media_kind: MediaKind::Text { ref text, .. },
|
media_kind: MediaKind::Text { ref text, .. },
|
||||||
..
|
..
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub use self::{
|
||||||
contact::Contact,
|
contact::Contact,
|
||||||
document::Document,
|
document::Document,
|
||||||
encrypted_credintials::EncryptedCredentials,
|
encrypted_credintials::EncryptedCredentials,
|
||||||
encrypted_passport_element::{ElementType, EncryptedPassportElement},
|
encrypted_passport_element::{EncryptedPassportElement, EncryptedPassportElementKind},
|
||||||
file::File,
|
file::File,
|
||||||
force_reply::ForceReply,
|
force_reply::ForceReply,
|
||||||
game::Game,
|
game::Game,
|
||||||
|
|
|
@ -6,63 +6,3 @@ pub struct PassportData {
|
||||||
pub data: Vec<EncryptedPassportElement>,
|
pub data: Vec<EncryptedPassportElement>,
|
||||||
pub credentials: EncryptedCredentials,
|
pub credentials: EncryptedCredentials,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::super::{ElementType, PassportFile};
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn must_serialize_passport_data_to_json() {
|
|
||||||
let expected_json = r#"{
|
|
||||||
"data":
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"type":"passport_registration",
|
|
||||||
"data":"somedata",
|
|
||||||
"phone_number":"1313",
|
|
||||||
"email":"someemail",
|
|
||||||
"front_size":
|
|
||||||
{
|
|
||||||
"file_id":"someId",
|
|
||||||
"file_size":13,
|
|
||||||
"file_date":13
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"credentials":
|
|
||||||
{
|
|
||||||
"data":"someData",
|
|
||||||
"hash":"1122",
|
|
||||||
"secret":"secret"
|
|
||||||
}
|
|
||||||
}"#
|
|
||||||
.replace("\n", "")
|
|
||||||
.replace(" ", "");
|
|
||||||
let passport_data = PassportData {
|
|
||||||
data: vec![EncryptedPassportElement {
|
|
||||||
element_type: ElementType::PassportRegistration,
|
|
||||||
data: "somedata".to_string(),
|
|
||||||
phone_number: "1313".to_string(),
|
|
||||||
email: "someemail".to_string(),
|
|
||||||
files: None,
|
|
||||||
front_size: Some(PassportFile {
|
|
||||||
file_id: "someId".to_string(),
|
|
||||||
file_size: 13,
|
|
||||||
file_date: 13,
|
|
||||||
}),
|
|
||||||
reverse_side: None,
|
|
||||||
selfie: None,
|
|
||||||
translation: None,
|
|
||||||
}],
|
|
||||||
credentials: EncryptedCredentials {
|
|
||||||
data: "someData".to_string(),
|
|
||||||
hash: "1122".to_string(),
|
|
||||||
secret: "secret".to_string(),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
let actual_json = serde_json::to_string(&passport_data).unwrap();
|
|
||||||
assert_eq!(actual_json, expected_json)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue