mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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;
|
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;
|
attachMenuBotsNotModified#f1d88a5c = AttachMenuBots;
|
||||||
attachMenuBots#3c4301c0 hash:long bots:Vector<AttachMenuBot> users:Vector<User> = 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.savedRingtone#b7263f6d = account.SavedRingtone;
|
||||||
account.savedRingtoneConverted#1f307eb7 document:Document = 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---
|
---functions---
|
||||||
|
|
||||||
invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X;
|
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.getAttachMenuBots#16fcc2cb hash:long = AttachMenuBots;
|
||||||
messages.getAttachMenuBot#77216192 bot:InputUser = AttachMenuBotsBot;
|
messages.getAttachMenuBot#77216192 bot:InputUser = AttachMenuBotsBot;
|
||||||
messages.toggleBotInAttachMenu#1aee33af bot:InputUser enabled:Bool = Bool;
|
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.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#d22ad148 flags:# silent:flags.5?true peer:InputPeer bot:InputUser query_id:long reply_to_msg_id:flags.0?int = Bool;
|
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.requestSimpleWebView#6abb2f73 flags:# bot:InputUser url:string theme_params:flags.0?DataJSON = SimpleWebViewResult;
|
||||||
messages.sendWebViewResultMessage#a4314f5 bot_query_id:string result:InputBotInlineResult = WebViewMessageSent;
|
messages.sendWebViewResultMessage#a4314f5 bot_query_id:string result:InputBotInlineResult = WebViewMessageSent;
|
||||||
messages.sendWebViewData#dc0242c8 bot:InputUser random_id:long button_text:string data:string = Updates;
|
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().requestBots();
|
||||||
session().attachWebView().attachBotsUpdates(
|
session().attachWebView().attachBotsUpdates(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
if (session().attachWebView().attachBots().empty()) {
|
refreshAttachBotsMenu();
|
||||||
_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());
|
|
||||||
}
|
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
_botKeyboardShow->addClickHandler([=] { toggleKeyboard(); });
|
_botKeyboardShow->addClickHandler([=] { toggleKeyboard(); });
|
||||||
|
@ -2419,6 +2390,28 @@ void HistoryWidget::setHistory(History *history) {
|
||||||
_migrated = _history ? _history->migrateFrom() : nullptr;
|
_migrated = _history ? _history->migrateFrom() : nullptr;
|
||||||
registerDraftSource();
|
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() {
|
void HistoryWidget::unregisterDraftSources() {
|
||||||
|
|
|
@ -631,6 +631,7 @@ private:
|
||||||
void refreshScheduledToggle();
|
void refreshScheduledToggle();
|
||||||
void setupSendAsToggle();
|
void setupSendAsToggle();
|
||||||
void refreshSendAsToggle();
|
void refreshSendAsToggle();
|
||||||
|
void refreshAttachBotsMenu();
|
||||||
|
|
||||||
bool kbWasHidden() const;
|
bool kbWasHidden() const;
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,25 @@ struct ParsedBot {
|
||||||
return nullptr;
|
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(
|
[[nodiscard]] std::optional<AttachWebViewBot> ParseAttachBot(
|
||||||
not_null<Main::Session*> session,
|
not_null<Main::Session*> session,
|
||||||
const MTPAttachMenuBot &bot) {
|
const MTPAttachMenuBot &bot) {
|
||||||
|
@ -84,6 +103,7 @@ struct ParsedBot {
|
||||||
.user = user,
|
.user = user,
|
||||||
.icon = ResolveIcon(session, data),
|
.icon = ResolveIcon(session, data),
|
||||||
.name = qs(data.vshort_name()),
|
.name = qs(data.vshort_name()),
|
||||||
|
.types = ResolvePeerTypes(data.vpeer_types().v),
|
||||||
.inactive = data.is_inactive(),
|
.inactive = data.is_inactive(),
|
||||||
} : std::optional<AttachWebViewBot>();
|
} : std::optional<AttachWebViewBot>();
|
||||||
});
|
});
|
||||||
|
@ -295,6 +315,22 @@ void BotAction::handleKeyPress(not_null<QKeyEvent*> e) {
|
||||||
|
|
||||||
} // namespace
|
} // 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)
|
AttachWebView::AttachWebView(not_null<Main::Session*> session)
|
||||||
: _session(session) {
|
: _session(session) {
|
||||||
}
|
}
|
||||||
|
@ -368,7 +404,8 @@ void AttachWebView::request(const WebViewButton &button) {
|
||||||
MTP_bytes(button.url),
|
MTP_bytes(button.url),
|
||||||
MTP_string(_startCommand),
|
MTP_string(_startCommand),
|
||||||
MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams().json)),
|
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) {
|
)).done([=](const MTPWebViewResult &result) {
|
||||||
_requestId = 0;
|
_requestId = 0;
|
||||||
result.match([&](const MTPDwebViewResultUrl &data) {
|
result.match([&](const MTPDwebViewResultUrl &data) {
|
||||||
|
@ -589,9 +626,10 @@ void AttachWebView::requestMenu(
|
||||||
_bot->input,
|
_bot->input,
|
||||||
_bot->inputUser,
|
_bot->inputUser,
|
||||||
MTP_string(url),
|
MTP_string(url),
|
||||||
MTPstring(),
|
MTPstring(), // url
|
||||||
MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams().json)),
|
MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams().json)),
|
||||||
MTPint()
|
MTPint(), // reply_to_msg_id
|
||||||
|
MTPInputPeer() // send_as
|
||||||
)).done([=](const MTPWebViewResult &result) {
|
)).done([=](const MTPWebViewResult &result) {
|
||||||
_requestId = 0;
|
_requestId = 0;
|
||||||
result.match([&](const MTPDwebViewResultUrl &data) {
|
result.match([&](const MTPDwebViewResultUrl &data) {
|
||||||
|
@ -713,7 +751,8 @@ void AttachWebView::started(uint64 queryId) {
|
||||||
_peer->input,
|
_peer->input,
|
||||||
_bot->inputUser,
|
_bot->inputUser,
|
||||||
MTP_long(queryId),
|
MTP_long(queryId),
|
||||||
MTP_int(_replyToMsgId.bare)
|
MTP_int(_replyToMsgId.bare),
|
||||||
|
MTPInputPeer() // send_as
|
||||||
)).done([=] {
|
)).done([=] {
|
||||||
_prolongId = 0;
|
_prolongId = 0;
|
||||||
}).send();
|
}).send();
|
||||||
|
@ -764,45 +803,42 @@ void AttachWebView::toggleInMenu(
|
||||||
|
|
||||||
std::unique_ptr<Ui::DropdownMenu> MakeAttachBotsMenu(
|
std::unique_ptr<Ui::DropdownMenu> MakeAttachBotsMenu(
|
||||||
not_null<QWidget*> parent,
|
not_null<QWidget*> parent,
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<PeerData*> peer,
|
||||||
Fn<void(bool)> forceShown,
|
|
||||||
Fn<void(bool)> attach) {
|
Fn<void(bool)> attach) {
|
||||||
auto result = std::make_unique<Ui::DropdownMenu>(
|
auto result = std::make_unique<Ui::DropdownMenu>(
|
||||||
parent,
|
parent,
|
||||||
st::dropdownMenuWithIcons);
|
st::dropdownMenuWithIcons);
|
||||||
const auto bots = &controller->session().attachWebView();
|
const auto bots = &peer->session().attachWebView();
|
||||||
const auto raw = result.get();
|
const auto raw = result.get();
|
||||||
const auto refresh = [=] {
|
raw->addAction(tr::lng_attach_photo_or_video(tr::now), [=] {
|
||||||
raw->clearActions();
|
attach(true);
|
||||||
raw->addAction(tr::lng_attach_photo_or_video(tr::now), [=] {
|
}, &st::menuIconPhoto);
|
||||||
attach(true);
|
raw->addAction(tr::lng_attach_document(tr::now), [=] {
|
||||||
}, &st::menuIconPhoto);
|
attach(false);
|
||||||
raw->addAction(tr::lng_attach_document(tr::now), [=] {
|
}, &st::menuIconFile);
|
||||||
attach(false);
|
for (const auto &bot : bots->attachBots()) {
|
||||||
}, &st::menuIconFile);
|
if (!PeerMatchesTypes(peer, bot.user, bot.types)) {
|
||||||
for (const auto &bot : bots->attachBots()) {
|
continue;
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
};
|
auto action = base::make_unique_q<BotAction>(
|
||||||
refresh();
|
raw,
|
||||||
bots->attachBotsUpdates(
|
raw->menu()->st(),
|
||||||
) | rpl::start_with_next(refresh, raw->lifetime());
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "mtproto/sender.h"
|
#include "mtproto/sender.h"
|
||||||
#include "base/weak_ptr.h"
|
#include "base/weak_ptr.h"
|
||||||
|
#include "base/flags.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class GenericBox;
|
class GenericBox;
|
||||||
|
@ -33,11 +34,26 @@ class DocumentMedia;
|
||||||
|
|
||||||
namespace InlineBots {
|
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 {
|
struct AttachWebViewBot {
|
||||||
not_null<UserData*> user;
|
not_null<UserData*> user;
|
||||||
DocumentData *icon = nullptr;
|
DocumentData *icon = nullptr;
|
||||||
std::shared_ptr<Data::DocumentMedia> media;
|
std::shared_ptr<Data::DocumentMedia> media;
|
||||||
QString name;
|
QString name;
|
||||||
|
PeerTypes types = 0;
|
||||||
bool inactive = false;
|
bool inactive = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -141,8 +157,7 @@ private:
|
||||||
|
|
||||||
[[nodiscard]] std::unique_ptr<Ui::DropdownMenu> MakeAttachBotsMenu(
|
[[nodiscard]] std::unique_ptr<Ui::DropdownMenu> MakeAttachBotsMenu(
|
||||||
not_null<QWidget*> parent,
|
not_null<QWidget*> parent,
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<PeerData*> peer,
|
||||||
Fn<void(bool)> forceShown,
|
|
||||||
Fn<void(bool)> attach);
|
Fn<void(bool)> attach);
|
||||||
|
|
||||||
} // namespace InlineBots
|
} // namespace InlineBots
|
||||||
|
|
Loading…
Add table
Reference in a new issue