mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Add editing of AddedByPhone privacy.
This commit is contained in:
@@ -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>>();
|
||||
|
Reference in New Issue
Block a user