mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-23 15:01:45 +01:00
Fix Message::url
This commit is contained in:
parent
7bf3894a31
commit
57a3731e6b
2 changed files with 26 additions and 16 deletions
|
@ -25,6 +25,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
- `user.id` now uses `UserId` type, `ChatId` now represents only _chat id_, not channel username, all `chat_id` function parameters now accept `Recipient` [**BC**]
|
- `user.id` now uses `UserId` type, `ChatId` now represents only _chat id_, not channel username, all `chat_id` function parameters now accept `Recipient` [**BC**]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- A bug in `Message::url` implementation ([#198][pr198])
|
||||||
|
|
||||||
## 0.4.5 - 2022-04-03
|
## 0.4.5 - 2022-04-03
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
@ -4,10 +4,11 @@ use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::types::{
|
use crate::types::{
|
||||||
Animation, Audio, Chat, ChatId, Contact, Dice, Document, Game, InlineKeyboardMarkup, Invoice,
|
Animation, Audio, BareChatId, Chat, ChatId, Contact, Dice, Document, Game,
|
||||||
Location, MessageAutoDeleteTimerChanged, MessageEntity, PassportData, PhotoSize, Poll,
|
InlineKeyboardMarkup, Invoice, Location, MessageAutoDeleteTimerChanged, MessageEntity,
|
||||||
ProximityAlertTriggered, Sticker, SuccessfulPayment, True, User, Venue, Video, VideoNote,
|
PassportData, PhotoSize, Poll, ProximityAlertTriggered, Sticker, SuccessfulPayment, True, User,
|
||||||
Voice, VoiceChatEnded, VoiceChatParticipantsInvited, VoiceChatScheduled, VoiceChatStarted,
|
Venue, Video, VideoNote, Voice, VoiceChatEnded, VoiceChatParticipantsInvited,
|
||||||
|
VoiceChatScheduled, VoiceChatStarted,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// This object represents a message.
|
/// This object represents a message.
|
||||||
|
@ -1050,30 +1051,35 @@ impl Message {
|
||||||
/// Note that for private groups the link will only be accessible for group
|
/// Note that for private groups the link will only be accessible for group
|
||||||
/// members.
|
/// members.
|
||||||
///
|
///
|
||||||
/// Returns `None` for private chats (i.e.: DMs).
|
/// Returns `None` for private chats (i.e.: DMs) and private groups (not
|
||||||
|
/// supergroups).
|
||||||
pub fn url(&self) -> Option<reqwest::Url> {
|
pub fn url(&self) -> Option<reqwest::Url> {
|
||||||
if self.chat.is_private() {
|
use BareChatId::*;
|
||||||
|
|
||||||
|
// Note: `t.me` links use bare chat ids
|
||||||
|
let chat_id = match self.chat.id.to_bare() {
|
||||||
// For private chats (i.e.: DMs) we can't produce "normal" t.me link.
|
// For private chats (i.e.: DMs) we can't produce "normal" t.me link.
|
||||||
//
|
//
|
||||||
// There are "tg://openmessage?user_id={0}&message_id={1}" links, which are
|
// There are "tg://openmessage?user_id={0}&message_id={1}" links, which are
|
||||||
// supposed to open any chat, including private messages, but they
|
// supposed to open any chat, including private messages, but they
|
||||||
// are only supported by some telegram clients (e.g. Plus Messenger,
|
// are only supported by some telegram clients (e.g. Plus Messenger,
|
||||||
// Telegram for Android 4.9+).
|
// Telegram for Android 4.9+).
|
||||||
return None;
|
User(_) => return None,
|
||||||
}
|
// Similarly to user chats, there is no way to create a link to a message in a normal,
|
||||||
|
// private group.
|
||||||
|
//
|
||||||
|
// (public groups are always supergroup which are in turn channels).
|
||||||
|
Group(_) => return None,
|
||||||
|
Channel(id) => id,
|
||||||
|
};
|
||||||
|
|
||||||
let url = match self.chat.username() {
|
let url = match self.chat.username() {
|
||||||
// If it's public group (i.e. not DM, not private group), we can produce
|
// If it's public group (i.e. not DM, not private group), we can produce
|
||||||
// "normal" t.me link (accessible to everyone).
|
// "normal" t.me link (accessible to everyone).
|
||||||
Some(username) => format!("https://t.me/{0}/{1}/", username, self.id),
|
Some(username) => format!("https://t.me/{0}/{1}/", username, self.id),
|
||||||
// For private groups we produce "private" t.me/c links. These are only
|
// For private supergroups and channels we produce "private" t.me/c links. These are
|
||||||
// accessible to the group members.
|
// only accessible to the group members.
|
||||||
None => format!(
|
None => format!("https://t.me/c/{0}/{1}/", chat_id, self.id),
|
||||||
"https://t.me/c/{0}/{1}/",
|
|
||||||
// FIXME: this may be wrong for private channels
|
|
||||||
(-self.chat.id.0) - 1000000000000,
|
|
||||||
self.id
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// UNWRAP:
|
// UNWRAP:
|
||||||
|
|
Loading…
Reference in a new issue