+EncryptedPassportElement

This commit is contained in:
Mr-Andersen 2019-09-21 11:38:58 +03:00
parent 4d13609d33
commit fc68705d71
4 changed files with 77 additions and 72 deletions

View file

@ -1,5 +1,5 @@
use crate::core::requests::{ChatId, RequestContext, RequestFuture, ResponseResult, Request}; use crate::requests::{ChatId, RequestContext, RequestFuture, ResponseResult, Request};
use crate::core::network; use crate::network;
/// Use this method to get up to date information about the chat /// Use this method to get up to date information about the chat
/// (current name of the user for one-on-one conversations, /// (current name of the user for one-on-one conversations,
@ -16,6 +16,19 @@ pub struct PinChatMessage<'a> {
disable_notification: bool disable_notification: 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: false }
}
pub fn disable_notification(mut self) -> Self {
self.disable_notification = true;
self
}
}
impl<'a> Request<'a> for PinChatMessage<'a> { impl<'a> Request<'a> for PinChatMessage<'a> {
type ReturnValue = bool; type ReturnValue = bool;

View file

@ -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: Vec<PassportFile>
PassportRegistration, },
TemporaryRegistration, DriverLicense {
PhoneNumber, data: String,
Email, front_side: PassportFile,
} reverse_side: PassportFile,
selfie: PassportFile,
#[cfg(test)] translation: 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: 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: 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: Vec<PassportFile>
email: "someemail".to_string(), },
files: None, BankStatement {
front_size: Some(PassportFile { files: Vec<PassportFile>,
file_id: "someId".to_string(), translation: Vec<PassportFile>
file_size: 13, },
file_date: 13, RentalAgreement {
}), files: Vec<PassportFile>,
reverse_side: None, translation: Vec<PassportFile>
selfie: None, },
translation: None, PassportRegistration {
}; files: Vec<PassportFile>,
translation: Vec<PassportFile>
let actual_json = serde_json::to_string(&passport_element).unwrap(); },
assert_eq!(actual_json, expected_json) TemporaryRegistration {
} files: Vec<PassportFile>,
translation: Vec<PassportFile>
},
PhoneNumber { phone_number: String },
Email { email: String }
} }

View file

@ -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, .. },
.. ..

View file

@ -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,