mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 05:07:10 +02:00
Provide privacy policy in mini-app.
This commit is contained in:
parent
5f8c007a0c
commit
b0fece2fd0
5 changed files with 76 additions and 23 deletions
|
@ -13,13 +13,9 @@ struct BotCommand final {
|
|||
QString command;
|
||||
QString description;
|
||||
|
||||
inline bool operator==(const BotCommand &other) const {
|
||||
return (command == other.command)
|
||||
&& (description == other.description);
|
||||
}
|
||||
inline bool operator!=(const BotCommand &other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
friend inline bool operator==(
|
||||
const BotCommand &,
|
||||
const BotCommand &) = default;
|
||||
};
|
||||
|
||||
[[nodiscard]] BotCommand BotCommandFromTL(const MTPBotCommand &result);
|
||||
|
|
|
@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_file_origin.h"
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_document_media.h"
|
||||
#include "data/data_peer_bot_command.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_web_page.h"
|
||||
#include "main/main_app_config.h"
|
||||
|
@ -1216,7 +1217,7 @@ void WebViewInstance::botHandleMenuButton(
|
|||
}
|
||||
break;
|
||||
case Button::RemoveFromMenu:
|
||||
case Button::RemoveFromMainMenu:
|
||||
case Button::RemoveFromMainMenu: {
|
||||
const auto &bots = _session->attachWebView().attachBots();
|
||||
const auto attached = ranges::find(
|
||||
bots,
|
||||
|
@ -1248,7 +1249,19 @@ void WebViewInstance::botHandleMenuButton(
|
|||
Ui::Text::WithEntities),
|
||||
done,
|
||||
}));
|
||||
break;
|
||||
} break;
|
||||
case Button::ShareGame: {
|
||||
const auto itemId = v::is<WebViewSourceGame>(_source)
|
||||
? v::get<WebViewSourceGame>(_source).messageId
|
||||
: FullMsgId();
|
||||
if (!_panel || !itemId) {
|
||||
return;
|
||||
} else if (const auto item = _session->data().message(itemId)) {
|
||||
FastShareMessage(uiShow(), item);
|
||||
} else {
|
||||
_panel->showToast({ tr::lng_message_not_found(tr::now) });
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1383,16 +1396,57 @@ void WebViewInstance::botInvokeCustomMethod(
|
|||
}).send();
|
||||
}
|
||||
|
||||
void WebViewInstance::botShareGameScore() {
|
||||
const auto itemId = v::is<WebViewSourceGame>(_source)
|
||||
? v::get<WebViewSourceGame>(_source).messageId
|
||||
: FullMsgId();
|
||||
if (!_panel || !itemId) {
|
||||
return;
|
||||
} else if (const auto item = _session->data().message(itemId)) {
|
||||
FastShareMessage(uiShow(), item);
|
||||
} else {
|
||||
_panel->showToast({ tr::lng_message_not_found(tr::now) });
|
||||
void WebViewInstance::botOpenPrivacyPolicy() {
|
||||
const auto bot = _bot;
|
||||
const auto weak = _context.controller;
|
||||
const auto command = u"privacy"_q;
|
||||
const auto findCommand = [=] {
|
||||
if (!bot->isBot()) {
|
||||
return QString();
|
||||
}
|
||||
for (const auto &data : bot->botInfo->commands) {
|
||||
const auto isSame = !data.command.compare(
|
||||
command,
|
||||
Qt::CaseInsensitive);
|
||||
if (isSame) {
|
||||
return data.command;
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
};
|
||||
const auto makeOtherContext = [=](bool forceWindow) {
|
||||
return QVariant::fromValue(ClickHandlerContext{
|
||||
.sessionWindow = (forceWindow
|
||||
? WindowForThread(weak, bot->owner().history(bot))
|
||||
: weak),
|
||||
.peer = bot,
|
||||
});
|
||||
};
|
||||
const auto sendCommand = [=] {
|
||||
const auto original = findCommand();
|
||||
if (original.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
BotCommandClickHandler('/' + original).onClick(ClickContext{
|
||||
Qt::LeftButton,
|
||||
makeOtherContext(true)
|
||||
});
|
||||
return true;
|
||||
};
|
||||
const auto openUrl = [=](const QString &url) {
|
||||
Core::App().iv().openWithIvPreferred(
|
||||
&_bot->session(),
|
||||
url,
|
||||
makeOtherContext(false));
|
||||
};
|
||||
if (const auto info = _bot->botInfo.get()) {
|
||||
if (!info->privacyPolicyUrl.isEmpty()) {
|
||||
openUrl(info->privacyPolicyUrl);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!sendCommand()) {
|
||||
openUrl(tr::lng_profile_bot_privacy_url(tr::now));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -275,7 +275,7 @@ private:
|
|||
void botSharePhone(Fn<void(bool shared)> callback) override;
|
||||
void botInvokeCustomMethod(
|
||||
Ui::BotWebView::CustomMethodRequest request) override;
|
||||
void botShareGameScore() override;
|
||||
void botOpenPrivacyPolicy() override;
|
||||
void botClose() override;
|
||||
|
||||
const std::shared_ptr<Ui::Show> _parentShow;
|
||||
|
|
|
@ -538,12 +538,15 @@ bool Panel::showWebview(
|
|||
}, &st::menuIconRestore);
|
||||
if (_menuButtons & MenuButton::ShareGame) {
|
||||
callback(tr::lng_iv_share(tr::now), [=] {
|
||||
_delegate->botShareGameScore();
|
||||
_delegate->botHandleMenuButton(MenuButton::ShareGame);
|
||||
}, &st::menuIconShare);
|
||||
} else {
|
||||
callback(tr::lng_bot_terms(tr::now), [=] {
|
||||
File::OpenUrl(tr::lng_mini_apps_tos_url(tr::now));
|
||||
}, &st::menuIconGroupLog);
|
||||
callback(tr::lng_profile_bot_privacy(tr::now), [=] {
|
||||
_delegate->botOpenPrivacyPolicy();
|
||||
}, &st::menuIconAntispam);
|
||||
}
|
||||
const auto main = (_menuButtons & MenuButton::RemoveFromMainMenu);
|
||||
if (main || (_menuButtons & MenuButton::RemoveFromMenu)) {
|
||||
|
@ -709,7 +712,7 @@ bool Panel::createWebview(const Webview::ThemeParams ¶ms) {
|
|||
} else if (command == "web_app_set_header_color") {
|
||||
processHeaderColor(arguments);
|
||||
} else if (command == "share_score") {
|
||||
_delegate->botShareGameScore();
|
||||
_delegate->botHandleMenuButton(MenuButton::ShareGame);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ public:
|
|||
virtual void botAllowWriteAccess(Fn<void(bool allowed)> callback) = 0;
|
||||
virtual void botSharePhone(Fn<void(bool shared)> callback) = 0;
|
||||
virtual void botInvokeCustomMethod(CustomMethodRequest request) = 0;
|
||||
virtual void botShareGameScore() = 0;
|
||||
virtual void botOpenPrivacyPolicy() = 0;
|
||||
virtual void botClose() = 0;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue