Add editing of AddedByPhone privacy.

This commit is contained in:
John Preston 2019-08-29 11:44:03 +03:00
parent 131ef4f15a
commit 405ccb8580
9 changed files with 128 additions and 11 deletions

View File

@ -631,6 +631,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_edit_privacy_phone_number_always_title" = "Always share with";
"lng_edit_privacy_phone_number_never_title" = "Never share with";
"lng_edit_privacy_phone_number_find" = "Who can find me by my number";
"lng_edit_privacy_phone_number_contacts" = "Users who add your number to their contacts will see it on Telegram only if they are your contacts.";
"lng_edit_privacy_lastseen_title" = "Last seen privacy";
"lng_edit_privacy_lastseen_header" = "Who can see your last seen time";
"lng_edit_privacy_lastseen_warning" = "Important: you won't be able to see Last Seen times for people with whom you don't share your Last Seen time. Approximate last seen will be shown instead (recently, within a week, within a month).";

View File

@ -162,6 +162,8 @@ MTPInputPrivacyKey ApiWrap::Privacy::Input(Key key) {
case Privacy::Key::Calls: return MTP_inputPrivacyKeyPhoneCall();
case Privacy::Key::Invites: return MTP_inputPrivacyKeyChatInvite();
case Privacy::Key::PhoneNumber: return MTP_inputPrivacyKeyPhoneNumber();
case Privacy::Key::AddedByPhone:
return MTP_inputPrivacyKeyAddedByPhone();
case Privacy::Key::LastSeen:
return MTP_inputPrivacyKeyStatusTimestamp();
case Privacy::Key::CallsPeer2Peer:
@ -180,6 +182,8 @@ std::optional<ApiWrap::Privacy::Key> ApiWrap::Privacy::KeyFromMTP(
switch (type) {
case mtpc_privacyKeyPhoneNumber:
case mtpc_inputPrivacyKeyPhoneNumber: return Key::PhoneNumber;
case mtpc_privacyKeyAddedByPhone:
case mtpc_inputPrivacyKeyAddedByPhone: return Key::AddedByPhone;
case mtpc_privacyKeyStatusTimestamp:
case mtpc_inputPrivacyKeyStatusTimestamp: return Key::LastSeen;
case mtpc_privacyKeyChatInvite:

View File

@ -93,6 +93,7 @@ public:
struct Privacy {
enum class Key {
PhoneNumber,
AddedByPhone,
LastSeen,
Calls,
Invites,

View File

@ -250,8 +250,9 @@ bool EditPrivacyBox::showExceptionLink(Exception exception) const {
Unexpected("Invalid exception value.");
}
Ui::Radioenum<EditPrivacyBox::Option> *EditPrivacyBox::addOption(
Ui::Radioenum<EditPrivacyBox::Option> *EditPrivacyBox::AddOption(
not_null<Ui::VerticalLayout*> container,
not_null<EditPrivacyController*> controller,
const std::shared_ptr<Ui::RadioenumGroup<Option>> &group,
Option option) {
return container->add(
@ -259,7 +260,7 @@ Ui::Radioenum<EditPrivacyBox::Option> *EditPrivacyBox::addOption(
container,
group,
option,
_controller->optionLabel(option),
controller->optionLabel(option),
st::settingsSendType),
st::settingsSendTypePadding);
}
@ -306,7 +307,7 @@ void EditPrivacyBox::setupContent() {
const auto addOptionRow = [&](Option option) {
return (_controller->hasOption(option) || (_value.option == option))
? addOption(content, group, option)
? AddOption(content, _controller.get(), group, option)
: nullptr;
};
const auto addExceptionLink = [=](Exception exception) {
@ -345,7 +346,7 @@ void EditPrivacyBox::setupContent() {
auto above = _controller->setupAboveWidget(
content,
std::move(optionValue));
rpl::duplicate(optionValue));
if (above) {
content->add(std::move(above));
}
@ -357,6 +358,14 @@ void EditPrivacyBox::setupContent() {
addLabel(content, _controller->warning());
AddSkip(content);
auto middle = _controller->setupMiddleWidget(
_window,
content,
std::move(optionValue));
if (middle) {
content->add(std::move(middle));
}
AddDivider(content);
AddSkip(content);
AddSubsectionTitle(content, tr::lng_edit_privacy_exceptions());
@ -373,6 +382,7 @@ void EditPrivacyBox::setupContent() {
const auto someAreDisallowed = (_value.option != Option::Everyone)
|| !_value.never.empty();
_controller->confirmSave(someAreDisallowed, crl::guard(this, [=] {
_controller->saveAdditional();
_window->session().api().savePrivacy(
_controller->apiKey(),
collectResult());

View File

@ -58,6 +58,12 @@ public:
rpl::producer<Option> option) {
return { nullptr };
}
[[nodiscard]] virtual object_ptr<Ui::RpWidget> setupMiddleWidget(
not_null<Window::SessionController*> controller,
not_null<QWidget*> parent,
rpl::producer<Option> option) {
return { nullptr };
}
[[nodiscard]] virtual object_ptr<Ui::RpWidget> setupBelowWidget(
not_null<Window::SessionController*> controller,
not_null<QWidget*> parent) {
@ -69,6 +75,8 @@ public:
FnMut<void()> saveCallback) {
saveCallback();
}
virtual void saveAdditional() {
}
virtual ~EditPrivacyController() = default;
@ -100,6 +108,12 @@ public:
std::unique_ptr<EditPrivacyController> controller,
const Value &value);
static Ui::Radioenum<Option> *AddOption(
not_null<Ui::VerticalLayout*> container,
not_null<EditPrivacyController*> controller,
const std::shared_ptr<Ui::RadioenumGroup<Option>> &group,
Option option);
protected:
void prepare() override;
@ -108,10 +122,6 @@ private:
void setupContent();
QVector<MTPInputPrivacyRule> collectResult();
Ui::Radioenum<Option> *addOption(
not_null<Ui::VerticalLayout*> container,
const std::shared_ptr<Ui::RadioenumGroup<Option>> &group,
Option option);
Ui::FlatLabel *addLabel(
not_null<Ui::VerticalLayout*> container,
rpl::producer<QString> text);

View File

@ -22,7 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace HistoryView {
namespace {
constexpr auto kMinimalSchedule = TimeId(30);
constexpr auto kMinimalSchedule = TimeId(10);
tr::phrase<> MonthDay(int index) {
switch (index) {

View File

@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/checkbox.h"
#include "ui/wrap/padding_wrap.h"
#include "ui/wrap/vertical_layout.h"
#include "ui/wrap/slide_wrap.h"
#include "ui/image/image_prepare.h"
#include "window/section_widget.h"
#include "window/window_session_controller.h"
@ -351,7 +352,16 @@ rpl::producer<QString> PhoneNumberPrivacyController::optionsTitleKey() {
}
rpl::producer<QString> PhoneNumberPrivacyController::warning() {
return tr::lng_edit_privacy_phone_number_warning();
using namespace rpl::mappers;
return rpl::combine(
_phoneNumberOption.value(),
_addedByPhone.value(),
(_1 == Option::Nobody) && (_2 != Option::Everyone)
) | rpl::map([](bool onlyContactsSee) {
return onlyContactsSee
? tr::lng_edit_privacy_phone_number_contacts()
: tr::lng_edit_privacy_phone_number_warning();
}) | rpl::flatten_latest();
}
rpl::producer<QString> PhoneNumberPrivacyController::exceptionButtonTextKey(
@ -378,6 +388,69 @@ rpl::producer<QString> PhoneNumberPrivacyController::exceptionsDescription() {
return tr::lng_edit_privacy_phone_number_exceptions();
}
object_ptr<Ui::RpWidget> PhoneNumberPrivacyController::setupMiddleWidget(
not_null<Window::SessionController*> controller,
not_null<QWidget*> parent,
rpl::producer<Option> optionValue) {
const auto key = ApiWrap::Privacy::Key::AddedByPhone;
controller->session().api().reloadPrivacy(key);
_phoneNumberOption = std::move(optionValue);
auto widget = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
parent,
object_ptr<Ui::VerticalLayout>(parent));
const auto container = widget->entity();
AddDivider(container);
AddSkip(container);
AddSubsectionTitle(container, tr::lng_edit_privacy_phone_number_find());
const auto group = std::make_shared<Ui::RadioenumGroup<Option>>();
group->setChangedCallback([=](Option value) {
_addedByPhone = value;
});
controller->session().api().privacyValue(
key
) | rpl::take(
1
) | rpl::start_with_next([=](const ApiWrap::Privacy &value) {
group->setValue(value.option);
}, widget->lifetime());
const auto addOption = [&](Option option) {
return EditPrivacyBox::AddOption(container, this, group, option);
};
addOption(Option::Everyone);
addOption(Option::Contacts);
AddSkip(container);
using namespace rpl::mappers;
widget->toggleOn(_phoneNumberOption.value(
) | rpl::map(
_1 == Option::Nobody
));
_saveAdditional = [=] {
const auto value = [&] {
switch (group->value()) {
case Option::Everyone: return MTP_inputPrivacyValueAllowAll();
default: return MTP_inputPrivacyValueAllowContacts();
}
}();
controller->session().api().savePrivacy(
MTP_inputPrivacyKeyAddedByPhone(),
QVector<MTPInputPrivacyRule>(1, value));
};
return std::move(widget);
}
void PhoneNumberPrivacyController::saveAdditional() {
if (_saveAdditional) {
_saveAdditional();
}
}
LastSeenPrivacyController::LastSeenPrivacyController(
not_null<::Main::Session*> session)
: _session(session) {
@ -427,7 +500,9 @@ rpl::producer<QString> LastSeenPrivacyController::exceptionsDescription() {
return tr::lng_edit_privacy_lastseen_exceptions();
}
void LastSeenPrivacyController::confirmSave(bool someAreDisallowed, FnMut<void()> saveCallback) {
void LastSeenPrivacyController::confirmSave(
bool someAreDisallowed,
FnMut<void()> saveCallback) {
if (someAreDisallowed && !_session->settings().lastSeenWarningSeen()) {
const auto session = _session;
auto weakBox = std::make_shared<QPointer<ConfirmBox>>();

View File

@ -62,6 +62,18 @@ public:
rpl::producer<QString> exceptionBoxTitle(Exception exception) override;
rpl::producer<QString> exceptionsDescription() override;
object_ptr<Ui::RpWidget> setupMiddleWidget(
not_null<Window::SessionController*> controller,
not_null<QWidget*> parent,
rpl::producer<Option> optionValue) override;
void saveAdditional() override;
private:
rpl::variable<Option> _phoneNumberOption = { Option::Contacts };
rpl::variable<Option> _addedByPhone = { Option::Everyone };
Fn<void()> _saveAdditional;
};
class LastSeenPrivacyController : public EditPrivacyController {

View File

@ -173,6 +173,8 @@ void SetupPrivacy(
Key::Invites,
[] { return std::make_unique<GroupsInvitePrivacyController>(); });
session->api().reloadPrivacy(ApiWrap::Privacy::Key::AddedByPhone);
AddSkip(container, st::settingsPrivacySecurityPadding);
AddDividerText(container, tr::lng_settings_group_privacy_about());
}