Added ability to share proxy with QR code.

This commit is contained in:
23rd 2025-06-30 10:50:14 +03:00
parent b97c8b9a17
commit 3a8898dd24
3 changed files with 30 additions and 9 deletions

View file

@ -1162,6 +1162,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_proxy_menu_delete" = "Delete"; "lng_proxy_menu_delete" = "Delete";
"lng_proxy_menu_restore" = "Restore"; "lng_proxy_menu_restore" = "Restore";
"lng_proxy_edit_share" = "Share"; "lng_proxy_edit_share" = "Share";
"lng_proxy_edit_share_qr_box_title" = "Share proxy with QR code";
"lng_proxy_address_label" = "Socket address"; "lng_proxy_address_label" = "Socket address";
"lng_proxy_credentials_optional" = "Credentials (optional)"; "lng_proxy_credentials_optional" = "Credentials (optional)";
"lng_proxy_credentials" = "Credentials"; "lng_proxy_credentials" = "Credentials";

View file

@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "storage/localstorage.h" #include "storage/localstorage.h"
#include "ui/basic_click_handlers.h" #include "ui/basic_click_handlers.h"
#include "ui/boxes/confirm_box.h" #include "ui/boxes/confirm_box.h"
#include "ui/boxes/peer_qr_box.h"
#include "ui/effects/animations.h" #include "ui/effects/animations.h"
#include "ui/effects/radial_animation.h" #include "ui/effects/radial_animation.h"
#include "ui/painter.h" #include "ui/painter.h"
@ -177,6 +178,7 @@ public:
rpl::producer<> restoreClicks() const; rpl::producer<> restoreClicks() const;
rpl::producer<> editClicks() const; rpl::producer<> editClicks() const;
rpl::producer<> shareClicks() const; rpl::producer<> shareClicks() const;
rpl::producer<> showQrClicks() const;
protected: protected:
int resizeGetHeight(int newWidth) override; int resizeGetHeight(int newWidth) override;
@ -198,6 +200,7 @@ private:
rpl::event_stream<> _restoreClicks; rpl::event_stream<> _restoreClicks;
rpl::event_stream<> _editClicks; rpl::event_stream<> _editClicks;
rpl::event_stream<> _shareClicks; rpl::event_stream<> _shareClicks;
rpl::event_stream<> _showQrClicks;
base::unique_qptr<Ui::DropdownMenu> _menu; base::unique_qptr<Ui::DropdownMenu> _menu;
bool _set = false; bool _set = false;
@ -319,6 +322,10 @@ rpl::producer<> ProxyRow::shareClicks() const {
return _shareClicks.events(); return _shareClicks.events();
} }
rpl::producer<> ProxyRow::showQrClicks() const {
return _showQrClicks.events();
}
void ProxyRow::setupControls(View &&view) { void ProxyRow::setupControls(View &&view) {
updateFields(std::move(view)); updateFields(std::move(view));
_toggled.stop(); _toggled.stop();
@ -563,6 +570,9 @@ void ProxyRow::showMenu() {
addAction(tr::lng_proxy_edit_share(tr::now), [=] { addAction(tr::lng_proxy_edit_share(tr::now), [=] {
_shareClicks.fire({}); _shareClicks.fire({});
}, &st::menuIconShare); }, &st::menuIconShare);
addAction(tr::lng_group_invite_context_qr(tr::now), [=] {
_showQrClicks.fire({});
}, &st::menuIconQrCode);
} }
if (_view.deleted) { if (_view.deleted) {
addAction(tr::lng_proxy_menu_restore(tr::now), [=] { addAction(tr::lng_proxy_menu_restore(tr::now), [=] {
@ -898,9 +908,11 @@ void ProxiesBox::setupButtons(int id, not_null<ProxyRow*> button) {
getDelegate()->show(_controller->editItemBox(id)); getDelegate()->show(_controller->editItemBox(id));
}, button->lifetime()); }, button->lifetime());
button->shareClicks( rpl::merge(
) | rpl::start_with_next([=] { button->shareClicks() | rpl::map_to(false),
_controller->shareItem(id); button->showQrClicks() | rpl::map_to(true)
) | rpl::start_with_next([=](bool qr) {
_controller->shareItem(id, qr);
}, button->lifetime()); }, button->lifetime());
button->clicks( button->clicks(
@ -1411,8 +1423,8 @@ void ProxiesBoxController::restoreItem(int id) {
setDeleted(id, false); setDeleted(id, false);
} }
void ProxiesBoxController::shareItem(int id) { void ProxiesBoxController::shareItem(int id, bool qr) {
share(findById(id)->data); share(findById(id)->data, qr);
} }
void ProxiesBoxController::applyItem(int id) { void ProxiesBoxController::applyItem(int id) {
@ -1653,10 +1665,11 @@ void ProxiesBoxController::updateView(const Item &item) {
deleted, deleted,
!deleted && supportsShare, !deleted && supportsShare,
supportsCalls, supportsCalls,
state }); state,
});
} }
void ProxiesBoxController::share(const ProxyData &proxy) { void ProxiesBoxController::share(const ProxyData &proxy, bool qr) {
if (proxy.type == Type::Http) { if (proxy.type == Type::Http) {
return; return;
} }
@ -1669,6 +1682,13 @@ void ProxiesBoxController::share(const ProxyData &proxy) {
? "&pass=" + qthelp::url_encode(proxy.password) : "") ? "&pass=" + qthelp::url_encode(proxy.password) : "")
+ ((proxy.type == Type::Mtproto && !proxy.password.isEmpty()) + ((proxy.type == Type::Mtproto && !proxy.password.isEmpty())
? "&secret=" + proxy.password : ""); ? "&secret=" + proxy.password : "");
if (qr) {
_show->showBox(Box([=](not_null<Ui::GenericBox*> box) {
Ui::FillPeerQrBox(box, nullptr, link, rpl::single(QString()));
box->setTitle(tr::lng_proxy_edit_share_qr_box_title());
}));
return;
}
QGuiApplication::clipboard()->setText(link); QGuiApplication::clipboard()->setText(link);
_show->showToast(tr::lng_username_copied(tr::now)); _show->showToast(tr::lng_username_copied(tr::now));
} }

View file

@ -73,7 +73,7 @@ public:
void deleteItem(int id); void deleteItem(int id);
void restoreItem(int id); void restoreItem(int id);
void shareItem(int id); void shareItem(int id, bool qr);
void applyItem(int id); void applyItem(int id);
object_ptr<Ui::BoxContent> editItemBox(int id); object_ptr<Ui::BoxContent> editItemBox(int id);
object_ptr<Ui::BoxContent> addNewItemBox(); object_ptr<Ui::BoxContent> addNewItemBox();
@ -106,7 +106,7 @@ private:
std::vector<Item>::iterator findByProxy(const ProxyData &proxy); std::vector<Item>::iterator findByProxy(const ProxyData &proxy);
void setDeleted(int id, bool deleted); void setDeleted(int id, bool deleted);
void updateView(const Item &item); void updateView(const Item &item);
void share(const ProxyData &proxy); void share(const ProxyData &proxy, bool qr = false);
void saveDelayed(); void saveDelayed();
void refreshChecker(Item &item); void refreshChecker(Item &item);
void setupChecker(int id, const Checker &checker); void setupChecker(int id, const Checker &checker);