From 346daee42112c092e9bc4a67418ecad31f2fd90d Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 17 Mar 2017 19:19:57 +0300 Subject: [PATCH] Edit groups and channels invite privacy. --- Telegram/Resources/langs/lang.strings | 11 +++++ .../SourceFiles/boxes/edit_privacy_box.cpp | 5 +-- Telegram/SourceFiles/boxes/peer_list_box.cpp | 5 +++ .../settings/settings_privacy_controllers.cpp | 45 +++++++++++++++++++ .../settings/settings_privacy_controllers.h | 17 +++++++ .../settings/settings_privacy_widget.cpp | 5 +++ .../settings/settings_privacy_widget.h | 2 + 7 files changed, 87 insertions(+), 3 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 01e38917d..569dcd888 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -406,6 +406,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org "lng_settings_blocked_users" = "Blocked users"; "lng_settings_last_seen_privacy" = "Last seen privacy"; +"lng_settings_groups_invite_privacy" = "Groups invite privacy"; "lng_settings_show_sessions" = "Show all sessions"; "lng_settings_reset" = "Terminate all other sessions"; "lng_settings_reset_sure" = "Are you sure you want to terminate\nall other sessions?"; @@ -456,6 +457,16 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org "lng_edit_privacy_lastseen_always_title" = "Always share with"; "lng_edit_privacy_lastseen_never_title" = "Never share with"; +"lng_edit_privacy_groups_title" = "Group invite privacy"; +"lng_edit_privacy_groups_everyone" = "Anyone can invite me to groups and channels"; +"lng_edit_privacy_groups_contacts" = "Only contacts can invite me to groups and channels"; +"lng_edit_privacy_groups_description" = "You can restrict who can add you to groups and channels with granular precision."; +"lng_edit_privacy_groups_always" = "Always allow{count:| # user| # users}"; +"lng_edit_privacy_groups_never" = "Never allow{count:| # user| # users}"; +"lng_edit_privacy_groups_exceptions" = "These users will or will not be able to add you to groups and channels regardless of the settings above."; +"lng_edit_privacy_groups_always_title" = "Always allow"; +"lng_edit_privacy_groups_never_title" = "Never allow"; + "lng_preview_loading" = "Getting Link Info..."; "lng_profile_chat_unaccessible" = "Group is inaccessible"; diff --git a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp index f73834e83..6b4a8506e 100644 --- a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp @@ -74,7 +74,6 @@ void PrivacyExceptionsBoxController::prepareViewHook() { void PrivacyExceptionsBoxController::rowClicked(PeerListBox::Row *row) { view()->setRowChecked(row, !row->checked()); - view()->updateRow(row); } std::unique_ptr PrivacyExceptionsBoxController::createRow(History *history) { @@ -190,12 +189,12 @@ int EditPrivacyBox::countDefaultHeight(int newWidth) { auto value = static_cast(Option::Everyone); auto selected = false; auto fake = object_ptr(nullptr, value, selected, label, description); - fake->resizeToWidth(newWidth); + fake->resizeToNaturalWidth(newWidth - st::editPrivacyOptionMargin.left() - st::editPrivacyOptionMargin.right()); return st::editPrivacyOptionMargin.top() + fake->heightNoMargins() + st::editPrivacyOptionMargin.bottom(); }; auto labelHeight = [this, newWidth](const QString &text, const style::FlatLabel &st) { auto fake = object_ptr(nullptr, text, Ui::FlatLabel::InitType::Simple, st); - fake->resizeToWidth(newWidth); + fake->resizeToNaturalWidth(newWidth - st::editPrivacyPadding.left() - st::editPrivacyPadding.right()); return st::editPrivacyPadding.top() + fake->heightNoMargins() + st::editPrivacyPadding.bottom(); }; auto linkMargins = exceptionLinkMargins(); diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index af07862b2..49822c0e6 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -141,9 +141,14 @@ void PeerListBox::setRowChecked(Row *row, bool checked) { if (checked) { addSelectItem(peer, Row::SetStyle::Animated); _inner->changeCheckState(row, checked, Row::SetStyle::Animated); + updateRow(row); + + // This call deletes row from _globalSearchRows. + _select->entity()->clearQuery(); } else { // The itemRemovedCallback will call changeCheckState() here. _select->entity()->removeItem(peer->id); + updateRow(row); } } diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index d36186015..b46410e8e 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -265,4 +265,49 @@ QString LastSeenPrivacyController::exceptionsDescription() { return lang(lng_edit_privacy_lastseen_exceptions); } +MTPInputPrivacyKey GroupsInvitePrivacyController::key() { + return MTP_inputPrivacyKeyChatInvite(); +} + +void GroupsInvitePrivacyController::save(QVector &&result) { + MTP::send(MTPaccount_SetPrivacy(MTP_inputPrivacyKeyChatInvite(), MTP_vector(result))); + view()->closeBox(); +} + +QString GroupsInvitePrivacyController::title() { + return lang(lng_edit_privacy_groups_title); +} + +QString GroupsInvitePrivacyController::optionDescription(Option option) { + switch (option) { + case Option::Everyone: return lang(lng_edit_privacy_groups_everyone); + case Option::Contacts: return lang(lng_edit_privacy_groups_contacts); + } + return QString(); +} + +QString GroupsInvitePrivacyController::description() { + return lang(lng_edit_privacy_groups_description); +} + +QString GroupsInvitePrivacyController::exceptionLinkText(Exception exception, int count) { + switch (exception) { + case Exception::Always: return lng_edit_privacy_groups_always(lt_count, count); + case Exception::Never: return lng_edit_privacy_groups_never(lt_count, count); + } + Unexpected("Invalid exception value."); +} + +QString GroupsInvitePrivacyController::exceptionBoxTitle(Exception exception) { + switch (exception) { + case Exception::Always: return lang(lng_edit_privacy_groups_always_title); + case Exception::Never: return lang(lng_edit_privacy_groups_never_title); + } + Unexpected("Invalid exception value."); +} + +QString GroupsInvitePrivacyController::exceptionsDescription() { + return lang(lng_edit_privacy_groups_exceptions); +} + } // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.h b/Telegram/SourceFiles/settings/settings_privacy_controllers.h index cd20c8ef4..c1ac68581 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.h +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.h @@ -64,4 +64,21 @@ public: }; +class GroupsInvitePrivacyController : public EditPrivacyBox::Controller, private base::Subscriber { +public: + using Option = EditPrivacyBox::Option; + using Exception = EditPrivacyBox::Exception; + + MTPInputPrivacyKey key() override; + void save(QVector &&result) override; + + QString title() override; + QString optionDescription(Option option) override; + QString description() override; + QString exceptionLinkText(Exception exception, int count) override; + QString exceptionBoxTitle(Exception exception) override; + QString exceptionsDescription() override; + +}; + } // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_privacy_widget.cpp b/Telegram/SourceFiles/settings/settings_privacy_widget.cpp index e84e888d6..0e2a71611 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_widget.cpp @@ -175,6 +175,7 @@ void PrivacyWidget::createControls() { addChildRow(_blockedUsers, marginSmall, lang(lng_settings_blocked_users), SLOT(onBlockedUsers())); addChildRow(_lastSeenPrivacy, marginSmall, lang(lng_settings_last_seen_privacy), SLOT(onLastSeenPrivacy())); + addChildRow(_groupsInvitePrivacy, marginSmall, lang(lng_settings_groups_invite_privacy), SLOT(onGroupsInvitePrivacy())); addChildRow(_localPasscodeState, marginSmall); auto label = lang(psIdleSupported() ? lng_passcode_autolock_away : lng_passcode_autolock_inactive); auto value = (Global::AutoLock() % 3600) ? lng_passcode_autolock_minutes(lt_count, Global::AutoLock() / 60) : lng_passcode_autolock_hours(lt_count, Global::AutoLock() / 3600); @@ -203,6 +204,10 @@ void PrivacyWidget::onLastSeenPrivacy() { Ui::show(Box(std::make_unique())); } +void PrivacyWidget::onGroupsInvitePrivacy() { + Ui::show(Box(std::make_unique())); +} + void PrivacyWidget::onAutoLock() { Ui::show(Box()); } diff --git a/Telegram/SourceFiles/settings/settings_privacy_widget.h b/Telegram/SourceFiles/settings/settings_privacy_widget.h index eb8a0511c..2288c32ba 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_widget.h +++ b/Telegram/SourceFiles/settings/settings_privacy_widget.h @@ -87,6 +87,7 @@ public: private slots: void onBlockedUsers(); void onLastSeenPrivacy(); + void onGroupsInvitePrivacy(); void onAutoLock(); void onShowSessions(); @@ -96,6 +97,7 @@ private: object_ptr _blockedUsers = { nullptr }; object_ptr _lastSeenPrivacy = { nullptr }; + object_ptr _groupsInvitePrivacy = { nullptr }; object_ptr _localPasscodeState = { nullptr }; object_ptr> _autoLock = { nullptr }; object_ptr _cloudPasswordState = { nullptr };