diff --git a/Telegram/SourceFiles/data/data_forum_topic.cpp b/Telegram/SourceFiles/data/data_forum_topic.cpp index b2c79c2f9..816cfeab7 100644 --- a/Telegram/SourceFiles/data/data_forum_topic.cpp +++ b/Telegram/SourceFiles/data/data_forum_topic.cpp @@ -223,6 +223,11 @@ bool ForumTopic::canWrite() const { && (!closed() || canToggleClosed()); } +bool ForumTopic::canSendPolls() const { + return canWrite() + && !channel()->amRestricted(ChatRestriction::SendPolls); +} + bool ForumTopic::canEdit() const { return my() || channel()->canManageTopics(); } diff --git a/Telegram/SourceFiles/data/data_forum_topic.h b/Telegram/SourceFiles/data/data_forum_topic.h index 0284971d4..14cab3434 100644 --- a/Telegram/SourceFiles/data/data_forum_topic.h +++ b/Telegram/SourceFiles/data/data_forum_topic.h @@ -65,6 +65,7 @@ public: [[nodiscard]] bool my() const; [[nodiscard]] bool canWrite() const; + [[nodiscard]] bool canSendPolls() const; [[nodiscard]] bool canEdit() const; [[nodiscard]] bool canToggleClosed() const; [[nodiscard]] bool canTogglePinned() const; diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index c8bd3ee3c..2e3788eb4 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -1024,17 +1024,34 @@ void TopBarWidget::updateControlsVisibility() { if (_unreadBadge) { _unreadBadge->setVisible(!_chooseForReportReason); } + const auto topic = _activeChat.key.topic(); const auto section = _activeChat.section; const auto historyMode = (section == Section::History); - const auto hasPollsMenu = _activeChat.key.peer() - && _activeChat.key.peer()->canSendPolls(); + const auto hasPollsMenu = (_activeChat.key.peer() + && _activeChat.key.peer()->canSendPolls()) + || (topic && topic->canSendPolls()); + const auto hasTopicMenu = [&] { + if (!topic) { + return false; + } + auto empty = true; + const auto callback = [&](const Ui::Menu::MenuCallback::Args&) { + empty = false; + return (QAction*)nullptr; + }; + Window::FillDialogsEntryMenu( + _controller, + _activeChat, + Ui::Menu::MenuCallback(callback)); + return !empty; + }(); const auto hasMenu = !_activeChat.key.folder() && (section == Section::History ? true : (section == Section::Scheduled) ? hasPollsMenu : (section == Section::Replies) - ? (hasPollsMenu || _activeChat.key.topic()) + ? (hasPollsMenu || hasTopicMenu) : (section == Section::ChatsList) ? (_activeChat.key.peer() && _activeChat.key.peer()->isForum()) : false); diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index f0c90acce..9e941fdbf 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -937,7 +937,7 @@ void Filler::addManageChat() { } void Filler::addCreatePoll() { - if (!_peer->canSendPolls()) { + if (!(_topic ? _topic->canSendPolls() : _peer->canSendPolls())) { return; } const auto peer = _peer; @@ -1044,7 +1044,6 @@ void Filler::addCreateTopic() { } const auto peer = _peer; const auto controller = _controller; - _addAction(PeerMenuCallback::Args{ .isSeparator = true }); _addAction(tr::lng_forum_create_topic(tr::now), [=] { if (const auto forum = peer->forum()) { controller->show(Box( @@ -1053,6 +1052,7 @@ void Filler::addCreateTopic() { forum->history())); } }, &st::menuIconDiscussion); + _addAction(PeerMenuCallback::Args{ .isSeparator = true }); } void Filler::addViewAsMessages() { @@ -1064,7 +1064,6 @@ void Filler::addViewAsMessages() { _addAction(tr::lng_forum_view_as_messages(tr::now), [=] { controller->showPeerHistory(peer->id); }, &st::menuIconViewReplies); - _addAction(PeerMenuCallback::Args{ .isSeparator = true }); } void Filler::addSearchTopics() { @@ -1083,22 +1082,22 @@ void Filler::fillChatsListActions() { if (!_peer || !_peer->isForum()) { return; } - addViewAsMessages(); - if (FillVideoChatMenu(_controller, _request, _addAction)) { - _addAction(PeerMenuCallback::Args{ .isSeparator = true }); - } + addCreateTopic(); addInfo(); + addViewAsMessages(); + addManageChat(); + FillVideoChatMenu(_controller, _request, _addAction); addNewMembers(); const auto &all = _peer->forum()->topicsList()->indexed()->all(); if (all.size() > kTopicsSearchMinCount) { addSearchTopics(); } + _addAction(PeerMenuCallback::Args{ .isSeparator = true }); if (_peer->asChannel()->amIn()) { addLeaveChat(); } else { addJoinChat(); } - addCreateTopic(); } void Filler::fillContextMenuActions() { @@ -1163,7 +1162,6 @@ void Filler::fillRepliesActions() { if (_topic) { addInfo(); addManageTopic(); - addManageChat(); } addCreatePoll(); addToggleTopicClosed();