mirror of https://github.com/procxx/kepka.git
Added opening EditPeerTypeBox when error of saving username was handled.
This commit is contained in:
parent
3d7b8b3162
commit
e024d9bbb0
|
@ -161,6 +161,7 @@ private:
|
|||
object_ptr<Ui::RpWidget> createPhotoEdit();
|
||||
object_ptr<Ui::RpWidget> createDescriptionEdit();
|
||||
void refreshHistoryVisibility(bool instant);
|
||||
void showEditPeerTypeBox(std::optional<LangKey> error = std::nullopt);
|
||||
void fillPrivacyTypeButton();
|
||||
void fillInviteLinkButton();
|
||||
void fillSignaturesButton();
|
||||
|
@ -217,6 +218,8 @@ private:
|
|||
std::deque<FnMut<void()>> _saveStagesQueue;
|
||||
Saving _savingData;
|
||||
|
||||
const rpl::event_stream<Privacy> _updadePrivacyType;
|
||||
|
||||
rpl::lifetime _lifetime;
|
||||
|
||||
};
|
||||
|
@ -395,10 +398,26 @@ void Controller::refreshHistoryVisibility(bool instant = false) {
|
|||
return;
|
||||
}
|
||||
_controls.historyVisibilityWrap->toggle(
|
||||
_privacySavedValue == Privacy::Private,
|
||||
_privacySavedValue != Privacy::Public,
|
||||
instant ? anim::type::instant : anim::type::normal);
|
||||
};
|
||||
|
||||
void Controller::showEditPeerTypeBox(std::optional<LangKey> error) {
|
||||
const auto boxCallback = [=](Privacy checked, QString publicLink) {
|
||||
_updadePrivacyType.fire(std::move(checked));
|
||||
_privacySavedValue = checked;
|
||||
_usernameSavedValue = publicLink;
|
||||
refreshHistoryVisibility();
|
||||
};
|
||||
Ui::show(Box<EditPeerTypeBox>(
|
||||
_peer,
|
||||
boxCallback,
|
||||
_privacySavedValue,
|
||||
_usernameSavedValue,
|
||||
error
|
||||
), LayerOption::KeepOther);
|
||||
}
|
||||
|
||||
void Controller::fillPrivacyTypeButton() {
|
||||
Expects(_controls.buttonsLayout != nullptr);
|
||||
// Create Privacy Button.
|
||||
|
@ -407,21 +426,8 @@ void Controller::fillPrivacyTypeButton() {
|
|||
? Privacy::Public
|
||||
: Privacy::Private;
|
||||
|
||||
const auto updateType = std::make_shared<rpl::event_stream<Privacy>>();
|
||||
|
||||
const auto boxCallback = [=](Privacy checked, QString publicLink) {
|
||||
updateType->fire(std::move(checked));
|
||||
_privacySavedValue = checked;
|
||||
_usernameSavedValue = publicLink;
|
||||
refreshHistoryVisibility();
|
||||
};
|
||||
const auto buttonCallback = [=] {
|
||||
Ui::show(Box<EditPeerTypeBox>(
|
||||
_peer,
|
||||
boxCallback,
|
||||
_privacySavedValue,
|
||||
_usernameSavedValue
|
||||
), LayerOption::KeepOther);
|
||||
showEditPeerTypeBox();
|
||||
};
|
||||
|
||||
AddButtonWithText(
|
||||
|
@ -430,7 +436,7 @@ void Controller::fillPrivacyTypeButton() {
|
|||
? lng_manage_peer_group_type
|
||||
: lng_manage_peer_channel_type)),
|
||||
|
||||
updateType->events(
|
||||
_updadePrivacyType.events(
|
||||
) | rpl::map([](Privacy flag) {
|
||||
return lang(Privacy::Public == flag
|
||||
? lng_manage_public_peer_title
|
||||
|
@ -438,7 +444,7 @@ void Controller::fillPrivacyTypeButton() {
|
|||
}),
|
||||
buttonCallback);
|
||||
|
||||
updateType->fire(std::move(_privacySavedValue.value()));
|
||||
_updadePrivacyType.fire(std::move(_privacySavedValue.value()));
|
||||
}
|
||||
|
||||
void Controller::fillInviteLinkButton() {
|
||||
|
@ -915,12 +921,12 @@ void Controller::saveUsername() {
|
|||
return lng_create_channel_link_invalid;
|
||||
} else if (type == qstr("USERNAME_OCCUPIED")
|
||||
|| type == qstr("USERNAMES_UNAVAILABLE")) {
|
||||
return lng_create_channel_link_invalid;
|
||||
return lng_create_channel_link_occupied;
|
||||
}
|
||||
return lng_create_channel_link_invalid;
|
||||
}();
|
||||
// Probably never happend.
|
||||
// showUsernameError(Lang::Viewer(errorKey));
|
||||
// Very rare case.
|
||||
showEditPeerTypeBox(errorKey);
|
||||
cancelSave();
|
||||
}).send();
|
||||
}
|
||||
|
|
|
@ -52,7 +52,8 @@ public:
|
|||
not_null<Ui::VerticalLayout*> container,
|
||||
not_null<PeerData*> peer,
|
||||
std::optional<Privacy> privacySavedValue,
|
||||
std::optional<QString> usernameSavedValue);
|
||||
std::optional<QString> usernameSavedValue,
|
||||
std::optional<LangKey> usernameError);
|
||||
|
||||
void createContent();
|
||||
QString getUsernameInput();
|
||||
|
@ -139,6 +140,7 @@ private:
|
|||
not_null<PeerData*> _peer;
|
||||
std::optional<Privacy> _privacySavedValue = std::nullopt;
|
||||
std::optional<QString> _usernameSavedValue = std::nullopt;
|
||||
std::optional<LangKey> _usernameError = std::nullopt;
|
||||
|
||||
bool _isGroup = false;
|
||||
bool _isInviteLink = false;
|
||||
|
@ -158,10 +160,12 @@ Controller::Controller(
|
|||
not_null<Ui::VerticalLayout*> container,
|
||||
not_null<PeerData*> peer,
|
||||
std::optional<Privacy> privacySavedValue,
|
||||
std::optional<QString> usernameSavedValue)
|
||||
std::optional<QString> usernameSavedValue,
|
||||
std::optional<LangKey> usernameError)
|
||||
: _peer(peer)
|
||||
, _privacySavedValue(privacySavedValue)
|
||||
, _usernameSavedValue(usernameSavedValue)
|
||||
, _usernameError(usernameError)
|
||||
, _isGroup(_peer->isChat() || _peer->isMegagroup())
|
||||
, _isInviteLink(!_privacySavedValue.has_value() && !_usernameSavedValue.has_value())
|
||||
, _isAllowSave(!_usernameSavedValue.value_or(QString()).isEmpty())
|
||||
|
@ -204,6 +208,13 @@ void Controller::createContent() {
|
|||
if (_controls.privacy->value() == Privacy::Private) {
|
||||
checkUsernameAvailability();
|
||||
}
|
||||
|
||||
if (_usernameError.has_value()) {
|
||||
showUsernameError(Lang::Viewer(_usernameError.value()));
|
||||
// Not focused actually.
|
||||
_controls.usernameInput->setDisplayFocused(true);
|
||||
setFocusUsername();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -508,6 +519,7 @@ void Controller::usernameChanged() {
|
|||
}
|
||||
|
||||
void Controller::showUsernameError(rpl::producer<QString> &&error) {
|
||||
_isAllowSave = false;
|
||||
showUsernameResult(std::move(error), &st::editPeerUsernameError);
|
||||
}
|
||||
|
||||
|
@ -720,11 +732,13 @@ EditPeerTypeBox::EditPeerTypeBox(
|
|||
not_null<PeerData*> peer,
|
||||
FnMut<void(Privacy, QString)> savedCallback,
|
||||
std::optional<Privacy> privacySaved,
|
||||
std::optional<QString> usernameSaved)
|
||||
std::optional<QString> usernameSaved,
|
||||
std::optional<LangKey> usernameError)
|
||||
: _peer(peer)
|
||||
, _savedCallback(std::move(savedCallback))
|
||||
, _privacySavedValue(privacySaved)
|
||||
, _usernameSavedValue(usernameSaved) {
|
||||
, _usernameSavedValue(usernameSaved)
|
||||
, _usernameError(usernameError) {
|
||||
}
|
||||
|
||||
void EditPeerTypeBox::prepare() {
|
||||
|
@ -737,7 +751,8 @@ void EditPeerTypeBox::prepare() {
|
|||
content,
|
||||
_peer,
|
||||
_privacySavedValue,
|
||||
_usernameSavedValue);
|
||||
_usernameSavedValue,
|
||||
_usernameError);
|
||||
_focusRequests.events(
|
||||
) | rpl::start_with_next(
|
||||
[=] { controller->setFocusUsername(); },
|
||||
|
|
|
@ -10,6 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "boxes/abstract_box.h"
|
||||
#include "base/timer.h"
|
||||
|
||||
enum LangKey : int;
|
||||
|
||||
namespace style {
|
||||
struct InfoProfileCountButton;
|
||||
} // namespace style
|
||||
|
@ -43,7 +45,8 @@ public:
|
|||
not_null<PeerData*> p,
|
||||
FnMut<void(Privacy, QString)> savedCallback,
|
||||
std::optional<Privacy> privacySaved = std::nullopt,
|
||||
std::optional<QString> usernameSaved = std::nullopt);
|
||||
std::optional<QString> usernameSaved = std::nullopt,
|
||||
std::optional<LangKey> usernameError = std::nullopt);
|
||||
|
||||
protected:
|
||||
void prepare() override;
|
||||
|
@ -56,6 +59,7 @@ private:
|
|||
|
||||
std::optional<Privacy> _privacySavedValue = std::nullopt;
|
||||
std::optional<QString> _usernameSavedValue = std::nullopt;
|
||||
std::optional<LangKey> _usernameError = std::nullopt;
|
||||
|
||||
rpl::event_stream<> _focusRequests;
|
||||
|
||||
|
|
Loading…
Reference in New Issue