Fix polls forwarding to private chats.

This commit is contained in:
John Preston 2023-02-07 16:28:59 +04:00
parent d7aa18cb0a
commit d889cd0e72
7 changed files with 23 additions and 27 deletions

View File

@ -96,7 +96,7 @@ ChatRestrictions TabbedPanelSendRestrictions() {
// Duplicated in CanSendAnyOfValue().
bool CanSendAnyOf(
not_null<Thread*> thread,
not_null<const Thread*> thread,
ChatRestrictions rights,
bool forbidInForums) {
const auto peer = thread->peer();
@ -107,7 +107,7 @@ bool CanSendAnyOf(
// Duplicated in CanSendAnyOfValue().
bool CanSendAnyOf(
not_null<PeerData*> peer,
not_null<const PeerData*> peer,
ChatRestrictions rights,
bool forbidInForums) {
if (const auto user = peer->asUser()) {

View File

@ -131,43 +131,43 @@ struct RestrictionsSetOptions {
[[nodiscard]] ChatRestrictions TabbedPanelSendRestrictions();
[[nodiscard]] bool CanSendAnyOf(
not_null<Thread*> thread,
not_null<const Thread*> thread,
ChatRestrictions rights,
bool forbidInForums = true);
[[nodiscard]] bool CanSendAnyOf(
not_null<PeerData*> peer,
not_null<const PeerData*> peer,
ChatRestrictions rights,
bool forbidInForums = true);
[[nodiscard]] inline bool CanSend(
not_null<Thread*> thread,
not_null<const Thread*> thread,
ChatRestriction right,
bool forbidInForums = true) {
return CanSendAnyOf(thread, right, forbidInForums);
}
[[nodiscard]] inline bool CanSend(
not_null<PeerData*> peer,
not_null<const PeerData*> peer,
ChatRestriction right,
bool forbidInForums = true) {
return CanSendAnyOf(peer, right, forbidInForums);
}
[[nodiscard]] inline bool CanSendTexts(
not_null<Thread*> thread,
not_null<const Thread*> thread,
bool forbidInForums = true) {
return CanSend(thread, ChatRestriction::SendOther, forbidInForums);
}
[[nodiscard]] inline bool CanSendTexts(
not_null<PeerData*> peer,
not_null<const PeerData*> peer,
bool forbidInForums = true) {
return CanSend(peer, ChatRestriction::SendOther, forbidInForums);
}
[[nodiscard]] inline bool CanSendAnything(
not_null<Thread*> thread,
not_null<const Thread*> thread,
bool forbidInForums = true) {
return CanSendAnyOf(thread, AllSendRestrictions(), forbidInForums);
}
[[nodiscard]] inline bool CanSendAnything(
not_null<PeerData*> peer,
not_null<const PeerData*> peer,
bool forbidInForums = true) {
return CanSendAnyOf(peer, AllSendRestrictions(), forbidInForums);
}

View File

@ -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()

View File

@ -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;

View File

@ -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;

View File

@ -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) {

View File

@ -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;
}