Merge pull request #58 from teloxide/fault_tolerant_get_updates

fault tolerant get updates
This commit is contained in:
Temirkhan Myrzamadi 2021-03-06 13:55:27 +03:00 committed by GitHub
commit c9c1120962
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 71 additions and 9 deletions

View file

@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [unreleased]
### Added
- `GetUpdatesFaultTolerant` - fault toletant version of `GetUpdates` ([#58][pr58]) (**BC**)
- Derive `Clone` for `AutoSend`.
[pr58]: https://github.com/teloxide/teloxide-core/pull/58
### Fixed
- `set_webhook` signature (make `allowed_updates` optional) ([#59][pr59])
@ -19,6 +26,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[pr57]: https://github.com/teloxide/teloxide-core/pull/57
[pr59]: https://github.com/teloxide/teloxide-core/pull/59
### Changed
- `NonStrictVec` -> `SemiparsedVec`.
## [0.1.1] - 2020-02-17
### Fixed

View file

@ -37,6 +37,7 @@ use crate::{
/// let myself: Me = bot.get_me().await?; // No .send()!
/// # Ok::<_, teloxide_core::RequestError>(()) };
/// ```
#[derive(Clone)]
pub struct AutoSend<B> {
bot: B,
}
@ -101,7 +102,8 @@ where
add_sticker_to_set, set_sticker_position_in_set, delete_sticker_from_set,
set_sticker_set_thumb, send_invoice, answer_shipping_query,
answer_pre_checkout_query, set_passport_data_errors, send_game,
set_game_score, set_game_score_inline, get_game_high_scores => f, fty
set_game_score, set_game_score_inline, get_game_high_scores,
get_updates_fault_tolerant => f, fty
}
}

View file

@ -118,7 +118,7 @@ where
add_sticker_to_set, set_sticker_position_in_set, delete_sticker_from_set,
set_sticker_set_thumb, send_invoice, answer_shipping_query,
answer_pre_checkout_query, set_passport_data_errors, send_game,
set_game_score, set_game_score_inline, get_game_high_scores => f, fty
set_game_score, set_game_score_inline, get_game_high_scores, get_updates_fault_tolerant => f, fty
}
}

View file

@ -112,7 +112,7 @@ impl<B: Requester> Requester for DefaultParseMode<B> {
add_sticker_to_set, set_sticker_position_in_set, delete_sticker_from_set,
set_sticker_set_thumb, send_invoice, answer_shipping_query,
answer_pre_checkout_query, set_passport_data_errors, send_game, set_game_score,
set_game_score_inline, get_game_high_scores => fid, fty
set_game_score_inline, get_game_high_scores, get_updates_fault_tolerant => fid, fty
}
}

View file

@ -469,7 +469,7 @@ where
add_sticker_to_set, set_sticker_position_in_set, delete_sticker_from_set,
set_sticker_set_thumb, answer_shipping_query, answer_pre_checkout_query,
set_passport_data_errors, send_game, set_game_score, set_game_score_inline,
get_game_high_scores => fid, ftyid
get_game_high_scores, get_updates_fault_tolerant => fid, ftyid
}
}

View file

@ -966,4 +966,13 @@ impl Requester for Bot {
payloads::GetGameHighScores::new(user_id, target),
)
}
type GetUpdatesFaultTolerant = JsonRequest<payloads::GetUpdatesFaultTolerant>;
fn get_updates_fault_tolerant(&self) -> Self::GetUpdatesFaultTolerant {
Self::GetUpdatesFaultTolerant::new(
self.clone(),
payloads::GetUpdatesFaultTolerant(payloads::GetUpdates::new()),
)
}
}

View file

