2014-10-22 18:39:03 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2014-10-22 18:39:03 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2014-10-22 18:39:03 +00:00
|
|
|
*/
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/username_box.h"
|
2014-10-22 18:39:03 +00:00
|
|
|
|
2022-10-12 00:07:09 +00:00
|
|
|
#include "boxes/peers/edit_peer_usernames_list.h"
|
2022-10-11 18:10:15 +00:00
|
|
|
#include "base/timer.h"
|
2021-10-18 01:33:25 +00:00
|
|
|
#include "boxes/peers/edit_peer_common.h"
|
2023-04-09 20:25:18 +00:00
|
|
|
#include "data/data_channel.h"
|
2022-10-11 18:10:15 +00:00
|
|
|
#include "data/data_session.h"
|
|
|
|
#include "data/data_user.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2023-04-09 23:32:53 +00:00
|
|
|
#include "main/main_app_config_values.h"
|
2022-10-11 18:10:15 +00:00
|
|
|
#include "main/main_session.h"
|
|
|
|
#include "mtproto/sender.h"
|
|
|
|
#include "settings/settings_common.h"
|
|
|
|
#include "ui/layers/generic_box.h"
|
|
|
|
#include "ui/painter.h"
|
|
|
|
#include "ui/text/text_utilities.h"
|
2022-11-26 18:36:12 +00:00
|
|
|
#include "ui/text/text_variant.h"
|
2022-10-11 18:10:15 +00:00
|
|
|
#include "ui/toast/toast.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2022-03-28 10:47:48 +00:00
|
|
|
#include "ui/widgets/fields/special_fields.h"
|
2022-10-11 18:10:15 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
2022-11-27 12:32:13 +00:00
|
|
|
#include "ui/wrap/follow_slide_wrap.h"
|
2022-11-26 18:36:12 +00:00
|
|
|
#include "ui/wrap/slide_wrap.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2022-10-11 18:10:15 +00:00
|
|
|
#include "styles/style_settings.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2022-11-27 12:32:13 +00:00
|
|
|
[[nodiscard]] TextWithEntities PurchaseAvailableText() {
|
|
|
|
constexpr auto kUsernameAuction = "auction";
|
|
|
|
return tr::lng_username_purchase_available(
|
|
|
|
tr::now,
|
|
|
|
lt_link,
|
|
|
|
Ui::Text::Link(
|
|
|
|
'@' + QString(kUsernameAuction),
|
|
|
|
u"https://t.me/"_q + kUsernameAuction),
|
|
|
|
Ui::Text::RichLangValue);
|
|
|
|
}
|
2022-11-26 16:34:25 +00:00
|
|
|
|
2022-10-11 18:10:15 +00:00
|
|
|
class UsernameEditor final : public Ui::RpWidget {
|
|
|
|
public:
|
2023-04-09 20:25:18 +00:00
|
|
|
UsernameEditor(not_null<Ui::RpWidget*>, not_null<PeerData*> peer);
|
2014-10-22 18:39:03 +00:00
|
|
|
|
2022-10-11 18:10:15 +00:00
|
|
|
void setInnerFocus();
|
2023-04-09 23:32:53 +00:00
|
|
|
void setEnabled(bool value);
|
2022-11-26 16:34:25 +00:00
|
|
|
[[nodiscard]] rpl::producer<> submitted() const;
|
|
|
|
[[nodiscard]] rpl::producer<> save();
|
2022-11-27 12:32:13 +00:00
|
|
|
[[nodiscard]] rpl::producer<UsernameCheckInfo> checkInfoChanged() const;
|
2022-10-11 18:10:15 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void updateFail(const QString &error);
|
|
|
|
void checkFail(const QString &error);
|
|
|
|
|
2022-11-26 18:36:12 +00:00
|
|
|
void checkInfoPurchaseAvailable();
|
|
|
|
|
2022-10-11 18:10:15 +00:00
|
|
|
void check();
|
|
|
|
void changed();
|
|
|
|
|
2022-11-26 16:34:25 +00:00
|
|
|
void checkInfoChange();
|
|
|
|
|
2023-04-09 20:25:18 +00:00
|
|
|
[[nodiscard]] QString editableUsername() const;
|
|
|
|
|
2022-10-11 18:10:15 +00:00
|
|
|
QString getName() const;
|
|
|
|
|
2023-04-09 20:25:18 +00:00
|
|
|
const not_null<PeerData*> _peer;
|
2022-10-11 18:10:15 +00:00
|
|
|
const not_null<Main::Session*> _session;
|
|
|
|
const style::margins &_padding;
|
|
|
|
MTP::Sender _api;
|
|
|
|
|
|
|
|
object_ptr<Ui::UsernameInput> _username;
|
|
|
|
|
|
|
|
mtpRequestId _saveRequestId = 0;
|
|
|
|
mtpRequestId _checkRequestId = 0;
|
|
|
|
QString _sentUsername, _checkUsername, _errorText, _goodText;
|
|
|
|
|
|
|
|
base::Timer _checkTimer;
|
|
|
|
|
2022-10-12 00:07:09 +00:00
|
|
|
rpl::event_stream<> _saved;
|
2022-11-27 12:32:13 +00:00
|
|
|
rpl::event_stream<UsernameCheckInfo> _checkInfoChanged;
|
2022-10-11 18:10:15 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
UsernameEditor::UsernameEditor(
|
|
|
|
not_null<Ui::RpWidget*>,
|
2023-04-09 20:25:18 +00:00
|
|
|
not_null<PeerData*> peer)
|
|
|
|
: _peer(peer)
|
|
|
|
, _session(&peer->session())
|
2021-10-17 21:30:25 +00:00
|
|
|
, _padding(st::usernamePadding)
|
2020-06-17 09:36:25 +00:00
|
|
|
, _api(&_session->mtp())
|
2019-08-06 16:40:08 +00:00
|
|
|
, _username(
|
2018-09-11 12:50:40 +00:00
|
|
|
this,
|
|
|
|
st::defaultInputField,
|
2022-11-26 21:20:17 +00:00
|
|
|
rpl::single(u"@username"_q),
|
2023-04-09 20:25:18 +00:00
|
|
|
editableUsername(),
|
2020-06-17 09:36:25 +00:00
|
|
|
QString())
|
2021-10-17 21:30:25 +00:00
|
|
|
, _checkTimer([=] { check(); }) {
|
2023-04-09 20:25:18 +00:00
|
|
|
_goodText = editableUsername().isEmpty()
|
2018-09-11 12:50:40 +00:00
|
|
|
? QString()
|
2019-06-19 15:09:03 +00:00
|
|
|
: tr::lng_username_available(tr::now);
|
2014-10-22 18:39:03 +00:00
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
connect(_username, &Ui::MaskedInputField::changed, [=] { changed(); });
|
2022-10-11 18:10:15 +00:00
|
|
|
|
2022-11-26 16:34:25 +00:00
|
|
|
resize(width(), (_padding.top() + _username->height()));
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
|
2022-10-12 00:07:09 +00:00
|
|
|
rpl::producer<> UsernameEditor::submitted() const {
|
|
|
|
return [=](auto consumer) {
|
|
|
|
auto lifetime = rpl::lifetime();
|
|
|
|
QObject::connect(
|
|
|
|
_username,
|
|
|
|
&Ui::MaskedInputField::submitted,
|
|
|
|
[=] { consumer.put_next({}); });
|
|
|
|
return lifetime;
|
|
|
|
};
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
|
2022-10-11 18:10:15 +00:00
|
|
|
void UsernameEditor::setInnerFocus() {
|
2023-04-20 21:23:49 +00:00
|
|
|
if (_username->isEnabled()) {
|
|
|
|
_username->setFocusFast();
|
|
|
|
}
|
2022-10-11 18:10:15 +00:00
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2023-04-09 23:32:53 +00:00
|
|
|
void UsernameEditor::setEnabled(bool value) {
|
|
|
|
_username->setEnabled(value);
|
2023-04-20 21:23:49 +00:00
|
|
|
_username->setDisplayFocused(value);
|
2023-04-09 23:32:53 +00:00
|
|
|
}
|
|
|
|
|
2022-10-11 18:10:15 +00:00
|
|
|
void UsernameEditor::resizeEvent(QResizeEvent *e) {
|
2021-10-17 21:30:25 +00:00
|
|
|
_username->resize(
|
|
|
|
width() - _padding.left() - _padding.right(),
|
|
|
|
_username->height());
|
|
|
|
_username->moveToLeft(_padding.left(), _padding.top());
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
|
2022-10-12 00:07:09 +00:00
|
|
|
rpl::producer<> UsernameEditor::save() {
|
2021-10-17 21:30:25 +00:00
|
|
|
if (_saveRequestId) {
|
2022-10-12 00:07:09 +00:00
|
|
|
return _saved.events();
|
2021-10-17 21:30:25 +00:00
|
|
|
}
|
2014-10-22 18:39:03 +00:00
|
|
|
|
|
|
|
_sentUsername = getName();
|
2020-06-11 16:09:46 +00:00
|
|
|
_saveRequestId = _api.request(MTPaccount_UpdateUsername(
|
|
|
|
MTP_string(_sentUsername)
|
|
|
|
)).done([=](const MTPUser &result) {
|
2021-10-17 21:30:25 +00:00
|
|
|
_saveRequestId = 0;
|
|
|
|
_session->data().processUser(result);
|
2022-10-12 00:07:09 +00:00
|
|
|
_saved.fire_done();
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
2021-10-17 21:30:25 +00:00
|
|
|
_saveRequestId = 0;
|
|
|
|
updateFail(error.type());
|
2020-06-11 16:09:46 +00:00
|
|
|
}).send();
|
2022-10-12 00:07:09 +00:00
|
|
|
return _saved.events();
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
|
2023-04-09 20:25:18 +00:00
|
|
|
QString UsernameEditor::editableUsername() const {
|
|
|
|
if (const auto user = _peer->asUser()) {
|
|
|
|
return user->editableUsername();
|
|
|
|
} else if (const auto channel = _peer->asChannel()) {
|
|
|
|
return channel->editableUsername();
|
|
|
|
} else {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-27 12:32:13 +00:00
|
|
|
rpl::producer<UsernameCheckInfo> UsernameEditor::checkInfoChanged() const {
|
2022-11-26 16:34:25 +00:00
|
|
|
return _checkInfoChanged.events();
|
|
|
|
}
|
|
|
|
|
2022-10-11 18:10:15 +00:00
|
|
|
void UsernameEditor::check() {
|
2020-06-11 16:09:46 +00:00
|
|
|
_api.request(base::take(_checkRequestId)).cancel();
|
|
|
|
|
2021-10-17 21:30:25 +00:00
|
|
|
const auto name = getName();
|
2021-10-18 01:33:25 +00:00
|
|
|
if (name.size() < Ui::EditPeer::kMinUsernameLength) {
|
2021-10-17 21:30:25 +00:00
|
|
|
return;
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
2021-10-17 21:30:25 +00:00
|
|
|
_checkUsername = name;
|
|
|
|
_checkRequestId = _api.request(MTPaccount_CheckUsername(
|
|
|
|
MTP_string(name)
|
|
|
|
)).done([=](const MTPBool &result) {
|
|
|
|
_checkRequestId = 0;
|
|
|
|
|
|
|
|
_errorText = (mtpIsTrue(result)
|
2023-04-09 20:25:18 +00:00
|
|
|
|| (_checkUsername == editableUsername()))
|
2021-10-17 21:30:25 +00:00
|
|
|
? QString()
|
|
|
|
: tr::lng_username_occupied(tr::now);
|
|
|
|
_goodText = _errorText.isEmpty()
|
|
|
|
? tr::lng_username_available(tr::now)
|
|
|
|
: QString();
|
|
|
|
|
2022-11-26 16:34:25 +00:00
|
|
|
checkInfoChange();
|
2021-10-17 21:30:25 +00:00
|
|
|
}).fail([=](const MTP::Error &error) {
|
|
|
|
_checkRequestId = 0;
|
|
|
|
checkFail(error.type());
|
|
|
|
}).send();
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
|
2022-10-11 18:10:15 +00:00
|
|
|
void UsernameEditor::changed() {
|
2021-10-17 21:30:25 +00:00
|
|
|
const auto name = getName();
|
2014-10-22 18:39:03 +00:00
|
|
|
if (name.isEmpty()) {
|
2014-11-25 12:15:29 +00:00
|
|
|
if (!_errorText.isEmpty() || !_goodText.isEmpty()) {
|
2016-12-20 13:03:51 +00:00
|
|
|
_errorText = _goodText = QString();
|
2022-11-27 12:32:13 +00:00
|
|
|
_checkInfoChanged.fire({ UsernameCheckInfo::Type::Default });
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
2021-10-17 21:30:25 +00:00
|
|
|
_checkTimer.cancel();
|
2014-10-22 18:39:03 +00:00
|
|
|
} else {
|
2021-10-17 21:30:25 +00:00
|
|
|
const auto len = int(name.size());
|
|
|
|
for (auto i = 0; i < len; ++i) {
|
|
|
|
const auto ch = name.at(i);
|
|
|
|
if ((ch < 'A' || ch > 'Z')
|
|
|
|
&& (ch < 'a' || ch > 'z')
|
|
|
|
&& (ch < '0' || ch > '9')
|
|
|
|
&& ch != '_'
|
|
|
|
&& (ch != '@' || i > 0)) {
|
2019-06-19 15:09:03 +00:00
|
|
|
if (_errorText != tr::lng_username_bad_symbols(tr::now)) {
|
|
|
|
_errorText = tr::lng_username_bad_symbols(tr::now);
|
2022-11-26 16:34:25 +00:00
|
|
|
checkInfoChange();
|
2014-11-25 12:15:29 +00:00
|
|
|
}
|
2021-10-17 21:30:25 +00:00
|
|
|
_checkTimer.cancel();
|
2014-11-25 12:15:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2021-10-18 01:33:25 +00:00
|
|
|
if (name.size() < Ui::EditPeer::kMinUsernameLength) {
|
2019-06-19 15:09:03 +00:00
|
|
|
if (_errorText != tr::lng_username_too_short(tr::now)) {
|
|
|
|
_errorText = tr::lng_username_too_short(tr::now);
|
2022-11-26 16:34:25 +00:00
|
|
|
checkInfoChange();
|
2014-11-25 12:15:29 +00:00
|
|
|
}
|
2021-10-17 21:30:25 +00:00
|
|
|
_checkTimer.cancel();
|
2014-11-25 12:15:29 +00:00
|
|
|
} else {
|
2016-12-20 13:03:51 +00:00
|
|
|
if (!_errorText.isEmpty() || !_goodText.isEmpty()) {
|
|
|
|
_errorText = _goodText = QString();
|
2022-11-26 16:34:25 +00:00
|
|
|
checkInfoChange();
|
2014-11-25 12:15:29 +00:00
|
|
|
}
|
2021-10-18 01:33:25 +00:00
|
|
|
_checkTimer.callOnce(Ui::EditPeer::kUsernameCheckTimeout);
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-26 16:34:25 +00:00
|
|
|
void UsernameEditor::checkInfoChange() {
|
|
|
|
if (!_errorText.isEmpty()) {
|
|
|
|
_checkInfoChanged.fire({
|
2022-11-27 12:32:13 +00:00
|
|
|
.type = UsernameCheckInfo::Type::Error,
|
|
|
|
.text = { _errorText },
|
2022-11-26 16:34:25 +00:00
|
|
|
});
|
|
|
|
} else if (!_goodText.isEmpty()) {
|
|
|
|
_checkInfoChanged.fire({
|
2022-11-27 12:32:13 +00:00
|
|
|
.type = UsernameCheckInfo::Type::Good,
|
|
|
|
.text = { _goodText },
|
2022-11-26 16:34:25 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
_checkInfoChanged.fire({
|
2022-11-27 12:32:13 +00:00
|
|
|
.type = UsernameCheckInfo::Type::Default,
|
|
|
|
.text = { tr::lng_username_choose(tr::now) },
|
2022-11-26 16:34:25 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-26 18:36:12 +00:00
|
|
|
void UsernameEditor::checkInfoPurchaseAvailable() {
|
|
|
|
_username->setFocus();
|
|
|
|
_username->showError();
|
2022-11-27 12:32:13 +00:00
|
|
|
_errorText = u".bad."_q;
|
2022-11-26 18:36:12 +00:00
|
|
|
|
|
|
|
_checkInfoChanged.fire({
|
2022-11-27 12:32:13 +00:00
|
|
|
.type = UsernameCheckInfo::Type::PurchaseAvailable,
|
2022-11-26 18:36:12 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-10-11 18:10:15 +00:00
|
|
|
void UsernameEditor::updateFail(const QString &error) {
|
2022-11-26 21:20:17 +00:00
|
|
|
if ((error == u"USERNAME_NOT_MODIFIED"_q)
|
2023-04-09 20:25:18 +00:00
|
|
|
|| (_sentUsername == editableUsername())) {
|
|
|
|
if (const auto user = _peer->asUser()) {
|
|
|
|
user->setName(
|
|
|
|
TextUtilities::SingleLine(user->firstName),
|
|
|
|
TextUtilities::SingleLine(user->lastName),
|
|
|
|
TextUtilities::SingleLine(user->nameOrPhone),
|
|
|
|
TextUtilities::SingleLine(_sentUsername));
|
|
|
|
}
|
2022-10-12 00:07:09 +00:00
|
|
|
_saved.fire_done();
|
2022-11-26 21:20:17 +00:00
|
|
|
} else if (error == u"USERNAME_INVALID"_q) {
|
2016-11-11 13:46:04 +00:00
|
|
|
_username->setFocus();
|
|
|
|
_username->showError();
|
2019-06-19 15:09:03 +00:00
|
|
|
_errorText = tr::lng_username_invalid(tr::now);
|
2022-11-26 16:34:25 +00:00
|
|
|
checkInfoChange();
|
2022-11-26 21:20:17 +00:00
|
|
|
} else if ((error == u"USERNAME_OCCUPIED"_q)
|
|
|
|
|| (error == u"USERNAMES_UNAVAILABLE"_q)) {
|
2016-11-11 13:46:04 +00:00
|
|
|
_username->setFocus();
|
|
|
|
_username->showError();
|
2019-06-19 15:09:03 +00:00
|
|
|
_errorText = tr::lng_username_occupied(tr::now);
|
2022-11-26 16:34:25 +00:00
|
|
|
checkInfoChange();
|
2022-11-26 21:20:17 +00:00
|
|
|
} else if (error == u"USERNAME_PURCHASE_AVAILABLE"_q) {
|
2022-11-26 18:36:12 +00:00
|
|
|
checkInfoPurchaseAvailable();
|
2020-06-11 16:09:46 +00:00
|
|
|
} else {
|
|
|
|
_username->setFocus();
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-11 18:10:15 +00:00
|
|
|
void UsernameEditor::checkFail(const QString &error) {
|
2022-11-26 21:20:17 +00:00
|
|
|
if (error == u"USERNAME_INVALID"_q) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_errorText = tr::lng_username_invalid(tr::now);
|
2022-11-26 16:34:25 +00:00
|
|
|
checkInfoChange();
|
2022-11-26 21:20:17 +00:00
|
|
|
} else if ((error == u"USERNAME_OCCUPIED"_q)
|
2023-04-09 20:25:18 +00:00
|
|
|
&& (_checkUsername != editableUsername())) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_errorText = tr::lng_username_occupied(tr::now);
|
2022-11-26 16:34:25 +00:00
|
|
|
checkInfoChange();
|
2022-11-26 21:20:17 +00:00
|
|
|
} else if (error == u"USERNAME_PURCHASE_AVAILABLE"_q) {
|
2022-11-26 18:36:12 +00:00
|
|
|
checkInfoPurchaseAvailable();
|
2020-06-11 16:09:46 +00:00
|
|
|
} else {
|
|
|
|
_goodText = QString();
|
|
|
|
_username->setFocus();
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-11 18:10:15 +00:00
|
|
|
QString UsernameEditor::getName() const {
|
2016-11-11 13:46:04 +00:00
|
|
|
return _username->text().replace('@', QString()).trimmed();
|
2014-10-22 18:39:03 +00:00
|
|
|
}
|
2015-10-06 19:49:23 +00:00
|
|
|
|
2022-10-11 18:10:15 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void UsernamesBox(
|
|
|
|
not_null<Ui::GenericBox*> box,
|
2023-04-09 20:25:18 +00:00
|
|
|
not_null<PeerData*> peer) {
|
|
|
|
const auto isBot = peer && peer->isUser() && peer->asUser()->isBot();
|
|
|
|
box->setTitle(isBot
|
|
|
|
? tr::lng_bot_username_title()
|
|
|
|
: tr::lng_username_title());
|
2022-10-11 18:10:15 +00:00
|
|
|
|
|
|
|
const auto container = box->verticalLayout();
|
|
|
|
|
|
|
|
const auto editor = box->addRow(
|
2023-04-09 20:25:18 +00:00
|
|
|
object_ptr<UsernameEditor>(box, peer),
|
2022-10-11 18:10:15 +00:00
|
|
|
{});
|
2023-04-09 23:32:53 +00:00
|
|
|
editor->setEnabled(!isBot);
|
2022-10-16 12:31:41 +00:00
|
|
|
box->setFocusCallback([=] { editor->setInnerFocus(); });
|
2022-10-11 18:10:15 +00:00
|
|
|
|
2022-11-27 12:32:13 +00:00
|
|
|
AddUsernameCheckLabel(container, editor->checkInfoChanged());
|
2022-11-26 16:34:25 +00:00
|
|
|
|
2023-04-09 23:32:53 +00:00
|
|
|
auto description = [&]() -> rpl::producer<TextWithEntities> {
|
|
|
|
if (!isBot) {
|
|
|
|
return rpl::combine(
|
|
|
|
tr::lng_username_description1(Ui::Text::RichLangValue),
|
|
|
|
tr::lng_username_description2(Ui::Text::RichLangValue)
|
|
|
|
) | rpl::map([](TextWithEntities d1, TextWithEntities d2) {
|
|
|
|
return d1.append("\n\n").append(std::move(d2));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (const auto url = AppConfig::FragmentLink(&peer->session())) {
|
|
|
|
const auto link = Ui::Text::Link(
|
|
|
|
tr::lng_bot_username_description1_link(tr::now),
|
|
|
|
*url);
|
|
|
|
return tr::lng_bot_username_description1(
|
|
|
|
lt_link,
|
|
|
|
rpl::single(link),
|
|
|
|
Ui::Text::RichLangValue);
|
|
|
|
}
|
|
|
|
return rpl::single<TextWithEntities>({});
|
|
|
|
}();
|
2022-10-11 18:10:15 +00:00
|
|
|
container->add(object_ptr<Ui::DividerLabel>(
|
|
|
|
container,
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
container,
|
2023-04-09 17:23:52 +00:00
|
|
|
std::move(description),
|
2022-10-11 18:10:15 +00:00
|
|
|
st::boxDividerLabel),
|
|
|
|
st::settingsDividerLabelPadding));
|
|
|
|
|
2022-10-12 00:07:09 +00:00
|
|
|
const auto list = box->addRow(
|
|
|
|
object_ptr<UsernamesList>(
|
|
|
|
box,
|
2023-04-09 20:25:18 +00:00
|
|
|
peer,
|
2023-05-02 09:33:19 +00:00
|
|
|
box->uiShow(),
|
2023-04-09 23:32:53 +00:00
|
|
|
!isBot
|
|
|
|
? [=] { box->scrollToY(0); editor->setInnerFocus(); }
|
|
|
|
: Fn<void()>(nullptr)),
|
2022-10-12 00:07:09 +00:00
|
|
|
{});
|
|
|
|
|
|
|
|
const auto finish = [=] {
|
|
|
|
list->save(
|
|
|
|
) | rpl::start_with_done([=] {
|
|
|
|
editor->save(
|
|
|
|
) | rpl::start_with_done([=] {
|
|
|
|
box->closeBox();
|
|
|
|
}, box->lifetime());
|
|
|
|
}, box->lifetime());
|
|
|
|
};
|
|
|
|
editor->submitted(
|
|
|
|
) | rpl::start_with_next(finish, editor->lifetime());
|
|
|
|
|
2023-07-27 23:44:20 +00:00
|
|
|
if (isBot) {
|
|
|
|
box->addButton(tr::lng_close(), [=] { box->closeBox(); });
|
|
|
|
} else {
|
|
|
|
box->addButton(tr::lng_settings_save(), finish);
|
|
|
|
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
|
|
|
}
|
2021-10-17 21:30:25 +00:00
|
|
|
}
|
2022-11-27 12:32:13 +00:00
|
|
|
|
|
|
|
void AddUsernameCheckLabel(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
rpl::producer<UsernameCheckInfo> checkInfo) {
|
|
|
|
const auto padding = st::boxRowPadding;
|
|
|
|
const auto &st = st::aboutRevokePublicLabel;
|
|
|
|
const auto skip = (st::usernameSkip - st.style.font->height) / 4;
|
|
|
|
|
|
|
|
auto wrapped = object_ptr<Ui::VerticalLayout>(container);
|
|
|
|
Settings::AddSkip(wrapped, skip);
|
|
|
|
const auto label = wrapped->add(object_ptr<Ui::FlatLabel>(wrapped, st));
|
|
|
|
Settings::AddSkip(wrapped, skip);
|
|
|
|
|
|
|
|
Settings::AddSkip(container, skip);
|
2022-12-06 18:13:15 +00:00
|
|
|
container->add(
|
|
|
|
object_ptr<Ui::FollowSlideWrap<Ui::VerticalLayout>>(
|
|
|
|
container,
|
|
|
|
std::move(wrapped)),
|
|
|
|
padding);
|
2022-11-27 12:32:13 +00:00
|
|
|
|
|
|
|
rpl::combine(
|
|
|
|
std::move(checkInfo),
|
|
|
|
container->widthValue()
|
|
|
|
) | rpl::start_with_next([=](const UsernameCheckInfo &info, int w) {
|
|
|
|
using Type = UsernameCheckInfo::Type;
|
|
|
|
label->setMarkedText((info.type == Type::PurchaseAvailable)
|
|
|
|
? PurchaseAvailableText()
|
|
|
|
: info.text);
|
|
|
|
const auto &color = (info.type == Type::Good)
|
|
|
|
? st::boxTextFgGood
|
|
|
|
: (info.type == Type::Error)
|
|
|
|
? st::boxTextFgError
|
|
|
|
: st::usernameDefaultFg;
|
|
|
|
label->setTextColorOverride(color->c);
|
|
|
|
label->resizeToWidth(w - padding.left() - padding.right());
|
|
|
|
}, label->lifetime());
|
|
|
|
Settings::AddSkip(container, skip);
|
|
|
|
}
|