Merge branch 'master' into input_file_refactor

This commit is contained in:
Hirrolot 2022-01-30 20:14:30 +06:00 committed by GitHub
commit bd4218c238
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 65 additions and 22 deletions

View file

@ -18,7 +18,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2021-12-19
toolchain: nightly-2022-01-17
override: true
components: rustfmt
@ -75,7 +75,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2021-12-19
toolchain: nightly-2022-01-17
override: true
components: clippy

View file

@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support for 5.4 telegram bot API ([#133][pr133])
- Support for 5.5 telegram bot API ([#143][pr143], [#164][pr164])
- `EditedMessageIsTooLong` error ([#109][pr109])
- `UntilDate` enum and use it for `{Restricted, Banned}::until_date` ([#116][pr116])
- `UntilDate` enum and use it for `{Restricted, Banned}::until_date` ([#117][pr117])
- `Limits::messages_per_min_channel` ([#121][pr121])
- `media_group_id` field to `MediaDocument` and `MediaAudio` ([#139][pr139])
- `caption_entities` method to `InputMediaPhoto` ([#140][pr140])
@ -22,7 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `UpdateKind::Error` ([#156][pr156])
[pr109]: https://github.com/teloxide/teloxide-core/pull/109
[pr116]: https://github.com/teloxide/teloxide-core/pull/116
[pr117]: https://github.com/teloxide/teloxide-core/pull/117
[pr121]: https://github.com/teloxide/teloxide-core/pull/121
[pr135]: https://github.com/teloxide/teloxide-core/pull/135
[pr139]: https://github.com/teloxide/teloxide-core/pull/139
@ -51,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- How forwarded messages are represented ([#151][pr151])
- `RequestError::InvalidJson` now has a `raw` field with raw json for easier debugability ([#150][pr150])
- `ChatPermissions` is now bitflags ([#157][pr157])
- Type of `WebhookInfo::ip_address` from `String` to `std::net::IpAddr` ([#172][pr172])
[pr115]: https://github.com/teloxide/teloxide-core/pull/115
[pr125]: https://github.com/teloxide/teloxide-core/pull/125
@ -58,15 +59,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[pr150]: https://github.com/teloxide/teloxide-core/pull/150
[pr157]: https://github.com/teloxide/teloxide-core/pull/157
[pr167]: https://github.com/teloxide/teloxide-core/pull/167
[pr172]: https://github.com/teloxide/teloxide-core/pull/172
### Fixed
- Deserialization of chat migrations, see issue [#427][issue427] ([#143][pr143])
- Type of `BanChatMember::until_date`: `u64` -> `chrono::DateTime<Utc>` ([#116][pr116])
- Type of `BanChatMember::until_date`: `u64` -> `chrono::DateTime<Utc>` ([#117][pr117])
- Type of `Poll::correct_option_id`: `i32` -> `u8` ([#119][pr119])
- Type of `Poll::open_period`: `i32` -> `u16` ([#119][pr119])
- `Throttle` adaptor not honouring chat/min limits ([#121][pr121])
- Make `SendPoll::poll_` optional ([#133][pr133])
- Make `SendPoll::type_` optional ([#133][pr133])
- Bug with `caption_entities`, see issue [#473][issue473]
- Type of response for `CopyMessage` method ([#141](pr141), [#142](pr142))
- Bad request serialization when the `language` field of `MessageEntityKind::Pre` is `None` ([#145](pr145))

View file

@ -1,4 +1,4 @@
[toolchain]
channel = "nightly-2021-12-19"
channel = "nightly-2022-01-17"
components = ["rustfmt", "clippy"]
profile = "minimal"

View file

@ -55,12 +55,12 @@ pub fn client_from_env() -> reqwest::Client {
/// durations, see the [issue 223].
///
/// The current settings are:
/// - The `connection/keep-alive` default header.
/// - A connection timeout of 5 seconds.
/// - A timeout of 17 seconds.
/// - `tcp_nodelay` is on.
///
/// ## Notes
///
/// 1. The settings may change in the future.
/// 2. If you are using the polling mechanism to get updates, the timeout
/// configured in the client should be bigger than the polling timeout.
@ -69,19 +69,10 @@ pub fn client_from_env() -> reqwest::Client {
///
/// [issue 223]: https://github.com/teloxide/teloxide/issues/223
pub fn default_reqwest_settings() -> reqwest::ClientBuilder {
use reqwest::header::{HeaderMap, CONNECTION};
let mut headers = HeaderMap::new();
headers.insert(CONNECTION, "keep-alive".parse().unwrap());
let connect_timeout = Duration::from_secs(5);
let timeout = connect_timeout + Duration::from_secs(12);
reqwest::Client::builder()
.connect_timeout(connect_timeout)
.timeout(timeout)
.connect_timeout(Duration::from_secs(5))
.timeout(Duration::from_secs(17))
.tcp_nodelay(true)
.default_headers(headers)
}
/// Creates URL for making HTTPS requests. See the [Telegram documentation].

View file

@ -292,3 +292,50 @@ pub(crate) mod serde_date_from_unix_timestamp {
))
}
}
pub(crate) mod option_url_from_string {
use reqwest::Url;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
pub(crate) fn serialize<S>(this: &Option<Url>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match this {
Some(url) => url.serialize(serializer),
None => "".serialize(serializer),
}
}
pub(crate) fn deserialize<'de, D>(deserializer: D) -> Result<Option<Url>, D::Error>
where
D: Deserializer<'de>,
{
Ok(reqwest::Url::deserialize(deserializer).ok())
}
#[test]
fn test() {
use std::str::FromStr;
#[derive(Serialize, Deserialize)]
struct Struct {
#[serde(with = "crate::types::option_url_from_string")]
url: Option<Url>,
}
{
let json = r#"{"url":""}"#;
let url: Struct = serde_json::from_str(json).unwrap();
assert_eq!(url.url, None);
assert_eq!(serde_json::to_string(&url).unwrap(), json.to_owned());
let json = r#"{"url":"https://github.com/token"}"#;
let url: Struct = serde_json::from_str(json).unwrap();
assert_eq!(
url.url,
Some(Url::from_str("https://github.com/token").unwrap())
);
assert_eq!(serde_json::to_string(&url).unwrap(), json.to_owned());
}
}
}

View file

@ -104,7 +104,7 @@ impl InlineQueryResultArticle {
self
}
pub fn thumb_url<S>(mut self, val: reqwest::Url) -> Self {
pub fn thumb_url(mut self, val: reqwest::Url) -> Self {
self.thumb_url = Some(val);
self
}

View file

@ -137,7 +137,7 @@ impl InlineQueryResultLocation {
self
}
pub fn thumb_url<S>(mut self, val: reqwest::Url) -> Self {
pub fn thumb_url(mut self, val: reqwest::Url) -> Self {
self.thumb_url = Some(val);
self
}

View file

@ -1,3 +1,5 @@
use std::net::IpAddr;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
@ -8,6 +10,7 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct WebhookInfo {
/// Webhook URL, `None` if webhook is not set up.
#[serde(with = "crate::types::option_url_from_string")]
pub url: Option<reqwest::Url>,
/// `true`, if a custom certificate was provided for webhook certificate
@ -18,7 +21,7 @@ pub struct WebhookInfo {
pub pending_update_count: u32,
/// Currently used webhook IP address.
pub ip_address: Option<String>,
pub ip_address: Option<IpAddr>,
/// Time of the most recent error that happened when trying to
/// deliver an update via webhook.