mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-03 09:49:07 +01:00
+EncryptedPassportElement
This commit is contained in:
parent
4d13609d33
commit
fc68705d71
4 changed files with 77 additions and 72 deletions
|
@ -1,5 +1,5 @@
|
|||
use crate::core::requests::{ChatId, RequestContext, RequestFuture, ResponseResult, Request};
|
||||
use crate::core::network;
|
||||
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,
|
||||
|
@ -16,6 +16,19 @@ pub struct PinChatMessage<'a> {
|
|||
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> {
|
||||
type ReturnValue = bool;
|
||||
|
||||
|
|
|
@ -1,75 +1,67 @@
|
|||
use super::passport_file::PassportFile;
|
||||
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
pub struct EncryptedPassportElement {
|
||||
#[serde(rename = "type")]
|
||||
pub element_type: ElementType,
|
||||
pub data: String,
|
||||
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>>,
|
||||
pub hash: String,
|
||||
#[serde(flatten)]
|
||||
pub kind: EncryptedPassportElementKind
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ElementType {
|
||||
PersonalData,
|
||||
Passport,
|
||||
DriverLicense,
|
||||
IdentityCard,
|
||||
Address,
|
||||
UtilityBill,
|
||||
BankStatement,
|
||||
RentalAgreement,
|
||||
PassportRegistration,
|
||||
TemporaryRegistration,
|
||||
PhoneNumber,
|
||||
Email,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::{ElementType, EncryptedPassportElement, PassportFile};
|
||||
#[test]
|
||||
fn must_serialize_encrypted_passport_element_to_json() {
|
||||
// given
|
||||
let expected_json = r#"
|
||||
{
|
||||
"type":"passport_registration",
|
||||
"data":"somedata",
|
||||
"phone_number":"1313",
|
||||
"email":"someemail",
|
||||
"front_size":{"file_id":"someId","file_size":13,"file_date":13}
|
||||
}"#
|
||||
.replace("\n", "")
|
||||
.replace(" ", "");
|
||||
|
||||
let passport_element = 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,
|
||||
};
|
||||
|
||||
let actual_json = serde_json::to_string(&passport_element).unwrap();
|
||||
assert_eq!(actual_json, expected_json)
|
||||
}
|
||||
pub enum EncryptedPassportElementKind {
|
||||
PersonalDetails {
|
||||
data: String
|
||||
},
|
||||
Passport {
|
||||
data: String,
|
||||
front_side: PassportFile,
|
||||
selfie: PassportFile,
|
||||
translation: Vec<PassportFile>
|
||||
},
|
||||
DriverLicense {
|
||||
data: String,
|
||||
front_side: PassportFile,
|
||||
reverse_side: PassportFile,
|
||||
selfie: PassportFile,
|
||||
translation: Vec<PassportFile>
|
||||
},
|
||||
IdentityCard {
|
||||
data: String,
|
||||
front_side: PassportFile,
|
||||
reverse_side: PassportFile,
|
||||
selfie: PassportFile,
|
||||
translation: Vec<PassportFile>
|
||||
},
|
||||
InternalPassport {
|
||||
data: String,
|
||||
front_side: PassportFile,
|
||||
selfie: PassportFile,
|
||||
translation: Vec<PassportFile>
|
||||
},
|
||||
Address {
|
||||
data: String
|
||||
},
|
||||
UtilityBill {
|
||||
files: Vec<PassportFile>,
|
||||
translation: Vec<PassportFile>
|
||||
},
|
||||
BankStatement {
|
||||
files: Vec<PassportFile>,
|
||||
translation: Vec<PassportFile>
|
||||
},
|
||||
RentalAgreement {
|
||||
files: Vec<PassportFile>,
|
||||
translation: Vec<PassportFile>
|
||||
},
|
||||
PassportRegistration {
|
||||
files: Vec<PassportFile>,
|
||||
translation: Vec<PassportFile>
|
||||
},
|
||||
TemporaryRegistration {
|
||||
files: Vec<PassportFile>,
|
||||
translation: Vec<PassportFile>
|
||||
},
|
||||
PhoneNumber { phone_number: String },
|
||||
Email { email: String }
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ pub struct Message {
|
|||
}
|
||||
|
||||
impl Message {
|
||||
fn text(&self) -> Option<&str> {
|
||||
pub fn text(&self) -> Option<&str> {
|
||||
if let MessageKind::Common {
|
||||
media_kind: MediaKind::Text { ref text, .. },
|
||||
..
|
||||
|
|
|
@ -12,7 +12,7 @@ pub use self::{
|
|||
contact::Contact,
|
||||
document::Document,
|
||||
encrypted_credintials::EncryptedCredentials,
|
||||
encrypted_passport_element::{ElementType, EncryptedPassportElement},
|
||||
encrypted_passport_element::{EncryptedPassportElement, EncryptedPassportElementKind},
|
||||
file::File,
|
||||
force_reply::ForceReply,
|
||||
game::Game,
|
||||
|
|
Loading…
Reference in a new issue