Merge pull request #208 from SpriteOvO/user-mention-shortcut

Add method `MessageEntity::user_mention`
This commit is contained in:
Waffle Maybe 2022-04-24 20:51:49 +04:00 committed by GitHub
commit 95f519073b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View file

@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support for Telegram Bot API [version 6.0](https://core.telegram.org/bots/api#april-16-2022)
- Note that some field were renamed
- Method `MessageEntity::user_mention` ([#208][pr208])
[pr208]: https://github.com/teloxide/teloxide-core/pull/208
### Changed
@ -191,8 +194,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Throttle` adaptor not honouring chat/min limits ([#121][pr121])
- 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))
- Type of response for `CopyMessage` method ([#141][pr141], [#142][pr142])
- Bad request serialization when the `language` field of `MessageEntityKind::Pre` is `None` ([#145][pr145])
- Deserialization of `MediaKind::Venue` ([#147][pr147])
- Deserialization of `VoiceChat{Started,Ended}` messages ([#153][pr153])
- Serialization of `BotCommandScope::Chat{,Administrators}` ([#154][pr154])

View file

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use crate::types::User;
use crate::types::{User, UserId};
/// This object represents one special entity in a text message.
///
@ -28,6 +28,16 @@ impl MessageEntity {
}
}
/// Create a message entity representing a text link in the form of
/// `tg://user/?id=...` that mentions user with `user_id`.
pub fn user_mention(user_id: UserId, offset: usize, length: usize) -> Self {
Self {
kind: MessageEntityKind::TextLink { url: user_id.url() },
offset,
length,
}
}
pub fn kind(mut self, val: MessageEntityKind) -> Self {
self.kind = val;
self