mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Improved code style in some peer boxes.
This commit is contained in:
parent
ee05e0af06
commit
2d37920a4c
2 changed files with 361 additions and 172 deletions
|
@ -8,15 +8,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "boxes/add_contact_box.h"
|
#include "boxes/add_contact_box.h"
|
||||||
|
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "mtproto/sender.h"
|
|
||||||
#include "base/flat_set.h"
|
|
||||||
#include "base/random.h"
|
#include "base/random.h"
|
||||||
#include "boxes/confirm_box.h"
|
#include "boxes/confirm_box.h"
|
||||||
#include "boxes/peer_list_controllers.h"
|
#include "boxes/peer_list_controllers.h"
|
||||||
#include "boxes/peers/add_participants_box.h"
|
#include "boxes/peers/add_participants_box.h"
|
||||||
#include "boxes/peers/edit_participant_box.h"
|
#include "boxes/peers/edit_participant_box.h"
|
||||||
#include "boxes/peers/edit_participants_box.h"
|
#include "boxes/peers/edit_participants_box.h"
|
||||||
#include "core/file_utilities.h"
|
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "chat_helpers/emoji_suggestions_widget.h"
|
#include "chat_helpers/emoji_suggestions_widget.h"
|
||||||
#include "countries/countries_instance.h" // Countries::ExtractPhoneCode.
|
#include "countries/countries_instance.h" // Countries::ExtractPhoneCode.
|
||||||
|
@ -36,8 +33,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/data_changes.h"
|
#include "data/data_changes.h"
|
||||||
#include "data/data_cloud_file.h"
|
#include "data/data_cloud_file.h"
|
||||||
#include "mainwidget.h"
|
|
||||||
#include "mainwindow.h"
|
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "api/api_invite_links.h"
|
#include "api/api_invite_links.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
@ -45,6 +40,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
#include "styles/style_dialogs.h"
|
#include "styles/style_dialogs.h"
|
||||||
|
#include "styles/style_widgets.h"
|
||||||
|
|
||||||
#include <QtGui/QGuiApplication>
|
#include <QtGui/QGuiApplication>
|
||||||
#include <QtGui/QClipboard>
|
#include <QtGui/QClipboard>
|
||||||
|
@ -73,7 +69,7 @@ void ChatCreateDone(
|
||||||
const MTPUpdates &updates) {
|
const MTPUpdates &updates) {
|
||||||
navigation->session().api().applyUpdates(updates);
|
navigation->session().api().applyUpdates(updates);
|
||||||
|
|
||||||
auto success = base::make_optional(&updates)
|
const auto success = base::make_optional(&updates)
|
||||||
| [](auto updates) -> std::optional<const QVector<MTPChat>*> {
|
| [](auto updates) -> std::optional<const QVector<MTPChat>*> {
|
||||||
switch (updates->type()) {
|
switch (updates->type()) {
|
||||||
case mtpc_updates:
|
case mtpc_updates:
|
||||||
|
@ -280,7 +276,8 @@ void AddContactBox::prepare() {
|
||||||
setTabOrder(_last, _first);
|
setTabOrder(_last, _first);
|
||||||
}
|
}
|
||||||
const auto readyToAdd = !_phone->getLastText().isEmpty()
|
const auto readyToAdd = !_phone->getLastText().isEmpty()
|
||||||
&& (!_first->getLastText().isEmpty() || !_last->getLastText().isEmpty());
|
&& (!_first->getLastText().isEmpty()
|
||||||
|
|| !_last->getLastText().isEmpty());
|
||||||
setTitle(readyToAdd
|
setTitle(readyToAdd
|
||||||
? tr::lng_confirm_contact_data()
|
? tr::lng_confirm_contact_data()
|
||||||
: tr::lng_enter_contact_data());
|
: tr::lng_enter_contact_data());
|
||||||
|
@ -290,11 +287,21 @@ void AddContactBox::prepare() {
|
||||||
connect(_last, &Ui::InputField::submitted, [=] { submit(); });
|
connect(_last, &Ui::InputField::submitted, [=] { submit(); });
|
||||||
connect(_phone, &Ui::PhoneInput::submitted, [=] { submit(); });
|
connect(_phone, &Ui::PhoneInput::submitted, [=] { submit(); });
|
||||||
|
|
||||||
setDimensions(st::boxWideWidth, st::contactPadding.top() + _first->height() + st::contactSkip + _last->height() + st::contactPhoneSkip + _phone->height() + st::contactPadding.bottom() + st::boxPadding.bottom());
|
setDimensions(
|
||||||
|
st::boxWideWidth,
|
||||||
|
st::contactPadding.top()
|
||||||
|
+ _first->height()
|
||||||
|
+ st::contactSkip
|
||||||
|
+ _last->height()
|
||||||
|
+ st::contactPhoneSkip
|
||||||
|
+ _phone->height()
|
||||||
|
+ st::contactPadding.bottom()
|
||||||
|
+ st::boxPadding.bottom());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddContactBox::setInnerFocus() {
|
void AddContactBox::setInnerFocus() {
|
||||||
if ((_first->getLastText().isEmpty() && _last->getLastText().isEmpty()) || !_phone->isEnabled()) {
|
if ((_first->getLastText().isEmpty() && _last->getLastText().isEmpty())
|
||||||
|
|| !_phone->isEnabled()) {
|
||||||
(_invertOrder ? _last : _first)->setFocusFast();
|
(_invertOrder ? _last : _first)->setFocusFast();
|
||||||
_phone->finishAnimating();
|
_phone->finishAnimating();
|
||||||
} else {
|
} else {
|
||||||
|
@ -309,8 +316,18 @@ void AddContactBox::paintEvent(QPaintEvent *e) {
|
||||||
if (_retrying) {
|
if (_retrying) {
|
||||||
p.setPen(st::boxTextFg);
|
p.setPen(st::boxTextFg);
|
||||||
p.setFont(st::boxTextFont);
|
p.setFont(st::boxTextFont);
|
||||||
auto textHeight = height() - st::contactPadding.top() - st::contactPadding.bottom() - st::boxPadding.bottom();
|
const auto textHeight = height()
|
||||||
p.drawText(QRect(st::boxPadding.left(), st::contactPadding.top(), width() - st::boxPadding.left() - st::boxPadding.right(), textHeight), tr::lng_contact_not_joined(tr::now, lt_name, _sentName), style::al_topleft);
|
- st::contactPadding.top()
|
||||||
|
- st::contactPadding.bottom()
|
||||||
|
- st::boxPadding.bottom();
|
||||||
|
p.drawText(
|
||||||
|
QRect(
|
||||||
|
st::boxPadding.left(),
|
||||||
|
st::contactPadding.top(),
|
||||||
|
width() - st::boxPadding.left() - st::boxPadding.right(),
|
||||||
|
textHeight),
|
||||||
|
tr::lng_contact_not_joined(tr::now, lt_name, _sentName),
|
||||||
|
style::al_topleft);
|
||||||
} else {
|
} else {
|
||||||
st::contactUserIcon.paint(
|
st::contactUserIcon.paint(
|
||||||
p,
|
p,
|
||||||
|
@ -328,18 +345,25 @@ void AddContactBox::paintEvent(QPaintEvent *e) {
|
||||||
void AddContactBox::resizeEvent(QResizeEvent *e) {
|
void AddContactBox::resizeEvent(QResizeEvent *e) {
|
||||||
BoxContent::resizeEvent(e);
|
BoxContent::resizeEvent(e);
|
||||||
|
|
||||||
_first->resize(width() - st::boxPadding.left() - st::contactPadding.left() - st::boxPadding.right(), _first->height());
|
_first->resize(
|
||||||
|
width()
|
||||||
|
- st::boxPadding.left()
|
||||||
|
- st::contactPadding.left()
|
||||||
|
- st::boxPadding.right(),
|
||||||
|
_first->height());
|
||||||
_last->resize(_first->width(), _last->height());
|
_last->resize(_first->width(), _last->height());
|
||||||
_phone->resize(_first->width(), _last->height());
|
_phone->resize(_first->width(), _last->height());
|
||||||
if (_invertOrder) {
|
const auto left = st::boxPadding.left() + st::contactPadding.left();
|
||||||
_last->moveToLeft(st::boxPadding.left() + st::contactPadding.left(), st::contactPadding.top());
|
const auto &firstRow = _invertOrder ? _last : _first;
|
||||||
_first->moveToLeft(st::boxPadding.left() + st::contactPadding.left(), _last->y() + _last->height() + st::contactSkip);
|
const auto &secondRow = _invertOrder ? _first : _last;
|
||||||
_phone->moveToLeft(st::boxPadding.left() + st::contactPadding.left(), _first->y() + _first->height() + st::contactPhoneSkip);
|
const auto &thirdRow = _phone;
|
||||||
} else {
|
firstRow->moveToLeft(left, st::contactPadding.top());
|
||||||
_first->moveToLeft(st::boxPadding.left() + st::contactPadding.left(), st::contactPadding.top());
|
secondRow->moveToLeft(
|
||||||
_last->moveToLeft(st::boxPadding.left() + st::contactPadding.left(), _first->y() + _first->height() + st::contactSkip);
|
left,
|
||||||
_phone->moveToLeft(st::boxPadding.left() + st::contactPadding.left(), _last->y() + _last->height() + st::contactPhoneSkip);
|
firstRow->y() + firstRow->height() + st::contactSkip);
|
||||||
}
|
thirdRow->moveToLeft(
|
||||||
|
left,
|
||||||
|
secondRow->y() + secondRow->height() + st::contactPhoneSkip);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddContactBox::submit() {
|
void AddContactBox::submit() {
|
||||||
|
@ -361,9 +385,11 @@ void AddContactBox::save() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto firstName = TextUtilities::PrepareForSending(_first->getLastText());
|
auto firstName = TextUtilities::PrepareForSending(
|
||||||
auto lastName = TextUtilities::PrepareForSending(_last->getLastText());
|
_first->getLastText());
|
||||||
auto phone = _phone->getLastText().trimmed();
|
auto lastName = TextUtilities::PrepareForSending(
|
||||||
|
_last->getLastText());
|
||||||
|
const auto phone = _phone->getLastText().trimmed();
|
||||||
if (firstName.isEmpty() && lastName.isEmpty()) {
|
if (firstName.isEmpty() && lastName.isEmpty()) {
|
||||||
if (_invertOrder) {
|
if (_invertOrder) {
|
||||||
_last->setFocus();
|
_last->setFocus();
|
||||||
|
@ -501,9 +527,15 @@ void GroupInfoBox::prepare() {
|
||||||
_description->setSubmitSettings(
|
_description->setSubmitSettings(
|
||||||
Core::App().settings().sendSubmitWay());
|
Core::App().settings().sendSubmitWay());
|
||||||
|
|
||||||
connect(_description, &Ui::InputField::resized, [=] { descriptionResized(); });
|
connect(_description, &Ui::InputField::resized, [=] {
|
||||||
connect(_description, &Ui::InputField::submitted, [=] { submit(); });
|
descriptionResized();
|
||||||
connect(_description, &Ui::InputField::cancelled, [=] { closeBox(); });
|
});
|
||||||
|
connect(_description, &Ui::InputField::submitted, [=] {
|
||||||
|
submit();
|
||||||
|
});
|
||||||
|
connect(_description, &Ui::InputField::cancelled, [=] {
|
||||||
|
closeBox();
|
||||||
|
});
|
||||||
|
|
||||||
Ui::Emoji::SuggestionsController::Init(
|
Ui::Emoji::SuggestionsController::Init(
|
||||||
getDelegate()->outerContainer(),
|
getDelegate()->outerContainer(),
|
||||||
|
@ -530,17 +562,34 @@ void GroupInfoBox::setInnerFocus() {
|
||||||
void GroupInfoBox::resizeEvent(QResizeEvent *e) {
|
void GroupInfoBox::resizeEvent(QResizeEvent *e) {
|
||||||
BoxContent::resizeEvent(e);
|
BoxContent::resizeEvent(e);
|
||||||
|
|
||||||
_photo->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), st::boxPadding.top() + st::newGroupInfoPadding.top());
|
_photo->moveToLeft(
|
||||||
|
st::boxPadding.left() + st::newGroupInfoPadding.left(),
|
||||||
|
st::boxPadding.top() + st::newGroupInfoPadding.top());
|
||||||
|
|
||||||
auto nameLeft = st::defaultUserpicButton.size.width()
|
const auto nameLeft = st::defaultUserpicButton.size.width()
|
||||||
+ st::newGroupNamePosition.x();
|
+ st::newGroupNamePosition.x();
|
||||||
_title->resize(width() - st::boxPadding.left() - st::newGroupInfoPadding.left() - st::boxPadding.right() - nameLeft, _title->height());
|
_title->resize(
|
||||||
_title->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left() + nameLeft, st::boxPadding.top() + st::newGroupInfoPadding.top() + st::newGroupNamePosition.y());
|
width()
|
||||||
|
- st::boxPadding.left()
|
||||||
|
- st::newGroupInfoPadding.left()
|
||||||
|
- st::boxPadding.right()
|
||||||
|
- nameLeft,
|
||||||
|
_title->height());
|
||||||
|
_title->moveToLeft(
|
||||||
|
st::boxPadding.left() + st::newGroupInfoPadding.left() + nameLeft,
|
||||||
|
st::boxPadding.top()
|
||||||
|
+ st::newGroupInfoPadding.top()
|
||||||
|
+ st::newGroupNamePosition.y());
|
||||||
if (_description) {
|
if (_description) {
|
||||||
_description->resize(width() - st::boxPadding.left() - st::newGroupInfoPadding.left() - st::boxPadding.right(), _description->height());
|
_description->resize(
|
||||||
auto descriptionLeft = st::boxPadding.left()
|
width()
|
||||||
|
- st::boxPadding.left()
|
||||||
|
- st::newGroupInfoPadding.left()
|
||||||
|
- st::boxPadding.right(),
|
||||||
|
_description->height());
|
||||||
|
const auto descriptionLeft = st::boxPadding.left()
|
||||||
+ st::newGroupInfoPadding.left();
|
+ st::newGroupInfoPadding.left();
|
||||||
auto descriptionTop = st::boxPadding.top()
|
const auto descriptionTop = st::boxPadding.top()
|
||||||
+ st::newGroupInfoPadding.top()
|
+ st::newGroupInfoPadding.top()
|
||||||
+ st::defaultUserpicButton.size.height()
|
+ st::defaultUserpicButton.size.height()
|
||||||
+ st::newGroupDescriptionPadding.top();
|
+ st::newGroupDescriptionPadding.top();
|
||||||
|
@ -654,7 +703,9 @@ void GroupInfoBox::submit() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupInfoBox::createChannel(const QString &title, const QString &description) {
|
void GroupInfoBox::createChannel(
|
||||||
|
const QString &title,
|
||||||
|
const QString &description) {
|
||||||
Expects(!_creationRequestId);
|
Expects(!_creationRequestId);
|
||||||
|
|
||||||
const auto flags = (_type == Type::Megagroup)
|
const auto flags = (_type == Type::Megagroup)
|
||||||
|
@ -677,11 +728,13 @@ void GroupInfoBox::createChannel(const QString &title, const QString &descriptio
|
||||||
case mtpc_updatesCombined:
|
case mtpc_updatesCombined:
|
||||||
return &updates->c_updatesCombined().vchats().v;
|
return &updates->c_updatesCombined().vchats().v;
|
||||||
}
|
}
|
||||||
LOG(("API Error: unexpected update cons %1 (GroupInfoBox::createChannel)").arg(updates->type()));
|
LOG(("API Error: unexpected update cons %1 "
|
||||||
|
"(GroupInfoBox::createChannel)").arg(updates->type()));
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
| [](auto chats) {
|
| [](auto chats) {
|
||||||
return (!chats->empty() && chats->front().type() == mtpc_channel)
|
return (!chats->empty()
|
||||||
|
&& chats->front().type() == mtpc_channel)
|
||||||
? base::make_optional(chats)
|
? base::make_optional(chats)
|
||||||
: std::nullopt;
|
: std::nullopt;
|
||||||
}
|
}
|
||||||
|
@ -700,7 +753,8 @@ void GroupInfoBox::createChannel(const QString &title, const QString &descriptio
|
||||||
checkInviteLink();
|
checkInviteLink();
|
||||||
};
|
};
|
||||||
if (!success) {
|
if (!success) {
|
||||||
LOG(("API Error: channel not found in updates (GroupInfoBox::creationDone)"));
|
LOG(("API Error: channel not found in updates "
|
||||||
|
"(GroupInfoBox::creationDone)"));
|
||||||
closeBox();
|
closeBox();
|
||||||
}
|
}
|
||||||
}).fail([this](const MTP::Error &error) {
|
}).fail([this](const MTP::Error &error) {
|
||||||
|
@ -813,7 +867,8 @@ SetupChannelBox::SetupChannelBox(
|
||||||
st::setupChannelLink,
|
st::setupChannelLink,
|
||||||
nullptr,
|
nullptr,
|
||||||
channel->username,
|
channel->username,
|
||||||
channel->session().createInternalLink(QString())) {
|
channel->session().createInternalLink(QString()))
|
||||||
|
, _checkTimer([=] { check(); }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupChannelBox::prepare() {
|
void SetupChannelBox::prepare() {
|
||||||
|
@ -825,7 +880,8 @@ void SetupChannelBox::prepare() {
|
||||||
_channel->inputChannel,
|
_channel->inputChannel,
|
||||||
MTP_string("preston")
|
MTP_string("preston")
|
||||||
)).fail([=](const MTP::Error &error) {
|
)).fail([=](const MTP::Error &error) {
|
||||||
firstCheckFail(error);
|
_checkRequestId = 0;
|
||||||
|
firstCheckFail(error.type());
|
||||||
}).send();
|
}).send();
|
||||||
|
|
||||||
addButton(tr::lng_settings_save(), [=] { save(); });
|
addButton(tr::lng_settings_save(), [=] { save(); });
|
||||||
|
@ -836,10 +892,9 @@ void SetupChannelBox::prepare() {
|
||||||
connect(_link, &Ui::MaskedInputField::changed, [=] { handleChange(); });
|
connect(_link, &Ui::MaskedInputField::changed, [=] { handleChange(); });
|
||||||
_link->setVisible(_privacyGroup->value() == Privacy::Public);
|
_link->setVisible(_privacyGroup->value() == Privacy::Public);
|
||||||
|
|
||||||
_checkTimer.setSingleShot(true);
|
_privacyGroup->setChangedCallback([=](Privacy value) {
|
||||||
connect(&_checkTimer, &QTimer::timeout, [=] { check(); });
|
privacyChanged(value);
|
||||||
|
});
|
||||||
_privacyGroup->setChangedCallback([this](Privacy value) { privacyChanged(value); });
|
|
||||||
|
|
||||||
_channel->session().changes().peerUpdates(
|
_channel->session().changes().peerUpdates(
|
||||||
_channel,
|
_channel,
|
||||||
|
@ -866,9 +921,20 @@ void SetupChannelBox::setInnerFocus() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupChannelBox::updateMaxHeight() {
|
void SetupChannelBox::updateMaxHeight() {
|
||||||
auto newHeight = st::boxPadding.top() + st::newGroupPadding.top() + _public->heightNoMargins() + _aboutPublicHeight + st::newGroupSkip + _private->heightNoMargins() + _aboutPrivate.countHeight(_aboutPublicWidth) + st::newGroupSkip + st::newGroupPadding.bottom();
|
auto newHeight = st::boxPadding.top()
|
||||||
if (!_channel->isMegagroup() || _privacyGroup->value() == Privacy::Public) {
|
+ st::newGroupPadding.top()
|
||||||
newHeight += st::newGroupLinkPadding.top() + _link->height() + st::newGroupLinkPadding.bottom();
|
+ _public->heightNoMargins()
|
||||||
|
+ _aboutPublicHeight
|
||||||
|
+ st::newGroupSkip
|
||||||
|
+ _private->heightNoMargins()
|
||||||
|
+ _aboutPrivate.countHeight(_aboutPublicWidth)
|
||||||
|
+ st::newGroupSkip
|
||||||
|
+ st::newGroupPadding.bottom();
|
||||||
|
if (!_channel->isMegagroup()
|
||||||
|
|| _privacyGroup->value() == Privacy::Public) {
|
||||||
|
newHeight += st::newGroupLinkPadding.top()
|
||||||
|
+ _link->height()
|
||||||
|
+ st::newGroupLinkPadding.bottom();
|
||||||
}
|
}
|
||||||
setDimensions(st::boxWideWidth, newHeight);
|
setDimensions(st::boxWideWidth, newHeight);
|
||||||
}
|
}
|
||||||
|
@ -894,17 +960,43 @@ void SetupChannelBox::paintEvent(QPaintEvent *e) {
|
||||||
p.fillRect(e->rect(), st::boxBg);
|
p.fillRect(e->rect(), st::boxBg);
|
||||||
p.setPen(st::newGroupAboutFg);
|
p.setPen(st::newGroupAboutFg);
|
||||||
|
|
||||||
QRect aboutPublic(st::boxPadding.left() + st::newGroupPadding.left() + st::defaultRadio.diameter + st::defaultBoxCheckbox.textPosition.x(), _public->bottomNoMargins(), _aboutPublicWidth, _aboutPublicHeight);
|
const auto aboutPublic = QRect(
|
||||||
_aboutPublic.drawLeft(p, aboutPublic.x(), aboutPublic.y(), aboutPublic.width(), width());
|
st::boxPadding.left()
|
||||||
|
+ st::newGroupPadding.left()
|
||||||
|
+ st::defaultRadio.diameter
|
||||||
|
+ st::defaultBoxCheckbox.textPosition.x(),
|
||||||
|
_public->bottomNoMargins(),
|
||||||
|
_aboutPublicWidth,
|
||||||
|
_aboutPublicHeight);
|
||||||
|
_aboutPublic.drawLeft(
|
||||||
|
p,
|
||||||
|
aboutPublic.x(),
|
||||||
|
aboutPublic.y(),
|
||||||
|
aboutPublic.width(),
|
||||||
|
width());
|
||||||
|
|
||||||
QRect aboutPrivate(st::boxPadding.left() + st::newGroupPadding.left() + st::defaultRadio.diameter + st::defaultBoxCheckbox.textPosition.x(), _private->bottomNoMargins(), _aboutPublicWidth, _aboutPublicHeight);
|
const auto aboutPrivate = QRect(
|
||||||
_aboutPrivate.drawLeft(p, aboutPrivate.x(), aboutPrivate.y(), aboutPrivate.width(), width());
|
st::boxPadding.left()
|
||||||
|
+ st::newGroupPadding.left()
|
||||||
|
+ st::defaultRadio.diameter
|
||||||
|
+ st::defaultBoxCheckbox.textPosition.x(),
|
||||||
|
_private->bottomNoMargins(),
|
||||||
|
_aboutPublicWidth,
|
||||||
|
_aboutPublicHeight);
|
||||||
|
_aboutPrivate.drawLeft(
|
||||||
|
p,
|
||||||
|
aboutPrivate.x(),
|
||||||
|
aboutPrivate.y(),
|
||||||
|
aboutPrivate.width(),
|
||||||
|
width());
|
||||||
|
|
||||||
if (!_channel->isMegagroup() || !_link->isHidden()) {
|
if (!_channel->isMegagroup() || !_link->isHidden()) {
|
||||||
p.setPen(st::boxTextFg);
|
p.setPen(st::boxTextFg);
|
||||||
p.setFont(st::newGroupLinkFont);
|
p.setFont(st::newGroupLinkFont);
|
||||||
p.drawTextLeft(
|
p.drawTextLeft(
|
||||||
st::boxPadding.left() + st::newGroupPadding.left() + st::defaultInputField.textMargins.left(),
|
st::boxPadding.left()
|
||||||
|
+ st::newGroupPadding.left()
|
||||||
|
+ st::defaultInputField.textMargins.left(),
|
||||||
_link->y() - st::newGroupLinkPadding.top() + st::newGroupLinkTop,
|
_link->y() - st::newGroupLinkPadding.top() + st::newGroupLinkTop,
|
||||||
width(),
|
width(),
|
||||||
(_link->isHidden()
|
(_link->isHidden()
|
||||||
|
@ -916,20 +1008,29 @@ void SetupChannelBox::paintEvent(QPaintEvent *e) {
|
||||||
if (!_channel->isMegagroup()) {
|
if (!_channel->isMegagroup()) {
|
||||||
QTextOption option(style::al_left);
|
QTextOption option(style::al_left);
|
||||||
option.setWrapMode(QTextOption::WrapAnywhere);
|
option.setWrapMode(QTextOption::WrapAnywhere);
|
||||||
p.setFont(_linkOver ? st::boxTextFont->underline() : st::boxTextFont);
|
p.setFont(_linkOver
|
||||||
|
? st::boxTextFont->underline()
|
||||||
|
: st::boxTextFont);
|
||||||
p.setPen(st::defaultLinkButton.color);
|
p.setPen(st::defaultLinkButton.color);
|
||||||
auto inviteLinkText = _channel->inviteLink().isEmpty() ? tr::lng_group_invite_create(tr::now) : _channel->inviteLink();
|
const auto inviteLinkText = _channel->inviteLink().isEmpty()
|
||||||
|
? tr::lng_group_invite_create(tr::now)
|
||||||
|
: _channel->inviteLink();
|
||||||
p.drawText(_invitationLink, inviteLinkText, option);
|
p.drawText(_invitationLink, inviteLinkText, option);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
const auto top = _link->y()
|
||||||
|
- st::newGroupLinkPadding.top()
|
||||||
|
+ st::newGroupLinkTop
|
||||||
|
+ st::newGroupLinkFont->ascent
|
||||||
|
- st::boxTextFont->ascent;
|
||||||
if (!_errorText.isEmpty()) {
|
if (!_errorText.isEmpty()) {
|
||||||
p.setPen(st::boxTextFgError);
|
p.setPen(st::boxTextFgError);
|
||||||
p.setFont(st::boxTextFont);
|
p.setFont(st::boxTextFont);
|
||||||
p.drawTextRight(st::boxPadding.right(), _link->y() - st::newGroupLinkPadding.top() + st::newGroupLinkTop + st::newGroupLinkFont->ascent - st::boxTextFont->ascent, width(), _errorText);
|
p.drawTextRight(st::boxPadding.right(), top, width(), _errorText);
|
||||||
} else if (!_goodText.isEmpty()) {
|
} else if (!_goodText.isEmpty()) {
|
||||||
p.setPen(st::boxTextFgGood);
|
p.setPen(st::boxTextFgGood);
|
||||||
p.setFont(st::boxTextFont);
|
p.setFont(st::boxTextFont);
|
||||||
p.drawTextRight(st::boxPadding.right(), _link->y() - st::newGroupLinkPadding.top() + st::newGroupLinkTop + st::newGroupLinkFont->ascent - st::boxTextFont->ascent, width(), _goodText);
|
p.drawTextRight(st::boxPadding.right(), top, width(), _goodText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -937,12 +1038,32 @@ void SetupChannelBox::paintEvent(QPaintEvent *e) {
|
||||||
void SetupChannelBox::resizeEvent(QResizeEvent *e) {
|
void SetupChannelBox::resizeEvent(QResizeEvent *e) {
|
||||||
BoxContent::resizeEvent(e);
|
BoxContent::resizeEvent(e);
|
||||||
|
|
||||||
_public->moveToLeft(st::boxPadding.left() + st::newGroupPadding.left(), st::boxPadding.top() + st::newGroupPadding.top());
|
const auto left = st::boxPadding.left() + st::newGroupPadding.left();
|
||||||
_private->moveToLeft(st::boxPadding.left() + st::newGroupPadding.left(), _public->bottomNoMargins() + _aboutPublicHeight + st::newGroupSkip);
|
_public->moveToLeft(
|
||||||
|
left,
|
||||||
|
st::boxPadding.top() + st::newGroupPadding.top());
|
||||||
|
_private->moveToLeft(
|
||||||
|
left,
|
||||||
|
_public->bottomNoMargins() + _aboutPublicHeight + st::newGroupSkip);
|
||||||
|
|
||||||
_link->resize(width() - st::boxPadding.left() - st::newGroupLinkPadding.left() - st::boxPadding.right(), _link->height());
|
_link->resize(
|
||||||
_link->moveToLeft(st::boxPadding.left() + st::newGroupLinkPadding.left(), _private->bottomNoMargins() + _aboutPrivate.countHeight(_aboutPublicWidth) + st::newGroupSkip + st::newGroupPadding.bottom() + st::newGroupLinkPadding.top());
|
width()
|
||||||
_invitationLink = QRect(_link->x(), _link->y() + (_link->height() / 2) - st::boxTextFont->height, _link->width(), 2 * st::boxTextFont->height);
|
- st::boxPadding.left()
|
||||||
|
- st::newGroupLinkPadding.left()
|
||||||
|
- st::boxPadding.right(),
|
||||||
|
_link->height());
|
||||||
|
_link->moveToLeft(
|
||||||
|
st::boxPadding.left() + st::newGroupLinkPadding.left(),
|
||||||
|
_private->bottomNoMargins()
|
||||||
|
+ _aboutPrivate.countHeight(_aboutPublicWidth)
|
||||||
|
+ st::newGroupSkip
|
||||||
|
+ st::newGroupPadding.bottom()
|
||||||
|
+ st::newGroupLinkPadding.top());
|
||||||
|
_invitationLink = QRect(
|
||||||
|
_link->x(),
|
||||||
|
_link->y() + (_link->height() / 2) - st::boxTextFont->height,
|
||||||
|
_link->width(),
|
||||||
|
2 * st::boxTextFont->height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupChannelBox::mouseMoveEvent(QMouseEvent *e) {
|
void SetupChannelBox::mouseMoveEvent(QMouseEvent *e) {
|
||||||
|
@ -982,9 +1103,13 @@ void SetupChannelBox::save() {
|
||||||
_channel->inputChannel,
|
_channel->inputChannel,
|
||||||
MTP_string(_sentUsername)
|
MTP_string(_sentUsername)
|
||||||
)).done([=](const MTPBool &result) {
|
)).done([=](const MTPBool &result) {
|
||||||
updateDone(result);
|
_channel->setName(
|
||||||
|
TextUtilities::SingleLine(_channel->name),
|
||||||
|
_sentUsername);
|
||||||
|
closeBox();
|
||||||
}).fail([=](const MTP::Error &error) {
|
}).fail([=](const MTP::Error &error) {
|
||||||
updateFail(error);
|
_saveRequestId = 0;
|
||||||
|
updateFail(error.type());
|
||||||
}).send();
|
}).send();
|
||||||
};
|
};
|
||||||
if (_saveRequestId) {
|
if (_saveRequestId) {
|
||||||
|
@ -1007,38 +1132,45 @@ void SetupChannelBox::save() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupChannelBox::handleChange() {
|
void SetupChannelBox::handleChange() {
|
||||||
QString name = _link->text().trimmed();
|
const auto name = _link->text().trimmed();
|
||||||
if (name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
if (!_errorText.isEmpty() || !_goodText.isEmpty()) {
|
if (!_errorText.isEmpty() || !_goodText.isEmpty()) {
|
||||||
_errorText = _goodText = QString();
|
_errorText = _goodText = QString();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
_checkTimer.stop();
|
_checkTimer.cancel();
|
||||||
} else {
|
} else {
|
||||||
int32 len = name.size();
|
const auto len = int(name.size());
|
||||||
for (int32 i = 0; i < len; ++i) {
|
for (auto i = 0; i < len; ++i) {
|
||||||
QChar ch = name.at(i);
|
const auto ch = name.at(i);
|
||||||
if ((ch < 'A' || ch > 'Z') && (ch < 'a' || ch > 'z') && (ch < '0' || ch > '9') && ch != '_') {
|
if ((ch < 'A' || ch > 'Z')
|
||||||
if (_errorText != tr::lng_create_channel_link_bad_symbols(tr::now)) {
|
&& (ch < 'a' || ch > 'z')
|
||||||
_errorText = tr::lng_create_channel_link_bad_symbols(tr::now);
|
&& (ch < '0' || ch > '9')
|
||||||
|
&& ch != '_') {
|
||||||
|
const auto badSymbols =
|
||||||
|
tr::lng_create_channel_link_bad_symbols(tr::now);
|
||||||
|
if (_errorText != badSymbols) {
|
||||||
|
_errorText = badSymbols;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
_checkTimer.stop();
|
_checkTimer.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (name.size() < kMinUsernameLength) {
|
if (name.size() < kMinUsernameLength) {
|
||||||
if (_errorText != tr::lng_create_channel_link_too_short(tr::now)) {
|
const auto tooShort =
|
||||||
_errorText = tr::lng_create_channel_link_too_short(tr::now);
|
tr::lng_create_channel_link_too_short(tr::now);
|
||||||
|
if (_errorText != tooShort) {
|
||||||
|
_errorText = tooShort;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
_checkTimer.stop();
|
_checkTimer.cancel();
|
||||||
} else {
|
} else {
|
||||||
if (!_errorText.isEmpty() || !_goodText.isEmpty()) {
|
if (!_errorText.isEmpty() || !_goodText.isEmpty()) {
|
||||||
_errorText = _goodText = QString();
|
_errorText = _goodText = QString();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
_checkTimer.start(UsernameCheckTimeout);
|
_checkTimer.callOnce(UsernameCheckTimeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1047,16 +1179,25 @@ void SetupChannelBox::check() {
|
||||||
if (_checkRequestId) {
|
if (_checkRequestId) {
|
||||||
_channel->session().api().request(_checkRequestId).cancel();
|
_channel->session().api().request(_checkRequestId).cancel();
|
||||||
}
|
}
|
||||||
QString link = _link->text().trimmed();
|
const auto link = _link->text().trimmed();
|
||||||
if (link.size() >= kMinUsernameLength) {
|
if (link.size() >= kMinUsernameLength) {
|
||||||
_checkUsername = link;
|
_checkUsername = link;
|
||||||
_checkRequestId = _api.request(MTPchannels_CheckUsername(
|
_checkRequestId = _api.request(MTPchannels_CheckUsername(
|
||||||
_channel->inputChannel,
|
_channel->inputChannel,
|
||||||
MTP_string(link)
|
MTP_string(link)
|
||||||
)).done([=](const MTPBool &result) {
|
)).done([=](const MTPBool &result) {
|
||||||
checkDone(result);
|
_checkRequestId = 0;
|
||||||
|
_errorText = (mtpIsTrue(result)
|
||||||
|
|| _checkUsername == _channel->username)
|
||||||
|
? QString()
|
||||||
|
: tr::lng_create_channel_link_occupied(tr::now);
|
||||||
|
_goodText = _errorText.isEmpty()
|
||||||
|
? tr::lng_create_channel_link_available(tr::now)
|
||||||
|
: QString();
|
||||||
|
update();
|
||||||
}).fail([=](const MTP::Error &error) {
|
}).fail([=](const MTP::Error &error) {
|
||||||
checkFail(error);
|
_checkRequestId = 0;
|
||||||
|
checkFail(error.type());
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1090,26 +1231,20 @@ void SetupChannelBox::privacyChanged(Privacy value) {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupChannelBox::updateDone(const MTPBool &result) {
|
void SetupChannelBox::updateFail(const QString &error) {
|
||||||
_channel->setName(TextUtilities::SingleLine(_channel->name), _sentUsername);
|
if ((error == "USERNAME_NOT_MODIFIED")
|
||||||
closeBox();
|
|| (_sentUsername == _channel->username)) {
|
||||||
}
|
|
||||||
|
|
||||||
void SetupChannelBox::updateFail(const MTP::Error &error) {
|
|
||||||
_saveRequestId = 0;
|
|
||||||
QString err(error.type());
|
|
||||||
if (err == "USERNAME_NOT_MODIFIED"
|
|
||||||
|| _sentUsername == _channel->username) {
|
|
||||||
_channel->setName(
|
_channel->setName(
|
||||||
TextUtilities::SingleLine(_channel->name),
|
TextUtilities::SingleLine(_channel->name),
|
||||||
TextUtilities::SingleLine(_sentUsername));
|
TextUtilities::SingleLine(_sentUsername));
|
||||||
closeBox();
|
closeBox();
|
||||||
} else if (err == "USERNAME_INVALID") {
|
} else if (error == "USERNAME_INVALID") {
|
||||||
_link->setFocus();
|
_link->setFocus();
|
||||||
_link->showError();
|
_link->showError();
|
||||||
_errorText = tr::lng_create_channel_link_invalid(tr::now);
|
_errorText = tr::lng_create_channel_link_invalid(tr::now);
|
||||||
update();
|
update();
|
||||||
} else if (err == "USERNAME_OCCUPIED" || err == "USERNAMES_UNAVAILABLE") {
|
} else if ((error == "USERNAME_OCCUPIED")
|
||||||
|
|| (error == "USERNAMES_UNAVAILABLE")) {
|
||||||
_link->setFocus();
|
_link->setFocus();
|
||||||
_link->showError();
|
_link->showError();
|
||||||
_errorText = tr::lng_create_channel_link_occupied(tr::now);
|
_errorText = tr::lng_create_channel_link_occupied(tr::now);
|
||||||
|
@ -1119,33 +1254,21 @@ void SetupChannelBox::updateFail(const MTP::Error &error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupChannelBox::checkDone(const MTPBool &result) {
|
void SetupChannelBox::checkFail(const QString &error) {
|
||||||
_checkRequestId = 0;
|
if (error == qstr("CHANNEL_PUBLIC_GROUP_NA")) {
|
||||||
QString newError = (mtpIsTrue(result) || _checkUsername == _channel->username) ? QString() : tr::lng_create_channel_link_occupied(tr::now);
|
|
||||||
QString newGood = newError.isEmpty() ? tr::lng_create_channel_link_available(tr::now) : QString();
|
|
||||||
if (_errorText != newError || _goodText != newGood) {
|
|
||||||
_errorText = newError;
|
|
||||||
_goodText = newGood;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetupChannelBox::checkFail(const MTP::Error &error) {
|
|
||||||
_checkRequestId = 0;
|
|
||||||
QString err(error.type());
|
|
||||||
if (err == qstr("CHANNEL_PUBLIC_GROUP_NA")) {
|
|
||||||
Ui::hideLayer();
|
Ui::hideLayer();
|
||||||
} else if (err == qstr("CHANNELS_ADMIN_PUBLIC_TOO_MUCH")) {
|
} else if (error == qstr("CHANNELS_ADMIN_PUBLIC_TOO_MUCH")) {
|
||||||
if (_existing) {
|
if (_existing) {
|
||||||
showRevokePublicLinkBoxForEdit();
|
showRevokePublicLinkBoxForEdit();
|
||||||
} else {
|
} else {
|
||||||
_tooMuchUsernames = true;
|
_tooMuchUsernames = true;
|
||||||
_privacyGroup->setValue(Privacy::Private);
|
_privacyGroup->setValue(Privacy::Private);
|
||||||
}
|
}
|
||||||
} else if (err == qstr("USERNAME_INVALID")) {
|
} else if (error == qstr("USERNAME_INVALID")) {
|
||||||
_errorText = tr::lng_create_channel_link_invalid(tr::now);
|
_errorText = tr::lng_create_channel_link_invalid(tr::now);
|
||||||
update();
|
update();
|
||||||
} else if (err == qstr("USERNAME_OCCUPIED") && _checkUsername != _channel->username) {
|
} else if (error == qstr("USERNAME_OCCUPIED")
|
||||||
|
&& _checkUsername != _channel->username) {
|
||||||
_errorText = tr::lng_create_channel_link_occupied(tr::now);
|
_errorText = tr::lng_create_channel_link_occupied(tr::now);
|
||||||
update();
|
update();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1171,12 +1294,10 @@ void SetupChannelBox::showRevokePublicLinkBoxForEdit() {
|
||||||
Ui::LayerOption::KeepOther);
|
Ui::LayerOption::KeepOther);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupChannelBox::firstCheckFail(const MTP::Error &error) {
|
void SetupChannelBox::firstCheckFail(const QString &error) {
|
||||||
_checkRequestId = 0;
|
if (error == qstr("CHANNEL_PUBLIC_GROUP_NA")) {
|
||||||
const auto &type = error.type();
|
|
||||||
if (type == qstr("CHANNEL_PUBLIC_GROUP_NA")) {
|
|
||||||
Ui::hideLayer();
|
Ui::hideLayer();
|
||||||
} else if (type == qstr("CHANNELS_ADMIN_PUBLIC_TOO_MUCH")) {
|
} else if (error == qstr("CHANNELS_ADMIN_PUBLIC_TOO_MUCH")) {
|
||||||
if (_existing) {
|
if (_existing) {
|
||||||
showRevokePublicLinkBoxForEdit();
|
showRevokePublicLinkBoxForEdit();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1192,8 +1313,16 @@ void SetupChannelBox::firstCheckFail(const MTP::Error &error) {
|
||||||
EditNameBox::EditNameBox(QWidget*, not_null<UserData*> user)
|
EditNameBox::EditNameBox(QWidget*, not_null<UserData*> user)
|
||||||
: _user(user)
|
: _user(user)
|
||||||
, _api(&_user->session().mtp())
|
, _api(&_user->session().mtp())
|
||||||
, _first(this, st::defaultInputField, tr::lng_signup_firstname(), _user->firstName)
|
, _first(
|
||||||
, _last(this, st::defaultInputField, tr::lng_signup_lastname(), _user->lastName)
|
this,
|
||||||
|
st::defaultInputField,
|
||||||
|
tr::lng_signup_firstname(),
|
||||||
|
_user->firstName)
|
||||||
|
, _last(
|
||||||
|
this,
|
||||||
|
st::defaultInputField,
|
||||||
|
tr::lng_signup_lastname(),
|
||||||
|
_user->lastName)
|
||||||
, _invertOrder(langFirstNameGoesSecond()) {
|
, _invertOrder(langFirstNameGoesSecond()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1241,19 +1370,28 @@ void EditNameBox::submit() {
|
||||||
void EditNameBox::resizeEvent(QResizeEvent *e) {
|
void EditNameBox::resizeEvent(QResizeEvent *e) {
|
||||||
BoxContent::resizeEvent(e);
|
BoxContent::resizeEvent(e);
|
||||||
|
|
||||||
_first->resize(width() - st::boxPadding.left() - st::newGroupInfoPadding.left() - st::boxPadding.right(), _first->height());
|
_first->resize(
|
||||||
|
width()
|
||||||
|
- st::boxPadding.left()
|
||||||
|
- st::newGroupInfoPadding.left()
|
||||||
|
- st::boxPadding.right(),
|
||||||
|
_first->height());
|
||||||
_last->resize(_first->size());
|
_last->resize(_first->size());
|
||||||
|
const auto left = st::boxPadding.left() + st::newGroupInfoPadding.left();
|
||||||
|
const auto skip = st::contactSkip;
|
||||||
if (_invertOrder) {
|
if (_invertOrder) {
|
||||||
_last->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), st::contactPadding.top());
|
_last->moveToLeft(left, st::contactPadding.top());
|
||||||
_first->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _last->y() + _last->height() + st::contactSkip);
|
_first->moveToLeft(left, _last->y() + _last->height() + skip);
|
||||||
} else {
|
} else {
|
||||||
_first->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), st::contactPadding.top());
|
_first->moveToLeft(left, st::contactPadding.top());
|
||||||
_last->moveToLeft(st::boxPadding.left() + st::newGroupInfoPadding.left(), _first->y() + _first->height() + st::contactSkip);
|
_last->moveToLeft(left, _first->y() + _first->height() + skip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditNameBox::save() {
|
void EditNameBox::save() {
|
||||||
if (_requestId) return;
|
if (_requestId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto first = TextUtilities::PrepareForSending(_first->getLastText());
|
auto first = TextUtilities::PrepareForSending(_first->getLastText());
|
||||||
auto last = TextUtilities::PrepareForSending(_last->getLastText());
|
auto last = TextUtilities::PrepareForSending(_last->getLastText());
|
||||||
|
@ -1279,29 +1417,27 @@ void EditNameBox::save() {
|
||||||
MTP_string(first),
|
MTP_string(first),
|
||||||
MTP_string(last),
|
MTP_string(last),
|
||||||
MTPstring()
|
MTPstring()
|
||||||
)).done([=](const MTPUser &result) {
|
)).done([=](const MTPUser &user) {
|
||||||
saveSelfDone(result);
|
_user->owner().processUser(user);
|
||||||
|
closeBox();
|
||||||
}).fail([=](const MTP::Error &error) {
|
}).fail([=](const MTP::Error &error) {
|
||||||
saveSelfFail(error);
|
_requestId = 0;
|
||||||
|
saveSelfFail(error.type());
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditNameBox::saveSelfDone(const MTPUser &user) {
|
void EditNameBox::saveSelfFail(const QString &error) {
|
||||||
_user->owner().processUsers(MTP_vector<MTPUser>(1, user));
|
if (error == "NAME_NOT_MODIFIED") {
|
||||||
closeBox();
|
_user->setName(
|
||||||
}
|
TextUtilities::SingleLine(_first->getLastText().trimmed()),
|
||||||
|
TextUtilities::SingleLine(_last->getLastText().trimmed()),
|
||||||
void EditNameBox::saveSelfFail(const MTP::Error &error) {
|
QString(),
|
||||||
auto err = error.type();
|
TextUtilities::SingleLine(_user->username));
|
||||||
auto first = TextUtilities::SingleLine(_first->getLastText().trimmed());
|
|
||||||
auto last = TextUtilities::SingleLine(_last->getLastText().trimmed());
|
|
||||||
if (err == "NAME_NOT_MODIFIED") {
|
|
||||||
_user->setName(first, last, QString(), TextUtilities::SingleLine(_user->username));
|
|
||||||
closeBox();
|
closeBox();
|
||||||
} else if (err == "FIRSTNAME_INVALID") {
|
} else if (error == "FIRSTNAME_INVALID") {
|
||||||
_first->setFocus();
|
_first->setFocus();
|
||||||
_first->showError();
|
_first->showError();
|
||||||
} else if (err == "LASTNAME_INVALID") {
|
} else if (error == "LASTNAME_INVALID") {
|
||||||
_last->setFocus();
|
_last->setFocus();
|
||||||
_last->showError();
|
_last->showError();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1316,8 +1452,11 @@ RevokePublicLinkBox::Inner::Inner(
|
||||||
: TWidget(parent)
|
: TWidget(parent)
|
||||||
, _session(session)
|
, _session(session)
|
||||||
, _api(&_session->mtp())
|
, _api(&_session->mtp())
|
||||||
, _rowHeight(st::contactsPadding.top() + st::contactsPhotoSize + st::contactsPadding.bottom())
|
, _rowHeight(st::contactsPadding.top()
|
||||||
, _revokeWidth(st::normalFont->width(tr::lng_channels_too_much_public_revoke(tr::now)))
|
+ st::contactsPhotoSize
|
||||||
|
+ st::contactsPadding.bottom())
|
||||||
|
, _revokeWidth(st::normalFont->width(
|
||||||
|
tr::lng_channels_too_much_public_revoke(tr::now)))
|
||||||
, _revokeCallback(std::move(revokeCallback)) {
|
, _revokeCallback(std::move(revokeCallback)) {
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
|
|
||||||
|
@ -1367,7 +1506,9 @@ RevokePublicLinkBox::RevokePublicLinkBox(
|
||||||
}
|
}
|
||||||
|
|
||||||
void RevokePublicLinkBox::prepare() {
|
void RevokePublicLinkBox::prepare() {
|
||||||
_innerTop = st::boxPadding.top() + _aboutRevoke->height() + st::boxPadding.top();
|
_innerTop = st::boxPadding.top()
|
||||||
|
+ _aboutRevoke->height()
|
||||||
|
+ st::boxPadding.top();
|
||||||
_inner = setInnerWidget(object_ptr<Inner>(this, _session, [=] {
|
_inner = setInnerWidget(object_ptr<Inner>(this, _session, [=] {
|
||||||
const auto callback = _revokeCallback;
|
const auto callback = _revokeCallback;
|
||||||
closeBox();
|
closeBox();
|
||||||
|
@ -1392,11 +1533,21 @@ void RevokePublicLinkBox::Inner::mouseMoveEvent(QMouseEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RevokePublicLinkBox::Inner::updateSelected() {
|
void RevokePublicLinkBox::Inner::updateSelected() {
|
||||||
auto point = mapFromGlobal(QCursor::pos());
|
const auto point = mapFromGlobal(QCursor::pos());
|
||||||
PeerData *selected = nullptr;
|
PeerData *selected = nullptr;
|
||||||
auto top = _rowsTop;
|
auto top = _rowsTop;
|
||||||
for (const auto &row : _rows) {
|
for (const auto &row : _rows) {
|
||||||
auto revokeLink = style::rtlrect(width() - st::contactsPadding.right() - st::contactsCheckPosition.x() - _revokeWidth, top + st::contactsPadding.top() + (st::contactsPhotoSize - st::normalFont->height) / 2, _revokeWidth, st::normalFont->height, width());
|
const auto revokeLink = style::rtlrect(
|
||||||
|
width()
|
||||||
|
- st::contactsPadding.right()
|
||||||
|
- st::contactsCheckPosition.x()
|
||||||
|
- _revokeWidth,
|
||||||
|
top
|
||||||
|
+ st::contactsPadding.top()
|
||||||
|
+ (st::contactsPhotoSize - st::normalFont->height) / 2,
|
||||||
|
_revokeWidth,
|
||||||
|
st::normalFont->height,
|
||||||
|
width());
|
||||||
if (revokeLink.contains(point)) {
|
if (revokeLink.contains(point)) {
|
||||||
selected = row.peer;
|
selected = row.peer;
|
||||||
break;
|
break;
|
||||||
|
@ -1405,7 +1556,9 @@ void RevokePublicLinkBox::Inner::updateSelected() {
|
||||||
}
|
}
|
||||||
if (selected != _selected) {
|
if (selected != _selected) {
|
||||||
_selected = selected;
|
_selected = selected;
|
||||||
setCursor((_selected || _pressed) ? style::cur_pointer : style::cur_default);
|
setCursor((_selected || _pressed)
|
||||||
|
? style::cur_pointer
|
||||||
|
: style::cur_default);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1418,21 +1571,26 @@ void RevokePublicLinkBox::Inner::mousePressEvent(QMouseEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RevokePublicLinkBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
|
void RevokePublicLinkBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
|
||||||
auto pressed = base::take(_pressed);
|
const auto pressed = base::take(_pressed);
|
||||||
setCursor((_selected || _pressed) ? style::cur_pointer : style::cur_default);
|
setCursor((_selected || _pressed)
|
||||||
|
? style::cur_pointer
|
||||||
|
: style::cur_default);
|
||||||
if (pressed && pressed == _selected) {
|
if (pressed && pressed == _selected) {
|
||||||
auto text_method = pressed->isMegagroup()
|
const auto textMethod = pressed->isMegagroup()
|
||||||
? tr::lng_channels_too_much_public_revoke_confirm_group
|
? tr::lng_channels_too_much_public_revoke_confirm_group
|
||||||
: tr::lng_channels_too_much_public_revoke_confirm_channel;
|
: tr::lng_channels_too_much_public_revoke_confirm_channel;
|
||||||
auto text = text_method(
|
const auto text = textMethod(
|
||||||
tr::now,
|
tr::now,
|
||||||
lt_link,
|
lt_link,
|
||||||
_session->createInternalLink(pressed->userName()),
|
_session->createInternalLink(pressed->userName()),
|
||||||
lt_group,
|
lt_group,
|
||||||
pressed->name);
|
pressed->name);
|
||||||
auto confirmText = tr::lng_channels_too_much_public_revoke(tr::now);
|
const auto confirmText = tr::lng_channels_too_much_public_revoke(
|
||||||
|
tr::now);
|
||||||
auto callback = crl::guard(this, [=](Fn<void()> &&close) {
|
auto callback = crl::guard(this, [=](Fn<void()> &&close) {
|
||||||
if (_revokeRequestId) return;
|
if (_revokeRequestId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
_revokeRequestId = _api.request(MTPchannels_UpdateUsername(
|
_revokeRequestId = _api.request(MTPchannels_UpdateUsername(
|
||||||
pressed->asChannel()->inputChannel,
|
pressed->asChannel()->inputChannel,
|
||||||
MTP_string()
|
MTP_string()
|
||||||
|
@ -1464,18 +1622,33 @@ void RevokePublicLinkBox::resizeEvent(QResizeEvent *e) {
|
||||||
_aboutRevoke->moveToLeft(st::boxPadding.left(), st::boxPadding.top());
|
_aboutRevoke->moveToLeft(st::boxPadding.left(), st::boxPadding.top());
|
||||||
}
|
}
|
||||||
|
|
||||||
void RevokePublicLinkBox::Inner::paintChat(Painter &p, const ChatRow &row, bool selected) const {
|
void RevokePublicLinkBox::Inner::paintChat(
|
||||||
auto peer = row.peer;
|
Painter &p,
|
||||||
peer->paintUserpicLeft(p, row.userpic, st::contactsPadding.left(), st::contactsPadding.top(), width(), st::contactsPhotoSize);
|
const ChatRow &row,
|
||||||
|
bool selected) const {
|
||||||
|
const auto peer = row.peer;
|
||||||
|
peer->paintUserpicLeft(
|
||||||
|
p,
|
||||||
|
row.userpic,
|
||||||
|
st::contactsPadding.left(),
|
||||||
|
st::contactsPadding.top(),
|
||||||
|
width(),
|
||||||
|
st::contactsPhotoSize);
|
||||||
|
|
||||||
p.setPen(st::contactsNameFg);
|
p.setPen(st::contactsNameFg);
|
||||||
|
|
||||||
int32 namex = st::contactsPadding.left() + st::contactsPhotoSize + st::contactsPadding.left();
|
const auto namex = st::contactsPadding.left()
|
||||||
int32 namew = width() - namex - st::contactsPadding.right() - (_revokeWidth + st::contactsCheckPosition.x() * 2);
|
+ st::contactsPhotoSize
|
||||||
|
+ st::contactsPadding.left();
|
||||||
|
auto namew = width()
|
||||||
|
- namex
|
||||||
|
- st::contactsPadding.right()
|
||||||
|
- (_revokeWidth + st::contactsCheckPosition.x() * 2);
|
||||||
|
|
||||||
const auto badgeStyle = Ui::PeerBadgeStyle{
|
const auto badgeStyle = Ui::PeerBadgeStyle{
|
||||||
&st::dialogsVerifiedIcon,
|
&st::dialogsVerifiedIcon,
|
||||||
&st::attentionButtonFg };
|
&st::attentionButtonFg
|
||||||
|
};
|
||||||
namew -= Ui::DrawPeerBadgeGetWidth(
|
namew -= Ui::DrawPeerBadgeGetWidth(
|
||||||
peer,
|
peer,
|
||||||
p,
|
p,
|
||||||
|
@ -1487,14 +1660,32 @@ void RevokePublicLinkBox::Inner::paintChat(Painter &p, const ChatRow &row, bool
|
||||||
namew,
|
namew,
|
||||||
width(),
|
width(),
|
||||||
badgeStyle);
|
badgeStyle);
|
||||||
row.name.drawLeftElided(p, namex, st::contactsPadding.top() + st::contactsNameTop, namew, width());
|
row.name.drawLeftElided(
|
||||||
|
p,
|
||||||
|
namex,
|
||||||
|
st::contactsPadding.top() + st::contactsNameTop,
|
||||||
|
namew,
|
||||||
|
width());
|
||||||
|
|
||||||
p.setFont(selected ? st::linkOverFont : st::linkFont);
|
p.setFont(selected ? st::linkOverFont : st::linkFont);
|
||||||
p.setPen(selected ? st::defaultLinkButton.overColor : st::defaultLinkButton.color);
|
p.setPen(selected
|
||||||
p.drawTextRight(st::contactsPadding.right() + st::contactsCheckPosition.x(), st::contactsPadding.top() + (st::contactsPhotoSize - st::normalFont->height) / 2, width(), tr::lng_channels_too_much_public_revoke(tr::now), _revokeWidth);
|
? st::defaultLinkButton.overColor
|
||||||
|
: st::defaultLinkButton.color);
|
||||||
|
p.drawTextRight(
|
||||||
|
st::contactsPadding.right() + st::contactsCheckPosition.x(),
|
||||||
|
st::contactsPadding.top()
|
||||||
|
+ (st::contactsPhotoSize - st::normalFont->height) / 2,
|
||||||
|
width(),
|
||||||
|
tr::lng_channels_too_much_public_revoke(tr::now),
|
||||||
|
_revokeWidth);
|
||||||
|
|
||||||
p.setPen(st::contactsStatusFg);
|
p.setPen(st::contactsStatusFg);
|
||||||
p.setTextPalette(st::revokePublicLinkStatusPalette);
|
p.setTextPalette(st::revokePublicLinkStatusPalette);
|
||||||
row.status.drawLeftElided(p, namex, st::contactsPadding.top() + st::contactsStatusTop, namew, width());
|
row.status.drawLeftElided(
|
||||||
|
p,
|
||||||
|
namex,
|
||||||
|
st::contactsPadding.top() + st::contactsStatusTop,
|
||||||
|
namew,
|
||||||
|
width());
|
||||||
p.restoreTextPalette();
|
p.restoreTextPalette();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "boxes/abstract_box.h"
|
#include "boxes/abstract_box.h"
|
||||||
|
#include "base/timer.h"
|
||||||
#include "mtproto/sender.h"
|
#include "mtproto/sender.h"
|
||||||
#include "styles/style_widgets.h"
|
|
||||||
|
|
||||||
#include <QtCore/QTimer>
|
|
||||||
|
|
||||||
class ConfirmBox;
|
class ConfirmBox;
|
||||||
class PeerListBox;
|
class PeerListBox;
|
||||||
|
@ -118,7 +116,10 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createChannel(const QString &title, const QString &description);
|
void createChannel(const QString &title, const QString &description);
|
||||||
void createGroup(not_null<PeerListBox*> selectUsersBox, const QString &title, const std::vector<not_null<PeerData*>> &users);
|
void createGroup(
|
||||||
|
not_null<PeerListBox*> selectUsersBox,
|
||||||
|
const QString &title,
|
||||||
|
const std::vector<not_null<PeerData*>> &users);
|
||||||
void submitName();
|
void submitName();
|
||||||
void submit();
|
void submit();
|
||||||
void checkInviteLink();
|
void checkInviteLink();
|
||||||
|
@ -176,12 +177,10 @@ private:
|
||||||
void check();
|
void check();
|
||||||
void save();
|
void save();
|
||||||
|
|
||||||
void updateDone(const MTPBool &result);
|
void updateFail(const QString &error);
|
||||||
void updateFail(const MTP::Error &error);
|
|
||||||
|
|
||||||
void checkDone(const MTPBool &result);
|
void checkFail(const QString &error);
|
||||||
void checkFail(const MTP::Error &error);
|
void firstCheckFail(const QString &error);
|
||||||
void firstCheckFail(const MTP::Error &error);
|
|
||||||
|
|
||||||
void updateMaxHeight();
|
void updateMaxHeight();
|
||||||
|
|
||||||
|
@ -209,7 +208,7 @@ private:
|
||||||
mtpRequestId _checkRequestId = 0;
|
mtpRequestId _checkRequestId = 0;
|
||||||
QString _sentUsername, _checkUsername, _errorText, _goodText;
|
QString _sentUsername, _checkUsername, _errorText, _goodText;
|
||||||
|
|
||||||
QTimer _checkTimer;
|
base::Timer _checkTimer;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -226,8 +225,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
void submit();
|
void submit();
|
||||||
void save();
|
void save();
|
||||||
void saveSelfDone(const MTPUser &user);
|
void saveSelfFail(const QString &error);
|
||||||
void saveSelfFail(const MTP::Error &error);
|
|
||||||
|
|
||||||
const not_null<UserData*> _user;
|
const not_null<UserData*> _user;
|
||||||
MTP::Sender _api;
|
MTP::Sender _api;
|
||||||
|
|
Loading…
Add table
Reference in a new issue