mirror of https://github.com/procxx/kepka.git
Refactored code.
- Slightly improved design. - Added "const" in EditPeerTypeBox & EditPeerInfoBox.
This commit is contained in:
parent
e024d9bbb0
commit
bd7ba3acb1
|
@ -145,8 +145,8 @@ private:
|
||||||
Ui::InputField *description = nullptr;
|
Ui::InputField *description = nullptr;
|
||||||
Ui::UserpicButton *photo = nullptr;
|
Ui::UserpicButton *photo = nullptr;
|
||||||
rpl::lifetime initialPhotoImageWaiting;
|
rpl::lifetime initialPhotoImageWaiting;
|
||||||
Ui::SlideWrap<Ui::RpWidget> *historyVisibilityWrap = nullptr;
|
|
||||||
Ui::VerticalLayout *buttonsLayout = nullptr;
|
Ui::VerticalLayout *buttonsLayout = nullptr;
|
||||||
|
Ui::SlideWrap<Ui::RpWidget> *historyVisibilityWrap = nullptr;
|
||||||
};
|
};
|
||||||
struct Saving {
|
struct Saving {
|
||||||
std::optional<QString> username;
|
std::optional<QString> username;
|
||||||
|
@ -160,22 +160,17 @@ private:
|
||||||
object_ptr<Ui::RpWidget> createTitleEdit();
|
object_ptr<Ui::RpWidget> createTitleEdit();
|
||||||
object_ptr<Ui::RpWidget> createPhotoEdit();
|
object_ptr<Ui::RpWidget> createPhotoEdit();
|
||||||
object_ptr<Ui::RpWidget> createDescriptionEdit();
|
object_ptr<Ui::RpWidget> createDescriptionEdit();
|
||||||
|
object_ptr<Ui::RpWidget> createManageGroupButtons();
|
||||||
|
object_ptr<Ui::RpWidget> createStickersEdit();
|
||||||
|
object_ptr<Ui::RpWidget> createDeleteButton();
|
||||||
|
|
||||||
void refreshHistoryVisibility(bool instant);
|
void refreshHistoryVisibility(bool instant);
|
||||||
void showEditPeerTypeBox(std::optional<LangKey> error = std::nullopt);
|
void showEditPeerTypeBox(std::optional<LangKey> error = std::nullopt);
|
||||||
void fillPrivacyTypeButton();
|
void fillPrivacyTypeButton();
|
||||||
void fillInviteLinkButton();
|
void fillInviteLinkButton();
|
||||||
void fillSignaturesButton();
|
void fillSignaturesButton();
|
||||||
void fillHistoryVisibilityButton();
|
void fillHistoryVisibilityButton();
|
||||||
void fillManageSection(not_null<Window::Navigation*> navigation, not_null<PeerData*> peer);
|
void fillManageSection();
|
||||||
object_ptr<Ui::RpWidget> createUsernameEdit();
|
|
||||||
object_ptr<Ui::RpWidget> createInviteLinkCreate();
|
|
||||||
object_ptr<Ui::RpWidget> createInviteLinkEdit();
|
|
||||||
object_ptr<Ui::RpWidget> createStickersEdit();
|
|
||||||
object_ptr<Ui::RpWidget> createDeleteButton();
|
|
||||||
|
|
||||||
object_ptr<Ui::RpWidget> createManageGroupButtons();
|
|
||||||
|
|
||||||
void observeInviteLink();
|
|
||||||
|
|
||||||
void submitTitle();
|
void submitTitle();
|
||||||
void submitDescription();
|
void submitDescription();
|
||||||
|
@ -252,7 +247,6 @@ void Controller::subscribeToMigration() {
|
||||||
|
|
||||||
void Controller::migrate(not_null<ChannelData*> channel) {
|
void Controller::migrate(not_null<ChannelData*> channel) {
|
||||||
_peer = channel;
|
_peer = channel;
|
||||||
// observeInviteLink();
|
|
||||||
_peer->updateFull();
|
_peer->updateFull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,9 +257,7 @@ object_ptr<Ui::VerticalLayout> Controller::createContent() {
|
||||||
|
|
||||||
_wrap->add(createPhotoAndTitleEdit());
|
_wrap->add(createPhotoAndTitleEdit());
|
||||||
_wrap->add(createDescriptionEdit());
|
_wrap->add(createDescriptionEdit());
|
||||||
|
|
||||||
_wrap->add(createManageGroupButtons());
|
_wrap->add(createManageGroupButtons());
|
||||||
|
|
||||||
_wrap->add(createStickersEdit());
|
_wrap->add(createStickersEdit());
|
||||||
_wrap->add(createDeleteButton());
|
_wrap->add(createDeleteButton());
|
||||||
|
|
||||||
|
@ -294,12 +286,12 @@ object_ptr<Ui::RpWidget> Controller::createPhotoAndTitleEdit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = object_ptr<Ui::RpWidget>(_wrap);
|
auto result = object_ptr<Ui::RpWidget>(_wrap);
|
||||||
auto container = result.data();
|
const auto container = result.data();
|
||||||
|
|
||||||
auto photoWrap = Ui::AttachParentChild(
|
const auto photoWrap = Ui::AttachParentChild(
|
||||||
container,
|
container,
|
||||||
createPhotoEdit());
|
createPhotoEdit());
|
||||||
auto titleEdit = Ui::AttachParentChild(
|
const auto titleEdit = Ui::AttachParentChild(
|
||||||
container,
|
container,
|
||||||
createTitleEdit());
|
createTitleEdit());
|
||||||
photoWrap->heightValue(
|
photoWrap->heightValue(
|
||||||
|
@ -308,7 +300,7 @@ object_ptr<Ui::RpWidget> Controller::createPhotoAndTitleEdit() {
|
||||||
}, photoWrap->lifetime());
|
}, photoWrap->lifetime());
|
||||||
container->widthValue(
|
container->widthValue(
|
||||||
) | rpl::start_with_next([titleEdit](int width) {
|
) | rpl::start_with_next([titleEdit](int width) {
|
||||||
auto left = st::editPeerPhotoMargins.left()
|
const auto left = st::editPeerPhotoMargins.left()
|
||||||
+ st::defaultUserpicButton.size.width();
|
+ st::defaultUserpicButton.size.width();
|
||||||
titleEdit->resizeToWidth(width - left);
|
titleEdit->resizeToWidth(width - left);
|
||||||
titleEdit->moveToLeft(left, 0, width);
|
titleEdit->moveToLeft(left, 0, width);
|
||||||
|
@ -393,6 +385,84 @@ object_ptr<Ui::RpWidget> Controller::createDescriptionEdit() {
|
||||||
return std::move(result);
|
return std::move(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object_ptr<Ui::RpWidget> Controller::createManageGroupButtons() {
|
||||||
|
Expects(_wrap != nullptr);
|
||||||
|
|
||||||
|
auto result = object_ptr<Ui::PaddingWrap<Ui::VerticalLayout>>(
|
||||||
|
_wrap,
|
||||||
|
object_ptr<Ui::VerticalLayout>(_wrap),
|
||||||
|
st::editPeerBottomButtonsLayoutMargins);
|
||||||
|
_controls.buttonsLayout = result->entity();
|
||||||
|
|
||||||
|
fillManageSection();
|
||||||
|
|
||||||
|
return std::move(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
object_ptr<Ui::RpWidget> Controller::createStickersEdit() {
|
||||||
|
Expects(_wrap != nullptr);
|
||||||
|
|
||||||
|
const auto channel = _peer->asChannel();
|
||||||
|
if (!channel || !channel->canEditStickers()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||||
|
_wrap,
|
||||||
|
object_ptr<Ui::VerticalLayout>(_wrap),
|
||||||
|
st::editPeerInvitesMargins);
|
||||||
|
const auto container = result->entity();
|
||||||
|
|
||||||
|
container->add(object_ptr<Ui::FlatLabel>(
|
||||||
|
container,
|
||||||
|
Lang::Viewer(lng_group_stickers),
|
||||||
|
st::editPeerSectionLabel));
|
||||||
|
container->add(object_ptr<Ui::FixedHeightWidget>(
|
||||||
|
container,
|
||||||
|
st::editPeerInviteLinkSkip));
|
||||||
|
|
||||||
|
container->add(object_ptr<Ui::FlatLabel>(
|
||||||
|
container,
|
||||||
|
Lang::Viewer(lng_group_stickers_description),
|
||||||
|
st::editPeerPrivacyLabel));
|
||||||
|
container->add(object_ptr<Ui::FixedHeightWidget>(
|
||||||
|
container,
|
||||||
|
st::editPeerInviteLinkSkip));
|
||||||
|
|
||||||
|
container->add(object_ptr<Ui::LinkButton>(
|
||||||
|
_wrap,
|
||||||
|
lang(lng_group_stickers_add),
|
||||||
|
st::editPeerInviteLinkButton)
|
||||||
|
)->addClickHandler([=] {
|
||||||
|
Ui::show(Box<StickersBox>(channel), LayerOption::KeepOther);
|
||||||
|
});
|
||||||
|
|
||||||
|
return std::move(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
object_ptr<Ui::RpWidget> Controller::createDeleteButton() {
|
||||||
|
Expects(_wrap != nullptr);
|
||||||
|
|
||||||
|
const auto channel = _peer->asChannel();
|
||||||
|
if (!channel || !channel->canDelete()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
const auto text = lang(_isGroup
|
||||||
|
? lng_profile_delete_group
|
||||||
|
: lng_profile_delete_channel);
|
||||||
|
auto result = object_ptr<Ui::PaddingWrap<Ui::LinkButton>>(
|
||||||
|
_wrap,
|
||||||
|
object_ptr<Ui::LinkButton>(
|
||||||
|
_wrap,
|
||||||
|
text,
|
||||||
|
st::editPeerDeleteButton),
|
||||||
|
st::editPeerDeleteButtonMargins);
|
||||||
|
result->entity()->addClickHandler([this] {
|
||||||
|
deleteWithConfirmation();
|
||||||
|
});
|
||||||
|
return std::move(result);
|
||||||
|
}
|
||||||
|
|
||||||
void Controller::refreshHistoryVisibility(bool instant = false) {
|
void Controller::refreshHistoryVisibility(bool instant = false) {
|
||||||
if (!_controls.historyVisibilityWrap) {
|
if (!_controls.historyVisibilityWrap) {
|
||||||
return;
|
return;
|
||||||
|
@ -486,14 +556,14 @@ void Controller::fillSignaturesButton() {
|
||||||
void Controller::fillHistoryVisibilityButton() {
|
void Controller::fillHistoryVisibilityButton() {
|
||||||
Expects(_controls.buttonsLayout != nullptr);
|
Expects(_controls.buttonsLayout != nullptr);
|
||||||
|
|
||||||
auto wrapLayout = _controls.buttonsLayout->add(object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
const auto wrapLayout = _controls.buttonsLayout->add(object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||||
_controls.buttonsLayout,
|
_controls.buttonsLayout,
|
||||||
object_ptr<Ui::VerticalLayout>(_controls.buttonsLayout),
|
object_ptr<Ui::VerticalLayout>(_controls.buttonsLayout),
|
||||||
st::boxOptionListPadding)); // Empty margins.
|
st::boxOptionListPadding)); // Empty margins.
|
||||||
_controls.historyVisibilityWrap = wrapLayout;
|
_controls.historyVisibilityWrap = wrapLayout;
|
||||||
|
|
||||||
const auto channel = _peer->asChannel();
|
const auto channel = _peer->asChannel();
|
||||||
auto container = wrapLayout->entity();
|
const auto container = wrapLayout->entity();
|
||||||
|
|
||||||
_historyVisibilitySavedValue = (!channel || channel->hiddenPreHistory())
|
_historyVisibilitySavedValue = (!channel || channel->hiddenPreHistory())
|
||||||
? HistoryVisibility::Hidden
|
? HistoryVisibility::Hidden
|
||||||
|
@ -531,13 +601,12 @@ void Controller::fillHistoryVisibilityButton() {
|
||||||
refreshHistoryVisibility(true);
|
refreshHistoryVisibility(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::fillManageSection(
|
void Controller::fillManageSection() {
|
||||||
not_null<Window::Navigation*> navigation,
|
|
||||||
not_null<PeerData*> peer) {
|
|
||||||
Expects(_controls.buttonsLayout != nullptr);
|
Expects(_controls.buttonsLayout != nullptr);
|
||||||
|
const auto navigation = App::wnd()->controller();
|
||||||
|
|
||||||
const auto chat = peer->asChat();
|
const auto chat = _peer->asChat();
|
||||||
const auto channel = peer->asChannel();
|
const auto channel = _peer->asChannel();
|
||||||
const auto isChannel = (!chat);
|
const auto isChannel = (!chat);
|
||||||
if (!chat && !channel) return;
|
if (!chat && !channel) return;
|
||||||
|
|
||||||
|
@ -604,29 +673,30 @@ void Controller::fillManageSection(
|
||||||
fillHistoryVisibilityButton();
|
fillHistoryVisibilityButton();
|
||||||
}
|
}
|
||||||
if (canEditPreHistoryHidden || canEditSignatures || canEditInviteLink) {
|
if (canEditPreHistoryHidden || canEditSignatures || canEditInviteLink) {
|
||||||
// Perhaps should fix extra 1-pixel line for design.
|
AddSkip(_controls.buttonsLayout,
|
||||||
AddSkip(_controls.buttonsLayout);
|
st::editPeerTopButtonsLayoutSkip,
|
||||||
|
st::editPeerTopButtonsLayoutSkipCustomBottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canEditPermissions) {
|
if (canEditPermissions) {
|
||||||
AddButtonWithCount(
|
AddButtonWithCount(
|
||||||
_controls.buttonsLayout,
|
_controls.buttonsLayout,
|
||||||
Lang::Viewer(lng_manage_peer_permissions),
|
Lang::Viewer(lng_manage_peer_permissions),
|
||||||
Info::Profile::RestrictionsCountValue(peer)
|
Info::Profile::RestrictionsCountValue(_peer)
|
||||||
| ToPositiveNumberStringRestrictions(),
|
| ToPositiveNumberStringRestrictions(),
|
||||||
[=] { ShowEditPermissions(peer); },
|
[=] { ShowEditPermissions(_peer); },
|
||||||
st::infoIconPermissions);
|
st::infoIconPermissions);
|
||||||
}
|
}
|
||||||
if (canViewAdmins) {
|
if (canViewAdmins) {
|
||||||
AddButtonWithCount(
|
AddButtonWithCount(
|
||||||
_controls.buttonsLayout,
|
_controls.buttonsLayout,
|
||||||
Lang::Viewer(lng_manage_peer_administrators),
|
Lang::Viewer(lng_manage_peer_administrators),
|
||||||
Info::Profile::AdminsCountValue(peer)
|
Info::Profile::AdminsCountValue(_peer)
|
||||||
| ToPositiveNumberString(),
|
| ToPositiveNumberString(),
|
||||||
[=] {
|
[=] {
|
||||||
ParticipantsBoxController::Start(
|
ParticipantsBoxController::Start(
|
||||||
navigation,
|
navigation,
|
||||||
peer,
|
_peer,
|
||||||
ParticipantsBoxController::Role::Admins);
|
ParticipantsBoxController::Role::Admins);
|
||||||
},
|
},
|
||||||
st::infoIconAdministrators);
|
st::infoIconAdministrators);
|
||||||
|
@ -635,12 +705,12 @@ void Controller::fillManageSection(
|
||||||
AddButtonWithCount(
|
AddButtonWithCount(
|
||||||
_controls.buttonsLayout,
|
_controls.buttonsLayout,
|
||||||
Lang::Viewer(lng_manage_peer_members),
|
Lang::Viewer(lng_manage_peer_members),
|
||||||
Info::Profile::MembersCountValue(peer)
|
Info::Profile::MembersCountValue(_peer)
|
||||||
| ToPositiveNumberString(),
|
| ToPositiveNumberString(),
|
||||||
[=] {
|
[=] {
|
||||||
ParticipantsBoxController::Start(
|
ParticipantsBoxController::Start(
|
||||||
navigation,
|
navigation,
|
||||||
peer,
|
_peer,
|
||||||
ParticipantsBoxController::Role::Members);
|
ParticipantsBoxController::Role::Members);
|
||||||
},
|
},
|
||||||
st::infoIconMembers);
|
st::infoIconMembers);
|
||||||
|
@ -654,7 +724,7 @@ void Controller::fillManageSection(
|
||||||
[=] {
|
[=] {
|
||||||
ParticipantsBoxController::Start(
|
ParticipantsBoxController::Start(
|
||||||
navigation,
|
navigation,
|
||||||
peer,
|
_peer,
|
||||||
ParticipantsBoxController::Role::Kicked);
|
ParticipantsBoxController::Role::Kicked);
|
||||||
},
|
},
|
||||||
st::infoIconBlacklist);
|
st::infoIconBlacklist);
|
||||||
|
@ -670,85 +740,8 @@ void Controller::fillManageSection(
|
||||||
st::infoIconRecentActions);
|
st::infoIconRecentActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
AddSkip(_controls.buttonsLayout);
|
AddSkip(_controls.buttonsLayout,
|
||||||
}
|
st::editPeerTopButtonsLayoutSkipCustomTop);
|
||||||
|
|
||||||
object_ptr<Ui::RpWidget> Controller::createManageGroupButtons() {
|
|
||||||
Expects(_wrap != nullptr);
|
|
||||||
|
|
||||||
auto result = object_ptr<Ui::PaddingWrap<Ui::VerticalLayout>>(
|
|
||||||
_wrap,
|
|
||||||
object_ptr<Ui::VerticalLayout>(_wrap),
|
|
||||||
st::editPeerBottomButtonsLayoutMargins);
|
|
||||||
_controls.buttonsLayout = result->entity();
|
|
||||||
|
|
||||||
fillManageSection(App::wnd()->controller(), _peer);
|
|
||||||
|
|
||||||
return std::move(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
object_ptr<Ui::RpWidget> Controller::createStickersEdit() {
|
|
||||||
Expects(_wrap != nullptr);
|
|
||||||
|
|
||||||
auto channel = _peer->asChannel();
|
|
||||||
if (!channel || !channel->canEditStickers()) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
||||||
_wrap,
|
|
||||||
object_ptr<Ui::VerticalLayout>(_wrap),
|
|
||||||
st::editPeerInvitesMargins);
|
|
||||||
auto container = result->entity();
|
|
||||||
|
|
||||||
container->add(object_ptr<Ui::FlatLabel>(
|
|
||||||
container,
|
|
||||||
Lang::Viewer(lng_group_stickers),
|
|
||||||
st::editPeerSectionLabel));
|
|
||||||
container->add(object_ptr<Ui::FixedHeightWidget>(
|
|
||||||
container,
|
|
||||||
st::editPeerInviteLinkSkip));
|
|
||||||
|
|
||||||
container->add(object_ptr<Ui::FlatLabel>(
|
|
||||||
container,
|
|
||||||
Lang::Viewer(lng_group_stickers_description),
|
|
||||||
st::editPeerPrivacyLabel));
|
|
||||||
container->add(object_ptr<Ui::FixedHeightWidget>(
|
|
||||||
container,
|
|
||||||
st::editPeerInviteLinkSkip));
|
|
||||||
|
|
||||||
container->add(object_ptr<Ui::LinkButton>(
|
|
||||||
_wrap,
|
|
||||||
lang(lng_group_stickers_add),
|
|
||||||
st::editPeerInviteLinkButton)
|
|
||||||
)->addClickHandler([=] {
|
|
||||||
Ui::show(Box<StickersBox>(channel), LayerOption::KeepOther);
|
|
||||||
});
|
|
||||||
|
|
||||||
return std::move(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
object_ptr<Ui::RpWidget> Controller::createDeleteButton() {
|
|
||||||
Expects(_wrap != nullptr);
|
|
||||||
|
|
||||||
auto channel = _peer->asChannel();
|
|
||||||
if (!channel || !channel->canDelete()) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
auto text = lang(_isGroup
|
|
||||||
? lng_profile_delete_group
|
|
||||||
: lng_profile_delete_channel);
|
|
||||||
auto result = object_ptr<Ui::PaddingWrap<Ui::LinkButton>>(
|
|
||||||
_wrap,
|
|
||||||
object_ptr<Ui::LinkButton>(
|
|
||||||
_wrap,
|
|
||||||
text,
|
|
||||||
st::editPeerDeleteButton),
|
|
||||||
st::editPeerDeleteButtonMargins);
|
|
||||||
result->entity()->addClickHandler([this] {
|
|
||||||
deleteWithConfirmation();
|
|
||||||
});
|
|
||||||
return std::move(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::submitTitle() {
|
void Controller::submitTitle() {
|
||||||
|
@ -792,7 +785,7 @@ bool Controller::validateUsername(Saving &to) const {
|
||||||
to.username = QString();
|
to.username = QString();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
auto username = _usernameSavedValue.value_or(
|
const auto username = _usernameSavedValue.value_or(
|
||||||
_peer->isChannel()
|
_peer->isChannel()
|
||||||
? _peer->asChannel()->username
|
? _peer->asChannel()->username
|
||||||
: QString()
|
: QString()
|
||||||
|
@ -808,7 +801,7 @@ bool Controller::validateTitle(Saving &to) const {
|
||||||
if (!_controls.title) {
|
if (!_controls.title) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
auto title = _controls.title->getLastText().trimmed();
|
const auto title = _controls.title->getLastText().trimmed();
|
||||||
if (title.isEmpty()) {
|
if (title.isEmpty()) {
|
||||||
_controls.title->showError();
|
_controls.title->showError();
|
||||||
_box->scrollToWidget(_controls.title);
|
_box->scrollToWidget(_controls.title);
|
||||||
|
@ -852,7 +845,7 @@ void Controller::save() {
|
||||||
if (!_saveStagesQueue.empty()) {
|
if (!_saveStagesQueue.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (auto saving = validate()) {
|
if (const auto saving = validate()) {
|
||||||
_savingData = *saving;
|
_savingData = *saving;
|
||||||
pushSaveStage([this] { saveUsername(); });
|
pushSaveStage([this] { saveUsername(); });
|
||||||
pushSaveStage([this] { saveTitle(); });
|
pushSaveStage([this] { saveTitle(); });
|
||||||
|
@ -1120,7 +1113,7 @@ EditPeerInfoBox::EditPeerInfoBox(
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditPeerInfoBox::prepare() {
|
void EditPeerInfoBox::prepare() {
|
||||||
auto controller = Ui::CreateChild<Controller>(this, this, _peer);
|
const auto controller = Ui::CreateChild<Controller>(this, this, _peer);
|
||||||
_focusRequests.events(
|
_focusRequests.events(
|
||||||
) | rpl::start_with_next(
|
) | rpl::start_with_next(
|
||||||
[=] { controller->setFocus(); },
|
[=] { controller->setFocus(); },
|
||||||
|
|
|
@ -134,9 +134,6 @@ private:
|
||||||
bool inviteLinkShown();
|
bool inviteLinkShown();
|
||||||
QString inviteLinkText();
|
QString inviteLinkText();
|
||||||
|
|
||||||
void subscribeToMigration();
|
|
||||||
void migrate(not_null<ChannelData*> channel);
|
|
||||||
|
|
||||||
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;
|
||||||
|
@ -171,20 +168,6 @@ Controller::Controller(
|
||||||
, _isAllowSave(!_usernameSavedValue.value_or(QString()).isEmpty())
|
, _isAllowSave(!_usernameSavedValue.value_or(QString()).isEmpty())
|
||||||
, _wrap(container)
|
, _wrap(container)
|
||||||
, _checkUsernameTimer([=] { checkUsernameAvailability(); }) {
|
, _checkUsernameTimer([=] { checkUsernameAvailability(); }) {
|
||||||
subscribeToMigration();
|
|
||||||
_peer->updateFull();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Controller::subscribeToMigration() {
|
|
||||||
SubscribeToMigration(
|
|
||||||
_peer,
|
|
||||||
_lifetime,
|
|
||||||
[=](not_null<ChannelData*> channel) { migrate(channel); });
|
|
||||||
}
|
|
||||||
|
|
||||||
void Controller::migrate(not_null<ChannelData*> channel) {
|
|
||||||
_peer = channel;
|
|
||||||
observeInviteLink();
|
|
||||||
_peer->updateFull();
|
_peer->updateFull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +191,6 @@ void Controller::createContent() {
|
||||||
if (_controls.privacy->value() == Privacy::Private) {
|
if (_controls.privacy->value() == Privacy::Private) {
|
||||||
checkUsernameAvailability();
|
checkUsernameAvailability();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_usernameError.has_value()) {
|
if (_usernameError.has_value()) {
|
||||||
showUsernameError(Lang::Viewer(_usernameError.value()));
|
showUsernameError(Lang::Viewer(_usernameError.value()));
|
||||||
// Not focused actually.
|
// Not focused actually.
|
||||||
|
@ -263,7 +245,7 @@ void Controller::fillPrivaciesButtons(
|
||||||
parent,
|
parent,
|
||||||
object_ptr<Ui::VerticalLayout>(parent),
|
object_ptr<Ui::VerticalLayout>(parent),
|
||||||
st::editPeerPrivaciesMargins));
|
st::editPeerPrivaciesMargins));
|
||||||
auto container = result->entity();
|
const auto container = result->entity();
|
||||||
|
|
||||||
const auto isPublic = _peer->isChannel()
|
const auto isPublic = _peer->isChannel()
|
||||||
&& _peer->asChannel()->isPublic();
|
&& _peer->asChannel()->isPublic();
|
||||||
|
@ -288,12 +270,6 @@ void Controller::fillPrivaciesButtons(
|
||||||
_controls.privacy->setChangedCallback([=](Privacy value) {
|
_controls.privacy->setChangedCallback([=](Privacy value) {
|
||||||
privacyChanged(value);
|
privacyChanged(value);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!isPublic) {
|
|
||||||
// checkUsernameAvailability();
|
|
||||||
}
|
|
||||||
|
|
||||||
// return std::move(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::setFocusUsername() {
|
void Controller::setFocusUsername() {
|
||||||
|
@ -327,7 +303,7 @@ object_ptr<Ui::RpWidget> Controller::createUsernameEdit() {
|
||||||
st::editPeerUsernameMargins);
|
st::editPeerUsernameMargins);
|
||||||
_controls.usernameWrap = result.data();
|
_controls.usernameWrap = result.data();
|
||||||
|
|
||||||
auto container = result->entity();
|
const auto container = result->entity();
|
||||||
container->add(object_ptr<Ui::PaddingWrap<Ui::FlatLabel>>(
|
container->add(object_ptr<Ui::PaddingWrap<Ui::FlatLabel>>(
|
||||||
container,
|
container,
|
||||||
object_ptr<Ui::FlatLabel>(
|
object_ptr<Ui::FlatLabel>(
|
||||||
|
@ -336,7 +312,7 @@ object_ptr<Ui::RpWidget> Controller::createUsernameEdit() {
|
||||||
st::editPeerSectionLabel),
|
st::editPeerSectionLabel),
|
||||||
st::editPeerUsernameTitleLabelMargins));
|
st::editPeerUsernameTitleLabelMargins));
|
||||||
|
|
||||||
auto placeholder = container->add(object_ptr<Ui::RpWidget>(
|
const auto placeholder = container->add(object_ptr<Ui::RpWidget>(
|
||||||
container));
|
container));
|
||||||
placeholder->setAttribute(Qt::WA_TransparentForMouseEvents);
|
placeholder->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
_controls.usernameInput = Ui::AttachParentChild(
|
_controls.usernameInput = Ui::AttachParentChild(
|
||||||
|
@ -372,19 +348,19 @@ object_ptr<Ui::RpWidget> Controller::createUsernameEdit() {
|
||||||
&Ui::UsernameInput::changed,
|
&Ui::UsernameInput::changed,
|
||||||
[this] { usernameChanged(); });
|
[this] { usernameChanged(); });
|
||||||
|
|
||||||
auto shown = (_controls.privacy->value() == Privacy::Public);
|
const auto shown = (_controls.privacy->value() == Privacy::Public);
|
||||||
result->toggle(shown, anim::type::instant);
|
result->toggle(shown, anim::type::instant);
|
||||||
|
|
||||||
return std::move(result);
|
return std::move(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::privacyChanged(Privacy value) {
|
void Controller::privacyChanged(Privacy value) {
|
||||||
auto toggleEditUsername = [&] {
|
const auto toggleEditUsername = [&] {
|
||||||
_controls.usernameWrap->toggle(
|
_controls.usernameWrap->toggle(
|
||||||
(value == Privacy::Public),
|
(value == Privacy::Public),
|
||||||
anim::type::instant);
|
anim::type::instant);
|
||||||
};
|
};
|
||||||
auto refreshVisibilities = [&] {
|
const auto refreshVisibilities = [&] {
|
||||||
// Now first we need to hide that was shown.
|
// Now first we need to hide that was shown.
|
||||||
// Otherwise box will change own Y position.
|
// Otherwise box will change own Y position.
|
||||||
|
|
||||||
|
@ -425,8 +401,8 @@ void Controller::checkUsernameAvailability() {
|
||||||
if (!_controls.usernameInput) {
|
if (!_controls.usernameInput) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto initial = (_controls.privacy->value() != Privacy::Public);
|
const auto initial = (_controls.privacy->value() != Privacy::Public);
|
||||||
auto checking = initial
|
const auto checking = initial
|
||||||
? qsl(".bad.")
|
? qsl(".bad.")
|
||||||
: getUsernameInput();
|
: getUsernameInput();
|
||||||
if (checking.size() < kMinUsernameLength) {
|
if (checking.size() < kMinUsernameLength) {
|
||||||
|
@ -482,7 +458,7 @@ void Controller::checkUsernameAvailability() {
|
||||||
|
|
||||||
void Controller::askUsernameRevoke() {
|
void Controller::askUsernameRevoke() {
|
||||||
_controls.privacy->setValue(Privacy::Private);
|
_controls.privacy->setValue(Privacy::Private);
|
||||||
auto revokeCallback = crl::guard(this, [this] {
|
const auto revokeCallback = crl::guard(this, [this] {
|
||||||
_usernameState = UsernameState::Normal;
|
_usernameState = UsernameState::Normal;
|
||||||
_controls.privacy->setValue(Privacy::Public);
|
_controls.privacy->setValue(Privacy::Public);
|
||||||
checkUsernameAvailability();
|
checkUsernameAvailability();
|
||||||
|
@ -494,13 +470,13 @@ void Controller::askUsernameRevoke() {
|
||||||
|
|
||||||
void Controller::usernameChanged() {
|
void Controller::usernameChanged() {
|
||||||
_isAllowSave = false;
|
_isAllowSave = false;
|
||||||
auto username = getUsernameInput();
|
const auto username = getUsernameInput();
|
||||||
if (username.isEmpty()) {
|
if (username.isEmpty()) {
|
||||||
_controls.usernameResult = nullptr;
|
_controls.usernameResult = nullptr;
|
||||||
_checkUsernameTimer.cancel();
|
_checkUsernameTimer.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto bad = ranges::find_if(username, [](QChar ch) {
|
const auto bad = ranges::find_if(username, [](QChar ch) {
|
||||||
return (ch < 'A' || ch > 'Z')
|
return (ch < 'A' || ch > 'Z')
|
||||||
&& (ch < 'a' || ch > 'z')
|
&& (ch < 'a' || ch > 'z')
|
||||||
&& (ch < '0' || ch > '9')
|
&& (ch < '0' || ch > '9')
|
||||||
|
@ -540,7 +516,7 @@ void Controller::showUsernameResult(
|
||||||
_controls.usernameWrap,
|
_controls.usernameWrap,
|
||||||
_usernameResultTexts.events() | rpl::flatten_latest(),
|
_usernameResultTexts.events() | rpl::flatten_latest(),
|
||||||
*st);
|
*st);
|
||||||
auto label = _controls.usernameResult.get();
|
const auto label = _controls.usernameResult.get();
|
||||||
label->show();
|
label->show();
|
||||||
label->widthValue(
|
label->widthValue(
|
||||||
) | rpl::start_with_next([label] {
|
) | rpl::start_with_next([label] {
|
||||||
|
@ -563,8 +539,8 @@ void Controller::revokeInviteLink() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::exportInviteLink(const QString &confirmation) {
|
void Controller::exportInviteLink(const QString &confirmation) {
|
||||||
auto boxPointer = std::make_shared<QPointer<ConfirmBox>>();
|
const auto boxPointer = std::make_shared<QPointer<ConfirmBox>>();
|
||||||
auto callback = crl::guard(this, [=] {
|
const auto callback = crl::guard(this, [=] {
|
||||||
if (const auto strong = *boxPointer) {
|
if (const auto strong = *boxPointer) {
|
||||||
strong->closeBox();
|
strong->closeBox();
|
||||||
}
|
}
|
||||||
|
@ -591,7 +567,6 @@ void Controller::observeInviteLink() {
|
||||||
if (!_controls.editInviteLinkWrap) {
|
if (!_controls.editInviteLinkWrap) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// return; //
|
|
||||||
Notify::PeerUpdateValue(
|
Notify::PeerUpdateValue(
|
||||||
_peer,
|
_peer,
|
||||||
Notify::PeerUpdate::Flag::InviteLinkChanged
|
Notify::PeerUpdate::Flag::InviteLinkChanged
|
||||||
|
@ -614,7 +589,7 @@ object_ptr<Ui::RpWidget> Controller::createInviteLinkEdit() {
|
||||||
st::editPeerInvitesMargins);
|
st::editPeerInvitesMargins);
|
||||||
_controls.editInviteLinkWrap = result.data();
|
_controls.editInviteLinkWrap = result.data();
|
||||||
|
|
||||||
auto container = result->entity();
|
const auto container = result->entity();
|
||||||
if (!_isInviteLink) {
|
if (!_isInviteLink) {
|
||||||
container->add(object_ptr<Ui::FlatLabel>(
|
container->add(object_ptr<Ui::FlatLabel>(
|
||||||
container,
|
container,
|
||||||
|
@ -652,11 +627,11 @@ object_ptr<Ui::RpWidget> Controller::createInviteLinkEdit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::refreshEditInviteLink() {
|
void Controller::refreshEditInviteLink() {
|
||||||
auto link = inviteLinkText();
|
const auto link = inviteLinkText();
|
||||||
auto text = TextWithEntities();
|
auto text = TextWithEntities();
|
||||||
if (!link.isEmpty()) {
|
if (!link.isEmpty()) {
|
||||||
text.text = link;
|
text.text = link;
|
||||||
auto remove = qstr("https://");
|
const auto remove = qstr("https://");
|
||||||
if (text.text.startsWith(remove)) {
|
if (text.text.startsWith(remove)) {
|
||||||
text.text.remove(0, remove.size());
|
text.text.remove(0, remove.size());
|
||||||
}
|
}
|
||||||
|
@ -687,7 +662,7 @@ object_ptr<Ui::RpWidget> Controller::createInviteLinkCreate() {
|
||||||
_wrap,
|
_wrap,
|
||||||
object_ptr<Ui::VerticalLayout>(_wrap),
|
object_ptr<Ui::VerticalLayout>(_wrap),
|
||||||
st::editPeerInvitesMargins);
|
st::editPeerInvitesMargins);
|
||||||
auto container = result->entity();
|
const auto container = result->entity();
|
||||||
|
|
||||||
if (!_isInviteLink) {
|
if (!_isInviteLink) {
|
||||||
container->add(object_ptr<Ui::FlatLabel>(
|
container->add(object_ptr<Ui::FlatLabel>(
|
||||||
|
@ -746,7 +721,7 @@ void EditPeerTypeBox::prepare() {
|
||||||
|
|
||||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||||
|
|
||||||
auto controller = Ui::CreateChild<Controller>(
|
const auto controller = Ui::CreateChild<Controller>(
|
||||||
this,
|
this,
|
||||||
content,
|
content,
|
||||||
_peer,
|
_peer,
|
||||||
|
@ -781,8 +756,3 @@ void EditPeerTypeBox::prepare() {
|
||||||
|
|
||||||
setDimensionsToContent(st::boxWideWidth, content);
|
setDimensionsToContent(st::boxWideWidth, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditPeerTypeBox::setupContent() {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -52,8 +52,6 @@ protected:
|
||||||
void prepare() override;
|
void prepare() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupContent();
|
|
||||||
|
|
||||||
not_null<PeerData*> _peer;
|
not_null<PeerData*> _peer;
|
||||||
FnMut<void(Privacy, QString)> _savedCallback;
|
FnMut<void(Privacy, QString)> _savedCallback;
|
||||||
|
|
||||||
|
|
|
@ -645,9 +645,12 @@ editPeerTopButtonsLayoutMargins: margins(0px, 12px, 0px, 6px);
|
||||||
editPeerTopButtonsLayoutSkip: 13px;
|
editPeerTopButtonsLayoutSkip: 13px;
|
||||||
editPeerTopButtonsLayoutSkipToBottom: 12px;
|
editPeerTopButtonsLayoutSkipToBottom: 12px;
|
||||||
|
|
||||||
|
editPeerTopButtonsLayoutSkipCustomTop: 14px;
|
||||||
|
editPeerTopButtonsLayoutSkipCustomBottom: 11px;
|
||||||
|
|
||||||
editPeerHistoryVisibilityTopSkip: 8px;
|
editPeerHistoryVisibilityTopSkip: 8px;
|
||||||
|
|
||||||
editPeerDeleteButtonMargins: margins(23px, 16px, 23px, 16px);
|
editPeerDeleteButtonMargins: margins(25px, 11px, 23px, 16px);
|
||||||
editPeerDeleteButton: sessionTerminateAllButton;
|
editPeerDeleteButton: sessionTerminateAllButton;
|
||||||
editPeerPhotoMargins: margins(23px, 16px, 23px, 8px);
|
editPeerPhotoMargins: margins(23px, 16px, 23px, 8px);
|
||||||
editPeerTitle: defaultInputField;
|
editPeerTitle: defaultInputField;
|
||||||
|
|
Loading…
Reference in New Issue