@ -1043,6 +1043,14 @@ macro_rules! requester_forward {
$body!(get_game_high_scores this (user_id: u32, target: T))
}
};
(@method get_updates_fault_tolerant $body:ident $ty:ident) => {
type GetUpdatesFaultTolerant = $ty![GetUpdatesFaultTolerant];
fn get_updates_fault_tolerant(&self) -> Self::GetUpdatesFaultTolerant {
let this = self;
$body!(get_updates_fault_tolerant this ())
}
};
}
#[macro_use]

View file

@ -178,3 +178,9 @@ pub use stop_poll::{StopPoll, StopPollSetters};
pub use unban_chat_member::{UnbanChatMember, UnbanChatMemberSetters};
pub use unpin_chat_message::{UnpinChatMessage, UnpinChatMessageSetters};
pub use upload_sticker_file::{UploadStickerFile, UploadStickerFileSetters};
// end of auto generated block
mod get_updates_fault_tolerant;
pub use get_updates_fault_tolerant::GetUpdatesFaultTolerant;

View file

@ -0,0 +1,18 @@
use serde::Serialize;
use crate::{
payloads::GetUpdates,
requests::Payload,
types::{SemiparsedVec, Update},
};
/// The fault tolerant version of [`GetUpdates`].
#[derive(Debug, PartialEq, Eq, Hash, Default, Clone, Serialize)]
#[serde(transparent)]
pub struct GetUpdatesFaultTolerant(pub GetUpdates);
impl Payload for GetUpdatesFaultTolerant {
type Output = SemiparsedVec<Update>;
const NAME: &'static str = GetUpdates::NAME;
}

View file

@ -747,6 +747,11 @@ pub trait Requester {
fn get_game_high_scores<T>(&self, user_id: u32, target: T) -> Self::GetGameHighScores
where
T: Into<TargetMessage>;
type GetUpdatesFaultTolerant: Request<Payload = GetUpdatesFaultTolerant, Err = Self::Err>;
/// For Telegram documentation see [`GetUpdatesFaultTolerant`].
fn get_updates_fault_tolerant(&self) -> Self::GetUpdatesFaultTolerant;
}
macro_rules! fty {
@ -784,7 +789,8 @@ macro_rules! forward_all {
add_sticker_to_set, set_sticker_position_in_set, delete_sticker_from_set,
set_sticker_set_thumb, send_invoice, answer_shipping_query,
answer_pre_checkout_query, set_passport_data_errors, send_game,
set_game_score, set_game_score_inline, get_game_high_scores => fwd_deref, fty
set_game_score, set_game_score_inline, get_game_high_scores,
get_updates_fault_tolerant => fwd_deref, fty
}
};
}

View file

@ -1,14 +1,16 @@
use serde::de::DeserializeOwned;
use serde_json::{from_value, Value};
/// A vector of possibly unparsed JSON objects.
///
/// Similar to `Vec<T>` but if it fails to deserialize element, it just saves
/// `Err((value, err))`
/// `Err((serde_json::Value, serde_json::Error))`.
#[derive(Debug, serde::Deserialize)]
#[serde(from = "Vec<serde_json::Value>")]
#[serde(bound = "T: DeserializeOwned")]
pub struct NonStrictVec<T>(pub Vec<Result<T, (serde_json::Value, serde_json::Error)>>);
pub struct SemiparsedVec<T>(pub Vec<Result<T, (serde_json::Value, serde_json::Error)>>);
impl<T: DeserializeOwned> From<Vec<serde_json::Value>> for NonStrictVec<T> {
impl<T: DeserializeOwned> From<Vec<serde_json::Value>> for SemiparsedVec<T> {
fn from(vec: Vec<Value>) -> Self {
Self(
vec.into_iter()
@ -22,7 +24,7 @@ impl<T: DeserializeOwned> From<Vec<serde_json::Value>> for NonStrictVec<T> {
fn test() {
use crate::types::Update;
let x: NonStrictVec<Update> = serde_json::from_str(
let x: SemiparsedVec<Update> = serde_json::from_str(
r#"[{
"update_id": 923808447,
"message": {