mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
Fix #1135
This commit is contained in:
parent
c765d1f14c
commit
dc691f780b
5 changed files with 47 additions and 34 deletions
33
Cargo.lock
generated
33
Cargo.lock
generated
|
@ -2230,7 +2230,7 @@ dependencies = [
|
||||||
"serde_cbor",
|
"serde_cbor",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"sqlx",
|
"sqlx",
|
||||||
"teloxide-core 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"teloxide-core",
|
||||||
"teloxide-macros 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"teloxide-macros 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
@ -2277,37 +2277,6 @@ dependencies = [
|
||||||
"xshell",
|
"xshell",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "teloxide-core"
|
|
||||||
version = "0.10.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b4308e2880a535d8c30e494d548af1deb573e1fc06f2574fdd01b8fccf7c801a"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags 1.3.2",
|
|
||||||
"bytes",
|
|
||||||
"chrono",
|
|
||||||
"derive_more",
|
|
||||||
"either",
|
|
||||||
"futures",
|
|
||||||
"log",
|
|
||||||
"mime",
|
|
||||||
"once_cell",
|
|
||||||
"pin-project",
|
|
||||||
"rc-box",
|
|
||||||
"reqwest",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"serde_with",
|
|
||||||
"take_mut",
|
|
||||||
"takecell",
|
|
||||||
"thiserror",
|
|
||||||
"tokio",
|
|
||||||
"tokio-util",
|
|
||||||
"url",
|
|
||||||
"uuid",
|
|
||||||
"vecrem",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "teloxide-macros"
|
name = "teloxide-macros"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
|
|
|
@ -447,6 +447,45 @@ pub(crate) mod option_url_from_string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue https://github.com/teloxide/teloxide/issues/1135
|
||||||
|
// Workaround to avoid flattening with serde-multipart requests (involving
|
||||||
|
// file-manipulations)
|
||||||
|
pub(crate) mod msg_id_as_int {
|
||||||
|
use crate::types::MessageId;
|
||||||
|
|
||||||
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
|
pub(crate) fn serialize<S>(MessageId(id): &MessageId, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
id.serialize(serializer)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn deserialize<'de, D>(deserializer: D) -> Result<MessageId, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
i32::deserialize(deserializer).map(MessageId)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test() {
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
struct Struct {
|
||||||
|
#[serde(with = "crate::types::msg_id_as_int")]
|
||||||
|
message_id: MessageId,
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
let json = r#"{"message_id":123}"#;
|
||||||
|
let s: Struct = serde_json::from_str(json).unwrap();
|
||||||
|
assert_eq!(s.message_id, MessageId(123));
|
||||||
|
assert_eq!(serde_json::to_string(&s).unwrap(), json.to_owned());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) mod option_msg_id_as_int {
|
pub(crate) mod option_msg_id_as_int {
|
||||||
use crate::types::MessageId;
|
use crate::types::MessageId;
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,9 @@ pub struct MessageId(pub i32);
|
||||||
//
|
//
|
||||||
// (we can't change the default format of `MessageId` because it's returned
|
// (we can't change the default format of `MessageId` because it's returned
|
||||||
// by some methods and we can't change serialization there)
|
// by some methods and we can't change serialization there)
|
||||||
|
// If you flatten `MessageId` within serde-multipart request, it will fail, see https://github.com/teloxide/teloxide/issues/1135
|
||||||
|
// Try to use `serde(with = "crate::types::msg_id_as_int")]` instead of
|
||||||
|
// `#[serde(flatten)]`
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct MessageIdRaw {
|
struct MessageIdRaw {
|
||||||
|
|
|
@ -8,7 +8,8 @@ use crate::types::{MessageEntity, MessageId, Recipient};
|
||||||
pub struct ReplyParameters {
|
pub struct ReplyParameters {
|
||||||
/// Identifier of the message that will be replied to in the current chat,
|
/// Identifier of the message that will be replied to in the current chat,
|
||||||
/// or in the chat _chat\_id_ if it is specified
|
/// or in the chat _chat\_id_ if it is specified
|
||||||
#[serde(flatten)]
|
// Issue https://github.com/teloxide/teloxide/issues/1135
|
||||||
|
#[serde(with = "crate::types::msg_id_as_int")]
|
||||||
pub message_id: MessageId,
|
pub message_id: MessageId,
|
||||||
/// If the message to be replied to is from a different chat, unique
|
/// If the message to be replied to is from a different chat, unique
|
||||||
/// identifier for the chat or username of the channel (in the format
|
/// identifier for the chat or username of the channel (in the format
|
||||||
|
|
|
@ -77,7 +77,8 @@ full = [
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
teloxide-core = { version = "0.10", default-features = false }
|
# replace me by the actual version when release, and return path when it's time to make 0-day fixes
|
||||||
|
teloxide-core = { path = "../../crates/teloxide-core", default-features = false }
|
||||||
teloxide-macros = { version = "0.8", optional = true }
|
teloxide-macros = { version = "0.8", optional = true }
|
||||||
|
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
|
Loading…
Reference in a new issue