Disabled editor in UsernamesBox for bots.

This commit is contained in:
23rd 2023-04-10 02:32:53 +03:00 committed by John Preston
parent ca2a0d41c9
commit a02ded6fd8
2 changed files with 32 additions and 13 deletions

View file

@ -432,7 +432,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_channel_usernames_description" = "Drag and drop links to change the order in which they will be displayed on the channel info page."; "lng_channel_usernames_description" = "Drag and drop links to change the order in which they will be displayed on the channel info page.";
"lng_bot_username_title" = "Username"; "lng_bot_username_title" = "Username";
"lng_bot_username_description1" = "If you set a public link, other people will be able to find your bot."; "lng_bot_username_description1" = "This link cannot be edited. You can acquire additional usernames on {link}.";
"lng_bot_username_description1_link" = "Fragment";
"lng_bot_usernames_activate_description" = "Do you want to show this link on the bot info page?"; "lng_bot_usernames_activate_description" = "Do you want to show this link on the bot info page?";
"lng_bot_usernames_deactivate_description" = "Do you want to hide this link from the bot info page?"; "lng_bot_usernames_deactivate_description" = "Do you want to hide this link from the bot info page?";
"lng_bot_usernames_description" = "Drag and drop links to change the order in which they will be displayed on the bot info page."; "lng_bot_usernames_description" = "Drag and drop links to change the order in which they will be displayed on the bot info page.";

View file

@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "main/main_app_config_values.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "mtproto/sender.h" #include "mtproto/sender.h"
#include "settings/settings_common.h" #include "settings/settings_common.h"
@ -49,6 +50,7 @@ public:
UsernameEditor(not_null<Ui::RpWidget*>, not_null<PeerData*> peer); UsernameEditor(not_null<Ui::RpWidget*>, not_null<PeerData*> peer);
void setInnerFocus(); void setInnerFocus();
void setEnabled(bool value);
[[nodiscard]] rpl::producer<> submitted() const; [[nodiscard]] rpl::producer<> submitted() const;
[[nodiscard]] rpl::producer<> save(); [[nodiscard]] rpl::producer<> save();
[[nodiscard]] rpl::producer<UsernameCheckInfo> checkInfoChanged() const; [[nodiscard]] rpl::producer<UsernameCheckInfo> checkInfoChanged() const;
@ -127,6 +129,10 @@ void UsernameEditor::setInnerFocus() {
_username->setFocusFast(); _username->setFocusFast();
} }
void UsernameEditor::setEnabled(bool value) {
_username->setEnabled(value);
}
void UsernameEditor::resizeEvent(QResizeEvent *e) { void UsernameEditor::resizeEvent(QResizeEvent *e) {
_username->resize( _username->resize(
width() - _padding.left() - _padding.right(), width() - _padding.left() - _padding.right(),
@ -329,18 +335,31 @@ void UsernamesBox(
const auto editor = box->addRow( const auto editor = box->addRow(
object_ptr<UsernameEditor>(box, peer), object_ptr<UsernameEditor>(box, peer),
{}); {});
editor->setEnabled(!isBot);
box->setFocusCallback([=] { editor->setInnerFocus(); }); box->setFocusCallback([=] { editor->setInnerFocus(); });
AddUsernameCheckLabel(container, editor->checkInfoChanged()); AddUsernameCheckLabel(container, editor->checkInfoChanged());
auto description = rpl::combine( auto description = [&]() -> rpl::producer<TextWithEntities> {
(isBot if (!isBot) {
? tr::lng_bot_username_description1 return rpl::combine(
: tr::lng_username_description1)(Ui::Text::RichLangValue), tr::lng_username_description1(Ui::Text::RichLangValue),
tr::lng_username_description2(Ui::Text::RichLangValue) tr::lng_username_description2(Ui::Text::RichLangValue)
) | rpl::map([](TextWithEntities d1, TextWithEntities d2) { ) | rpl::map([](TextWithEntities d1, TextWithEntities d2) {
return d1.append("\n\n").append(std::move(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>({});
}();
container->add(object_ptr<Ui::DividerLabel>( container->add(object_ptr<Ui::DividerLabel>(
container, container,
object_ptr<Ui::FlatLabel>( object_ptr<Ui::FlatLabel>(
@ -354,10 +373,9 @@ void UsernamesBox(
box, box,
peer, peer,
std::make_shared<Ui::BoxShow>(box), std::make_shared<Ui::BoxShow>(box),
[=] { !isBot
box->scrollToY(0); ? [=] { box->scrollToY(0); editor->setInnerFocus(); }
editor->setInnerFocus(); : Fn<void()>(nullptr)),
}),
{}); {});
const auto finish = [=] { const auto finish = [=] {