mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 15:17:07 +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
Telegram/SourceFiles
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/text/text_utilities.h"
|
||||
#include "ui/wrap/slide_wrap.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
#include "history/history.h"
|
||||
|
@ -211,7 +212,7 @@ Ui::Radioenum<EditPrivacyBox::Option> *EditPrivacyBox::AddOption(
|
|||
|
||||
Ui::FlatLabel *EditPrivacyBox::addLabel(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
rpl::producer<QString> text,
|
||||
rpl::producer<TextWithEntities> text,
|
||||
int topSkip) {
|
||||
if (!text) {
|
||||
return nullptr;
|
||||
|
@ -228,15 +229,17 @@ Ui::FlatLabel *EditPrivacyBox::addLabel(
|
|||
)->entity();
|
||||
}
|
||||
|
||||
void EditPrivacyBox::addLabelOrDivider(
|
||||
Ui::FlatLabel *EditPrivacyBox::addLabelOrDivider(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
rpl::producer<QString> text,
|
||||
rpl::producer<TextWithEntities> text,
|
||||
int topSkip) {
|
||||
if (!addLabel(container, std::move(text), topSkip)) {
|
||||
container->add(
|
||||
object_ptr<Ui::BoxContentDivider>(container),
|
||||
{ 0, topSkip, 0, 0 });
|
||||
if (const auto result = addLabel(container, std::move(text), topSkip)) {
|
||||
return result;
|
||||
}
|
||||
container->add(
|
||||
object_ptr<Ui::BoxContentDivider>(container),
|
||||
{ 0, topSkip, 0, 0 });
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void EditPrivacyBox::setupContent() {
|
||||
|
@ -320,10 +323,13 @@ void EditPrivacyBox::setupContent() {
|
|||
addOptionRow(Option::Everyone);
|
||||
addOptionRow(Option::Contacts);
|
||||
addOptionRow(Option::Nobody);
|
||||
addLabelOrDivider(
|
||||
const auto warning = addLabelOrDivider(
|
||||
content,
|
||||
_controller->warning(),
|
||||
st::settingsSectionSkip + st::settingsPrivacySkipTop);
|
||||
if (warning) {
|
||||
_controller->prepareWarningLabel(warning);
|
||||
}
|
||||
|
||||
auto middle = _controller->setupMiddleWidget(
|
||||
_window,
|
||||
|
@ -342,7 +348,7 @@ void EditPrivacyBox::setupContent() {
|
|||
const auto never = addExceptionLink(Exception::Never);
|
||||
addLabel(
|
||||
content,
|
||||
_controller->exceptionsDescription(),
|
||||
_controller->exceptionsDescription() | Ui::Text::ToWithEntities(),
|
||||
st::settingsSectionSkip);
|
||||
|
||||
if (auto below = _controller->setupBelowWidget(_window, content)) {
|
||||
|
|
|
@ -46,9 +46,11 @@ public:
|
|||
}
|
||||
[[nodiscard]] virtual rpl::producer<QString> optionsTitleKey() = 0;
|
||||
[[nodiscard]] virtual QString optionLabel(Option option);
|
||||
[[nodiscard]] virtual rpl::producer<QString> warning() {
|
||||
[[nodiscard]] virtual rpl::producer<TextWithEntities> warning() {
|
||||
return nullptr;
|
||||
}
|
||||
virtual void prepareWarningLabel(not_null<Ui::FlatLabel*> warning) {
|
||||
}
|
||||
[[nodiscard]] virtual rpl::producer<QString> exceptionButtonTextKey(
|
||||
Exception exception) = 0;
|
||||
[[nodiscard]] virtual rpl::producer<QString> exceptionBoxTitle(
|
||||
|
@ -127,11 +129,11 @@ private:
|
|||
|
||||
Ui::FlatLabel *addLabel(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
rpl::producer<QString> text,
|
||||
rpl::producer<TextWithEntities> text,
|
||||
int topSkip);
|
||||
void addLabelOrDivider(
|
||||
Ui::FlatLabel *addLabelOrDivider(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
rpl::producer<QString> text,
|
||||
rpl::producer<TextWithEntities> text,
|
||||
int topSkip);
|
||||
|
||||
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/cached_round_corners.h"
|
||||
#include "ui/text/format_values.h" // Ui::FormatPhone
|
||||
#include "ui/text/text_utilities.h"
|
||||
#include "window/section_widget.h"
|
||||
#include "window/window_controller.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "boxes/peer_list_controllers.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_settings.h"
|
||||
|
||||
#include <QtGui/QGuiApplication>
|
||||
#include <QtGui/QClipboard>
|
||||
|
||||
namespace Settings {
|
||||
namespace {
|
||||
|
||||
|
@ -52,6 +57,10 @@ using UserPrivacy = Api::UserPrivacy;
|
|||
using PrivacyRule = Api::UserPrivacy::Rule;
|
||||
using Option = EditPrivacyBox::Option;
|
||||
|
||||
[[nodiscard]] QString PublicLinkByPhone(not_null<UserData*> user) {
|
||||
return user->session().createInternalLinkFull('+' + user->phone());
|
||||
}
|
||||
|
||||
class BlockPeerBoxController final : public ChatsListBoxController {
|
||||
public:
|
||||
explicit BlockPeerBoxController(not_null<Main::Session*> session);
|
||||
|
@ -431,6 +440,11 @@ std::unique_ptr<PeerListRow> BlockedBoxController::createRow(
|
|||
return row;
|
||||
}
|
||||
|
||||
PhoneNumberPrivacyController::PhoneNumberPrivacyController(
|
||||
not_null<Window::SessionController*> controller)
|
||||
: _controller(controller) {
|
||||
}
|
||||
|
||||
UserPrivacy::Key PhoneNumberPrivacyController::key() {
|
||||
return Key::PhoneNumber;
|
||||
}
|
||||
|
@ -443,19 +457,46 @@ rpl::producer<QString> PhoneNumberPrivacyController::optionsTitleKey() {
|
|||
return tr::lng_edit_privacy_phone_number_header();
|
||||
}
|
||||
|
||||
rpl::producer<QString> PhoneNumberPrivacyController::warning() {
|
||||
rpl::producer<TextWithEntities> PhoneNumberPrivacyController::warning() {
|
||||
using namespace rpl::mappers;
|
||||
const auto self = _controller->session().user();
|
||||
return rpl::combine(
|
||||
_phoneNumberOption.value(),
|
||||
_addedByPhone.value(),
|
||||
(_1 == Option::Nobody) && (_2 != Option::Everyone)
|
||||
) | rpl::map([](bool onlyContactsSee) {
|
||||
) | rpl::map([=](bool onlyContactsSee) {
|
||||
return onlyContactsSee
|
||||
? tr::lng_edit_privacy_phone_number_contacts()
|
||||
: tr::lng_edit_privacy_phone_number_warning();
|
||||
? tr::lng_edit_privacy_phone_number_contacts(
|
||||
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();
|
||||
}
|
||||
|
||||
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(
|
||||
Exception exception) {
|
||||
switch (exception) {
|
||||
|
@ -554,8 +595,8 @@ rpl::producer<QString> LastSeenPrivacyController::optionsTitleKey() {
|
|||
return tr::lng_edit_privacy_lastseen_header();
|
||||
}
|
||||
|
||||
rpl::producer<QString> LastSeenPrivacyController::warning() {
|
||||
return tr::lng_edit_privacy_lastseen_warning();
|
||||
rpl::producer<TextWithEntities> LastSeenPrivacyController::warning() {
|
||||
return tr::lng_edit_privacy_lastseen_warning(Ui::Text::WithEntities);
|
||||
}
|
||||
|
||||
rpl::producer<QString> LastSeenPrivacyController::exceptionButtonTextKey(
|
||||
|
@ -721,8 +762,8 @@ QString CallsPeer2PeerPrivacyController::optionLabel(
|
|||
Unexpected("Option value in optionsLabelKey.");
|
||||
}
|
||||
|
||||
rpl::producer<QString> CallsPeer2PeerPrivacyController::warning() {
|
||||
return tr::lng_settings_peer_to_peer_about();
|
||||
rpl::producer<TextWithEntities> CallsPeer2PeerPrivacyController::warning() {
|
||||
return tr::lng_settings_peer_to_peer_about(Ui::Text::WithEntities);
|
||||
}
|
||||
|
||||
rpl::producer<QString> CallsPeer2PeerPrivacyController::exceptionButtonTextKey(
|
||||
|
@ -767,8 +808,8 @@ rpl::producer<QString> ForwardsPrivacyController::optionsTitleKey() {
|
|||
return tr::lng_edit_privacy_forwards_header();
|
||||
}
|
||||
|
||||
rpl::producer<QString> ForwardsPrivacyController::warning() {
|
||||
return tr::lng_edit_privacy_forwards_warning();
|
||||
rpl::producer<TextWithEntities> ForwardsPrivacyController::warning() {
|
||||
return tr::lng_edit_privacy_forwards_warning(Ui::Text::WithEntities);
|
||||
}
|
||||
|
||||
rpl::producer<QString> ForwardsPrivacyController::exceptionButtonTextKey(
|
||||
|
|
|
@ -57,11 +57,15 @@ public:
|
|||
using Option = EditPrivacyBox::Option;
|
||||
using Exception = EditPrivacyBox::Exception;
|
||||
|
||||
explicit PhoneNumberPrivacyController(
|
||||
not_null<Window::SessionController*> controller);
|
||||
|
||||
Key key() override;
|
||||
|
||||
rpl::producer<QString> title() 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(
|
||||
Exception exception) override;
|
||||
rpl::producer<QString> exceptionBoxTitle(Exception exception) override;
|
||||
|
@ -75,6 +79,7 @@ public:
|
|||
void saveAdditional() override;
|
||||
|
||||
private:
|
||||
const not_null<Window::SessionController*> _controller;
|
||||
rpl::variable<Option> _phoneNumberOption = { Option::Contacts };
|
||||
rpl::variable<Option> _addedByPhone = { Option::Everyone };
|
||||
Fn<void()> _saveAdditional;
|
||||
|
@ -92,7 +97,7 @@ public:
|
|||
|
||||
rpl::producer<QString> title() override;
|
||||
rpl::producer<QString> optionsTitleKey() override;
|
||||
rpl::producer<QString> warning() override;
|
||||
rpl::producer<TextWithEntities> warning() override;
|
||||
rpl::producer<QString> exceptionButtonTextKey(
|
||||
Exception exception) override;
|
||||
rpl::producer<QString> exceptionBoxTitle(Exception exception) override;
|
||||
|
@ -154,7 +159,7 @@ public:
|
|||
rpl::producer<QString> title() override;
|
||||
rpl::producer<QString> optionsTitleKey() override;
|
||||
QString optionLabel(EditPrivacyBox::Option option) override;
|
||||
rpl::producer<QString> warning() override;
|
||||
rpl::producer<TextWithEntities> warning() override;
|
||||
rpl::producer<QString> exceptionButtonTextKey(
|
||||
Exception exception) override;
|
||||
rpl::producer<QString> exceptionBoxTitle(Exception exception) override;
|
||||
|
@ -176,7 +181,7 @@ public:
|
|||
|
||||
rpl::producer<QString> title() override;
|
||||
rpl::producer<QString> optionsTitleKey() override;
|
||||
rpl::producer<QString> warning() override;
|
||||
rpl::producer<TextWithEntities> warning() override;
|
||||
rpl::producer<QString> exceptionButtonTextKey(
|
||||
Exception exception) override;
|
||||
rpl::producer<QString> exceptionBoxTitle(Exception exception) override;
|
||||
|
|
|
@ -143,7 +143,8 @@ void SetupPrivacy(
|
|||
tr::lng_settings_phone_number_privacy(),
|
||||
{ &st::settingsIconCalls, kIconGreen },
|
||||
Key::PhoneNumber,
|
||||
[] { return std::make_unique<PhoneNumberPrivacyController>(); });
|
||||
[=] { return std::make_unique<PhoneNumberPrivacyController>(
|
||||
controller); });
|
||||
add(
|
||||
tr::lng_settings_last_seen(),
|
||||
{ &st::settingsIconOnline, kIconLightBlue },
|
||||
|
|
Loading…
Add table
Reference in a new issue