Show "Hide read time" only on non-trivial privacy.

This commit is contained in:
John Preston 2024-01-16 16:53:46 +04:00
parent 5daa5a00f0
commit 3710d61a09
5 changed files with 49 additions and 10 deletions

View file

@ -1108,7 +1108,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_edit_privacy_lastseen_always_title" = "Always share with"; "lng_edit_privacy_lastseen_always_title" = "Always share with";
"lng_edit_privacy_lastseen_never_title" = "Never share with"; "lng_edit_privacy_lastseen_never_title" = "Never share with";
"lng_edit_lastseen_hide_read_time" = "Hide read time"; "lng_edit_lastseen_hide_read_time" = "Hide read time";
"lng_edit_lastseen_hide_read_time_about" = "Do not show the time when you read a message to people you hid your last seen from. If you turn this on, their read time will also be hidden from you. This does not affect group chats."; "lng_edit_lastseen_hide_read_time_about" = "Hide the time when you read messages from people who can't see your last seen. If you turn this on, their read time will also be hidden from you. This setting does not affect group chats.";
"lng_edit_lastseen_subscribe" = "Subscribe to Telegram Premium"; "lng_edit_lastseen_subscribe" = "Subscribe to Telegram Premium";
"lng_edit_lastseen_subscribe_about" = "If you subscribe to Premium, you will see other users' last seen and read time even if you hid yours from them (unless they specifically restricted it)."; "lng_edit_lastseen_subscribe_about" = "If you subscribe to Premium, you will see other users' last seen and read time even if you hid yours from them (unless they specifically restricted it).";

View file

@ -379,7 +379,7 @@ void EditPrivacyBox::setupContent() {
auto middle = _controller->setupMiddleWidget( auto middle = _controller->setupMiddleWidget(
_window, _window,
content, content,
std::move(optionValue)); rpl::duplicate(optionValue));
if (middle) { if (middle) {
content->add(std::move(middle)); content->add(std::move(middle));
} }
@ -396,7 +396,11 @@ void EditPrivacyBox::setupContent() {
_controller->exceptionsDescription() | Ui::Text::ToWithEntities(), _controller->exceptionsDescription() | Ui::Text::ToWithEntities(),
st::defaultVerticalListSkip); st::defaultVerticalListSkip);
if (auto below = _controller->setupBelowWidget(_window, content)) { auto below = _controller->setupBelowWidget(
_window,
content,
rpl::duplicate(optionValue));
if (below) {
content->add(std::move(below)); content->add(std::move(below));
} }

View file

@ -75,7 +75,8 @@ public:
} }
[[nodiscard]] virtual object_ptr<Ui::RpWidget> setupBelowWidget( [[nodiscard]] virtual object_ptr<Ui::RpWidget> setupBelowWidget(
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
not_null<QWidget*> parent) { not_null<QWidget*> parent,
rpl::producer<Option> option) {
return { nullptr }; return { nullptr };
} }

View file

@ -669,9 +669,17 @@ auto LastSeenPrivacyController::exceptionsDescription() const
object_ptr<Ui::RpWidget> LastSeenPrivacyController::setupBelowWidget( object_ptr<Ui::RpWidget> LastSeenPrivacyController::setupBelowWidget(
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
not_null<QWidget*> parent) { not_null<QWidget*> parent,
auto result = object_ptr<Ui::VerticalLayout>(parent); rpl::producer<Option> option) {
const auto content = result.data(); using namespace rpl::mappers;
auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
parent,
object_ptr<Ui::VerticalLayout>(parent));
_option = std::move(option);
const auto content = result->entity();
Ui::AddSkip(content); Ui::AddSkip(content);
@ -704,9 +712,22 @@ object_ptr<Ui::RpWidget> LastSeenPrivacyController::setupBelowWidget(
tr::lng_edit_lastseen_subscribe_about()); tr::lng_edit_lastseen_subscribe_about());
} }
result->toggleOn(rpl::combine(
_option.value(),
_exceptionsNever.value(),
(_1 != Option::Everyone) || (_2 > 0)));
return result; return result;
} }
void LastSeenPrivacyController::handleExceptionsChange(
Exception exception,
rpl::producer<int> value) {
if (exception == Exception::Never) {
_exceptionsNever = std::move(value);
}
}
void LastSeenPrivacyController::confirmSave( void LastSeenPrivacyController::confirmSave(
bool someAreDisallowed, bool someAreDisallowed,
Fn<void()> saveCallback) { Fn<void()> saveCallback) {
@ -732,6 +753,10 @@ void LastSeenPrivacyController::confirmSave(
} }
void LastSeenPrivacyController::saveAdditional() { void LastSeenPrivacyController::saveAdditional() {
if (_option.current() == Option::Everyone
&& !_exceptionsNever.current()) {
return;
}
const auto privacy = &_session->api().globalPrivacy(); const auto privacy = &_session->api().globalPrivacy();
if (privacy->hideReadTimeCurrent() != _hideReadTime) { if (privacy->hideReadTimeCurrent() != _hideReadTime) {
privacy->updateHideReadTime(_hideReadTime); privacy->updateHideReadTime(_hideReadTime);
@ -811,7 +836,8 @@ auto CallsPrivacyController::exceptionsDescription() const
object_ptr<Ui::RpWidget> CallsPrivacyController::setupBelowWidget( object_ptr<Ui::RpWidget> CallsPrivacyController::setupBelowWidget(
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
not_null<QWidget*> parent) { not_null<QWidget*> parent,
rpl::producer<Option> option) {
auto result = object_ptr<Ui::VerticalLayout>(parent); auto result = object_ptr<Ui::VerticalLayout>(parent);
const auto content = result.data(); const auto content = result.data();

View file

@ -109,9 +109,14 @@ public:
Exception exception) const override; Exception exception) const override;
rpl::producer<QString> exceptionsDescription() const override; rpl::producer<QString> exceptionsDescription() const override;
void handleExceptionsChange(
Exception exception,
rpl::producer<int> value) override;
object_ptr<Ui::RpWidget> setupBelowWidget( object_ptr<Ui::RpWidget> setupBelowWidget(
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
not_null<QWidget*> parent) override; not_null<QWidget*> parent,
rpl::producer<Option> option) override;
void confirmSave( void confirmSave(
bool someAreDisallowed, bool someAreDisallowed,
@ -121,6 +126,8 @@ public:
private: private:
const not_null<::Main::Session*> _session; const not_null<::Main::Session*> _session;
rpl::variable<Option> _option;
rpl::variable<int> _exceptionsNever;
bool _hideReadTime = false; bool _hideReadTime = false;
}; };
@ -159,7 +166,8 @@ public:
object_ptr<Ui::RpWidget> setupBelowWidget( object_ptr<Ui::RpWidget> setupBelowWidget(
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
not_null<QWidget*> parent) override; not_null<QWidget*> parent,
rpl::producer<Option> option) override;
}; };