mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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_bot" = "View bot";
|
||||||
"lng_view_button_group" = "View group";
|
"lng_view_button_group" = "View group";
|
||||||
"lng_view_button_channel" = "View channel";
|
"lng_view_button_channel" = "View channel";
|
||||||
|
"lng_view_button_bot_app" = "Open app";
|
||||||
"lng_view_button_background" = "View background";
|
"lng_view_button_background" = "View background";
|
||||||
"lng_view_button_theme" = "View theme";
|
"lng_view_button_theme" = "View theme";
|
||||||
"lng_view_button_message" = "View message";
|
"lng_view_button_message" = "View message";
|
||||||
|
|
|
@ -162,16 +162,18 @@ WebPageType ParseWebPageType(
|
||||||
} else if (type == u"telegram_megagroup_request"_q
|
} else if (type == u"telegram_megagroup_request"_q
|
||||||
|| type == u"telegram_chat_request"_q) {
|
|| type == u"telegram_chat_request"_q) {
|
||||||
return WebPageType::GroupWithRequest;
|
return WebPageType::GroupWithRequest;
|
||||||
} else if (type == u"telegram_message"_q) {
|
} else if (type == u"telegram_message"_q) {
|
||||||
return WebPageType::Message;
|
return WebPageType::Message;
|
||||||
} else if (type == u"telegram_bot"_q) {
|
} else if (type == u"telegram_bot"_q) {
|
||||||
return WebPageType::Bot;
|
return WebPageType::Bot;
|
||||||
} else if (type == u"telegram_voicechat"_q) {
|
} else if (type == u"telegram_voicechat"_q) {
|
||||||
return WebPageType::VoiceChat;
|
return WebPageType::VoiceChat;
|
||||||
} else if (type == u"telegram_livestream"_q) {
|
} else if (type == u"telegram_livestream"_q) {
|
||||||
return WebPageType::Livestream;
|
return WebPageType::Livestream;
|
||||||
} else if (type == u"telegram_user"_q) {
|
} else if (type == u"telegram_user"_q) {
|
||||||
return WebPageType::User;
|
return WebPageType::User;
|
||||||
|
} else if (type == u"telegram_botapp"_q) {
|
||||||
|
return WebPageType::BotApp;
|
||||||
} else if (hasIV) {
|
} else if (hasIV) {
|
||||||
return WebPageType::ArticleWithIV;
|
return WebPageType::ArticleWithIV;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -31,6 +31,7 @@ enum class WebPageType {
|
||||||
User,
|
User,
|
||||||
Bot,
|
Bot,
|
||||||
Profile,
|
Profile,
|
||||||
|
BotApp,
|
||||||
|
|
||||||
WallPaper,
|
WallPaper,
|
||||||
Theme,
|
Theme,
|
||||||
|
|
|
@ -71,18 +71,29 @@ inline auto WebPageToPhrase(not_null<WebPageData*> webpage) {
|
||||||
? tr::lng_view_button_bot(tr::now)
|
? tr::lng_view_button_bot(tr::now)
|
||||||
: (type == WebPageType::User)
|
: (type == WebPageType::User)
|
||||||
? tr::lng_view_button_user(tr::now)
|
? tr::lng_view_button_user(tr::now)
|
||||||
|
: (type == WebPageType::BotApp)
|
||||||
|
? tr::lng_view_button_bot_app(tr::now)
|
||||||
: QString());
|
: QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] ClickHandlerPtr MakeWebPageClickHandler(
|
[[nodiscard]] ClickHandlerPtr MakeWebPageButtonClickHandler(
|
||||||
not_null<Data::Media*> media) {
|
not_null<Data::Media*> media) {
|
||||||
Expects(media->webpage() != nullptr);
|
Expects(media->webpage() != nullptr);
|
||||||
|
|
||||||
const auto url = media->webpage()->url;
|
const auto url = media->webpage()->url;
|
||||||
|
const auto type = media->webpage()->type;
|
||||||
return std::make_shared<LambdaClickHandler>([=](ClickContext context) {
|
return std::make_shared<LambdaClickHandler>([=](ClickContext context) {
|
||||||
const auto my = context.other.value<ClickHandlerContext>();
|
const auto my = context.other.value<ClickHandlerContext>();
|
||||||
if (const auto controller = my.sessionWindow.get()) {
|
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::User)
|
||||||
|| (type == WebPageType::VoiceChat)
|
|| (type == WebPageType::VoiceChat)
|
||||||
|| (type == WebPageType::Livestream)
|
|| (type == WebPageType::Livestream)
|
||||||
|
|| (type == WebPageType::BotApp)
|
||||||
|| ((type == WebPageType::Theme)
|
|| ((type == WebPageType::Theme)
|
||||||
&& webpage->document
|
&& webpage->document
|
||||||
&& webpage->document->isTheme())
|
&& webpage->document->isTheme())
|
||||||
|
@ -160,7 +172,7 @@ ViewButton::Inner::Inner(
|
||||||
not_null<Data::Media*> media,
|
not_null<Data::Media*> media,
|
||||||
Fn<void()> updateCallback)
|
Fn<void()> updateCallback)
|
||||||
: margins(st::historyViewButtonMargins)
|
: margins(st::historyViewButtonMargins)
|
||||||
, link(MakeWebPageClickHandler(media))
|
, link(MakeWebPageButtonClickHandler(media))
|
||||||
, updateCallback(std::move(updateCallback))
|
, updateCallback(std::move(updateCallback))
|
||||||
, belowInfo(false)
|
, belowInfo(false)
|
||||||
, text(st::historyViewButtonTextStyle, WebPageToPhrase(media->webpage())) {
|
, text(st::historyViewButtonTextStyle, WebPageToPhrase(media->webpage())) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue