From e3e89a1691837a9f1e2a0dacd8250e2ca38fc35a Mon Sep 17 00:00:00 2001 From: fr0staman Date: Sun, 9 Jul 2023 15:00:04 +0300 Subject: [PATCH 1/3] Use `u64` instead of `i64` for `user_id` in `html::user_mention` and `markdown::user_mention` --- crates/teloxide/src/utils/html.rs | 2 +- crates/teloxide/src/utils/markdown.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/teloxide/src/utils/html.rs b/crates/teloxide/src/utils/html.rs index 70c4dabf..a321eda2 100644 --- a/crates/teloxide/src/utils/html.rs +++ b/crates/teloxide/src/utils/html.rs @@ -56,7 +56,7 @@ pub fn link(url: &str, text: &str) -> String { /// Builds an inline user mention link with an anchor. #[must_use = "This function returns a new string, rather than mutating the argument, so calling it \ without using its output does nothing useful"] -pub fn user_mention(user_id: i64, text: &str) -> String { +pub fn user_mention(user_id: u64, text: &str) -> String { link(format!("tg://user?id={user_id}").as_str(), text) } diff --git a/crates/teloxide/src/utils/markdown.rs b/crates/teloxide/src/utils/markdown.rs index f181536a..4be607c5 100644 --- a/crates/teloxide/src/utils/markdown.rs +++ b/crates/teloxide/src/utils/markdown.rs @@ -71,7 +71,7 @@ pub fn link(url: &str, text: &str) -> String { /// Builds an inline user mention link with an anchor. #[must_use = "This function returns a new string, rather than mutating the argument, so calling it \ without using its output does nothing useful"] -pub fn user_mention(user_id: i64, text: &str) -> String { +pub fn user_mention(user_id: u64, text: &str) -> String { link(format!("tg://user?id={user_id}").as_str(), text) } From 878ad80b63fdd43e1951b443773ecc06f6cf4ff9 Mon Sep 17 00:00:00 2001 From: fr0staman Date: Sun, 9 Jul 2023 15:11:56 +0300 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 801294ae..c35ac920 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## unreleased +### Fixed +- Use `u64` instead of `i64` for `user_id` in `html::user_mention` and `markdown::user_mention` ([PR 896](https://github.com/teloxide/teloxide/pull/896)) + ## 0.12.2 - 2023-02-15 ### Fixed From 1630830a7d755b872c4998d872cc3db807576e0d Mon Sep 17 00:00:00 2001 From: fr0staman Date: Sun, 9 Jul 2023 21:23:11 +0300 Subject: [PATCH 3/3] Use `UserId` instead of `u64` for `user_id` in `user_mention` --- CHANGELOG.md | 2 +- crates/teloxide/src/utils/html.rs | 6 +++--- crates/teloxide/src/utils/markdown.rs | 9 ++++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c35ac920..48e31dc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## unreleased ### Fixed -- Use `u64` instead of `i64` for `user_id` in `html::user_mention` and `markdown::user_mention` ([PR 896](https://github.com/teloxide/teloxide/pull/896)) +- 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)) ## 0.12.2 - 2023-02-15 diff --git a/crates/teloxide/src/utils/html.rs b/crates/teloxide/src/utils/html.rs index a321eda2..e003ab41 100644 --- a/crates/teloxide/src/utils/html.rs +++ b/crates/teloxide/src/utils/html.rs @@ -2,7 +2,7 @@ //! //! [spec]: https://core.telegram.org/bots/api#html-style -use teloxide_core::types::User; +use teloxide_core::types::{User, UserId}; /// Applies the bold font style to the string. /// @@ -56,7 +56,7 @@ pub fn link(url: &str, text: &str) -> String { /// Builds an inline user mention link with an anchor. #[must_use = "This function returns a new string, rather than mutating the argument, so calling it \ without using its output does nothing useful"] -pub fn user_mention(user_id: u64, text: &str) -> String { +pub fn user_mention(user_id: UserId, text: &str) -> String { link(format!("tg://user?id={user_id}").as_str(), text) } @@ -158,7 +158,7 @@ mod tests { #[test] fn test_user_mention() { assert_eq!( - user_mention(123_456_789, ""), + user_mention(UserId(123_456_789), ""), "<pwner666>", ); } diff --git a/crates/teloxide/src/utils/markdown.rs b/crates/teloxide/src/utils/markdown.rs index 4be607c5..4e072e6b 100644 --- a/crates/teloxide/src/utils/markdown.rs +++ b/crates/teloxide/src/utils/markdown.rs @@ -2,7 +2,7 @@ //! //! [spec]: https://core.telegram.org/bots/api#markdownv2-style -use teloxide_core::types::User; +use teloxide_core::types::{User, UserId}; /// Applies the bold font style to the string. /// @@ -71,7 +71,7 @@ pub fn link(url: &str, text: &str) -> String { /// Builds an inline user mention link with an anchor. #[must_use = "This function returns a new string, rather than mutating the argument, so calling it \ without using its output does nothing useful"] -pub fn user_mention(user_id: u64, text: &str) -> String { +pub fn user_mention(user_id: UserId, text: &str) -> String { link(format!("tg://user?id={user_id}").as_str(), text) } @@ -203,7 +203,10 @@ mod tests { #[test] fn test_user_mention() { - assert_eq!(user_mention(123_456_789, "pwner666"), "[pwner666](tg://user?id=123456789)"); + assert_eq!( + user_mention(UserId(123_456_789), "pwner666"), + "[pwner666](tg://user?id=123456789)" + ); } #[test]