2022-03-29 09:00:10 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "mtproto/sender.h"
|
|
|
|
#include "base/weak_ptr.h"
|
2022-04-28 12:16:26 +00:00
|
|
|
#include "base/flags.h"
|
2022-03-29 09:00:10 +00:00
|
|
|
|
2023-03-01 13:27:13 +00:00
|
|
|
namespace Api {
|
|
|
|
struct SendAction;
|
|
|
|
} // namespace Api
|
|
|
|
|
2022-03-29 09:00:10 +00:00
|
|
|
namespace Ui {
|
|
|
|
class GenericBox;
|
2022-03-29 12:13:54 +00:00
|
|
|
class DropdownMenu;
|
2022-03-29 09:00:10 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
|
|
|
namespace Ui::BotWebView {
|
|
|
|
class Panel;
|
|
|
|
} // namespace Ui::BotWebView
|
|
|
|
|
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
2022-03-29 12:13:54 +00:00
|
|
|
namespace Window {
|
|
|
|
class SessionController;
|
|
|
|
} // namespace Window
|
|
|
|
|
2022-03-29 14:14:11 +00:00
|
|
|
namespace Data {
|
|
|
|
class DocumentMedia;
|
|
|
|
} // namespace Data
|
|
|
|
|
2022-03-29 09:00:10 +00:00
|
|
|
namespace InlineBots {
|
|
|
|
|
2022-04-28 12:16:26 +00:00
|
|
|
enum class PeerType : uint8 {
|
|
|
|
SameBot = 0x01,
|
|
|
|
Bot = 0x02,
|
|
|
|
User = 0x04,
|
|
|
|
Group = 0x08,
|
|
|
|
Broadcast = 0x10,
|
|
|
|
};
|
|
|
|
using PeerTypes = base::flags<PeerType>;
|
|
|
|
|
|
|
|
[[nodiscard]] bool PeerMatchesTypes(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
not_null<UserData*> bot,
|
|
|
|
PeerTypes types);
|
2022-06-10 13:38:52 +00:00
|
|
|
[[nodiscard]] PeerTypes ParseChooseTypes(QStringView choose);
|
2022-04-28 12:16:26 +00:00
|
|
|
|
2022-03-29 12:13:54 +00:00
|
|
|
struct AttachWebViewBot {
|
|
|
|
not_null<UserData*> user;
|
2022-03-31 09:24:13 +00:00
|
|
|
DocumentData *icon = nullptr;
|
2022-03-29 14:14:11 +00:00
|
|
|
std::shared_ptr<Data::DocumentMedia> media;
|
2022-03-29 12:13:54 +00:00
|
|
|
QString name;
|
2022-04-28 12:16:26 +00:00
|
|
|
PeerTypes types = 0;
|
2022-03-29 14:14:11 +00:00
|
|
|
bool inactive = false;
|
2022-06-03 16:07:33 +00:00
|
|
|
bool hasSettings = false;
|
2022-12-21 08:06:54 +00:00
|
|
|
bool requestWriteAccess = false;
|
2022-03-29 12:13:54 +00:00
|
|
|
};
|
|
|
|
|
2022-03-29 09:00:10 +00:00
|
|
|
class AttachWebView final : public base::has_weak_ptr {
|
|
|
|
public:
|
|
|
|
explicit AttachWebView(not_null<Main::Session*> session);
|
|
|
|
~AttachWebView();
|
|
|
|
|
|
|
|
struct WebViewButton {
|
|
|
|
QString text;
|
2022-03-31 09:24:13 +00:00
|
|
|
QString startCommand;
|
2022-03-29 09:00:10 +00:00
|
|
|
QByteArray url;
|
2022-12-20 16:43:19 +00:00
|
|
|
bool fromMenu = false;
|
2023-03-01 13:27:13 +00:00
|
|
|
bool fromSwitch = false;
|
2022-03-29 09:00:10 +00:00
|
|
|
};
|
2022-03-31 09:24:13 +00:00
|
|
|
void request(
|
2023-03-01 13:27:13 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2022-10-28 07:57:09 +00:00
|
|
|
const Api::SendAction &action,
|
2022-03-31 09:24:13 +00:00
|
|
|
const QString &botUsername,
|
|
|
|
const QString &startCommand);
|
2022-03-29 09:00:10 +00:00
|
|
|
void request(
|
2023-03-01 13:27:13 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2022-10-28 07:57:09 +00:00
|
|
|
const Api::SendAction &action,
|
2022-03-29 09:00:10 +00:00
|
|
|
not_null<UserData*> bot,
|
2022-03-31 09:24:13 +00:00
|
|
|
const WebViewButton &button);
|
2022-03-29 09:21:10 +00:00
|
|
|
void requestSimple(
|
2022-04-06 07:45:51 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2022-03-29 09:21:10 +00:00
|
|
|
not_null<UserData*> bot,
|
|
|
|
const WebViewButton &button);
|
2022-04-07 12:16:43 +00:00
|
|
|
void requestMenu(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<UserData*> bot);
|
2023-03-03 08:35:49 +00:00
|
|
|
void requestApp(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
const Api::SendAction &action,
|
|
|
|
not_null<UserData*> bot,
|
|
|
|
const QString &appName,
|
|
|
|
const QString &startParam,
|
|
|
|
bool forceConfirmation);
|
2022-03-29 09:00:10 +00:00
|
|
|
|
|
|
|
void cancel();
|
2022-03-29 10:34:57 +00:00
|
|
|
|
2022-03-29 12:13:54 +00:00
|
|
|
void requestBots();
|
|
|
|
[[nodiscard]] const std::vector<AttachWebViewBot> &attachBots() const {
|
|
|
|
return _attachBots;
|
|
|
|
}
|
|
|
|
[[nodiscard]] rpl::producer<> attachBotsUpdates() const {
|
|
|
|
return _attachBotsUpdates.events();
|
|
|
|
}
|
|
|
|
|
2022-03-31 09:24:13 +00:00
|
|
|
void requestAddToMenu(
|
2023-03-01 13:27:13 +00:00
|
|
|
not_null<UserData*> bot,
|
|
|
|
const QString &startCommand);
|
|
|
|
void requestAddToMenu(
|
2022-03-31 09:24:13 +00:00
|
|
|
not_null<UserData*> bot,
|
2022-06-02 20:26:41 +00:00
|
|
|
const QString &startCommand,
|
2023-03-01 13:27:13 +00:00
|
|
|
Window::SessionController *controller,
|
|
|
|
std::optional<Api::SendAction> action,
|
|
|
|
PeerTypes chooseTypes);
|
2022-03-29 14:14:11 +00:00
|
|
|
void removeFromMenu(not_null<UserData*> bot);
|
|
|
|
|
2022-03-29 10:34:57 +00:00
|
|
|
static void ClearAll();
|
|
|
|
|
|
|
|
private:
|
2023-03-01 13:27:13 +00:00
|
|
|
struct Context;
|
|
|
|
|
|
|
|
[[nodiscard]] static Context LookupContext(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
const Api::SendAction &action);
|
|
|
|
[[nodiscard]] static bool IsSame(
|
|
|
|
const std::unique_ptr<Context> &a,
|
|
|
|
const Context &b);
|
|
|
|
|
|
|
|
void requestWithOptionalConfirm(
|
|
|
|
not_null<UserData*> bot,
|
|
|
|
const WebViewButton &button,
|
|
|
|
const Context &context,
|
|
|
|
Window::SessionController *controllerForConfirm = nullptr);
|
|
|
|
|
2022-03-29 09:00:10 +00:00
|
|
|
void resolve();
|
2022-03-31 09:24:13 +00:00
|
|
|
void request(const WebViewButton &button);
|
2022-04-06 07:45:51 +00:00
|
|
|
void requestSimple(const WebViewButton &button);
|
2022-03-29 09:00:10 +00:00
|
|
|
void resolveUsername(
|
|
|
|
const QString &username,
|
|
|
|
Fn<void(not_null<PeerData*>)> done);
|
|
|
|
|
2022-04-06 07:45:51 +00:00
|
|
|
void confirmOpen(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
Fn<void()> done);
|
|
|
|
|
2022-12-21 08:06:54 +00:00
|
|
|
enum class ToggledState {
|
|
|
|
Removed,
|
|
|
|
Added,
|
|
|
|
AllowedToWrite,
|
|
|
|
};
|
2022-03-29 14:14:11 +00:00
|
|
|
void toggleInMenu(
|
|
|
|
not_null<UserData*> bot,
|
2022-12-21 08:06:54 +00:00
|
|
|
ToggledState state,
|
2022-03-29 16:12:47 +00:00
|
|
|
Fn<void()> callback = nullptr);
|
2022-03-29 09:00:10 +00:00
|
|
|
|
|
|
|
void show(
|
|
|
|
uint64 queryId,
|
|
|
|
const QString &url,
|
2022-12-20 16:43:19 +00:00
|
|
|
const QString &buttonText = QString(),
|
2023-01-12 08:18:25 +00:00
|
|
|
bool allowClipboardRead = false);
|
2022-03-29 14:14:11 +00:00
|
|
|
void confirmAddToMenu(
|
|
|
|
AttachWebViewBot bot,
|
|
|
|
Fn<void()> callback = nullptr);
|
2023-03-03 08:35:49 +00:00
|
|
|
void confirmAppOpen(bool requestWriteAccess);
|
|
|
|
void requestAppView(bool allowWrite);
|
2022-03-29 10:34:57 +00:00
|
|
|
void started(uint64 queryId);
|
2022-03-29 09:00:10 +00:00
|
|
|
|
2023-03-03 08:35:49 +00:00
|
|
|
void showToast(
|
|
|
|
const QString &text,
|
|
|
|
Window::SessionController *controller = nullptr);
|
|
|
|
|
2022-03-29 09:00:10 +00:00
|
|
|
const not_null<Main::Session*> _session;
|
|
|
|
|
2023-03-01 13:27:13 +00:00
|
|
|
std::unique_ptr<Context> _context;
|
2022-03-29 09:00:10 +00:00
|
|
|
UserData *_bot = nullptr;
|
|
|
|
QString _botUsername;
|
2023-03-03 08:35:49 +00:00
|
|
|
QString _botAppName;
|
2022-03-31 09:24:13 +00:00
|
|
|
QString _startCommand;
|
2023-03-03 08:35:49 +00:00
|
|
|
BotAppData *_app = nullptr;
|
2022-03-29 09:00:10 +00:00
|
|
|
QPointer<Ui::GenericBox> _confirmAddBox;
|
|
|
|
|
|
|
|
mtpRequestId _requestId = 0;
|
2022-03-29 10:34:57 +00:00
|
|
|
mtpRequestId _prolongId = 0;
|
2022-03-29 09:00:10 +00:00
|
|
|
|
2022-03-29 12:13:54 +00:00
|
|
|
uint64 _botsHash = 0;
|
|
|
|
mtpRequestId _botsRequestId = 0;
|
|
|
|
|
2023-03-01 13:27:13 +00:00
|
|
|
std::unique_ptr<Context> _addToMenuContext;
|
2022-03-29 14:14:11 +00:00
|
|
|
UserData *_addToMenuBot = nullptr;
|
|
|
|
mtpRequestId _addToMenuId = 0;
|
2022-03-31 09:24:13 +00:00
|
|
|
QString _addToMenuStartCommand;
|
2022-06-02 20:26:41 +00:00
|
|
|
base::weak_ptr<Window::SessionController> _addToMenuChooseController;
|
|
|
|
PeerTypes _addToMenuChooseTypes;
|
2022-03-29 14:14:11 +00:00
|
|
|
|
2022-03-29 12:13:54 +00:00
|
|
|
std::vector<AttachWebViewBot> _attachBots;
|
|
|
|
rpl::event_stream<> _attachBotsUpdates;
|
|
|
|
|
2022-03-29 09:00:10 +00:00
|
|
|
std::unique_ptr<Ui::BotWebView::Panel> _panel;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-03-29 12:13:54 +00:00
|
|
|
[[nodiscard]] std::unique_ptr<Ui::DropdownMenu> MakeAttachBotsMenu(
|
|
|
|
not_null<QWidget*> parent,
|
2023-03-01 13:27:13 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2022-04-28 12:16:26 +00:00
|
|
|
not_null<PeerData*> peer,
|
2022-10-28 07:57:09 +00:00
|
|
|
Fn<Api::SendAction()> actionFactory,
|
2022-04-05 06:49:55 +00:00
|
|
|
Fn<void(bool)> attach);
|
2022-03-29 12:13:54 +00:00
|
|
|
|
2022-03-29 09:00:10 +00:00
|
|
|
} // namespace InlineBots
|