mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Update API scheme on layer 142.
This commit is contained in:
parent
877be8e6cb
commit
8890f263af
5 changed files with 123 additions and 72 deletions
|
@ -1342,7 +1342,7 @@ attachMenuBotIconColor#4576f3f0 name:string color:int = AttachMenuBotIconColor;
|
|||
|
||||
attachMenuBotIcon#b2a7386b flags:# name:string icon:Document colors:flags.0?Vector<AttachMenuBotIconColor> = AttachMenuBotIcon;
|
||||
|
||||
attachMenuBot#e93cb772 flags:# inactive:flags.0?true bot_id:long short_name:string icons:Vector<AttachMenuBotIcon> = AttachMenuBot;
|
||||
attachMenuBot#c8aa2cd2 flags:# inactive:flags.0?true bot_id:long short_name:string peer_types:Vector<AttachMenuPeerType> icons:Vector<AttachMenuBotIcon> = AttachMenuBot;
|
||||
|
||||
attachMenuBotsNotModified#f1d88a5c = AttachMenuBots;
|
||||
attachMenuBots#3c4301c0 hash:long bots:Vector<AttachMenuBot> users:Vector<User> = AttachMenuBots;
|
||||
|
@ -1370,6 +1370,12 @@ notificationSoundRingtone#ff6c8049 id:long = NotificationSound;
|
|||
account.savedRingtone#b7263f6d = account.SavedRingtone;
|
||||
account.savedRingtoneConverted#1f307eb7 document:Document = account.SavedRingtone;
|
||||
|
||||
attachMenuPeerTypeSameBotPM#7d6be90e = AttachMenuPeerType;
|
||||
attachMenuPeerTypeBotPM#c32bfa1a = AttachMenuPeerType;
|
||||
attachMenuPeerTypePM#f146d31f = AttachMenuPeerType;
|
||||
attachMenuPeerTypeChat#509113f = AttachMenuPeerType;
|
||||
attachMenuPeerTypeBroadcast#7bfbdefc = AttachMenuPeerType;
|
||||
|
||||
---functions---
|
||||
|
||||
invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X;
|
||||
|
@ -1665,8 +1671,8 @@ messages.searchSentMedia#107e31a0 q:string filter:MessagesFilter limit:int = mes
|
|||
messages.getAttachMenuBots#16fcc2cb hash:long = AttachMenuBots;
|
||||
messages.getAttachMenuBot#77216192 bot:InputUser = AttachMenuBotsBot;
|
||||
messages.toggleBotInAttachMenu#1aee33af bot:InputUser enabled:Bool = Bool;
|
||||
messages.requestWebView#fa04dff flags:# from_bot_menu:flags.4?true silent:flags.5?true peer:InputPeer bot:InputUser url:flags.1?string start_param:flags.3?string theme_params:flags.2?DataJSON reply_to_msg_id:flags.0?int = WebViewResult;
|
||||
messages.prolongWebView#d22ad148 flags:# silent:flags.5?true peer:InputPeer bot:InputUser query_id:long reply_to_msg_id:flags.0?int = Bool;
|
||||
messages.requestWebView#91b15831 flags:# from_bot_menu:flags.4?true silent:flags.5?true peer:InputPeer bot:InputUser url:flags.1?string start_param:flags.3?string theme_params:flags.2?DataJSON reply_to_msg_id:flags.0?int send_as:flags.13?InputPeer = WebViewResult;
|
||||
messages.prolongWebView#ea5fbcce flags:# silent:flags.5?true peer:InputPeer bot:InputUser query_id:long reply_to_msg_id:flags.0?int send_as:flags.13?InputPeer = Bool;
|
||||
messages.requestSimpleWebView#6abb2f73 flags:# bot:InputUser url:string theme_params:flags.0?DataJSON = SimpleWebViewResult;
|
||||
messages.sendWebViewResultMessage#a4314f5 bot_query_id:string result:InputBotInlineResult = WebViewMessageSent;
|
||||
messages.sendWebViewData#dc0242c8 bot:InputUser random_id:long button_text:string data:string = Updates;
|
||||
|
|
|
@ -484,36 +484,7 @@ HistoryWidget::HistoryWidget(
|
|||
session().attachWebView().requestBots();
|
||||
session().attachWebView().attachBotsUpdates(
|
||||
) | rpl::start_with_next([=] {
|
||||
if (session().attachWebView().attachBots().empty()) {
|
||||
_attachBotsMenu = nullptr;
|
||||
return;
|
||||
} else if (!_attachBotsMenu) {
|
||||
const auto forceShown = [=](bool shown) {
|
||||
if (shown) {
|
||||
_attachBotsMenu->setAutoHiding(false);
|
||||
} else {
|
||||
_attachBotsMenu->hideAnimated();
|
||||
_attachBotsMenu->setAutoHiding(true);
|
||||
}
|
||||
};
|
||||
const auto attach = [=](bool compress) {
|
||||
chooseAttach(compress);
|
||||
};
|
||||
_attachBotsMenu = InlineBots::MakeAttachBotsMenu(
|
||||
this,
|
||||
controller,
|
||||
forceShown,
|
||||
attach);
|
||||
_attachBotsMenu->setOrigin(
|
||||
Ui::PanelAnimation::Origin::BottomLeft);
|
||||
if (_history && _history->peer->isUser()) {
|
||||
_attachToggle->installEventFilter(_attachBotsMenu.get());
|
||||
}
|
||||
_attachBotsMenu->heightValue(
|
||||
) | rpl::start_with_next([=] {
|
||||
moveFieldControls();
|
||||
}, _attachBotsMenu->lifetime());
|
||||
}
|
||||
refreshAttachBotsMenu();
|
||||
}, lifetime());
|
||||
|
||||
_botKeyboardShow->addClickHandler([=] { toggleKeyboard(); });
|
||||
|
@ -2419,6 +2390,28 @@ void HistoryWidget::setHistory(History *history) {
|
|||
_migrated = _history ? _history->migrateFrom() : nullptr;
|
||||
registerDraftSource();
|
||||
}
|
||||
refreshAttachBotsMenu();
|
||||
}
|
||||
|
||||
void HistoryWidget::refreshAttachBotsMenu() {
|
||||
_attachBotsMenu = nullptr;
|
||||
if (!_history) {
|
||||
return;
|
||||
}
|
||||
_attachBotsMenu = InlineBots::MakeAttachBotsMenu(
|
||||
this,
|
||||
_history->peer,
|
||||
[=](bool compress) { chooseAttach(compress); });
|
||||
if (!_attachBotsMenu) {
|
||||
return;
|
||||
}
|
||||
_attachBotsMenu->setOrigin(
|
||||
Ui::PanelAnimation::Origin::BottomLeft);
|
||||
_attachToggle->installEventFilter(_attachBotsMenu.get());
|
||||
_attachBotsMenu->heightValue(
|
||||
) | rpl::start_with_next([=] {
|
||||
moveFieldControls();
|
||||
}, _attachBotsMenu->lifetime());
|
||||
}
|
||||
|
||||
void HistoryWidget::unregisterDraftSources() {
|
||||
|
|
|
@ -631,6 +631,7 @@ private:
|
|||
void refreshScheduledToggle();
|
||||
void setupSendAsToggle();
|
||||
void refreshSendAsToggle();
|
||||
void refreshAttachBotsMenu();
|
||||
|
||||
bool kbWasHidden() const;
|
||||
|
||||
|
|
|
@ -71,6 +71,25 @@ struct ParsedBot {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
[[nodiscard]] PeerTypes ResolvePeerTypes(
|
||||
const QVector<MTPAttachMenuPeerType> &types) {
|
||||
auto result = PeerTypes();
|
||||
for (const auto &type : types) {
|
||||
result |= type.match([&](const MTPDattachMenuPeerTypeSameBotPM &) {
|
||||
return PeerType::SameBot;
|
||||
}, [&](const MTPDattachMenuPeerTypeBotPM &) {
|
||||
return PeerType::Bot;
|
||||
}, [&](const MTPDattachMenuPeerTypePM &) {
|
||||
return PeerType::User;
|
||||
}, [&](const MTPDattachMenuPeerTypeChat &) {
|
||||
return PeerType::Group;
|
||||
}, [&](const MTPDattachMenuPeerTypeBroadcast &) {
|
||||
return PeerType::Broadcast;
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::optional<AttachWebViewBot> ParseAttachBot(
|
||||
not_null<Main::Session*> session,
|
||||
const MTPAttachMenuBot &bot) {
|
||||
|
@ -84,6 +103,7 @@ struct ParsedBot {
|
|||
.user = user,
|
||||
.icon = ResolveIcon(session, data),
|
||||
.name = qs(data.vshort_name()),
|
||||
.types = ResolvePeerTypes(data.vpeer_types().v),
|
||||
.inactive = data.is_inactive(),
|
||||
} : std::optional<AttachWebViewBot>();
|
||||
});
|
||||
|
@ -295,6 +315,22 @@ void BotAction::handleKeyPress(not_null<QKeyEvent*> e) {
|
|||
|
||||
} // namespace
|
||||
|
||||
bool PeerMatchesTypes(
|
||||
not_null<PeerData*> peer,
|
||||
not_null<UserData*> bot,
|
||||
PeerTypes types) {
|
||||
if (const auto user = peer->asUser()) {
|
||||
return (user == bot)
|
||||
? (types & PeerType::SameBot)
|
||||
: user->isBot()
|
||||
? (types & PeerType::Bot)
|
||||
: (types & PeerType::User);
|
||||
} else if (peer->isBroadcast()) {
|
||||
return (types & PeerType::Broadcast);
|
||||
}
|
||||
return (types & PeerType::Group);
|
||||
}
|
||||
|
||||
AttachWebView::AttachWebView(not_null<Main::Session*> session)
|
||||
: _session(session) {
|
||||
}
|
||||
|
@ -368,7 +404,8 @@ void AttachWebView::request(const WebViewButton &button) {
|
|||
MTP_bytes(button.url),
|
||||
MTP_string(_startCommand),
|
||||
MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams().json)),
|
||||
MTPint() // reply_to_msg_id
|
||||
MTPint(), // reply_to_msg_id
|
||||
MTPInputPeer() // send_as
|
||||
)).done([=](const MTPWebViewResult &result) {
|
||||
_requestId = 0;
|
||||
result.match([&](const MTPDwebViewResultUrl &data) {
|
||||
|
@ -589,9 +626,10 @@ void AttachWebView::requestMenu(
|
|||
_bot->input,
|
||||
_bot->inputUser,
|
||||
MTP_string(url),
|
||||
MTPstring(),
|
||||
MTPstring(), // url
|
||||
MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams().json)),
|
||||
MTPint()
|
||||
MTPint(), // reply_to_msg_id
|
||||
MTPInputPeer() // send_as
|
||||
)).done([=](const MTPWebViewResult &result) {
|
||||
_requestId = 0;
|
||||
result.match([&](const MTPDwebViewResultUrl &data) {
|
||||
|
@ -713,7 +751,8 @@ void AttachWebView::started(uint64 queryId) {
|
|||
_peer->input,
|
||||
_bot->inputUser,
|
||||
MTP_long(queryId),
|
||||
MTP_int(_replyToMsgId.bare)
|
||||
MTP_int(_replyToMsgId.bare),
|
||||
MTPInputPeer() // send_as
|
||||
)).done([=] {
|
||||
_prolongId = 0;
|
||||
}).send();
|
||||
|
@ -764,45 +803,42 @@ void AttachWebView::toggleInMenu(
|
|||
|
||||
std::unique_ptr<Ui::DropdownMenu> MakeAttachBotsMenu(
|
||||
not_null<QWidget*> parent,
|
||||
not_null<Window::SessionController*> controller,
|
||||
Fn<void(bool)> forceShown,
|
||||
not_null<PeerData*> peer,
|
||||
Fn<void(bool)> attach) {
|
||||
auto result = std::make_unique<Ui::DropdownMenu>(
|
||||
parent,
|
||||
st::dropdownMenuWithIcons);
|
||||
const auto bots = &controller->session().attachWebView();
|
||||
const auto bots = &peer->session().attachWebView();
|
||||
const auto raw = result.get();
|
||||
const auto refresh = [=] {
|
||||
raw->clearActions();
|
||||
raw->addAction(tr::lng_attach_photo_or_video(tr::now), [=] {
|
||||
attach(true);
|
||||
}, &st::menuIconPhoto);
|
||||
raw->addAction(tr::lng_attach_document(tr::now), [=] {
|
||||
attach(false);
|
||||
}, &st::menuIconFile);
|
||||
for (const auto &bot : bots->attachBots()) {
|
||||
const auto callback = [=] {
|
||||
const auto active = controller->activeChatCurrent();
|
||||
if (const auto history = active.history()) {
|
||||
bots->request(nullptr, history->peer, bot.user, {});
|
||||
}
|
||||
};
|
||||
auto action = base::make_unique_q<BotAction>(
|
||||
raw,
|
||||
raw->menu()->st(),
|
||||
bot,
|
||||
callback);
|
||||
action->forceShown(
|
||||
) | rpl::start_with_next([=](bool shown) {
|
||||
forceShown(shown);
|
||||
}, action->lifetime());
|
||||
raw->addAction(std::move(action));
|
||||
raw->addAction(tr::lng_attach_photo_or_video(tr::now), [=] {
|
||||
attach(true);
|
||||
}, &st::menuIconPhoto);
|
||||
raw->addAction(tr::lng_attach_document(tr::now), [=] {
|
||||
attach(false);
|
||||
}, &st::menuIconFile);
|
||||
for (const auto &bot : bots->attachBots()) {
|
||||
if (!PeerMatchesTypes(peer, bot.user, bot.types)) {
|
||||
continue;
|
||||
}
|
||||
};
|
||||
refresh();
|
||||
bots->attachBotsUpdates(
|
||||
) | rpl::start_with_next(refresh, raw->lifetime());
|
||||
|
||||
auto action = base::make_unique_q<BotAction>(
|
||||
raw,
|
||||
raw->menu()->st(),
|
||||
bot,
|
||||
[=] { bots->request(nullptr, peer, bot.user, {}); });
|
||||
action->forceShown(
|
||||
) | rpl::start_with_next([=](bool shown) {
|
||||
if (shown) {
|
||||
raw->setAutoHiding(false);
|
||||
} else {
|
||||
raw->hideAnimated();
|
||||
raw->setAutoHiding(true);
|
||||
}
|
||||
}, action->lifetime());
|
||||
raw->addAction(std::move(action));
|
||||
}
|
||||
if (raw->actions().size() < 3) {
|
||||
return nullptr;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "mtproto/sender.h"
|
||||
#include "base/weak_ptr.h"
|
||||
#include "base/flags.h"
|
||||
|
||||
namespace Ui {
|
||||
class GenericBox;
|
||||
|
@ -33,11 +34,26 @@ class DocumentMedia;
|
|||
|
||||
namespace InlineBots {
|
||||
|
||||
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);
|
||||
|
||||
struct AttachWebViewBot {
|
||||
not_null<UserData*> user;
|
||||
DocumentData *icon = nullptr;
|
||||
std::shared_ptr<Data::DocumentMedia> media;
|
||||
QString name;
|
||||
PeerTypes types = 0;
|
||||
bool inactive = false;
|
||||
};
|
||||
|
||||
|
@ -141,8 +157,7 @@ private:
|
|||
|
||||
[[nodiscard]] std::unique_ptr<Ui::DropdownMenu> MakeAttachBotsMenu(
|
||||
not_null<QWidget*> parent,
|
||||
not_null<Window::SessionController*> controller,
|
||||
Fn<void(bool)> forceShown,
|
||||
not_null<PeerData*> peer,
|
||||
Fn<void(bool)> attach);
|
||||
|
||||
} // namespace InlineBots
|
||||
|
|
Loading…
Add table
Reference in a new issue