mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Copy t.me/+phonenumber link from Phone Number Privacy.
This commit is contained in:
parent
bea2cfd363
commit
616d099c07
5 changed files with 83 additions and 28 deletions
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/widgets/checkbox.h"
|
#include "ui/widgets/checkbox.h"
|
||||||
#include "ui/widgets/labels.h"
|
#include "ui/widgets/labels.h"
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
|
#include "ui/text/text_utilities.h"
|
||||||
#include "ui/wrap/slide_wrap.h"
|
#include "ui/wrap/slide_wrap.h"
|
||||||
#include "ui/wrap/vertical_layout.h"
|
#include "ui/wrap/vertical_layout.h"
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
|
@ -211,7 +212,7 @@ Ui::Radioenum<EditPrivacyBox::Option> *EditPrivacyBox::AddOption(
|
||||||
|
|
||||||
Ui::FlatLabel *EditPrivacyBox::addLabel(
|
Ui::FlatLabel *EditPrivacyBox::addLabel(
|
||||||
not_null<Ui::VerticalLayout*> container,
|
not_null<Ui::VerticalLayout*> container,
|
||||||
rpl::producer<QString> text,
|
rpl::producer<TextWithEntities> text,
|
||||||
int topSkip) {
|
int topSkip) {
|
||||||
if (!text) {
|
if (!text) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -228,15 +229,17 @@ Ui::FlatLabel *EditPrivacyBox::addLabel(
|
||||||
)->entity();
|
)->entity();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditPrivacyBox::addLabelOrDivider(
|
Ui::FlatLabel *EditPrivacyBox::addLabelOrDivider(
|
||||||
not_null<Ui::VerticalLayout*> container,
|
not_null<Ui::VerticalLayout*> container,
|
||||||
rpl::producer<QString> text,
|
rpl::producer<TextWithEntities> text,
|
||||||
int topSkip) {
|
int topSkip) {
|
||||||
if (!addLabel(container, std::move(text), topSkip)) {
|
if (const auto result = addLabel(container, std::move(text), topSkip)) {
|
||||||
container->add(
|
return result;
|
||||||
object_ptr<Ui::BoxContentDivider>(container),
|
|
||||||
{ 0, topSkip, 0, 0 });
|
|
||||||
}
|
}
|
||||||
|
container->add(
|
||||||
|
object_ptr<Ui::BoxContentDivider>(container),
|
||||||
|
{ 0, topSkip, 0, 0 });
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditPrivacyBox::setupContent() {
|
void EditPrivacyBox::setupContent() {
|
||||||
|
@ -320,10 +323,13 @@ void EditPrivacyBox::setupContent() {
|
||||||
addOptionRow(Option::Everyone);
|
addOptionRow(Option::Everyone);
|
||||||
addOptionRow(Option::Contacts);
|
addOptionRow(Option::Contacts);
|
||||||
addOptionRow(Option::Nobody);
|
addOptionRow(Option::Nobody);
|
||||||
addLabelOrDivider(
|
const auto warning = addLabelOrDivider(
|
||||||
content,
|
content,
|
||||||
_controller->warning(),
|
_controller->warning(),
|
||||||
st::settingsSectionSkip + st::settingsPrivacySkipTop);
|
st::settingsSectionSkip + st::settingsPrivacySkipTop);
|
||||||
|
if (warning) {
|
||||||
|
_controller->prepareWarningLabel(warning);
|
||||||
|
}
|
||||||
|
|
||||||
auto middle = _controller->setupMiddleWidget(
|
auto middle = _controller->setupMiddleWidget(
|
||||||
_window,
|
_window,
|
||||||
|
@ -342,7 +348,7 @@ void EditPrivacyBox::setupContent() {
|
||||||
const auto never = addExceptionLink(Exception::Never);
|
const auto never = addExceptionLink(Exception::Never);
|
||||||
addLabel(
|
addLabel(
|
||||||
content,
|
content,
|
||||||
_controller->exceptionsDescription(),
|
_controller->exceptionsDescription() | Ui::Text::ToWithEntities(),
|
||||||
st::settingsSectionSkip);
|
st::settingsSectionSkip);
|
||||||
|
|
||||||
if (auto below = _controller->setupBelowWidget(_window, content)) {
|
if (auto below = _controller->setupBelowWidget(_window, content)) {
|
||||||
|
|
|
@ -46,9 +46,11 @@ public:
|
||||||
}
|
}
|
||||||
[[nodiscard]] virtual rpl::producer<QString> optionsTitleKey() = 0;
|
[[nodiscard]] virtual rpl::producer<QString> optionsTitleKey() = 0;
|
||||||
[[nodiscard]] virtual QString optionLabel(Option option);
|
[[nodiscard]] virtual QString optionLabel(Option option);
|
||||||
[[nodiscard]] virtual rpl::producer<QString> warning() {
|
[[nodiscard]] virtual rpl::producer<TextWithEntities> warning() {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
virtual void prepareWarningLabel(not_null<Ui::FlatLabel*> warning) {
|
||||||
|
}
|
||||||
[[nodiscard]] virtual rpl::producer<QString> exceptionButtonTextKey(
|
[[nodiscard]] virtual rpl::producer<QString> exceptionButtonTextKey(
|
||||||
Exception exception) = 0;
|
Exception exception) = 0;
|
||||||
[[nodiscard]] virtual rpl::producer<QString> exceptionBoxTitle(
|
[[nodiscard]] virtual rpl::producer<QString> exceptionBoxTitle(
|
||||||
|
@ -127,11 +129,11 @@ private:
|
||||||
|
|
||||||
Ui::FlatLabel *addLabel(
|
Ui::FlatLabel *addLabel(
|
||||||
not_null<Ui::VerticalLayout*> container,
|
not_null<Ui::VerticalLayout*> container,
|
||||||
rpl::producer<QString> text,
|
rpl::producer<TextWithEntities> text,
|
||||||
int topSkip);
|
int topSkip);
|
||||||
void addLabelOrDivider(
|
Ui::FlatLabel *addLabelOrDivider(
|
||||||
not_null<Ui::VerticalLayout*> container,
|
not_null<Ui::VerticalLayout*> container,
|
||||||
rpl::producer<QString> text,
|
rpl::producer<TextWithEntities> text,
|
||||||
int topSkip);
|
int topSkip);
|
||||||
|
|
||||||
void editExceptions(Exception exception, Fn<void()> done);
|
void editExceptions(Exception exception, Fn<void()> done);
|
||||||
|
|
|
@ -35,7 +35,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/image/image_prepare.h"
|
#include "ui/image/image_prepare.h"
|
||||||
#include "ui/cached_round_corners.h"
|
#include "ui/cached_round_corners.h"
|
||||||
#include "ui/text/format_values.h" // Ui::FormatPhone
|
#include "ui/text/format_values.h" // Ui::FormatPhone
|
||||||
|
#include "ui/text/text_utilities.h"
|
||||||
#include "window/section_widget.h"
|
#include "window/section_widget.h"
|
||||||
|
#include "window/window_controller.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "boxes/peer_list_controllers.h"
|
#include "boxes/peer_list_controllers.h"
|
||||||
#include "ui/boxes/confirm_box.h"
|
#include "ui/boxes/confirm_box.h"
|
||||||
|
@ -45,6 +47,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
#include "styles/style_settings.h"
|
#include "styles/style_settings.h"
|
||||||
|
|
||||||
|
#include <QtGui/QGuiApplication>
|
||||||
|
#include <QtGui/QClipboard>
|
||||||
|
|
||||||
namespace Settings {
|
namespace Settings {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -52,6 +57,10 @@ using UserPrivacy = Api::UserPrivacy;
|
||||||
using PrivacyRule = Api::UserPrivacy::Rule;
|
using PrivacyRule = Api::UserPrivacy::Rule;
|
||||||
using Option = EditPrivacyBox::Option;
|
using Option = EditPrivacyBox::Option;
|
||||||
|
|
||||||
|
[[nodiscard]] QString PublicLinkByPhone(not_null<UserData*> user) {
|
||||||
|
return user->session().createInternalLinkFull('+' + user->phone());
|
||||||
|
}
|
||||||
|
|
||||||
class BlockPeerBoxController final : public ChatsListBoxController {
|
class BlockPeerBoxController final : public ChatsListBoxController {
|
||||||
public:
|
public:
|
||||||
explicit BlockPeerBoxController(not_null<Main::Session*> session);
|
explicit BlockPeerBoxController(not_null<Main::Session*> session);
|
||||||
|
@ -431,6 +440,11 @@ std::unique_ptr<PeerListRow> BlockedBoxController::createRow(
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PhoneNumberPrivacyController::PhoneNumberPrivacyController(
|
||||||
|
not_null<Window::SessionController*> controller)
|
||||||
|
: _controller(controller) {
|
||||||
|
}
|
||||||
|
|
||||||
UserPrivacy::Key PhoneNumberPrivacyController::key() {
|
UserPrivacy::Key PhoneNumberPrivacyController::key() {
|
||||||
return Key::PhoneNumber;
|
return Key::PhoneNumber;
|
||||||
}
|
}
|
||||||
|
@ -443,19 +457,46 @@ rpl::producer<QString> PhoneNumberPrivacyController::optionsTitleKey() {
|
||||||
return tr::lng_edit_privacy_phone_number_header();
|
return tr::lng_edit_privacy_phone_number_header();
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<QString> PhoneNumberPrivacyController::warning() {
|
rpl::producer<TextWithEntities> PhoneNumberPrivacyController::warning() {
|
||||||
using namespace rpl::mappers;
|
using namespace rpl::mappers;
|
||||||
|
const auto self = _controller->session().user();
|
||||||
return rpl::combine(
|
return rpl::combine(
|
||||||
_phoneNumberOption.value(),
|
_phoneNumberOption.value(),
|
||||||
_addedByPhone.value(),
|
_addedByPhone.value(),
|
||||||
(_1 == Option::Nobody) && (_2 != Option::Everyone)
|
(_1 == Option::Nobody) && (_2 != Option::Everyone)
|
||||||
) | rpl::map([](bool onlyContactsSee) {
|
) | rpl::map([=](bool onlyContactsSee) {
|
||||||
return onlyContactsSee
|
return onlyContactsSee
|
||||||
? tr::lng_edit_privacy_phone_number_contacts()
|
? tr::lng_edit_privacy_phone_number_contacts(
|
||||||
: tr::lng_edit_privacy_phone_number_warning();
|
Ui::Text::WithEntities)
|
||||||
|
: rpl::combine(
|
||||||
|
tr::lng_edit_privacy_phone_number_warning(),
|
||||||
|
tr::lng_username_link()
|
||||||
|
) | rpl::map([=](const QString &warning, const QString &added) {
|
||||||
|
auto base = TextWithEntities{
|
||||||
|
warning + "\n\n" + added + "\n",
|
||||||
|
};
|
||||||
|
const auto link = PublicLinkByPhone(self);
|
||||||
|
return base.append(Ui::Text::Link(link, link));
|
||||||
|
});
|
||||||
}) | rpl::flatten_latest();
|
}) | rpl::flatten_latest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PhoneNumberPrivacyController::prepareWarningLabel(
|
||||||
|
not_null<Ui::FlatLabel*> warning) {
|
||||||
|
warning->setClickHandlerFilter([=](
|
||||||
|
const ClickHandlerPtr &link,
|
||||||
|
Qt::MouseButton button) {
|
||||||
|
if (button == Qt::LeftButton) {
|
||||||
|
QGuiApplication::clipboard()->setText(PublicLinkByPhone(
|
||||||
|
_controller->session().user()));
|
||||||
|
_controller->window().showToast(
|
||||||
|
tr::lng_username_copied(tr::now));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
rpl::producer<QString> PhoneNumberPrivacyController::exceptionButtonTextKey(
|
rpl::producer<QString> PhoneNumberPrivacyController::exceptionButtonTextKey(
|
||||||
Exception exception) {
|
Exception exception) {
|
||||||
switch (exception) {
|
switch (exception) {
|
||||||
|
@ -554,8 +595,8 @@ rpl::producer<QString> LastSeenPrivacyController::optionsTitleKey() {
|
||||||
return tr::lng_edit_privacy_lastseen_header();
|
return tr::lng_edit_privacy_lastseen_header();
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<QString> LastSeenPrivacyController::warning() {
|
rpl::producer<TextWithEntities> LastSeenPrivacyController::warning() {
|
||||||
return tr::lng_edit_privacy_lastseen_warning();
|
return tr::lng_edit_privacy_lastseen_warning(Ui::Text::WithEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<QString> LastSeenPrivacyController::exceptionButtonTextKey(
|
rpl::producer<QString> LastSeenPrivacyController::exceptionButtonTextKey(
|
||||||
|
@ -721,8 +762,8 @@ QString CallsPeer2PeerPrivacyController::optionLabel(
|
||||||
Unexpected("Option value in optionsLabelKey.");
|
Unexpected("Option value in optionsLabelKey.");
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<QString> CallsPeer2PeerPrivacyController::warning() {
|
rpl::producer<TextWithEntities> CallsPeer2PeerPrivacyController::warning() {
|
||||||
return tr::lng_settings_peer_to_peer_about();
|
return tr::lng_settings_peer_to_peer_about(Ui::Text::WithEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<QString> CallsPeer2PeerPrivacyController::exceptionButtonTextKey(
|
rpl::producer<QString> CallsPeer2PeerPrivacyController::exceptionButtonTextKey(
|
||||||
|
@ -767,8 +808,8 @@ rpl::producer<QString> ForwardsPrivacyController::optionsTitleKey() {
|
||||||
return tr::lng_edit_privacy_forwards_header();
|
return tr::lng_edit_privacy_forwards_header();
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<QString> ForwardsPrivacyController::warning() {
|
rpl::producer<TextWithEntities> ForwardsPrivacyController::warning() {
|
||||||
return tr::lng_edit_privacy_forwards_warning();
|
return tr::lng_edit_privacy_forwards_warning(Ui::Text::WithEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<QString> ForwardsPrivacyController::exceptionButtonTextKey(
|
rpl::producer<QString> ForwardsPrivacyController::exceptionButtonTextKey(
|
||||||
|
|
|
@ -57,11 +57,15 @@ public:
|
||||||
using Option = EditPrivacyBox::Option;
|
using Option = EditPrivacyBox::Option;
|
||||||
using Exception = EditPrivacyBox::Exception;
|
using Exception = EditPrivacyBox::Exception;
|
||||||
|
|
||||||
|
explicit PhoneNumberPrivacyController(
|
||||||
|
not_null<Window::SessionController*> controller);
|
||||||
|
|
||||||
Key key() override;
|
Key key() override;
|
||||||
|
|
||||||
rpl::producer<QString> title() override;
|
rpl::producer<QString> title() override;
|
||||||
rpl::producer<QString> optionsTitleKey() override;
|
rpl::producer<QString> optionsTitleKey() override;
|
||||||
rpl::producer<QString> warning() override;
|
rpl::producer<TextWithEntities> warning() override;
|
||||||
|
void prepareWarningLabel(not_null<Ui::FlatLabel*> warning) override;
|
||||||
rpl::producer<QString> exceptionButtonTextKey(
|
rpl::producer<QString> exceptionButtonTextKey(
|
||||||
Exception exception) override;
|
Exception exception) override;
|
||||||
rpl::producer<QString> exceptionBoxTitle(Exception exception) override;
|
rpl::producer<QString> exceptionBoxTitle(Exception exception) override;
|
||||||
|
@ -75,6 +79,7 @@ public:
|
||||||
void saveAdditional() override;
|
void saveAdditional() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const not_null<Window::SessionController*> _controller;
|
||||||
rpl::variable<Option> _phoneNumberOption = { Option::Contacts };
|
rpl::variable<Option> _phoneNumberOption = { Option::Contacts };
|
||||||
rpl::variable<Option> _addedByPhone = { Option::Everyone };
|
rpl::variable<Option> _addedByPhone = { Option::Everyone };
|
||||||
Fn<void()> _saveAdditional;
|
Fn<void()> _saveAdditional;
|
||||||
|
@ -92,7 +97,7 @@ public:
|
||||||
|
|
||||||
rpl::producer<QString> title() override;
|
rpl::producer<QString> title() override;
|
||||||
rpl::producer<QString> optionsTitleKey() override;
|
rpl::producer<QString> optionsTitleKey() override;
|
||||||
rpl::producer<QString> warning() override;
|
rpl::producer<TextWithEntities> warning() override;
|
||||||
rpl::producer<QString> exceptionButtonTextKey(
|
rpl::producer<QString> exceptionButtonTextKey(
|
||||||
Exception exception) override;
|
Exception exception) override;
|
||||||
rpl::producer<QString> exceptionBoxTitle(Exception exception) override;
|
rpl::producer<QString> exceptionBoxTitle(Exception exception) override;
|
||||||
|
@ -154,7 +159,7 @@ public:
|
||||||
rpl::producer<QString> title() override;
|
rpl::producer<QString> title() override;
|
||||||
rpl::producer<QString> optionsTitleKey() override;
|
rpl::producer<QString> optionsTitleKey() override;
|
||||||
QString optionLabel(EditPrivacyBox::Option option) override;
|
QString optionLabel(EditPrivacyBox::Option option) override;
|
||||||
rpl::producer<QString> warning() override;
|
rpl::producer<TextWithEntities> warning() override;
|
||||||
rpl::producer<QString> exceptionButtonTextKey(
|
rpl::producer<QString> exceptionButtonTextKey(
|
||||||
Exception exception) override;
|
Exception exception) override;
|
||||||
rpl::producer<QString> exceptionBoxTitle(Exception exception) override;
|
rpl::producer<QString> exceptionBoxTitle(Exception exception) override;
|
||||||
|
@ -176,7 +181,7 @@ public:
|
||||||
|
|
||||||
rpl::producer<QString> title() override;
|
rpl::producer<QString> title() override;
|
||||||
rpl::producer<QString> optionsTitleKey() override;
|
rpl::producer<QString> optionsTitleKey() override;
|
||||||
rpl::producer<QString> warning() override;
|
rpl::producer<TextWithEntities> warning() override;
|
||||||
rpl::producer<QString> exceptionButtonTextKey(
|
rpl::producer<QString> exceptionButtonTextKey(
|
||||||
Exception exception) override;
|
Exception exception) override;
|
||||||
rpl::producer<QString> exceptionBoxTitle(Exception exception) override;
|
rpl::producer<QString> exceptionBoxTitle(Exception exception) override;
|
||||||
|
|
|
@ -143,7 +143,8 @@ void SetupPrivacy(
|
||||||
tr::lng_settings_phone_number_privacy(),
|
tr::lng_settings_phone_number_privacy(),
|
||||||
{ &st::settingsIconCalls, kIconGreen },
|
{ &st::settingsIconCalls, kIconGreen },
|
||||||
Key::PhoneNumber,
|
Key::PhoneNumber,
|
||||||
[] { return std::make_unique<PhoneNumberPrivacyController>(); });
|
[=] { return std::make_unique<PhoneNumberPrivacyController>(
|
||||||
|
controller); });
|
||||||
add(
|
add(
|
||||||
tr::lng_settings_last_seen(),
|
tr::lng_settings_last_seen(),
|
||||||
{ &st::settingsIconOnline, kIconLightBlue },
|
{ &st::settingsIconOnline, kIconLightBlue },
|
||||||
|
|
Loading…
Add table
Reference in a new issue