diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index bf06350e4..e1ce9c23c 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -160,6 +160,7 @@ PRIVATE boxes/peers/edit_participant_box.h boxes/peers/edit_participants_box.cpp boxes/peers/edit_participants_box.h + boxes/peers/edit_peer_common.h boxes/peers/edit_peer_info_box.cpp boxes/peers/edit_peer_info_box.h boxes/peers/edit_peer_invite_link.cpp diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index ed2c37db4..4bd142cd5 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/confirm_box.h" #include "boxes/peer_list_controllers.h" #include "boxes/peers/add_participants_box.h" +#include "boxes/peers/edit_peer_common.h" #include "boxes/peers/edit_participant_box.h" #include "boxes/peers/edit_participants_box.h" #include "core/application.h" @@ -47,11 +48,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace { -constexpr auto kMaxGroupChannelTitle = 128; // See also edit_peer_info_box. -constexpr auto kMaxUserFirstLastName = 64; // See also edit_contact_box. -constexpr auto kMaxChannelDescription = 255; // See also edit_peer_info_box. -constexpr auto kMinUsernameLength = 5; - bool IsValidPhone(QString phone) { phone = phone.replace(QRegularExpression(qsl("[^\\d]")), QString()); return (phone.length() >= 8) @@ -504,7 +500,7 @@ void GroupInfoBox::prepare() { ? tr::lng_dlg_new_channel_name : tr::lng_dlg_new_group_name)(), _initialTitle); - _title->setMaxLength(kMaxGroupChannelTitle); + _title->setMaxLength(Ui::EditPeer::kMaxGroupChannelTitle); _title->setInstantReplaces(Ui::InstantReplaces::Default()); _title->setInstantReplacesEnabled( Core::App().settings().replaceEmojiValue()); @@ -520,7 +516,7 @@ void GroupInfoBox::prepare() { Ui::InputField::Mode::MultiLine, tr::lng_create_group_description()); _description->show(); - _description->setMaxLength(kMaxChannelDescription); + _description->setMaxLength(Ui::EditPeer::kMaxChannelDescription); _description->setInstantReplaces(Ui::InstantReplaces::Default()); _description->setInstantReplacesEnabled( Core::App().settings().replaceEmojiValue()); @@ -1157,7 +1153,7 @@ void SetupChannelBox::handleChange() { return; } } - if (name.size() < kMinUsernameLength) { + if (name.size() < Ui::EditPeer::kMinUsernameLength) { const auto tooShort = tr::lng_create_channel_link_too_short(tr::now); if (_errorText != tooShort) { @@ -1170,7 +1166,7 @@ void SetupChannelBox::handleChange() { _errorText = _goodText = QString(); update(); } - _checkTimer.callOnce(UsernameCheckTimeout); + _checkTimer.callOnce(Ui::EditPeer::kUsernameCheckTimeout); } } } @@ -1180,7 +1176,7 @@ void SetupChannelBox::check() { _channel->session().api().request(_checkRequestId).cancel(); } const auto link = _link->text().trimmed(); - if (link.size() >= kMinUsernameLength) { + if (link.size() >= Ui::EditPeer::kMinUsernameLength) { _checkUsername = link; _checkRequestId = _api.request(MTPchannels_CheckUsername( _channel->inputChannel, @@ -1340,8 +1336,8 @@ void EditNameBox::prepare() { if (_invertOrder) { setTabOrder(_last, _first); } - _first->setMaxLength(kMaxUserFirstLastName); - _last->setMaxLength(kMaxUserFirstLastName); + _first->setMaxLength(Ui::EditPeer::kMaxUserFirstLastName); + _last->setMaxLength(Ui::EditPeer::kMaxUserFirstLastName); connect(_first, &Ui::InputField::submitted, [=] { submit(); }); connect(_last, &Ui::InputField::submitted, [=] { submit(); }); diff --git a/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp index 42feaef29..b7c473362 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "data/data_session.h" +#include "boxes/peers/edit_peer_common.h" #include "ui/wrap/vertical_layout.h" #include "ui/widgets/labels.h" #include "ui/widgets/input_fields.h" @@ -26,8 +27,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace { -constexpr auto kMaxUserFirstLastName = 64; // See also add_contact_box. - QString UserPhone(not_null user) { const auto phone = user->phone(); return phone.isEmpty() @@ -222,8 +221,8 @@ void Controller::initNameFields( }; QObject::connect(first, &Ui::InputField::submitted, submit); QObject::connect(last, &Ui::InputField::submitted, submit); - first->setMaxLength(kMaxUserFirstLastName); - first->setMaxLength(kMaxUserFirstLastName); + first->setMaxLength(Ui::EditPeer::kMaxUserFirstLastName); + first->setMaxLength(Ui::EditPeer::kMaxUserFirstLastName); } void Controller::setupWarning() { diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_common.h b/Telegram/SourceFiles/boxes/peers/edit_peer_common.h new file mode 100644 index 000000000..3105a0ab8 --- /dev/null +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_common.h @@ -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 + +namespace Ui::EditPeer { + +constexpr auto kMaxGroupChannelTitle = 128; +constexpr auto kMaxUserFirstLastName = 64; +constexpr auto kMaxChannelDescription = 255; +constexpr auto kMinUsernameLength = 5; +constexpr auto kUsernameCheckTimeout = crl::time(200); + +} // namespace Ui::EditPeer diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index 5b80bd8c3..05bd96f73 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -13,6 +13,7 @@ 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_common.h" #include "boxes/peers/edit_peer_type_box.h" #include "boxes/peers/edit_peer_history_visibility_box.h" #include "boxes/peers/edit_peer_permissions_box.h" @@ -249,9 +250,6 @@ void ShowEditPermissions( namespace { -constexpr auto kMaxGroupChannelTitle = 128; // See also add_contact_box. -constexpr auto kMaxChannelDescription = 255; // See also add_contact_box. - class Controller : public base::has_weak_ptr { public: Controller( @@ -475,7 +473,7 @@ object_ptr Controller::createTitleEdit() { : tr::lng_dlg_new_channel_name)(), _peer->name), st::editPeerTitleMargins); - result->entity()->setMaxLength(kMaxGroupChannelTitle); + result->entity()->setMaxLength(Ui::EditPeer::kMaxGroupChannelTitle); result->entity()->setInstantReplaces(Ui::InstantReplaces::Default()); result->entity()->setInstantReplacesEnabled( Core::App().settings().replaceEmojiValue()); @@ -509,7 +507,7 @@ object_ptr Controller::createDescriptionEdit() { tr::lng_create_group_description(), _peer->about()), st::editPeerDescriptionMargins); - result->entity()->setMaxLength(kMaxChannelDescription); + result->entity()->setMaxLength(Ui::EditPeer::kMaxChannelDescription); result->entity()->setInstantReplaces(Ui::InstantReplaces::Default()); result->entity()->setInstantReplacesEnabled( Core::App().settings().replaceEmojiValue()); diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp index ff7a754aa..b8dea8142 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp @@ -14,6 +14,7 @@ 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_common.h" #include "boxes/peers/edit_peer_info_box.h" // CreateButton. #include "boxes/peers/edit_peer_invite_link.h" #include "boxes/peers/edit_peer_invite_links.h" @@ -55,9 +56,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace { -constexpr auto kUsernameCheckTimeout = crl::time(200); -constexpr auto kMinUsernameLength = 5; - class Controller : public base::has_weak_ptr { public: Controller( @@ -419,7 +417,7 @@ void Controller::checkUsernameAvailability() { const auto checking = initial ? qsl(".bad.") : getUsernameInput(); - if (checking.size() < kMinUsernameLength) { + if (checking.size() < Ui::EditPeer::kMinUsernameLength) { return; } if (_checkUsernameRequestId) { @@ -496,11 +494,11 @@ void Controller::usernameChanged() { }); if (bad) { showUsernameError(tr::lng_create_channel_link_bad_symbols()); - } else if (username.size() < kMinUsernameLength) { + } else if (username.size() < Ui::EditPeer::kMinUsernameLength) { showUsernameError(tr::lng_create_channel_link_too_short()); } else { _controls.usernameResult = nullptr; - _checkUsernameTimer.callOnce(kUsernameCheckTimeout); + _checkUsernameTimer.callOnce(Ui::EditPeer::kUsernameCheckTimeout); } } diff --git a/Telegram/SourceFiles/boxes/username_box.cpp b/Telegram/SourceFiles/boxes/username_box.cpp index bf59dea1b..96bd3d477 100644 --- a/Telegram/SourceFiles/boxes/username_box.cpp +++ b/Telegram/SourceFiles/boxes/username_box.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "boxes/username_box.h" +#include "boxes/peers/edit_peer_common.h" #include "lang/lang_keys.h" #include "ui/widgets/buttons.h" #include "ui/special_fields.h" @@ -20,12 +21,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include -namespace { - -constexpr auto kMinUsernameLength = 5; - -} // namespace - UsernameBox::UsernameBox(QWidget*, not_null session) : _session(session) , _textStyle(st::usernameTextStyle) @@ -190,7 +185,7 @@ void UsernameBox::check() { _api.request(base::take(_checkRequestId)).cancel(); const auto name = getName(); - if (name.size() < kMinUsernameLength) { + if (name.size() < Ui::EditPeer::kMinUsernameLength) { return; } _checkUsername = name; @@ -240,7 +235,7 @@ void UsernameBox::changed() { return; } } - if (name.size() < kMinUsernameLength) { + if (name.size() < Ui::EditPeer::kMinUsernameLength) { if (_errorText != tr::lng_username_too_short(tr::now)) { _errorText = tr::lng_username_too_short(tr::now); update(); @@ -251,7 +246,7 @@ void UsernameBox::changed() { _errorText = _goodText = QString(); update(); } - _checkTimer.callOnce(UsernameCheckTimeout); + _checkTimer.callOnce(Ui::EditPeer::kUsernameCheckTimeout); } } } diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index 978089c50..68a8816c1 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -29,7 +29,6 @@ enum { PreloadHeightsCount = 3, // when 3 screens to scroll left make a preload request SearchPeopleLimit = 5, - UsernameCheckTimeout = 200, MaxMessageSize = 4096,