mirror of
https://github.com/vale981/tdesktop
synced 2025-03-05 09:41:41 -05:00
Allow to create channel invite link in boxes.
SetupChannelBox (public/private) and MaxInviteBox are suggesting to copy the channel invite link. Now they suggest to create it in case the channel didn't have the invite link already.
This commit is contained in:
parent
949104d879
commit
cabf35f2b3
5 changed files with 36 additions and 13 deletions
|
@ -482,6 +482,11 @@ void SetupChannelBox::prepare() {
|
|||
connect(&_checkTimer, SIGNAL(timeout()), this, SLOT(onCheck()));
|
||||
|
||||
_privacyGroup->setChangedCallback([this](Privacy value) { privacyChanged(value); });
|
||||
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::InviteLinkChanged, [this](const Notify::PeerUpdate &update) {
|
||||
if (update.peer == _channel) {
|
||||
rtlupdate(_invitationLink);
|
||||
}
|
||||
}));
|
||||
|
||||
updateMaxHeight();
|
||||
}
|
||||
|
@ -541,7 +546,8 @@ void SetupChannelBox::paintEvent(QPaintEvent *e) {
|
|||
option.setWrapMode(QTextOption::WrapAnywhere);
|
||||
p.setFont(_linkOver ? st::boxTextFont->underline() : st::boxTextFont);
|
||||
p.setPen(st::defaultLinkButton.color);
|
||||
p.drawText(_invitationLink, _channel->inviteLink(), option);
|
||||
auto inviteLinkText = _channel->inviteLink().isEmpty() ? lang(lng_group_invite_create) : _channel->inviteLink();
|
||||
p.drawText(_invitationLink, inviteLinkText, option);
|
||||
}
|
||||
} else {
|
||||
if (!_errorText.isEmpty()) {
|
||||
|
@ -573,8 +579,12 @@ void SetupChannelBox::mouseMoveEvent(QMouseEvent *e) {
|
|||
|
||||
void SetupChannelBox::mousePressEvent(QMouseEvent *e) {
|
||||
if (_linkOver) {
|
||||
QGuiApplication::clipboard()->setText(_channel->inviteLink());
|
||||
Ui::Toast::Show(lang(lng_create_channel_link_copied));
|
||||
if (_channel->inviteLink().isEmpty()) {
|
||||
App::api()->exportInviteLink(_channel);
|
||||
} else {
|
||||
QGuiApplication::clipboard()->setText(_channel->inviteLink());
|
||||
Ui::Toast::Show(lang(lng_create_channel_link_copied));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "core/click_handler_types.h"
|
||||
#include "storage/localstorage.h"
|
||||
#include "auth_session.h"
|
||||
#include "observer_peer.h"
|
||||
|
||||
TextParseOptions _confirmBoxTextOptions = {
|
||||
TextParseLinks | TextParseMultiline | TextParseRichText, // flags
|
||||
|
@ -216,9 +217,9 @@ InformBox::InformBox(QWidget*, const QString &text, base::lambda<void()> closedC
|
|||
InformBox::InformBox(QWidget*, const QString &text, const QString &doneText, base::lambda<void()> closedCallback) : ConfirmBox(ConfirmBox::InformBoxTag(), text, doneText, std::move(closedCallback)) {
|
||||
}
|
||||
|
||||
MaxInviteBox::MaxInviteBox(QWidget*, const QString &link)
|
||||
: _text(st::boxLabelStyle, lng_participant_invite_sorry(lt_count, Global::ChatSizeMax()), _confirmBoxTextOptions, st::boxWidth - st::boxPadding.left() - st::boxButtonPadding.right())
|
||||
, _link(link) {
|
||||
MaxInviteBox::MaxInviteBox(QWidget*, gsl::not_null<ChannelData*> channel) : BoxContent()
|
||||
, _channel(channel)
|
||||
, _text(st::boxLabelStyle, lng_participant_invite_sorry(lt_count, Global::ChatSizeMax()), _confirmBoxTextOptions, st::boxWidth - st::boxPadding.left() - st::boxButtonPadding.right()) {
|
||||
}
|
||||
|
||||
void MaxInviteBox::prepare() {
|
||||
|
@ -229,6 +230,12 @@ void MaxInviteBox::prepare() {
|
|||
_textWidth = st::boxWidth - st::boxPadding.left() - st::boxButtonPadding.right();
|
||||
_textHeight = qMin(_text.countHeight(_textWidth), 16 * st::boxLabelStyle.lineHeight);
|
||||
setDimensions(st::boxWidth, st::boxPadding.top() + _textHeight + st::boxTextFont->height + st::boxTextFont->height * 2 + st::newGroupLinkPadding.bottom());
|
||||
|
||||
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::InviteLinkChanged, [this](const Notify::PeerUpdate &update) {
|
||||
if (update.peer == _channel) {
|
||||
rtlupdate(_invitationLink);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
void MaxInviteBox::mouseMoveEvent(QMouseEvent *e) {
|
||||
|
@ -238,8 +245,12 @@ void MaxInviteBox::mouseMoveEvent(QMouseEvent *e) {
|
|||
void MaxInviteBox::mousePressEvent(QMouseEvent *e) {
|
||||
mouseMoveEvent(e);
|
||||
if (_linkOver) {
|
||||
Application::clipboard()->setText(_link);
|
||||
Ui::Toast::Show(lang(lng_create_channel_link_copied));
|
||||
if (_channel->inviteLink().isEmpty()) {
|
||||
App::api()->exportInviteLink(_channel);
|
||||
} else {
|
||||
QGuiApplication::clipboard()->setText(_channel->inviteLink());
|
||||
Ui::Toast::Show(lang(lng_create_channel_link_copied));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -271,7 +282,8 @@ void MaxInviteBox::paintEvent(QPaintEvent *e) {
|
|||
option.setWrapMode(QTextOption::WrapAnywhere);
|
||||
p.setFont(_linkOver ? st::defaultInputField.font->underline() : st::defaultInputField.font);
|
||||
p.setPen(st::defaultLinkButton.color);
|
||||
p.drawText(_invitationLink, _link, option);
|
||||
auto inviteLinkText = _channel->inviteLink().isEmpty() ? lang(lng_group_invite_create) : _channel->inviteLink();
|
||||
p.drawText(_invitationLink, inviteLinkText, option);
|
||||
}
|
||||
|
||||
void MaxInviteBox::resizeEvent(QResizeEvent *e) {
|
||||
|
|
|
@ -100,7 +100,7 @@ public:
|
|||
|
||||
class MaxInviteBox : public BoxContent {
|
||||
public:
|
||||
MaxInviteBox(QWidget*, const QString &link);
|
||||
MaxInviteBox(QWidget*, gsl::not_null<ChannelData*> channel);
|
||||
|
||||
protected:
|
||||
void prepare() override;
|
||||
|
@ -114,10 +114,11 @@ protected:
|
|||
private:
|
||||
void updateSelected(const QPoint &cursorGlobalPosition);
|
||||
|
||||
gsl::not_null<ChannelData*> _channel;
|
||||
|
||||
Text _text;
|
||||
int32 _textWidth, _textHeight;
|
||||
|
||||
QString _link;
|
||||
QRect _invitationLink;
|
||||
bool _linkOver = false;
|
||||
|
||||
|
|
|
@ -1468,7 +1468,7 @@ void ContactsBox::Inner::changeCheckState(ContactData *data, PeerData *peer) {
|
|||
} else if (selectedCount() < ((_channel && _channel->isMegagroup()) ? Global::MegagroupSizeMax() : Global::ChatSizeMax())) {
|
||||
changePeerCheckState(data, peer, true);
|
||||
} else if (_channel && !_channel->isMegagroup()) {
|
||||
Ui::show(Box<MaxInviteBox>(_channel->inviteLink()), KeepOtherLayers);
|
||||
Ui::show(Box<MaxInviteBox>(_channel), KeepOtherLayers);
|
||||
} else if (!_channel && selectedCount() >= Global::ChatSizeMax() && selectedCount() < Global::MegagroupSizeMax()) {
|
||||
Ui::show(Box<InformBox>(lng_profile_add_more_after_upgrade(lt_count, Global::MegagroupSizeMax())), KeepOtherLayers);
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ void ParticipantsBoxController::Start(gsl::not_null<ChannelData*> channel, Role
|
|||
void ParticipantsBoxController::addNewItem() {
|
||||
if (_role == Role::Members) {
|
||||
if (_channel->membersCount() >= Global::ChatSizeMax()) {
|
||||
Ui::show(Box<MaxInviteBox>(_channel->inviteLink()), KeepOtherLayers);
|
||||
Ui::show(Box<MaxInviteBox>(_channel), KeepOtherLayers);
|
||||
} else {
|
||||
auto already = MembersAlreadyIn();
|
||||
for (auto i = 0, count = delegate()->peerListFullRowsCount(); i != count; ++i) {
|
||||
|
|
Loading…
Add table
Reference in a new issue