2017-03-16 15:15:07 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-03-16 15:15:07 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-03-16 15:15:07 +00:00
|
|
|
*/
|
|
|
|
#include "boxes/edit_privacy_box.h"
|
|
|
|
|
|
|
|
#include "ui/widgets/checkbox.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
2022-03-01 12:30:55 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
2017-09-13 16:57:44 +00:00
|
|
|
#include "ui/wrap/slide_wrap.h"
|
2018-09-19 09:06:21 +00:00
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2017-08-14 12:53:49 +00:00
|
|
|
#include "boxes/peer_list_controllers.h"
|
2018-09-19 09:06:21 +00:00
|
|
|
#include "settings/settings_common.h"
|
2019-05-20 18:40:53 +00:00
|
|
|
#include "settings/settings_privacy_security.h"
|
2018-09-12 17:02:30 +00:00
|
|
|
#include "calls/calls_instance.h"
|
2018-09-11 09:11:52 +00:00
|
|
|
#include "base/binary_guard.h"
|
|
|
|
#include "lang/lang_keys.h"
|
2017-03-17 17:19:46 +00:00
|
|
|
#include "apiwrap.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_user.h"
|
2019-05-20 18:40:53 +00:00
|
|
|
#include "data/data_chat.h"
|
|
|
|
#include "data/data_channel.h"
|
2019-07-24 14:00:30 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2018-09-19 09:06:21 +00:00
|
|
|
#include "styles/style_settings.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
2017-03-16 15:15:07 +00:00
|
|
|
|
2017-03-17 12:05:50 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class PrivacyExceptionsBoxController : public ChatsListBoxController {
|
|
|
|
public:
|
2019-06-18 15:00:55 +00:00
|
|
|
PrivacyExceptionsBoxController(
|
2020-12-21 19:43:23 +00:00
|
|
|
not_null<Main::Session*> session,
|
2019-06-18 15:00:55 +00:00
|
|
|
rpl::producer<QString> title,
|
|
|
|
const std::vector<not_null<PeerData*>> &selected);
|
2019-07-25 18:55:11 +00:00
|
|
|
|
|
|
|
Main::Session &session() const override;
|
2017-08-17 08:31:24 +00:00
|
|
|
void rowClicked(not_null<PeerListRow*> row) override;
|
2017-06-13 21:08:47 +00:00
|
|
|
|
2017-03-17 12:05:50 +00:00
|
|
|
protected:
|
|
|
|
void prepareViewHook() override;
|
2017-08-17 08:31:24 +00:00
|
|
|
std::unique_ptr<Row> createRow(not_null<History*> history) override;
|
2017-03-17 12:05:50 +00:00
|
|
|
|
|
|
|
private:
|
2020-12-21 19:43:23 +00:00
|
|
|
const not_null<Main::Session*> _session;
|
2019-06-18 15:00:55 +00:00
|
|
|
rpl::producer<QString> _title;
|
2019-05-20 18:40:53 +00:00
|
|
|
std::vector<not_null<PeerData*>> _selected;
|
2017-03-17 12:05:50 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-05-20 18:40:53 +00:00
|
|
|
PrivacyExceptionsBoxController::PrivacyExceptionsBoxController(
|
2020-12-21 19:43:23 +00:00
|
|
|
not_null<Main::Session*> session,
|
2019-06-18 15:00:55 +00:00
|
|
|
rpl::producer<QString> title,
|
2019-05-20 18:40:53 +00:00
|
|
|
const std::vector<not_null<PeerData*>> &selected)
|
2020-12-21 19:43:23 +00:00
|
|
|
: ChatsListBoxController(session)
|
|
|
|
, _session(session)
|
2019-07-25 18:55:11 +00:00
|
|
|
, _title(std::move(title))
|
2017-06-13 21:08:47 +00:00
|
|
|
, _selected(selected) {
|
2017-03-17 12:05:50 +00:00
|
|
|
}
|
|
|
|
|
2019-07-25 18:55:11 +00:00
|
|
|
Main::Session &PrivacyExceptionsBoxController::session() const {
|
2020-12-21 19:43:23 +00:00
|
|
|
return *_session;
|
2019-07-25 18:55:11 +00:00
|
|
|
}
|
|
|
|
|
2017-03-17 12:05:50 +00:00
|
|
|
void PrivacyExceptionsBoxController::prepareViewHook() {
|
2019-06-18 15:00:55 +00:00
|
|
|
delegate()->peerListSetTitle(std::move(_title));
|
2020-03-13 13:05:21 +00:00
|
|
|
delegate()->peerListAddSelectedPeers(_selected);
|
2017-06-13 21:08:47 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void PrivacyExceptionsBoxController::rowClicked(not_null<PeerListRow*> row) {
|
2020-11-05 11:58:36 +00:00
|
|
|
const auto peer = row->peer();
|
|
|
|
|
|
|
|
// This call may delete row, if it was a search result row.
|
2017-06-13 21:08:47 +00:00
|
|
|
delegate()->peerListSetRowChecked(row, !row->checked());
|
2020-11-05 11:58:36 +00:00
|
|
|
|
|
|
|
if (const auto channel = peer->asChannel()) {
|
2019-05-20 18:40:53 +00:00
|
|
|
if (!channel->membersCountKnown()) {
|
|
|
|
channel->updateFull();
|
|
|
|
}
|
|
|
|
}
|
2017-03-17 12:05:50 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
std::unique_ptr<PrivacyExceptionsBoxController::Row> PrivacyExceptionsBoxController::createRow(not_null<History*> history) {
|
2020-09-11 15:33:26 +00:00
|
|
|
if (history->peer->isSelf() || history->peer->isRepliesChat()) {
|
2017-08-13 16:14:00 +00:00
|
|
|
return nullptr;
|
2019-05-20 18:40:53 +00:00
|
|
|
} else if (!history->peer->isUser()
|
|
|
|
&& !history->peer->isChat()
|
|
|
|
&& !history->peer->isMegagroup()) {
|
|
|
|
return nullptr;
|
2017-08-13 16:14:00 +00:00
|
|
|
}
|
2019-05-20 18:40:53 +00:00
|
|
|
auto result = std::make_unique<Row>(history);
|
|
|
|
const auto count = [&] {
|
|
|
|
if (const auto chat = history->peer->asChat()) {
|
|
|
|
return chat->count;
|
|
|
|
} else if (const auto channel = history->peer->asChannel()) {
|
|
|
|
return channel->membersCountKnown()
|
|
|
|
? channel->membersCount()
|
|
|
|
: 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}();
|
|
|
|
if (count > 0) {
|
|
|
|
result->setCustomStatus(
|
2019-06-19 16:39:25 +00:00
|
|
|
tr::lng_chat_status_members(tr::now, lt_count_decimal, count));
|
2017-03-17 12:05:50 +00:00
|
|
|
}
|
2019-05-20 18:40:53 +00:00
|
|
|
return result;
|
2017-03-17 12:05:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2023-05-09 15:34:04 +00:00
|
|
|
bool EditPrivacyController::hasOption(Option option) const {
|
|
|
|
return (option != Option::CloseFriends);
|
|
|
|
}
|
|
|
|
|
2022-07-14 20:10:50 +00:00
|
|
|
QString EditPrivacyController::optionLabel(Option option) const {
|
2018-11-16 05:40:42 +00:00
|
|
|
switch (option) {
|
2019-06-19 15:09:03 +00:00
|
|
|
case Option::Everyone: return tr::lng_edit_privacy_everyone(tr::now);
|
|
|
|
case Option::Contacts: return tr::lng_edit_privacy_contacts(tr::now);
|
2023-05-01 06:44:57 +00:00
|
|
|
case Option::CloseFriends:
|
|
|
|
return tr::lng_edit_privacy_close_friends(tr::now);
|
2019-06-19 15:09:03 +00:00
|
|
|
case Option::Nobody: return tr::lng_edit_privacy_nobody(tr::now);
|
2018-11-16 05:40:42 +00:00
|
|
|
}
|
|
|
|
Unexpected("Option value in optionsLabelKey.");
|
|
|
|
}
|
|
|
|
|
2018-09-11 09:11:52 +00:00
|
|
|
EditPrivacyBox::EditPrivacyBox(
|
|
|
|
QWidget*,
|
2019-07-24 14:00:30 +00:00
|
|
|
not_null<Window::SessionController*> window,
|
2019-05-21 12:51:24 +00:00
|
|
|
std::unique_ptr<EditPrivacyController> controller,
|
2018-09-19 09:06:21 +00:00
|
|
|
const Value &value)
|
2019-07-24 14:00:30 +00:00
|
|
|
: _window(window)
|
|
|
|
, _controller(std::move(controller))
|
2018-09-19 09:06:21 +00:00
|
|
|
, _value(value) {
|
2017-03-16 15:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditPrivacyBox::prepare() {
|
|
|
|
_controller->setView(this);
|
|
|
|
|
2018-09-19 09:06:21 +00:00
|
|
|
setupContent();
|
2017-03-19 08:29:05 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 18:40:53 +00:00
|
|
|
void EditPrivacyBox::editExceptions(
|
2018-09-19 09:06:21 +00:00
|
|
|
Exception exception,
|
|
|
|
Fn<void()> done) {
|
|
|
|
auto controller = std::make_unique<PrivacyExceptionsBoxController>(
|
2020-12-21 19:43:23 +00:00
|
|
|
&_window->session(),
|
2019-06-18 15:00:55 +00:00
|
|
|
_controller->exceptionBoxTitle(exception),
|
2019-05-20 18:40:53 +00:00
|
|
|
exceptions(exception));
|
2018-09-19 09:06:21 +00:00
|
|
|
auto initBox = [=, controller = controller.get()](
|
|
|
|
not_null<PeerListBox*> box) {
|
2019-06-18 16:53:27 +00:00
|
|
|
box->addButton(tr::lng_settings_save(), crl::guard(this, [=] {
|
2020-12-21 19:43:23 +00:00
|
|
|
exceptions(exception) = box->collectSelectedRows();
|
2019-05-20 18:40:53 +00:00
|
|
|
const auto type = [&] {
|
2017-06-13 21:08:47 +00:00
|
|
|
switch (exception) {
|
|
|
|
case Exception::Always: return Exception::Never;
|
|
|
|
case Exception::Never: return Exception::Always;
|
|
|
|
}
|
|
|
|
Unexpected("Invalid exception value.");
|
2019-05-20 18:40:53 +00:00
|
|
|
}();
|
|
|
|
auto &removeFrom = exceptions(type);
|
|
|
|
for (const auto peer : exceptions(exception)) {
|
|
|
|
removeFrom.erase(
|
|
|
|
ranges::remove(removeFrom, peer),
|
|
|
|
end(removeFrom));
|
2017-03-17 12:05:50 +00:00
|
|
|
}
|
2018-09-19 09:06:21 +00:00
|
|
|
done();
|
2017-06-13 21:08:47 +00:00
|
|
|
box->closeBox();
|
|
|
|
}));
|
2019-06-18 16:53:27 +00:00
|
|
|
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
2017-06-13 21:08:47 +00:00
|
|
|
};
|
2021-06-13 07:37:52 +00:00
|
|
|
_window->show(
|
2023-05-02 09:33:19 +00:00
|
|
|
Box<PeerListBox>(std::move(controller), std::move(initBox)));
|
2017-03-16 15:15:07 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 18:40:53 +00:00
|
|
|
std::vector<not_null<PeerData*>> &EditPrivacyBox::exceptions(Exception exception) {
|
2017-03-17 12:05:50 +00:00
|
|
|
switch (exception) {
|
2019-05-20 18:40:53 +00:00
|
|
|
case Exception::Always: return _value.always;
|
|
|
|
case Exception::Never: return _value.never;
|
2017-03-17 12:05:50 +00:00
|
|
|
}
|
|
|
|
Unexpected("Invalid exception value.");
|
|
|
|
}
|
|
|
|
|
2018-09-19 09:06:21 +00:00
|
|
|
bool EditPrivacyBox::showExceptionLink(Exception exception) const {
|
2017-03-17 12:05:50 +00:00
|
|
|
switch (exception) {
|
2018-09-19 09:06:21 +00:00
|
|
|
case Exception::Always:
|
|
|
|
return (_value.option == Option::Contacts)
|
2023-05-01 06:44:57 +00:00
|
|
|
|| (_value.option == Option::CloseFriends)
|
2018-09-19 09:06:21 +00:00
|
|
|
|| (_value.option == Option::Nobody);
|
|
|
|
case Exception::Never:
|
|
|
|
return (_value.option == Option::Everyone)
|
2023-05-01 06:44:57 +00:00
|
|
|
|| (_value.option == Option::Contacts)
|
|
|
|
|| (_value.option == Option::CloseFriends);
|
2017-03-17 12:05:50 +00:00
|
|
|
}
|
|
|
|
Unexpected("Invalid exception value.");
|
2017-03-16 15:15:07 +00:00
|
|
|
}
|
|
|
|
|
2019-08-29 08:44:03 +00:00
|
|
|
Ui::Radioenum<EditPrivacyBox::Option> *EditPrivacyBox::AddOption(
|
2018-09-19 09:06:21 +00:00
|
|
|
not_null<Ui::VerticalLayout*> container,
|
2019-08-29 08:44:03 +00:00
|
|
|
not_null<EditPrivacyController*> controller,
|
2018-09-19 09:06:21 +00:00
|
|
|
const std::shared_ptr<Ui::RadioenumGroup<Option>> &group,
|
|
|
|
Option option) {
|
|
|
|
return container->add(
|
|
|
|
object_ptr<Ui::Radioenum<Option>>(
|
|
|
|
container,
|
|
|
|
group,
|
|
|
|
option,
|
2019-08-29 08:44:03 +00:00
|
|
|
controller->optionLabel(option),
|
2022-02-13 13:30:43 +00:00
|
|
|
st::settingsPrivacyOption),
|
|
|
|
(st::settingsSendTypePadding + style::margins(
|
|
|
|
-st::lineWidth,
|
|
|
|
st::settingsPrivacySkipTop,
|
|
|
|
0,
|
|
|
|
0)));
|
2017-03-16 15:15:07 +00:00
|
|
|
}
|
|
|
|
|
2018-11-16 05:40:42 +00:00
|
|
|
Ui::FlatLabel *EditPrivacyBox::addLabel(
|
2018-09-19 09:06:21 +00:00
|
|
|
not_null<Ui::VerticalLayout*> container,
|
2022-03-01 12:30:55 +00:00
|
|
|
rpl::producer<TextWithEntities> text,
|
2022-02-13 13:30:43 +00:00
|
|
|
int topSkip) {
|
|
|
|
if (!text) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2023-04-04 13:17:07 +00:00
|
|
|
auto label = object_ptr<Ui::FlatLabel>(
|
|
|
|
container,
|
|
|
|
rpl::duplicate(text),
|
|
|
|
st::boxDividerLabel);
|
|
|
|
const auto result = label.data();
|
|
|
|
container->add(
|
2022-02-13 13:30:43 +00:00
|
|
|
object_ptr<Ui::DividerLabel>(
|
2018-09-19 09:06:21 +00:00
|
|
|
container,
|
2023-04-04 13:17:07 +00:00
|
|
|
std::move(label),
|
2022-02-13 13:30:43 +00:00
|
|
|
st::settingsDividerLabelPadding),
|
2023-04-04 13:17:07 +00:00
|
|
|
{ 0, topSkip, 0, 0 });
|
|
|
|
return result;
|
2022-02-13 13:30:43 +00:00
|
|
|
}
|
|
|
|
|
2022-03-01 12:30:55 +00:00
|
|
|
Ui::FlatLabel *EditPrivacyBox::addLabelOrDivider(
|
2022-02-13 13:30:43 +00:00
|
|
|
not_null<Ui::VerticalLayout*> container,
|
2022-03-01 12:30:55 +00:00
|
|
|
rpl::producer<TextWithEntities> text,
|
2022-02-13 13:30:43 +00:00
|
|
|
int topSkip) {
|
2022-03-01 12:30:55 +00:00
|
|
|
if (const auto result = addLabel(container, std::move(text), topSkip)) {
|
|
|
|
return result;
|
2022-02-13 13:30:43 +00:00
|
|
|
}
|
2022-03-01 12:30:55 +00:00
|
|
|
container->add(
|
|
|
|
object_ptr<Ui::BoxContentDivider>(container),
|
|
|
|
{ 0, topSkip, 0, 0 });
|
|
|
|
return nullptr;
|
2018-09-19 09:06:21 +00:00
|
|
|
}
|
2017-03-16 15:15:07 +00:00
|
|
|
|
2018-09-19 09:06:21 +00:00
|
|
|
void EditPrivacyBox::setupContent() {
|
|
|
|
using namespace Settings;
|
|
|
|
|
2019-06-18 15:00:55 +00:00
|
|
|
setTitle(_controller->title());
|
2018-09-20 18:25:43 +00:00
|
|
|
|
2018-09-19 09:06:21 +00:00
|
|
|
auto wrap = object_ptr<Ui::VerticalLayout>(this);
|
|
|
|
const auto content = wrap.data();
|
|
|
|
setInnerWidget(object_ptr<Ui::OverrideMargins>(
|
|
|
|
this,
|
|
|
|
std::move(wrap)));
|
|
|
|
|
|
|
|
const auto group = std::make_shared<Ui::RadioenumGroup<Option>>(
|
|
|
|
_value.option);
|
2019-03-19 13:50:36 +00:00
|
|
|
const auto toggle = Ui::CreateChild<rpl::event_stream<Option>>(content);
|
2018-09-19 09:06:21 +00:00
|
|
|
group->setChangedCallback([=](Option value) {
|
|
|
|
_value.option = value;
|
2019-03-19 13:50:36 +00:00
|
|
|
toggle->fire_copy(value);
|
2018-09-19 09:06:21 +00:00
|
|
|
});
|
2019-03-19 13:50:36 +00:00
|
|
|
auto optionValue = toggle->events_starting_with_copy(_value.option);
|
2018-09-19 09:06:21 +00:00
|
|
|
|
2018-11-16 05:40:42 +00:00
|
|
|
const auto addOptionRow = [&](Option option) {
|
2018-09-19 09:06:21 +00:00
|
|
|
return (_controller->hasOption(option) || (_value.option == option))
|
2019-08-29 08:44:03 +00:00
|
|
|
? AddOption(content, _controller.get(), group, option)
|
2018-09-19 09:06:21 +00:00
|
|
|
: nullptr;
|
2017-03-19 08:29:05 +00:00
|
|
|
};
|
2018-09-19 09:06:21 +00:00
|
|
|
const auto addExceptionLink = [=](Exception exception) {
|
2018-11-21 10:09:46 +00:00
|
|
|
const auto update = Ui::CreateChild<rpl::event_stream<>>(content);
|
2022-03-11 05:55:21 +00:00
|
|
|
auto label = update->events_starting_with({}) | rpl::map([=] {
|
2019-05-20 18:40:53 +00:00
|
|
|
return Settings::ExceptionUsersCount(exceptions(exception));
|
2018-09-19 09:06:21 +00:00
|
|
|
}) | rpl::map([](int count) {
|
|
|
|
return count
|
2019-06-19 16:39:25 +00:00
|
|
|
? tr::lng_edit_privacy_exceptions_count(tr::now, lt_count, count)
|
2019-06-19 15:09:03 +00:00
|
|
|
: tr::lng_edit_privacy_exceptions_add(tr::now);
|
2018-09-19 09:06:21 +00:00
|
|
|
});
|
2022-12-19 14:36:02 +00:00
|
|
|
_controller->handleExceptionsChange(
|
|
|
|
exception,
|
|
|
|
update->events_starting_with({}) | rpl::map([=] {
|
|
|
|
return Settings::ExceptionUsersCount(exceptions(exception));
|
|
|
|
}));
|
2018-09-19 09:06:21 +00:00
|
|
|
auto text = _controller->exceptionButtonTextKey(exception);
|
|
|
|
const auto button = content->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Button>>(
|
|
|
|
content,
|
2022-02-13 13:30:43 +00:00
|
|
|
CreateButton(
|
2018-09-19 09:06:21 +00:00
|
|
|
content,
|
2019-06-18 12:16:43 +00:00
|
|
|
rpl::duplicate(text),
|
2023-08-14 12:04:33 +00:00
|
|
|
st::settingsButtonNoIcon)));
|
2018-09-19 09:06:21 +00:00
|
|
|
CreateRightLabel(
|
|
|
|
button->entity(),
|
|
|
|
std::move(label),
|
2023-08-14 12:04:33 +00:00
|
|
|
st::settingsButtonNoIcon,
|
2019-06-18 12:16:43 +00:00
|
|
|
std::move(text));
|
2019-03-19 13:50:36 +00:00
|
|
|
button->toggleOn(rpl::duplicate(
|
|
|
|
optionValue
|
2018-09-19 09:06:21 +00:00
|
|
|
) | rpl::map([=] {
|
|
|
|
return showExceptionLink(exception);
|
|
|
|
}))->entity()->addClickHandler([=] {
|
2019-05-20 18:40:53 +00:00
|
|
|
editExceptions(exception, [=] { update->fire({}); });
|
2018-09-19 09:06:21 +00:00
|
|
|
});
|
|
|
|
return button;
|
2017-03-16 15:15:07 +00:00
|
|
|
};
|
2017-03-19 08:29:05 +00:00
|
|
|
|
2019-03-19 13:50:36 +00:00
|
|
|
auto above = _controller->setupAboveWidget(
|
|
|
|
content,
|
2022-02-13 13:30:43 +00:00
|
|
|
rpl::duplicate(optionValue),
|
|
|
|
getDelegate()->outerContainer());
|
2019-03-19 13:50:36 +00:00
|
|
|
if (above) {
|
|
|
|
content->add(std::move(above));
|
|
|
|
}
|
|
|
|
|
2022-02-13 13:30:43 +00:00
|
|
|
AddSubsectionTitle(
|
|
|
|
content,
|
|
|
|
_controller->optionsTitleKey(),
|
|
|
|
{ 0, st::settingsPrivacySkipTop, 0, 0 });
|
2018-11-16 05:40:42 +00:00
|
|
|
addOptionRow(Option::Everyone);
|
|
|
|
addOptionRow(Option::Contacts);
|
2023-05-01 06:44:57 +00:00
|
|
|
addOptionRow(Option::CloseFriends);
|
2018-11-16 05:40:42 +00:00
|
|
|
addOptionRow(Option::Nobody);
|
2022-03-01 12:30:55 +00:00
|
|
|
const auto warning = addLabelOrDivider(
|
2022-02-13 13:30:43 +00:00
|
|
|
content,
|
|
|
|
_controller->warning(),
|
|
|
|
st::settingsSectionSkip + st::settingsPrivacySkipTop);
|
2022-03-01 12:30:55 +00:00
|
|
|
if (warning) {
|
|
|
|
_controller->prepareWarningLabel(warning);
|
|
|
|
}
|
2018-09-19 09:06:21 +00:00
|
|
|
|
2019-08-29 08:44:03 +00:00
|
|
|
auto middle = _controller->setupMiddleWidget(
|
|
|
|
_window,
|
|
|
|
content,
|
|
|
|
std::move(optionValue));
|
|
|
|
if (middle) {
|
|
|
|
content->add(std::move(middle));
|
|
|
|
}
|
|
|
|
|
2018-09-19 09:06:21 +00:00
|
|
|
AddSkip(content);
|
2022-02-13 13:30:43 +00:00
|
|
|
AddSubsectionTitle(
|
|
|
|
content,
|
|
|
|
tr::lng_edit_privacy_exceptions(),
|
|
|
|
{ 0, st::settingsPrivacySkipTop, 0, 0 });
|
2018-09-19 09:06:21 +00:00
|
|
|
const auto always = addExceptionLink(Exception::Always);
|
|
|
|
const auto never = addExceptionLink(Exception::Never);
|
2022-02-13 13:30:43 +00:00
|
|
|
addLabel(
|
|
|
|
content,
|
2022-03-01 12:30:55 +00:00
|
|
|
_controller->exceptionsDescription() | Ui::Text::ToWithEntities(),
|
2022-02-13 13:30:43 +00:00
|
|
|
st::settingsSectionSkip);
|
2018-09-19 09:06:21 +00:00
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
if (auto below = _controller->setupBelowWidget(_window, content)) {
|
2019-05-21 12:51:24 +00:00
|
|
|
content->add(std::move(below));
|
|
|
|
}
|
|
|
|
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(tr::lng_settings_save(), [=] {
|
2018-09-19 09:06:21 +00:00
|
|
|
const auto someAreDisallowed = (_value.option != Option::Everyone)
|
2019-05-20 18:40:53 +00:00
|
|
|
|| !_value.never.empty();
|
2018-09-19 09:06:21 +00:00
|
|
|
_controller->confirmSave(someAreDisallowed, crl::guard(this, [=] {
|
2021-07-31 14:11:53 +00:00
|
|
|
_value.ignoreAlways = !showExceptionLink(Exception::Always);
|
|
|
|
_value.ignoreNever = !showExceptionLink(Exception::Never);
|
|
|
|
|
2019-08-29 08:44:03 +00:00
|
|
|
_controller->saveAdditional();
|
2021-07-31 14:11:53 +00:00
|
|
|
_window->session().api().userPrivacy().save(
|
|
|
|
_controller->key(),
|
|
|
|
_value);
|
2017-03-17 18:44:55 +00:00
|
|
|
closeBox();
|
|
|
|
}));
|
2017-03-17 17:19:46 +00:00
|
|
|
});
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(tr::lng_cancel(), [this] { closeBox(); });
|
2017-03-19 08:29:05 +00:00
|
|
|
|
2023-08-14 12:04:33 +00:00
|
|
|
const auto linkHeight = st::settingsButtonNoIcon.padding.top()
|
|
|
|
+ st::settingsButtonNoIcon.height
|
|
|
|
+ st::settingsButtonNoIcon.padding.bottom();
|
2018-09-19 09:06:21 +00:00
|
|
|
|
|
|
|
widthValue(
|
|
|
|
) | rpl::start_with_next([=](int width) {
|
|
|
|
content->resizeToWidth(width);
|
|
|
|
}, content->lifetime());
|
|
|
|
|
|
|
|
content->heightValue(
|
|
|
|
) | rpl::map([=](int height) {
|
|
|
|
return height - always->height() - never->height() + 2 * linkHeight;
|
|
|
|
}) | rpl::distinct_until_changed(
|
|
|
|
) | rpl::start_with_next([=](int height) {
|
|
|
|
setDimensions(st::boxWideWidth, height);
|
|
|
|
}, content->lifetime());
|
2018-09-12 17:02:30 +00:00
|
|
|
}
|