From d889cd0e72b2a589bf1e06c27f5b37c8bdb9ebc7 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 7 Feb 2023 16:28:59 +0400 Subject: [PATCH] Fix polls forwarding to private chats. --- .../data/data_chat_participant_status.cpp | 4 ++-- .../data/data_chat_participant_status.h | 16 ++++++++-------- Telegram/SourceFiles/data/data_peer.cpp | 12 ++++++++---- Telegram/SourceFiles/data/data_peer.h | 1 + Telegram/SourceFiles/data/data_peer_values.cpp | 10 +--------- .../history/view/history_view_top_bar_widget.cpp | 2 +- Telegram/SourceFiles/window/window_peer_menu.cpp | 5 ++--- 7 files changed, 23 insertions(+), 27 deletions(-) diff --git a/Telegram/SourceFiles/data/data_chat_participant_status.cpp b/Telegram/SourceFiles/data/data_chat_participant_status.cpp index 0a4922989..af45ba79c 100644 --- a/Telegram/SourceFiles/data/data_chat_participant_status.cpp +++ b/Telegram/SourceFiles/data/data_chat_participant_status.cpp @@ -96,7 +96,7 @@ ChatRestrictions TabbedPanelSendRestrictions() { // Duplicated in CanSendAnyOfValue(). bool CanSendAnyOf( - not_null thread, + not_null thread, ChatRestrictions rights, bool forbidInForums) { const auto peer = thread->peer(); @@ -107,7 +107,7 @@ bool CanSendAnyOf( // Duplicated in CanSendAnyOfValue(). bool CanSendAnyOf( - not_null peer, + not_null peer, ChatRestrictions rights, bool forbidInForums) { if (const auto user = peer->asUser()) { diff --git a/Telegram/SourceFiles/data/data_chat_participant_status.h b/Telegram/SourceFiles/data/data_chat_participant_status.h index 30dba03bf..2227e8042 100644 --- a/Telegram/SourceFiles/data/data_chat_participant_status.h +++ b/Telegram/SourceFiles/data/data_chat_participant_status.h @@ -131,43 +131,43 @@ struct RestrictionsSetOptions { [[nodiscard]] ChatRestrictions TabbedPanelSendRestrictions(); [[nodiscard]] bool CanSendAnyOf( - not_null thread, + not_null thread, ChatRestrictions rights, bool forbidInForums = true); [[nodiscard]] bool CanSendAnyOf( - not_null peer, + not_null peer, ChatRestrictions rights, bool forbidInForums = true); [[nodiscard]] inline bool CanSend( - not_null thread, + not_null thread, ChatRestriction right, bool forbidInForums = true) { return CanSendAnyOf(thread, right, forbidInForums); } [[nodiscard]] inline bool CanSend( - not_null peer, + not_null peer, ChatRestriction right, bool forbidInForums = true) { return CanSendAnyOf(peer, right, forbidInForums); } [[nodiscard]] inline bool CanSendTexts( - not_null thread, + not_null thread, bool forbidInForums = true) { return CanSend(thread, ChatRestriction::SendOther, forbidInForums); } [[nodiscard]] inline bool CanSendTexts( - not_null peer, + not_null peer, bool forbidInForums = true) { return CanSend(peer, ChatRestriction::SendOther, forbidInForums); } [[nodiscard]] inline bool CanSendAnything( - not_null thread, + not_null thread, bool forbidInForums = true) { return CanSendAnyOf(thread, AllSendRestrictions(), forbidInForums); } [[nodiscard]] inline bool CanSendAnything( - not_null peer, + not_null peer, bool forbidInForums = true) { return CanSendAnyOf(peer, AllSendRestrictions(), forbidInForums); } diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index e5c36129e..560736b46 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "data/data_chat.h" +#include "data/data_chat_participant_status.h" #include "data/data_channel.h" #include "data/data_changes.h" #include "data/data_photo.h" @@ -475,6 +476,13 @@ bool PeerData::canPinMessages() const { Unexpected("Peer type in PeerData::canPinMessages."); } +bool PeerData::canCreatePolls() const { + if (const auto user = asUser()) { + return user->isBot() && !user->isSupport(); + } + return Data::CanSend(this, ChatRestriction::SendPolls); +} + bool PeerData::canCreateTopics() const { if (const auto channel = asChannel()) { return channel->isForum() @@ -940,10 +948,6 @@ Data::RestrictionCheckResult PeerData::amRestricted( ? ((user->flags() & UserDataFlag::VoiceMessagesForbidden) ? Result::Explicit() : Result::Allowed()) - : (right == ChatRestriction::SendPolls) - ? ((!user->isBot() || user->isSupport()) - ? Result::Explicit() - : Result::Allowed()) : (right == ChatRestriction::PinMessages) ? ((user->flags() & UserDataFlag::CanPinMessages) ? Result::Allowed() diff --git a/Telegram/SourceFiles/data/data_peer.h b/Telegram/SourceFiles/data/data_peer.h index 3d966d1a3..1940e573b 100644 --- a/Telegram/SourceFiles/data/data_peer.h +++ b/Telegram/SourceFiles/data/data_peer.h @@ -317,6 +317,7 @@ public: [[nodiscard]] bool canPinMessages() const; [[nodiscard]] bool canEditMessagesIndefinitely() const; + [[nodiscard]] bool canCreatePolls() const; [[nodiscard]] bool canCreateTopics() const; [[nodiscard]] bool canManageTopics() const; [[nodiscard]] bool canExportChatHistory() const; diff --git a/Telegram/SourceFiles/data/data_peer_values.cpp b/Telegram/SourceFiles/data/data_peer_values.cpp index c7622ea24..1670afa8f 100644 --- a/Telegram/SourceFiles/data/data_peer_values.cpp +++ b/Telegram/SourceFiles/data/data_peer_values.cpp @@ -215,19 +215,11 @@ inline auto DefaultRestrictionValue( return rpl::single(false); } using namespace rpl::mappers; - const auto other = rights & ~(ChatRestriction::SendPolls - | ChatRestriction::SendVoiceMessages + const auto other = rights & ~(ChatRestriction::SendVoiceMessages | ChatRestriction::SendVideoMessages); if (other) { return PeerFlagValue(user, UserDataFlag::Deleted) | rpl::map(!_1); - } else if (rights & ChatRestriction::SendPolls) { - if (CanSend(user, ChatRestriction::SendPolls)) { - return PeerFlagValue(user, UserDataFlag::Deleted) - | rpl::map(!_1); - } else if (rights == ChatRestriction::SendPolls) { - return rpl::single(false); - } } const auto mask = UserDataFlag::Deleted | UserDataFlag::VoiceMessagesForbidden; 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 edcf5d785..917b49a3c 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -1033,7 +1033,7 @@ void TopBarWidget::updateControlsVisibility() { const auto section = _activeChat.section; const auto historyMode = (section == Section::History); const auto hasPollsMenu = (_activeChat.key.peer() - && Data::CanSend(_activeChat.key.peer(), ChatRestriction::SendPolls)) + && _activeChat.key.peer()->canCreatePolls()) || (topic && Data::CanSend(topic, ChatRestriction::SendPolls)); const auto hasTopicMenu = [&] { if (!topic || section != Section::Replies) { diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 2e00071fa..7dceba837 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -991,10 +991,9 @@ void Filler::addManageChat() { } void Filler::addCreatePoll() { - constexpr auto kRight = ChatRestriction::SendPolls; const auto can = _topic - ? Data::CanSend(_topic, kRight) - : Data::CanSend(_peer, kRight); + ? Data::CanSend(_topic, ChatRestriction::SendPolls) + : _peer->canCreatePolls(); if (!can) { return; }