2015-12-07 13:05:00 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2015-12-07 13:05:00 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2015-12-07 13:05:00 +00:00
|
|
|
*/
|
2017-09-13 16:57:44 +00:00
|
|
|
#include "facades.h"
|
|
|
|
|
2020-06-29 13:33:27 +00:00
|
|
|
#include "api/api_bot.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
#include "info/info_memento.h"
|
2022-03-29 09:00:10 +00:00
|
|
|
#include "inline_bots/bot_attach_web_view.h"
|
2016-05-24 16:13:07 +00:00
|
|
|
#include "core/click_handler_types.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2019-02-13 12:36:59 +00:00
|
|
|
#include "media/clip/media_clip_reader.h"
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2020-01-15 13:30:29 +00:00
|
|
|
#include "window/window_peer_menu.h"
|
2017-12-18 15:44:50 +00:00
|
|
|
#include "history/history_item_components.h"
|
2019-09-17 16:13:12 +00:00
|
|
|
#include "base/platform/base_platform_info.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_peer.h"
|
|
|
|
#include "data/data_user.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
2015-12-07 13:05:00 +00:00
|
|
|
#include "mainwidget.h"
|
2017-12-07 13:02:24 +00:00
|
|
|
#include "apiwrap.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2020-06-26 11:48:28 +00:00
|
|
|
#include "main/main_domain.h"
|
2021-10-18 21:36:55 +00:00
|
|
|
#include "ui/boxes/confirm_box.h"
|
2019-05-22 14:29:02 +00:00
|
|
|
#include "boxes/url_auth_box.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "ui/layers/layer_widget.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "history/history_item.h"
|
2019-08-02 13:21:09 +00:00
|
|
|
#include "history/view/media/history_view_media.h"
|
2021-03-23 12:34:34 +00:00
|
|
|
#include "payments/payments_checkout_process.h"
|
2018-01-04 10:22:53 +00:00
|
|
|
#include "data/data_session.h"
|
2020-10-10 09:15:37 +00:00
|
|
|
#include "styles/style_chat.h"
|
2015-12-24 20:29:33 +00:00
|
|
|
|
2020-06-26 11:48:28 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
[[nodiscard]] MainWidget *CheckMainWidget(not_null<Main::Session*> session) {
|
|
|
|
if (const auto m = App::main()) { // multi good
|
|
|
|
if (&m->session() == session) {
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (&Core::App().domain().active() != &session->account()) {
|
|
|
|
Core::App().domain().activate(&session->account());
|
|
|
|
}
|
|
|
|
if (const auto m = App::main()) { // multi good
|
|
|
|
if (&m->session() == session) {
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2015-12-07 13:05:00 +00:00
|
|
|
namespace App {
|
2016-12-09 18:56:01 +00:00
|
|
|
|
2020-06-10 18:08:17 +00:00
|
|
|
void hideSingleUseKeyboard(not_null<const HistoryItem*> message) {
|
2020-06-26 11:48:28 +00:00
|
|
|
if (const auto m = CheckMainWidget(&message->history()->session())) {
|
|
|
|
m->hideSingleUseKeyboard(message->history()->peer, message->id);
|
2016-11-20 12:54:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-27 18:11:51 +00:00
|
|
|
bool insertBotCommand(const QString &cmd) {
|
2020-06-10 18:08:17 +00:00
|
|
|
if (const auto m = App::main()) { // multi good
|
2017-03-27 18:11:51 +00:00
|
|
|
return m->insertBotCommand(cmd);
|
2016-04-14 19:24:42 +00:00
|
|
|
}
|
2016-04-11 10:59:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-12-07 13:05:00 +00:00
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
void activateBotCommand(
|
2021-07-26 23:45:01 +00:00
|
|
|
Window::SessionController *sessionController,
|
2017-12-18 15:44:50 +00:00
|
|
|
not_null<const HistoryItem*> msg,
|
|
|
|
int row,
|
|
|
|
int column) {
|
2020-06-08 15:17:33 +00:00
|
|
|
const auto button = HistoryMessageMarkupButton::Get(
|
|
|
|
&msg->history()->owner(),
|
|
|
|
msg->fullId(),
|
|
|
|
row,
|
|
|
|
column);
|
|
|
|
if (!button) {
|
|
|
|
return;
|
|
|
|
}
|
2016-04-11 10:59:01 +00:00
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
using ButtonType = HistoryMessageMarkupButton::Type;
|
2016-04-11 10:59:01 +00:00
|
|
|
switch (button->type) {
|
2016-09-02 16:11:23 +00:00
|
|
|
case ButtonType::Default: {
|
2016-04-11 10:59:01 +00:00
|
|
|
// Copy string before passing it to the sending method
|
|
|
|
// because the original button can be destroyed inside.
|
2021-07-26 23:45:01 +00:00
|
|
|
if (sessionController) {
|
2021-11-07 08:06:00 +00:00
|
|
|
MsgId replyTo = msg->isRegular() ? msg->id : 0;
|
2021-07-26 23:45:01 +00:00
|
|
|
sessionController->content()->sendBotCommand({
|
|
|
|
.peer = msg->history()->peer,
|
|
|
|
.command = QString(button->text),
|
|
|
|
.context = msg->fullId(),
|
|
|
|
.replyTo = replyTo,
|
|
|
|
});
|
|
|
|
}
|
2016-04-11 10:59:01 +00:00
|
|
|
} break;
|
|
|
|
|
2016-09-02 16:11:23 +00:00
|
|
|
case ButtonType::Callback:
|
|
|
|
case ButtonType::Game: {
|
2020-06-29 13:33:27 +00:00
|
|
|
Api::SendBotCallbackData(
|
|
|
|
const_cast<HistoryItem*>(msg.get()),
|
|
|
|
row,
|
|
|
|
column);
|
2016-04-11 10:59:01 +00:00
|
|
|
} break;
|
|
|
|
|
2020-08-25 10:57:17 +00:00
|
|
|
case ButtonType::CallbackWithPassword: {
|
|
|
|
Api::SendBotCallbackDataWithPassword(
|
|
|
|
const_cast<HistoryItem*>(msg.get()),
|
|
|
|
row,
|
|
|
|
column);
|
|
|
|
} break;
|
|
|
|
|
2017-03-05 13:39:10 +00:00
|
|
|
case ButtonType::Buy: {
|
2021-03-31 05:56:45 +00:00
|
|
|
Payments::CheckoutProcess::Start(
|
|
|
|
msg,
|
|
|
|
Payments::Mode::Payment,
|
|
|
|
crl::guard(App::wnd(), [] { App::wnd()->activate(); }));
|
2017-03-05 13:39:10 +00:00
|
|
|
} break;
|
|
|
|
|
2016-09-02 16:11:23 +00:00
|
|
|
case ButtonType::Url: {
|
2016-04-11 10:59:01 +00:00
|
|
|
auto url = QString::fromUtf8(button->data);
|
2016-12-20 13:03:51 +00:00
|
|
|
auto skipConfirmation = false;
|
2020-06-10 18:08:17 +00:00
|
|
|
if (const auto bot = msg->getMessageBot()) {
|
2016-12-20 13:03:51 +00:00
|
|
|
if (bot->isVerified()) {
|
|
|
|
skipConfirmation = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (skipConfirmation) {
|
2018-07-09 18:13:48 +00:00
|
|
|
UrlClickHandler::Open(url);
|
2016-12-20 13:03:51 +00:00
|
|
|
} else {
|
2018-07-09 18:13:48 +00:00
|
|
|
HiddenUrlClickHandler::Open(url);
|
2016-12-20 13:03:51 +00:00
|
|
|
}
|
2016-04-11 10:59:01 +00:00
|
|
|
} break;
|
|
|
|
|
2016-09-02 16:11:23 +00:00
|
|
|
case ButtonType::RequestLocation: {
|
2016-11-20 12:54:07 +00:00
|
|
|
hideSingleUseKeyboard(msg);
|
2022-02-27 08:23:20 +00:00
|
|
|
Ui::show(Ui::MakeInformBox(tr::lng_bot_share_location_unavailable()));
|
2016-04-11 10:59:01 +00:00
|
|
|
} break;
|
|
|
|
|
2016-09-02 16:11:23 +00:00
|
|
|
case ButtonType::RequestPhone: {
|
2016-11-20 12:54:07 +00:00
|
|
|
hideSingleUseKeyboard(msg);
|
2017-12-07 13:02:24 +00:00
|
|
|
const auto msgId = msg->id;
|
|
|
|
const auto history = msg->history();
|
2022-02-27 08:23:20 +00:00
|
|
|
Ui::show(Ui::MakeConfirmBox({
|
|
|
|
.text = tr::lng_bot_share_phone(),
|
|
|
|
.confirmed = [=] {
|
2021-10-18 22:28:08 +00:00
|
|
|
Ui::showPeerHistory(history, ShowAtTheEndMsgId);
|
|
|
|
auto action = Api::SendAction(history);
|
|
|
|
action.clearDraft = false;
|
|
|
|
action.replyTo = msgId;
|
|
|
|
history->session().api().shareContact(
|
|
|
|
history->session().user(),
|
|
|
|
action);
|
2022-02-27 08:23:20 +00:00
|
|
|
},
|
|
|
|
.confirmText = tr::lng_bot_share_phone_confirm(),
|
|
|
|
}));
|
2016-04-11 10:59:01 +00:00
|
|
|
} break;
|
|
|
|
|
2020-01-15 13:30:29 +00:00
|
|
|
case ButtonType::RequestPoll: {
|
|
|
|
hideSingleUseKeyboard(msg);
|
|
|
|
auto chosen = PollData::Flags();
|
|
|
|
auto disabled = PollData::Flags();
|
|
|
|
if (!button->data.isEmpty()) {
|
|
|
|
disabled |= PollData::Flag::Quiz;
|
|
|
|
if (button->data[0]) {
|
|
|
|
chosen |= PollData::Flag::Quiz;
|
|
|
|
}
|
|
|
|
}
|
2020-06-26 11:48:28 +00:00
|
|
|
if (const auto m = CheckMainWidget(&msg->history()->session())) {
|
2020-11-11 20:47:40 +00:00
|
|
|
const auto replyToId = MsgId(0);
|
|
|
|
Window::PeerMenuCreatePoll(
|
|
|
|
m->controller(),
|
|
|
|
msg->history()->peer,
|
|
|
|
replyToId,
|
|
|
|
chosen,
|
|
|
|
disabled);
|
2020-06-10 18:08:17 +00:00
|
|
|
}
|
2020-01-15 13:30:29 +00:00
|
|
|
} break;
|
|
|
|
|
2016-09-02 16:11:23 +00:00
|
|
|
case ButtonType::SwitchInlineSame:
|
|
|
|
case ButtonType::SwitchInline: {
|
2020-06-10 18:08:17 +00:00
|
|
|
const auto session = &msg->history()->session();
|
2020-06-26 11:48:28 +00:00
|
|
|
if (const auto m = CheckMainWidget(session)) {
|
|
|
|
if (const auto bot = msg->getMessageBot()) {
|
|
|
|
const auto fastSwitchDone = [&] {
|
|
|
|
auto samePeer = (button->type == ButtonType::SwitchInlineSame);
|
|
|
|
if (samePeer) {
|
|
|
|
Notify::switchInlineBotButtonReceived(session, QString::fromUtf8(button->data), bot, msg->id);
|
|
|
|
return true;
|
2020-11-12 15:46:17 +00:00
|
|
|
} else if (bot->isBot() && bot->botInfo->inlineReturnTo.key) {
|
2020-06-26 11:48:28 +00:00
|
|
|
if (Notify::switchInlineBotButtonReceived(session, QString::fromUtf8(button->data))) {
|
2016-04-11 10:59:01 +00:00
|
|
|
return true;
|
2016-04-10 20:59:07 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-26 11:48:28 +00:00
|
|
|
return false;
|
|
|
|
}();
|
|
|
|
if (!fastSwitchDone) {
|
|
|
|
m->inlineSwitchLayer('@' + bot->username + ' ' + QString::fromUtf8(button->data));
|
2016-04-08 14:16:52 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-29 17:17:00 +00:00
|
|
|
}
|
2016-04-11 10:59:01 +00:00
|
|
|
} break;
|
2019-05-22 14:29:02 +00:00
|
|
|
|
|
|
|
case ButtonType::Auth:
|
|
|
|
UrlAuthBox::Activate(msg, row, column);
|
|
|
|
break;
|
2021-11-05 12:05:11 +00:00
|
|
|
|
|
|
|
case ButtonType::UserProfile: {
|
|
|
|
const auto session = &msg->history()->session();
|
|
|
|
const auto userId = UserId(button->data.toULongLong());
|
|
|
|
if (const auto user = session->data().userLoaded(userId)) {
|
|
|
|
const auto &windows = session->windows();
|
|
|
|
if (!windows.empty()) {
|
|
|
|
windows.front()->showPeerInfo(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
2022-03-24 13:41:59 +00:00
|
|
|
|
|
|
|
case ButtonType::WebView: {
|
2022-03-29 09:00:10 +00:00
|
|
|
if (const auto bot = msg->getMessageBot()) {
|
|
|
|
bot->session().attachWebView().request(
|
|
|
|
bot,
|
|
|
|
bot,
|
|
|
|
{ .text = button->text, .url = button->data });
|
2022-03-28 14:02:54 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case ButtonType::SimpleWebView: {
|
2022-03-29 09:00:10 +00:00
|
|
|
if (const auto bot = msg->getMessageBot()) {
|
|
|
|
bot->session().attachWebView().requestSimple(
|
|
|
|
bot,
|
2022-03-29 09:21:10 +00:00
|
|
|
{ .text = button->text, .url = button->data });
|
2022-03-25 15:35:07 +00:00
|
|
|
}
|
2022-03-24 13:41:59 +00:00
|
|
|
} break;
|
2016-03-28 12:51:22 +00:00
|
|
|
}
|
2016-04-11 10:59:01 +00:00
|
|
|
}
|
2016-03-28 12:51:22 +00:00
|
|
|
|
2016-04-11 10:59:01 +00:00
|
|
|
} // namespace App
|
|
|
|
|
2015-12-07 13:05:00 +00:00
|
|
|
namespace Ui {
|
2015-12-07 18:09:05 +00:00
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
void showPeerProfile(not_null<PeerData*> peer) {
|
|
|
|
if (const auto window = App::wnd()) { // multi good
|
2019-06-06 10:21:40 +00:00
|
|
|
if (const auto controller = window->sessionController()) {
|
2020-06-18 18:04:16 +00:00
|
|
|
if (&controller->session() == &peer->session()) {
|
|
|
|
controller->showPeerInfo(peer);
|
2020-07-02 08:15:21 +00:00
|
|
|
return;
|
2020-06-18 18:04:16 +00:00
|
|
|
}
|
2017-10-03 13:05:58 +00:00
|
|
|
}
|
2020-06-26 11:48:28 +00:00
|
|
|
if (&Core::App().domain().active() != &peer->session().account()) {
|
|
|
|
Core::App().domain().activate(&peer->session().account());
|
|
|
|
}
|
|
|
|
if (const auto controller = window->sessionController()) {
|
|
|
|
if (&controller->session() == &peer->session()) {
|
|
|
|
controller->showPeerInfo(peer);
|
|
|
|
}
|
|
|
|
}
|
2016-05-19 12:03:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
void showPeerProfile(not_null<const History*> history) {
|
2020-06-18 18:04:16 +00:00
|
|
|
showPeerProfile(history->peer);
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
void showChatsList(not_null<Main::Session*> session) {
|
2020-06-26 11:48:28 +00:00
|
|
|
if (const auto m = CheckMainWidget(session)) {
|
|
|
|
m->ui_showPeerHistory(
|
|
|
|
0,
|
2021-02-26 14:38:16 +00:00
|
|
|
::Window::SectionShow::Way::ClearStack,
|
2020-06-26 11:48:28 +00:00
|
|
|
0);
|
2017-09-20 10:23:57 +00:00
|
|
|
}
|
2018-01-11 19:33:26 +00:00
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
void showPeerHistory(not_null<const History*> history, MsgId msgId) {
|
2020-06-10 18:08:17 +00:00
|
|
|
showPeerHistory(history->peer, msgId);
|
2018-01-13 12:45:11 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 18:08:17 +00:00
|
|
|
void showPeerHistory(not_null<const PeerData*> peer, MsgId msgId) {
|
2020-06-26 11:48:28 +00:00
|
|
|
if (const auto m = CheckMainWidget(&peer->session())) {
|
|
|
|
m->ui_showPeerHistory(
|
|
|
|
peer->id,
|
2021-02-26 14:38:16 +00:00
|
|
|
::Window::SectionShow::Way::ClearStack,
|
2020-06-26 11:48:28 +00:00
|
|
|
msgId);
|
2020-06-10 18:08:17 +00:00
|
|
|
}
|
2019-01-04 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
2016-05-12 16:05:20 +00:00
|
|
|
bool skipPaintEvent(QWidget *widget, QPaintEvent *event) {
|
|
|
|
if (auto w = App::wnd()) {
|
|
|
|
if (w->contentOverlapped(widget, event)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-11 10:59:01 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
2015-12-07 13:05:00 +00:00
|
|
|
namespace Notify {
|
|
|
|
|
2020-06-10 18:08:17 +00:00
|
|
|
bool switchInlineBotButtonReceived(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const QString &query,
|
|
|
|
UserData *samePeerBot,
|
|
|
|
MsgId samePeerReplyTo) {
|
2020-06-26 11:48:28 +00:00
|
|
|
if (const auto m = CheckMainWidget(session)) {
|
|
|
|
return m->notify_switchInlineBotButtonReceived(
|
|
|
|
query,
|
|
|
|
samePeerBot,
|
|
|
|
samePeerReplyTo);
|
2016-04-08 14:16:52 +00:00
|
|
|
}
|
2016-04-11 10:59:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-04-08 14:16:52 +00:00
|
|
|
|
2016-04-11 10:59:01 +00:00
|
|
|
} // namespace Notify
|