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