mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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();
|
_botCommandStart->hide();
|
||||||
|
|
||||||
session().attachWebView().requestBots();
|
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([=] {
|
) | rpl::start_with_next([=] {
|
||||||
refreshAttachBotsMenu();
|
refreshAttachBotsMenu();
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
|
@ -1044,17 +1044,32 @@ std::unique_ptr<Ui::DropdownMenu> MakeAttachBotsMenu(
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
Fn<Api::SendAction()> actionFactory,
|
Fn<Api::SendAction()> actionFactory,
|
||||||
Fn<void(bool)> attach) {
|
Fn<void(bool)> attach) {
|
||||||
|
if (!Data::CanSend(peer, ChatRestriction::SendInline)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
auto result = std::make_unique<Ui::DropdownMenu>(
|
auto result = std::make_unique<Ui::DropdownMenu>(
|
||||||
parent,
|
parent,
|
||||||
st::dropdownMenuWithIcons);
|
st::dropdownMenuWithIcons);
|
||||||
const auto bots = &peer->session().attachWebView();
|
const auto bots = &peer->session().attachWebView();
|
||||||
const auto raw = result.get();
|
const auto raw = result.get();
|
||||||
raw->addAction(tr::lng_attach_photo_or_video(tr::now), [=] {
|
auto minimal = 0;
|
||||||
attach(true);
|
if (Data::CanSend(peer, ChatRestriction::SendPhotos, false)) {
|
||||||
}, &st::menuIconPhoto);
|
++minimal;
|
||||||
raw->addAction(tr::lng_attach_document(tr::now), [=] {
|
raw->addAction(tr::lng_attach_photo_or_video(tr::now), [=] {
|
||||||
attach(false);
|
attach(true);
|
||||||
}, &st::menuIconFile);
|
}, &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()) {
|
for (const auto &bot : bots->attachBots()) {
|
||||||
if (!PeerMatchesTypes(peer, bot.user, bot.types)) {
|
if (!PeerMatchesTypes(peer, bot.user, bot.types)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -1082,7 +1097,7 @@ std::unique_ptr<Ui::DropdownMenu> MakeAttachBotsMenu(
|
||||||
}, action->lifetime());
|
}, action->lifetime());
|
||||||
raw->addAction(std::move(action));
|
raw->addAction(std::move(action));
|
||||||
}
|
}
|
||||||
if (raw->actions().size() < 3) {
|
if (raw->actions().size() <= minimal) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Add table
Reference in a new issue