Removed item for poll creation from menu when it is impossible.

This commit is contained in:
23rd 2024-04-26 18:46:44 +03:00
parent 363c191a6e
commit aff2be605e
1 changed files with 28 additions and 0 deletions

View File

@ -1085,6 +1085,34 @@ void Filler::addViewStatistics() {
}
void Filler::addCreatePoll() {
const auto isJoinChannel = [&] {
if (_request.section != Section::Replies) {
if (const auto c = _peer->asChannel(); c && !c->amIn()) {
return true;
}
}
return false;
}();
const auto isBotStart = [&] {
const auto user = _peer ? _peer->asUser() : nullptr;
if (!user || !user->isBot()) {
return false;
} else if (!user->botInfo->startToken.isEmpty()) {
return true;
}
const auto history = _peer->owner().history(_peer);
if (history && history->isEmpty() && !history->lastMessage()) {
return true;
}
return false;
}();
const auto isBlocked = [&] {
return _peer && _peer->isUser() && _peer->asUser()->isBlocked();
}();
if (isBlocked || isJoinChannel || isBotStart) {
return;
}
const auto can = _topic
? Data::CanSend(_topic, ChatRestriction::SendPolls)
: _peer->canCreatePolls();