mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Check restrictions in attach menu bots.
This commit is contained in:
parent
36bf54b0d1
commit
6834cdb969
2 changed files with 29 additions and 8 deletions
|
@ -491,7 +491,13 @@ HistoryWidget::HistoryWidget(
|
|||
_botCommandStart->hide();
|
||||
|
||||
session().attachWebView().requestBots();
|
||||
session().attachWebView().attachBotsUpdates(
|
||||
rpl::merge(
|
||||
session().attachWebView().attachBotsUpdates(),
|
||||
session().changes().peerUpdates(
|
||||
Data::PeerUpdate::Flag::Rights
|
||||
) | rpl::filter([=](const Data::PeerUpdate &update) {
|
||||
return update.peer == _peer;
|
||||
}) | rpl::to_empty
|
||||
) | rpl::start_with_next([=] {
|
||||
refreshAttachBotsMenu();
|
||||
}, lifetime());
|
||||
|
|
|
@ -1044,17 +1044,32 @@ std::unique_ptr<Ui::DropdownMenu> MakeAttachBotsMenu(
|
|||
not_null<PeerData*> peer,
|
||||
Fn<Api::SendAction()> actionFactory,
|
||||
Fn<void(bool)> attach) {
|
||||
if (!Data::CanSend(peer, ChatRestriction::SendInline)) {
|
||||
return nullptr;
|
||||
}
|
||||
auto result = std::make_unique<Ui::DropdownMenu>(
|
||||
parent,
|
||||
st::dropdownMenuWithIcons);
|
||||
const auto bots = &peer->session().attachWebView();
|
||||
const auto raw = result.get();
|
||||
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);
|
||||
auto minimal = 0;
|
||||
if (Data::CanSend(peer, ChatRestriction::SendPhotos, false)) {
|
||||
++minimal;
|
||||
raw->addAction(tr::lng_attach_photo_or_video(tr::now), [=] {
|
||||
attach(true);
|
||||
}, &st::menuIconPhoto);
|
||||
}
|
||||
const auto fileTypes = ChatRestriction::SendVideos
|
||||
| ChatRestriction::SendGifs
|
||||
| ChatRestriction::SendStickers
|
||||
| ChatRestriction::SendMusic
|
||||
| ChatRestriction::SendFiles;
|
||||
if (Data::CanSendAnyOf(peer, fileTypes)) {
|
||||
++minimal;
|
||||
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;
|
||||
|
@ -1082,7 +1097,7 @@ std::unique_ptr<Ui::DropdownMenu> MakeAttachBotsMenu(
|
|||
}, action->lifetime());
|
||||
raw->addAction(std::move(action));
|
||||
}
|
||||
if (raw->actions().size() < 3) {
|
||||
if (raw->actions().size() <= minimal) {
|
||||
return nullptr;
|
||||
}
|
||||
return result;
|
||||
|
|
Loading…
Add table
Reference in a new issue