mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Pass context chat from one webview to another.
This commit is contained in:
parent
87f52cf7df
commit
d57d95c53f
7 changed files with 33 additions and 7 deletions
|
@ -38,6 +38,7 @@ class SessionController;
|
||||||
class PeerData;
|
class PeerData;
|
||||||
struct ClickHandlerContext {
|
struct ClickHandlerContext {
|
||||||
FullMsgId itemId;
|
FullMsgId itemId;
|
||||||
|
QString attachBotWebviewUrl;
|
||||||
// Is filled from sections.
|
// Is filled from sections.
|
||||||
Fn<HistoryView::ElementDelegate*()> elementDelegate;
|
Fn<HistoryView::ElementDelegate*()> elementDelegate;
|
||||||
base::weak_ptr<Window::SessionController> sessionWindow;
|
base::weak_ptr<Window::SessionController> sessionWindow;
|
||||||
|
|
|
@ -447,6 +447,7 @@ bool ResolveUsernameOrPhone(
|
||||||
? std::make_optional(params.value(u"voicechat"_q))
|
? std::make_optional(params.value(u"voicechat"_q))
|
||||||
: std::nullopt),
|
: std::nullopt),
|
||||||
.clickFromMessageId = myContext.itemId,
|
.clickFromMessageId = myContext.itemId,
|
||||||
|
.clickFromAttachBotWebviewUrl = myContext.attachBotWebviewUrl,
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -473,7 +474,7 @@ bool ResolvePrivatePost(
|
||||||
if (!channelId || (msgId && !IsServerMsgId(msgId))) {
|
if (!channelId || (msgId && !IsServerMsgId(msgId))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const auto fromMessageId = context.value<ClickHandlerContext>().itemId;
|
const auto my = context.value<ClickHandlerContext>();
|
||||||
using Navigation = Window::SessionNavigation;
|
using Navigation = Window::SessionNavigation;
|
||||||
controller->showPeerByLink(Navigation::PeerByLinkInfo{
|
controller->showPeerByLink(Navigation::PeerByLinkInfo{
|
||||||
.usernameOrId = channelId,
|
.usernameOrId = channelId,
|
||||||
|
@ -487,7 +488,8 @@ bool ResolvePrivatePost(
|
||||||
Navigation::ThreadId{ threadId }
|
Navigation::ThreadId{ threadId }
|
||||||
}
|
}
|
||||||
: Navigation::RepliesByLinkInfo{ v::null },
|
: Navigation::RepliesByLinkInfo{ v::null },
|
||||||
.clickFromMessageId = fromMessageId,
|
.clickFromMessageId = my.itemId,
|
||||||
|
.clickFromAttachBotWebviewUrl = my.attachBotWebviewUrl,
|
||||||
});
|
});
|
||||||
controller->window().activate();
|
controller->window().activate();
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -345,7 +345,8 @@ void Stories::parseAndApply(const MTPUserStories &stories) {
|
||||||
}
|
}
|
||||||
sort(list);
|
sort(list);
|
||||||
};
|
};
|
||||||
if (result.user->isBot()
|
if (result.user->isSelf()
|
||||||
|
|| result.user->isBot()
|
||||||
|| result.user->isServiceUser()
|
|| result.user->isServiceUser()
|
||||||
|| result.user->isContact()) {
|
|| result.user->isContact()) {
|
||||||
const auto hidden = result.user->hasStoriesHidden();
|
const auto hidden = result.user->hasStoriesHidden();
|
||||||
|
|
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "inline_bots/bot_attach_web_view.h"
|
#include "inline_bots/bot_attach_web_view.h"
|
||||||
|
|
||||||
#include "api/api_common.h"
|
#include "api/api_common.h"
|
||||||
|
#include "core/click_handler_types.h"
|
||||||
#include "data/data_bot_app.h"
|
#include "data/data_bot_app.h"
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
#include "data/data_file_origin.h"
|
#include "data/data_file_origin.h"
|
||||||
|
@ -568,7 +569,7 @@ void AttachWebView::cancel() {
|
||||||
_session->api().request(base::take(_requestId)).cancel();
|
_session->api().request(base::take(_requestId)).cancel();
|
||||||
_session->api().request(base::take(_prolongId)).cancel();
|
_session->api().request(base::take(_prolongId)).cancel();
|
||||||
_panel = nullptr;
|
_panel = nullptr;
|
||||||
_context = nullptr;
|
_lastShownContext = base::take(_context);
|
||||||
_bot = nullptr;
|
_bot = nullptr;
|
||||||
_app = nullptr;
|
_app = nullptr;
|
||||||
_botUsername = QString();
|
_botUsername = QString();
|
||||||
|
@ -713,6 +714,14 @@ void AttachWebView::removeFromMenu(not_null<UserData*> bot) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<Api::SendAction> AttachWebView::lookupLastAction(
|
||||||
|
const QString &url) const {
|
||||||
|
if (_lastShownUrl == url && _lastShownContext) {
|
||||||
|
return _lastShownContext->action;
|
||||||
|
}
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
void AttachWebView::resolve() {
|
void AttachWebView::resolve() {
|
||||||
resolveUsername(_botUsername, [=](not_null<PeerData*> bot) {
|
resolveUsername(_botUsername, [=](not_null<PeerData*> bot) {
|
||||||
if (!_context) {
|
if (!_context) {
|
||||||
|
@ -1049,7 +1058,7 @@ void AttachWebView::show(
|
||||||
}
|
}
|
||||||
crl::on_main(this, [=] { cancel(); });
|
crl::on_main(this, [=] { cancel(); });
|
||||||
});
|
});
|
||||||
const auto handleLocalUri = [close](QString uri) {
|
const auto handleLocalUri = [close, url](QString uri) {
|
||||||
const auto local = Core::TryConvertUrlToLocal(uri);
|
const auto local = Core::TryConvertUrlToLocal(uri);
|
||||||
if (uri == local || Core::InternalPassportLink(local)) {
|
if (uri == local || Core::InternalPassportLink(local)) {
|
||||||
return local.startsWith(u"tg://"_q);
|
return local.startsWith(u"tg://"_q);
|
||||||
|
@ -1058,7 +1067,10 @@ void AttachWebView::show(
|
||||||
}
|
}
|
||||||
close();
|
close();
|
||||||
crl::on_main([=] {
|
crl::on_main([=] {
|
||||||
UrlClickHandler::Open(local, {});
|
const auto variant = QVariant::fromValue(ClickHandlerContext{
|
||||||
|
.attachBotWebviewUrl = url,
|
||||||
|
});
|
||||||
|
UrlClickHandler::Open(local, variant);
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
@ -1142,6 +1154,7 @@ void AttachWebView::show(
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_lastShownUrl = url;
|
||||||
_panel = Ui::BotWebView::Show({
|
_panel = Ui::BotWebView::Show({
|
||||||
.url = url,
|
.url = url,
|
||||||
.userDataPath = _session->domain().local().webviewDataPath(),
|
.userDataPath = _session->domain().local().webviewDataPath(),
|
||||||
|
|
|
@ -122,6 +122,9 @@ public:
|
||||||
PeerTypes chooseTypes);
|
PeerTypes chooseTypes);
|
||||||
void removeFromMenu(not_null<UserData*> bot);
|
void removeFromMenu(not_null<UserData*> bot);
|
||||||
|
|
||||||
|
[[nodiscard]] std::optional<Api::SendAction> lookupLastAction(
|
||||||
|
const QString &url) const;
|
||||||
|
|
||||||
static void ClearAll();
|
static void ClearAll();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -180,6 +183,8 @@ private:
|
||||||
const not_null<Main::Session*> _session;
|
const not_null<Main::Session*> _session;
|
||||||
|
|
||||||
std::unique_ptr<Context> _context;
|
std::unique_ptr<Context> _context;
|
||||||
|
std::unique_ptr<Context> _lastShownContext;
|
||||||
|
QString _lastShownUrl;
|
||||||
UserData *_bot = nullptr;
|
UserData *_bot = nullptr;
|
||||||
QString _botUsername;
|
QString _botUsername;
|
||||||
QString _botAppName;
|
QString _botAppName;
|
||||||
|
|
|
@ -521,10 +521,13 @@ void SessionNavigation::showPeerByLinkResolved(
|
||||||
const auto contextPeer = item
|
const auto contextPeer = item
|
||||||
? item->history()->peer
|
? item->history()->peer
|
||||||
: bot;
|
: bot;
|
||||||
|
const auto action = bot->session().attachWebView().lookupLastAction(
|
||||||
|
info.clickFromAttachBotWebviewUrl
|
||||||
|
).value_or(Api::SendAction(bot->owner().history(contextPeer)));
|
||||||
crl::on_main(this, [=] {
|
crl::on_main(this, [=] {
|
||||||
bot->session().attachWebView().requestApp(
|
bot->session().attachWebView().requestApp(
|
||||||
parentController(),
|
parentController(),
|
||||||
Api::SendAction(bot->owner().history(contextPeer)),
|
action,
|
||||||
bot,
|
bot,
|
||||||
info.botAppName,
|
info.botAppName,
|
||||||
info.startToken,
|
info.startToken,
|
||||||
|
|
|
@ -217,6 +217,7 @@ public:
|
||||||
InlineBots::PeerTypes attachBotChooseTypes;
|
InlineBots::PeerTypes attachBotChooseTypes;
|
||||||
std::optional<QString> voicechatHash;
|
std::optional<QString> voicechatHash;
|
||||||
FullMsgId clickFromMessageId;
|
FullMsgId clickFromMessageId;
|
||||||
|
QString clickFromAttachBotWebviewUrl;
|
||||||
};
|
};
|
||||||
void showPeerByLink(const PeerByLinkInfo &info);
|
void showPeerByLink(const PeerByLinkInfo &info);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue