mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Add an "Open App" button for bot app link previews.
This commit is contained in:
parent
b95ea28e12
commit
1b3cf0a654
4 changed files with 24 additions and 8 deletions
|
@ -3543,6 +3543,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_view_button_bot" = "View bot";
|
||||
"lng_view_button_group" = "View group";
|
||||
"lng_view_button_channel" = "View channel";
|
||||
"lng_view_button_bot_app" = "Open app";
|
||||
"lng_view_button_background" = "View background";
|
||||
"lng_view_button_theme" = "View theme";
|
||||
"lng_view_button_message" = "View message";
|
||||
|
|
|
@ -162,16 +162,18 @@ WebPageType ParseWebPageType(
|
|||
} else if (type == u"telegram_megagroup_request"_q
|
||||
|| type == u"telegram_chat_request"_q) {
|
||||
return WebPageType::GroupWithRequest;
|
||||
} else if (type == u"telegram_message"_q) {
|
||||
} else if (type == u"telegram_message"_q) {
|
||||
return WebPageType::Message;
|
||||
} else if (type == u"telegram_bot"_q) {
|
||||
} else if (type == u"telegram_bot"_q) {
|
||||
return WebPageType::Bot;
|
||||
} else if (type == u"telegram_voicechat"_q) {
|
||||
} else if (type == u"telegram_voicechat"_q) {
|
||||
return WebPageType::VoiceChat;
|
||||
} else if (type == u"telegram_livestream"_q) {
|
||||
} else if (type == u"telegram_livestream"_q) {
|
||||
return WebPageType::Livestream;
|
||||
} else if (type == u"telegram_user"_q) {
|
||||
} else if (type == u"telegram_user"_q) {
|
||||
return WebPageType::User;
|
||||
} else if (type == u"telegram_botapp"_q) {
|
||||
return WebPageType::BotApp;
|
||||
} else if (hasIV) {
|
||||
return WebPageType::ArticleWithIV;
|
||||
} else {
|
||||
|
|
|
@ -31,6 +31,7 @@ enum class WebPageType {
|
|||
User,
|
||||
Bot,
|
||||
Profile,
|
||||
BotApp,
|
||||
|
||||
WallPaper,
|
||||
Theme,
|
||||
|
|
|
@ -71,18 +71,29 @@ inline auto WebPageToPhrase(not_null<WebPageData*> webpage) {
|
|||
? tr::lng_view_button_bot(tr::now)
|
||||
: (type == WebPageType::User)
|
||||
? tr::lng_view_button_user(tr::now)
|
||||
: (type == WebPageType::BotApp)
|
||||
? tr::lng_view_button_bot_app(tr::now)
|
||||
: QString());
|
||||
}
|
||||
|
||||
[[nodiscard]] ClickHandlerPtr MakeWebPageClickHandler(
|
||||
[[nodiscard]] ClickHandlerPtr MakeWebPageButtonClickHandler(
|
||||
not_null<Data::Media*> media) {
|
||||
Expects(media->webpage() != nullptr);
|
||||
|
||||
const auto url = media->webpage()->url;
|
||||
const auto type = media->webpage()->type;
|
||||
return std::make_shared<LambdaClickHandler>([=](ClickContext context) {
|
||||
const auto my = context.other.value<ClickHandlerContext>();
|
||||
if (const auto controller = my.sessionWindow.get()) {
|
||||
HiddenUrlClickHandler::Open(url, context.other);
|
||||
if (type == WebPageType::BotApp) {
|
||||
// Bot Web Apps always show confirmation on hidden urls.
|
||||
//
|
||||
// But from the dedicated "Open App" button we don't want
|
||||
// to request users confirmation on non-first app opening.
|
||||
UrlClickHandler::Open(url, context.other);
|
||||
} else {
|
||||
HiddenUrlClickHandler::Open(url, context.other);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -124,6 +135,7 @@ bool ViewButton::MediaHasViewButton(
|
|||
|| (type == WebPageType::User)
|
||||
|| (type == WebPageType::VoiceChat)
|
||||
|| (type == WebPageType::Livestream)
|
||||
|| (type == WebPageType::BotApp)
|
||||
|| ((type == WebPageType::Theme)
|
||||
&& webpage->document
|
||||
&& webpage->document->isTheme())
|
||||
|
@ -160,7 +172,7 @@ ViewButton::Inner::Inner(
|
|||
not_null<Data::Media*> media,
|
||||
Fn<void()> updateCallback)
|
||||
: margins(st::historyViewButtonMargins)
|
||||
, link(MakeWebPageClickHandler(media))
|
||||
, link(MakeWebPageButtonClickHandler(media))
|
||||
, updateCallback(std::move(updateCallback))
|
||||
, belowInfo(false)
|
||||
, text(st::historyViewButtonTextStyle, WebPageToPhrase(media->webpage())) {
|
||||
|
|
Loading…
Add table
Reference in a new issue