Merge pull request #994 from Desiders/fix-audio-duration-type

Fix audio duration type
This commit is contained in:
Waffle Maybe 2024-01-16 18:05:08 +00:00 committed by GitHub
commit 83fc16d9f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 9 deletions

View file

@ -50,6 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Use `UserId` instead of `i64` for `user_id` in `html::user_mention` and `markdown::user_mention` ([PR 896](https://github.com/teloxide/teloxide/pull/896))
- Greatly improved the speed of graceful shutdown (`^C`) ([PR 938](https://github.com/teloxide/teloxide/pull/938))
- Fix typos in docstrings ([PR 953](https://github.com/teloxide/teloxide/pull/953))
- Use `Seconds` instead of `String` in `InlineQueryResultAudio` for `audio_duration` ([PR 994](https://github.com/teloxide/teloxide/pull/994))
### Changed

View file

@ -356,10 +356,10 @@ mod tests {
})),
caption_entities: None,
performer: Some(String::from("performer")),
audio_duration: Some("1".into()),
audio_duration: Some(Seconds::from_seconds(1)),
});
let expected_json = r#"{"type":"audio","id":"id","audio_url":"http://audio_url/","title":"title","caption":"caption","parse_mode":"HTML","performer":"performer","audio_duration":"1","reply_markup":{"inline_keyboard":[]},"input_message_content":{"message_text":"message_text","parse_mode":"MarkdownV2","disable_web_page_preview":true}}"#;
let expected_json = r#"{"type":"audio","id":"id","audio_url":"http://audio_url/","title":"title","caption":"caption","parse_mode":"HTML","performer":"performer","audio_duration":1,"reply_markup":{"inline_keyboard":[]},"input_message_content":{"message_text":"message_text","parse_mode":"MarkdownV2","disable_web_page_preview":true}}"#;
let actual_json = serde_json::to_string(&structure).unwrap();
assert_eq!(expected_json, actual_json);

View file

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use crate::types::{InlineKeyboardMarkup, InputMessageContent, MessageEntity, ParseMode};
use crate::types::{InlineKeyboardMarkup, InputMessageContent, MessageEntity, ParseMode, Seconds};
/// Represents a link to an MP3 audio file. By default, this audio file will be
/// sent by the user.
@ -40,7 +40,7 @@ pub struct InlineQueryResultAudio {
pub performer: Option<String>,
/// Audio duration in seconds.
pub audio_duration: Option<String>,
pub audio_duration: Option<Seconds>,
/// [Inline keyboard] attached to the message.
///
@ -123,11 +123,8 @@ impl InlineQueryResultAudio {
self
}
pub fn audio_duration<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.audio_duration = Some(val.into());
pub fn audio_duration(mut self, val: Seconds) -> Self {
self.audio_duration = Some(val);
self
}