Disable creating public polls in channels.

This commit is contained in:
John Preston 2020-01-13 14:18:15 +03:00
parent aac6d0df27
commit d72d1aabe6
3 changed files with 23 additions and 8 deletions

View File

@ -712,8 +712,10 @@ void Options::checkLastOption() {
CreatePollBox::CreatePollBox( CreatePollBox::CreatePollBox(
QWidget*, QWidget*,
not_null<Main::Session*> session, not_null<Main::Session*> session,
PublicVotes publicVotes,
Api::SendType sendType) Api::SendType sendType)
: _session(session) : _session(session)
, _publicVotes(publicVotes)
, _sendType(sendType) { , _sendType(sendType) {
} }
@ -813,13 +815,15 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
AddSkip(container); AddSkip(container);
AddSubsectionTitle(container, tr::lng_polls_create_settings()); AddSubsectionTitle(container, tr::lng_polls_create_settings());
const auto anonymous = container->add( const auto anonymous = (_publicVotes == PublicVotes::Enabled)
object_ptr<Ui::Checkbox>( ? container->add(
container, object_ptr<Ui::Checkbox>(
tr::lng_polls_create_anonymous(tr::now), container,
true, tr::lng_polls_create_anonymous(tr::now),
st::defaultCheckbox), true,
st::createPollCheckboxMargin); st::defaultCheckbox),
st::createPollCheckboxMargin)
: nullptr;
const auto multiple = container->add( const auto multiple = container->add(
object_ptr<Ui::Checkbox>( object_ptr<Ui::Checkbox>(
container, container,
@ -873,7 +877,9 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
auto result = PollData(&_session->data(), id); auto result = PollData(&_session->data(), id);
result.question = question->getLastText().trimmed(); result.question = question->getLastText().trimmed();
result.answers = options->toPollAnswers(); result.answers = options->toPollAnswers();
result.setFlags((anonymous->checked() ? Flag(0) : Flag::PublicVotes) const auto publicVotes = (anonymous && !anonymous->checked());
result.setFlags(Flag(0)
| (publicVotes ? Flag::PublicVotes : Flag(0))
| (multiple->checked() ? Flag::MultiChoice : Flag(0)) | (multiple->checked() ? Flag::MultiChoice : Flag(0))
| (quiz->checked() ? Flag::Quiz : Flag(0))); | (quiz->checked() ? Flag::Quiz : Flag(0)));
return result; return result;

View File

@ -27,10 +27,15 @@ public:
PollData poll; PollData poll;
Api::SendOptions options; Api::SendOptions options;
}; };
enum class PublicVotes {
Enabled,
Disabled,
};
CreatePollBox( CreatePollBox(
QWidget*, QWidget*,
not_null<Main::Session*> session, not_null<Main::Session*> session,
PublicVotes publicVotes,
Api::SendType sendType); Api::SendType sendType);
rpl::producer<Result> submitRequests() const; rpl::producer<Result> submitRequests() const;
@ -47,6 +52,7 @@ private:
not_null<Ui::VerticalLayout*> container); not_null<Ui::VerticalLayout*> container);
const not_null<Main::Session*> _session; const not_null<Main::Session*> _session;
const PublicVotes _publicVotes = PublicVotes();
const Api::SendType _sendType = Api::SendType(); const Api::SendType _sendType = Api::SendType();
Fn<void()> _setInnerFocus; Fn<void()> _setInnerFocus;
Fn<rpl::producer<bool>()> _dataIsValidValue; Fn<rpl::producer<bool>()> _dataIsValidValue;

View File

@ -710,6 +710,9 @@ void PeerMenuShareContactBox(
void PeerMenuCreatePoll(not_null<PeerData*> peer) { void PeerMenuCreatePoll(not_null<PeerData*> peer) {
const auto box = Ui::show(Box<CreatePollBox>( const auto box = Ui::show(Box<CreatePollBox>(
&peer->session(), &peer->session(),
((peer->isChannel() && !peer->isMegagroup())
? CreatePollBox::PublicVotes::Disabled
: CreatePollBox::PublicVotes::Enabled),
Api::SendType::Normal)); Api::SendType::Normal));
const auto lock = box->lifetime().make_state<bool>(false); const auto lock = box->lifetime().make_state<bool>(false);
box->submitRequests( box->submitRequests(