Added external link to username field when it is available for purchase.

This commit is contained in:
23rd 2024-01-29 23:28:04 +03:00 committed by John Preston
parent 32d3b90cdc
commit 42842619b0
4 changed files with 33 additions and 22 deletions

View file

@ -433,7 +433,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_username_invalid" = "This username is invalid."; "lng_username_invalid" = "This username is invalid.";
"lng_username_occupied" = "This username is already occupied."; "lng_username_occupied" = "This username is already occupied.";
"lng_username_too_short" = "This username is too short."; "lng_username_too_short" = "This username is too short.";
"lng_username_purchase_available" = "Sorry, this link is occupied by someone. But it's available for purchase through\nofficial {link}."; "lng_username_purchase_available" = "**This username is already taken.** However, it is currently available for purchase. {link}";
"lng_username_purchase_available_link" = "Learn more...";
"lng_username_bad_symbols" = "Only a-z, 0-9, and underscores allowed."; "lng_username_bad_symbols" = "Only a-z, 0-9, and underscores allowed.";
"lng_username_available" = "This username is available."; "lng_username_available" = "This username is available.";
"lng_username_not_found" = "User @{user} not found."; "lng_username_not_found" = "User @{user} not found.";

View file

@ -585,9 +585,8 @@ void Controller::checkUsernameAvailability() {
showUsernameError(tr::lng_create_channel_link_invalid()); showUsernameError(tr::lng_create_channel_link_invalid());
} else if (type == u"USERNAME_PURCHASE_AVAILABLE"_q) { } else if (type == u"USERNAME_PURCHASE_AVAILABLE"_q) {
_goodUsername = false; _goodUsername = false;
_usernameCheckInfo.fire({ _usernameCheckInfo.fire(
.type = UsernameCheckInfo::Type::PurchaseAvailable, UsernameCheckInfo::PurchaseAvailable(checking, _peer));
});
} else if (type == u"USERNAME_OCCUPIED"_q && checking != username) { } else if (type == u"USERNAME_OCCUPIED"_q && checking != username) {
showUsernameError(tr::lng_create_channel_link_occupied()); showUsernameError(tr::lng_create_channel_link_occupied());
} }

View file

@ -33,17 +33,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace { namespace {
[[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);
}
class UsernameEditor final : public Ui::RpWidget { class UsernameEditor final : public Ui::RpWidget {
public: public:
UsernameEditor(not_null<Ui::RpWidget*>, not_null<PeerData*> peer); UsernameEditor(not_null<Ui::RpWidget*>, not_null<PeerData*> peer);
@ -268,9 +257,8 @@ void UsernameEditor::checkInfoPurchaseAvailable() {
_username->showError(); _username->showError();
_errorText = u".bad."_q; _errorText = u".bad."_q;
_checkInfoChanged.fire({ _checkInfoChanged.fire(
.type = UsernameCheckInfo::Type::PurchaseAvailable, UsernameCheckInfo::PurchaseAvailable(_checkUsername, _peer));
});
} }
void UsernameEditor::updateFail(const QString &error) { void UsernameEditor::updateFail(const QString &error) {
@ -424,9 +412,7 @@ void AddUsernameCheckLabel(
container->widthValue() container->widthValue()
) | rpl::start_with_next([=](const UsernameCheckInfo &info, int w) { ) | rpl::start_with_next([=](const UsernameCheckInfo &info, int w) {
using Type = UsernameCheckInfo::Type; using Type = UsernameCheckInfo::Type;
label->setMarkedText((info.type == Type::PurchaseAvailable) label->setMarkedText(info.text);
? PurchaseAvailableText()
: info.text);
const auto &color = (info.type == Type::Good) const auto &color = (info.type == Type::Good)
? st::boxTextFgGood ? st::boxTextFgGood
: (info.type == Type::Error) : (info.type == Type::Error)
@ -437,3 +423,25 @@ void AddUsernameCheckLabel(
}, label->lifetime()); }, label->lifetime());
Ui::AddSkip(container, skip); Ui::AddSkip(container, skip);
} }
UsernameCheckInfo UsernameCheckInfo::PurchaseAvailable(
const QString &username,
not_null<PeerData*> peer) {
if (const auto fragmentLink = AppConfig::FragmentLink(&peer->session())) {
return {
.type = UsernameCheckInfo::Type::Default,
.text = tr::lng_username_purchase_available(
tr::now,
lt_link,
Ui::Text::Link(
tr::lng_username_purchase_available_link(tr::now),
(*fragmentLink) + u"/username/"_q + username),
Ui::Text::RichLangValue),
};
} else {
return {
.type = UsernameCheckInfo::Type::Error,
.text = { u"INTERNAL_SERVER_ERROR"_q },
};
}
}

View file

@ -19,11 +19,14 @@ void UsernamesBox(
not_null<PeerData*> peer); not_null<PeerData*> peer);
struct UsernameCheckInfo final { struct UsernameCheckInfo final {
[[nodiscard]] static UsernameCheckInfo PurchaseAvailable(
const QString &username,
not_null<PeerData*> peer);
enum class Type { enum class Type {
Good, Good,
Error, Error,
Default, Default,
PurchaseAvailable,
}; };
Type type; Type type;
TextWithEntities text; TextWithEntities text;