Add a way to go ChatId -> UserId

This commit is contained in:
Maybe Waffle 2023-07-29 14:03:10 +04:00
parent 10846e19fd
commit 529b38afee
2 changed files with 11 additions and 0 deletions

View file

@ -16,9 +16,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Seconds` type, which represents a duration is seconds ([#859][pr859])
- `VideoChatEnded::duration` field that was previously missed ([#859][pr859])
- `ThreadId` newtype over `MessageId`, used for identifying reply threads ([#887][pr887])
- `ChatId::as_user` ([#905][pr905])
[pr851]: https://github.com/teloxide/teloxide/pull/851
[pr887]: https://github.com/teloxide/teloxide/pull/887
[pr905]: https://github.com/teloxide/teloxide/pull/905
### Fixed

View file

@ -50,6 +50,15 @@ impl ChatId {
matches!(self.to_bare(), BareChatId::Channel(_))
}
/// Returns user id, if this is an id of a user.
#[must_use]
pub fn as_user(self) -> Option<UserId> {
match self.to_bare() {
BareChatId::User(u) => Some(u),
BareChatId::Group(_) | BareChatId::Channel(_) => None,
}
}
/// Converts this id to "bare" MTProto peer id.
///
/// See [`BareChatId`] for more.