mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 14:45:14 +00:00
Improve permanent link edit design.
This commit is contained in:
91
Telegram/SourceFiles/boxes/peers/edit_peer_invite_links.cpp
Normal file
91
Telegram/SourceFiles/boxes/peers/edit_peer_invite_links.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "boxes/peers/edit_peer_invite_links.h"
|
||||
|
||||
#include "data/data_changes.h"
|
||||
#include "data/data_peer.h"
|
||||
#include "main/main_session.h"
|
||||
#include "api/api_invite_links.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "ui/controls/invite_link_label.h"
|
||||
#include "ui/toast/toast.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "apiwrap.h"
|
||||
#include "styles/style_info.h"
|
||||
|
||||
#include <QtGui/QGuiApplication>
|
||||
|
||||
void AddPermanentLinkBlock(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
not_null<PeerData*> peer) {
|
||||
const auto computePermanentLink = [=] {
|
||||
const auto &links = peer->session().api().inviteLinks().links(
|
||||
peer).links;
|
||||
const auto link = links.empty() ? nullptr : &links.front();
|
||||
return (link && link->permanent && !link->revoked) ? link : nullptr;
|
||||
};
|
||||
auto value = peer->session().changes().peerFlagsValue(
|
||||
peer,
|
||||
Data::PeerUpdate::Flag::InviteLinks
|
||||
) | rpl::map([=] {
|
||||
const auto link = computePermanentLink();
|
||||
return link
|
||||
? std::make_tuple(link->link, link->usage)
|
||||
: std::make_tuple(QString(), 0);
|
||||
}) | rpl::start_spawning(container->lifetime());
|
||||
|
||||
const auto copyLink = [=] {
|
||||
if (const auto link = computePermanentLink()) {
|
||||
QGuiApplication::clipboard()->setText(link->link);
|
||||
Ui::Toast::Show(tr::lng_group_invite_copied(tr::now));
|
||||
}
|
||||
};
|
||||
const auto shareLink = [=] {
|
||||
if (const auto link = computePermanentLink()) {
|
||||
QGuiApplication::clipboard()->setText(link->link);
|
||||
Ui::Toast::Show(tr::lng_group_invite_copied(tr::now));
|
||||
}
|
||||
};
|
||||
const auto revokeLink = [=] {
|
||||
if (const auto link = computePermanentLink()) {
|
||||
QGuiApplication::clipboard()->setText(link->link);
|
||||
Ui::Toast::Show(tr::lng_group_invite_copied(tr::now));
|
||||
}
|
||||
};
|
||||
|
||||
auto link = rpl::duplicate(
|
||||
value
|
||||
) | rpl::map([=](QString link, int usage) {
|
||||
const auto prefix = qstr("https://");
|
||||
return link.startsWith(prefix) ? link.mid(prefix.size()) : link;
|
||||
});
|
||||
const auto createMenu = [=] {
|
||||
auto result = base::make_unique_q<Ui::PopupMenu>(container);
|
||||
result->addAction(
|
||||
tr::lng_group_invite_context_copy(tr::now),
|
||||
copyLink);
|
||||
result->addAction(
|
||||
tr::lng_group_invite_context_share(tr::now),
|
||||
shareLink);
|
||||
result->addAction(
|
||||
tr::lng_group_invite_context_revoke(tr::now),
|
||||
revokeLink);
|
||||
return result;
|
||||
};
|
||||
const auto label = container->lifetime().make_state<Ui::InviteLinkLabel>(
|
||||
container,
|
||||
std::move(link),
|
||||
createMenu);
|
||||
container->add(
|
||||
label->take(),
|
||||
st::inviteLinkFieldPadding);
|
||||
|
||||
label->clicks(
|
||||
) | rpl::start_with_next(copyLink, label->lifetime());
|
||||
}
|
18
Telegram/SourceFiles/boxes/peers/edit_peer_invite_links.h
Normal file
18
Telegram/SourceFiles/boxes/peers/edit_peer_invite_links.h
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
class PeerData;
|
||||
|
||||
namespace Ui {
|
||||
class VerticalLayout;
|
||||
} // namespace Ui
|
||||
|
||||
void AddPermanentLinkBlock(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
not_null<PeerData*> peer);
|
@@ -14,6 +14,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "boxes/confirm_box.h"
|
||||
#include "boxes/peer_list_controllers.h"
|
||||
#include "boxes/peers/edit_participants_box.h"
|
||||
#include "boxes/peers/edit_peer_info_box.h" // CreateButton.
|
||||
#include "boxes/peers/edit_peer_invite_links.h"
|
||||
#include "chat_helpers/emoji_suggestions_widget.h"
|
||||
#include "core/application.h"
|
||||
#include "data/data_channel.h"
|
||||
@@ -32,15 +34,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/widgets/input_fields.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "ui/widgets/box_content_divider.h"
|
||||
#include "ui/wrap/padding_wrap.h"
|
||||
#include "ui/wrap/slide_wrap.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
#include "ui/special_fields.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "settings/settings_common.h"
|
||||
#include "styles/style_layers.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_info.h"
|
||||
#include "styles/style_settings.h"
|
||||
|
||||
#include <QtGui/QGuiApplication>
|
||||
#include <QtGui/QClipboard>
|
||||
@@ -101,8 +106,6 @@ private:
|
||||
object_ptr<Ui::RpWidget> createUsernameEdit();
|
||||
object_ptr<Ui::RpWidget> createInviteLinkBlock();
|
||||
|
||||
void observeInviteLink();
|
||||
|
||||
void privacyChanged(Privacy value);
|
||||
|
||||
void checkUsernameAvailability();
|
||||
@@ -114,8 +117,6 @@ private:
|
||||
rpl::producer<QString> &&text,
|
||||
not_null<const style::FlatLabel*> st);
|
||||
|
||||
bool canEditInviteLink() const;
|
||||
void refreshInviteLinkBlock();
|
||||
void createInviteLink();
|
||||
void revokeInviteLink(const QString &link);
|
||||
|
||||
@@ -178,6 +179,18 @@ void Controller::createContent() {
|
||||
_wrap->add(createInviteLinkBlock());
|
||||
_wrap->add(createUsernameEdit());
|
||||
|
||||
using namespace Settings;
|
||||
AddSkip(_wrap.get());
|
||||
_wrap->add(EditPeerInfoBox::CreateButton(
|
||||
_wrap.get(),
|
||||
tr::lng_group_invite_manage(),
|
||||
rpl::single(QString()),
|
||||
[=] { /*ShowEditInviteLinks(_navigation, _peer);*/ },
|
||||
st::manageGroupButton,
|
||||
&st::infoIconInviteLinks));
|
||||
AddSkip(_wrap.get());
|
||||
AddDividerText(_wrap.get(), tr::lng_group_invite_manage_about());
|
||||
|
||||
if (_controls.privacy->value() == Privacy::NoUsername) {
|
||||
checkUsernameAvailability();
|
||||
}
|
||||
@@ -292,21 +305,23 @@ object_ptr<Ui::RpWidget> Controller::createUsernameEdit() {
|
||||
|
||||
auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||
_wrap,
|
||||
object_ptr<Ui::VerticalLayout>(_wrap),
|
||||
st::editPeerUsernameMargins);
|
||||
object_ptr<Ui::VerticalLayout>(_wrap));
|
||||
_controls.usernameWrap = result.data();
|
||||
|
||||
const auto container = result->entity();
|
||||
container->add(object_ptr<Ui::PaddingWrap<Ui::FlatLabel>>(
|
||||
container,
|
||||
|
||||
using namespace Settings;
|
||||
AddSkip(container);
|
||||
container->add(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
container,
|
||||
tr::lng_create_group_link(),
|
||||
st::editPeerSectionLabel),
|
||||
st::editPeerUsernameTitleLabelMargins));
|
||||
st::settingsSubsectionTitle),
|
||||
st::settingsSubsectionTitlePadding);
|
||||
|
||||
const auto placeholder = container->add(object_ptr<Ui::RpWidget>(
|
||||
container));
|
||||
const auto placeholder = container->add(
|
||||
object_ptr<Ui::RpWidget>(container),
|
||||
st::editPeerUsernameFieldMargins);
|
||||
placeholder->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
_controls.usernameInput = Ui::AttachParentChild(
|
||||
container,
|
||||
@@ -328,13 +343,9 @@ object_ptr<Ui::RpWidget> Controller::createUsernameEdit() {
|
||||
}, placeholder->lifetime());
|
||||
_controls.usernameInput->move(placeholder->pos());
|
||||
|
||||
container->add(object_ptr<Ui::PaddingWrap<Ui::FlatLabel>>(
|
||||
AddDividerText(
|
||||
container,
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
container,
|
||||
tr::lng_create_channel_link_about(),
|
||||
st::editPeerPrivacyLabel),
|
||||
st::editPeerUsernameAboutLabelMargins));
|
||||
tr::lng_create_channel_link_about());
|
||||
|
||||
QObject::connect(
|
||||
_controls.usernameInput,
|
||||
@@ -348,6 +359,11 @@ object_ptr<Ui::RpWidget> Controller::createUsernameEdit() {
|
||||
}
|
||||
|
||||
void Controller::privacyChanged(Privacy value) {
|
||||
const auto toggleInviteLink = [&] {
|
||||
_controls.inviteLinkWrap->toggle(
|
||||
(value != Privacy::HasUsername),
|
||||
anim::type::instant);
|
||||
};
|
||||
const auto toggleEditUsername = [&] {
|
||||
_controls.usernameWrap->toggle(
|
||||
(value == Privacy::HasUsername),
|
||||
@@ -358,14 +374,14 @@ void Controller::privacyChanged(Privacy value) {
|
||||
// Otherwise box will change own Y position.
|
||||
|
||||
if (value == Privacy::HasUsername) {
|
||||
refreshInviteLinkBlock();
|
||||
toggleInviteLink();
|
||||
toggleEditUsername();
|
||||
|
||||
_controls.usernameResult = nullptr;
|
||||
checkUsernameAvailability();
|
||||
} else {
|
||||
toggleEditUsername();
|
||||
refreshInviteLinkBlock();
|
||||
toggleInviteLink();
|
||||
}
|
||||
};
|
||||
if (value == Privacy::HasUsername) {
|
||||
@@ -538,100 +554,38 @@ void Controller::revokeInviteLink(const QString &link) {
|
||||
Ui::show(std::move(box), Ui::LayerOption::KeepOther);
|
||||
}
|
||||
|
||||
bool Controller::canEditInviteLink() const {
|
||||
if (const auto channel = _peer->asChannel()) {
|
||||
return channel->canHaveInviteLink();
|
||||
} else if (const auto chat = _peer->asChat()) {
|
||||
return chat->canHaveInviteLink();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Controller::observeInviteLink() {
|
||||
if (!_controls.inviteLinkWrap) {
|
||||
return;
|
||||
}
|
||||
_peer->session().changes().peerFlagsValue(
|
||||
_peer,
|
||||
Data::PeerUpdate::Flag::InviteLinks
|
||||
) | rpl::start_with_next([=] {
|
||||
refreshInviteLinkBlock();
|
||||
}, _controls.inviteLinkWrap->lifetime());
|
||||
}
|
||||
|
||||
object_ptr<Ui::RpWidget> Controller::createInviteLinkBlock() {
|
||||
Expects(_wrap != nullptr);
|
||||
|
||||
if (!canEditInviteLink()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||
_wrap,
|
||||
object_ptr<Ui::VerticalLayout>(_wrap),
|
||||
st::editPeerInvitesMargins);
|
||||
object_ptr<Ui::VerticalLayout>(_wrap));
|
||||
_controls.inviteLinkWrap = result.data();
|
||||
|
||||
const auto container = result->entity();
|
||||
container->add(object_ptr<Ui::FlatLabel>(
|
||||
container,
|
||||
tr::lng_profile_invite_link_section(),
|
||||
st::editPeerSectionLabel));
|
||||
container->add(object_ptr<Ui::FixedHeightWidget>(
|
||||
container,
|
||||
st::editPeerInviteLinkBoxBottomSkip));
|
||||
|
||||
_controls.inviteLink = container->add(object_ptr<Ui::FlatLabel>(
|
||||
container,
|
||||
st::editPeerInviteLink));
|
||||
_controls.inviteLink->setSelectable(true);
|
||||
_controls.inviteLink->setContextCopyText(QString());
|
||||
_controls.inviteLink->setBreakEverywhere(true);
|
||||
_controls.inviteLink->setClickHandlerFilter([=](auto&&...) {
|
||||
QGuiApplication::clipboard()->setText(inviteLinkText());
|
||||
Ui::Toast::Show(tr::lng_group_invite_copied(tr::now));
|
||||
return false;
|
||||
});
|
||||
using namespace Settings;
|
||||
AddSkip(container);
|
||||
container->add(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
container,
|
||||
tr::lng_create_permanent_link_title(),
|
||||
st::settingsSubsectionTitle),
|
||||
st::settingsSubsectionTitlePadding);
|
||||
|
||||
container->add(object_ptr<Ui::FixedHeightWidget>(
|
||||
container,
|
||||
st::editPeerInviteLinkSkip));
|
||||
container->add(object_ptr<Ui::LinkButton>(
|
||||
container,
|
||||
tr::lng_group_invite_create_new(tr::now),
|
||||
st::editPeerInviteLinkButton)
|
||||
)->addClickHandler([=] { revokeInviteLink(inviteLinkText()); });
|
||||
AddPermanentLinkBlock(container, _peer);
|
||||
|
||||
observeInviteLink();
|
||||
AddSkip(container);
|
||||
|
||||
AddDividerText(
|
||||
container,
|
||||
((_peer->isMegagroup() || _peer->asChat())
|
||||
? tr::lng_group_invite_about_permanent_group()
|
||||
: tr::lng_group_invite_about_permanent_channel()));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Controller::refreshInviteLinkBlock() {
|
||||
const auto link = inviteLinkText();
|
||||
auto text = TextWithEntities();
|
||||
if (!link.isEmpty()) {
|
||||
text.text = link;
|
||||
const auto remove = qstr("https://");
|
||||
if (text.text.startsWith(remove)) {
|
||||
text.text.remove(0, remove.size());
|
||||
}
|
||||
text.entities.push_back({
|
||||
EntityType::CustomUrl,
|
||||
0,
|
||||
text.text.size(),
|
||||
link });
|
||||
}
|
||||
_controls.inviteLink->setMarkedText(text);
|
||||
|
||||
// Hack to expand FlatLabel width to naturalWidth again.
|
||||
_controls.inviteLinkWrap->resizeToWidth(st::boxWideWidth);
|
||||
|
||||
_controls.inviteLinkWrap->toggle(
|
||||
inviteLinkShown() && !link.isEmpty(),
|
||||
anim::type::instant);
|
||||
}
|
||||
|
||||
bool Controller::inviteLinkShown() {
|
||||
return !_controls.privacy
|
||||
|| (_controls.privacy->value() == Privacy::NoUsername);
|
||||
|
Reference in New Issue
Block a user