mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 15:13:57 +02:00
Return invite-link-only box.
This commit is contained in:
parent
cb2d77d386
commit
34ec1c371c
3 changed files with 69 additions and 34 deletions
|
@ -332,6 +332,7 @@ private:
|
||||||
void showEditLinkedChatBox();
|
void showEditLinkedChatBox();
|
||||||
void fillPrivacyTypeButton();
|
void fillPrivacyTypeButton();
|
||||||
void fillLinkedChatButton();
|
void fillLinkedChatButton();
|
||||||
|
void fillInviteLinkButton();
|
||||||
void fillSignaturesButton();
|
void fillSignaturesButton();
|
||||||
void fillHistoryVisibilityButton();
|
void fillHistoryVisibilityButton();
|
||||||
void fillManageSection();
|
void fillManageSection();
|
||||||
|
@ -640,8 +641,6 @@ void Controller::refreshHistoryVisibility(anim::type animated) {
|
||||||
|
|
||||||
void Controller::showEditPeerTypeBox(
|
void Controller::showEditPeerTypeBox(
|
||||||
std::optional<rpl::producer<QString>> error) {
|
std::optional<rpl::producer<QString>> error) {
|
||||||
Expects(_privacySavedValue.has_value());
|
|
||||||
|
|
||||||
const auto boxCallback = crl::guard(this, [=](
|
const auto boxCallback = crl::guard(this, [=](
|
||||||
Privacy checked, QString publicLink) {
|
Privacy checked, QString publicLink) {
|
||||||
_privacyTypeUpdates.fire(std::move(checked));
|
_privacyTypeUpdates.fire(std::move(checked));
|
||||||
|
@ -654,7 +653,7 @@ void Controller::showEditPeerTypeBox(
|
||||||
_peer,
|
_peer,
|
||||||
_channelHasLocationOriginalValue,
|
_channelHasLocationOriginalValue,
|
||||||
boxCallback,
|
boxCallback,
|
||||||
*_privacySavedValue,
|
_privacySavedValue,
|
||||||
_usernameSavedValue,
|
_usernameSavedValue,
|
||||||
error),
|
error),
|
||||||
Ui::LayerOption::KeepOther);
|
Ui::LayerOption::KeepOther);
|
||||||
|
@ -800,6 +799,20 @@ void Controller::fillLinkedChatButton() {
|
||||||
_linkedChatUpdates.fire_copy(*_linkedChatSavedValue);
|
_linkedChatUpdates.fire_copy(*_linkedChatSavedValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Controller::fillInviteLinkButton() {
|
||||||
|
Expects(_controls.buttonsLayout != nullptr);
|
||||||
|
|
||||||
|
const auto buttonCallback = [=] {
|
||||||
|
Ui::show(Box<EditPeerTypeBox>(_peer), Ui::LayerOption::KeepOther);
|
||||||
|
};
|
||||||
|
|
||||||
|
AddButtonWithText(
|
||||||
|
_controls.buttonsLayout,
|
||||||
|
tr::lng_profile_invite_link_section(),
|
||||||
|
rpl::single(QString()), //Empty text.
|
||||||
|
buttonCallback);
|
||||||
|
}
|
||||||
|
|
||||||
void Controller::fillSignaturesButton() {
|
void Controller::fillSignaturesButton() {
|
||||||
Expects(_controls.buttonsLayout != nullptr);
|
Expects(_controls.buttonsLayout != nullptr);
|
||||||
|
|
||||||
|
@ -880,13 +893,6 @@ void Controller::fillManageSection() {
|
||||||
? channel->canEditUsername()
|
? channel->canEditUsername()
|
||||||
: chat->canEditUsername();
|
: chat->canEditUsername();
|
||||||
}();
|
}();
|
||||||
const auto canEditInviteLink = [&] {
|
|
||||||
return isChannel
|
|
||||||
? (channel->amCreator()
|
|
||||||
|| (channel->adminRights() & ChatAdminRight::f_invite_users))
|
|
||||||
: (chat->amCreator()
|
|
||||||
|| (chat->adminRights() & ChatAdminRight::f_invite_users));
|
|
||||||
}();
|
|
||||||
const auto canEditSignatures = [&] {
|
const auto canEditSignatures = [&] {
|
||||||
return isChannel
|
return isChannel
|
||||||
? (channel->canEditSignatures() && !channel->isMegagroup())
|
? (channel->canEditSignatures() && !channel->isMegagroup())
|
||||||
|
@ -953,6 +959,8 @@ void Controller::fillManageSection() {
|
||||||
|
|
||||||
if (canEditUsername) {
|
if (canEditUsername) {
|
||||||
fillPrivacyTypeButton();
|
fillPrivacyTypeButton();
|
||||||
|
} else if (canEditInviteLinks) {
|
||||||
|
fillInviteLinkButton();
|
||||||
}
|
}
|
||||||
if (canViewOrEditLinkedChat) {
|
if (canViewOrEditLinkedChat) {
|
||||||
fillLinkedChatButton();
|
fillLinkedChatButton();
|
||||||
|
@ -965,7 +973,7 @@ void Controller::fillManageSection() {
|
||||||
}
|
}
|
||||||
if (canEditPreHistoryHidden
|
if (canEditPreHistoryHidden
|
||||||
|| canEditSignatures
|
|| canEditSignatures
|
||||||
|| canEditInviteLink
|
|| canEditInviteLinks
|
||||||
|| canViewOrEditLinkedChat
|
|| canViewOrEditLinkedChat
|
||||||
|| canEditUsername) {
|
|| canEditUsername) {
|
||||||
AddSkip(
|
AddSkip(
|
||||||
|
|
|
@ -64,7 +64,7 @@ public:
|
||||||
not_null<Ui::VerticalLayout*> container,
|
not_null<Ui::VerticalLayout*> container,
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
bool useLocationPhrases,
|
bool useLocationPhrases,
|
||||||
Privacy privacySavedValue,
|
std::optional<Privacy> privacySavedValue,
|
||||||
std::optional<QString> usernameSavedValue);
|
std::optional<QString> usernameSavedValue);
|
||||||
|
|
||||||
void createContent();
|
void createContent();
|
||||||
|
@ -72,7 +72,9 @@ public:
|
||||||
void setFocusUsername();
|
void setFocusUsername();
|
||||||
|
|
||||||
rpl::producer<QString> getTitle() {
|
rpl::producer<QString> getTitle() {
|
||||||
return _isGroup
|
return !_privacySavedValue
|
||||||
|
? tr::lng_create_invite_link_title()
|
||||||
|
: _isGroup
|
||||||
? tr::lng_manage_peer_group_type()
|
? tr::lng_manage_peer_group_type()
|
||||||
: tr::lng_manage_peer_channel_type();
|
: tr::lng_manage_peer_channel_type();
|
||||||
}
|
}
|
||||||
|
@ -120,7 +122,7 @@ private:
|
||||||
|
|
||||||
void fillPrivaciesButtons(
|
void fillPrivaciesButtons(
|
||||||
not_null<Ui::VerticalLayout*> parent,
|
not_null<Ui::VerticalLayout*> parent,
|
||||||
Privacy savedValue);
|
std::optional<Privacy> savedValue);
|
||||||
void addRoundButton(
|
void addRoundButton(
|
||||||
not_null<Ui::VerticalLayout*> container,
|
not_null<Ui::VerticalLayout*> container,
|
||||||
Privacy value,
|
Privacy value,
|
||||||
|
@ -132,7 +134,7 @@ private:
|
||||||
|
|
||||||
not_null<PeerData*> _peer;
|
not_null<PeerData*> _peer;
|
||||||
MTP::Sender _api;
|
MTP::Sender _api;
|
||||||
Privacy _privacySavedValue = Privacy();
|
std::optional<Privacy> _privacySavedValue;
|
||||||
std::optional<QString> _usernameSavedValue;
|
std::optional<QString> _usernameSavedValue;
|
||||||
|
|
||||||
bool _useLocationPhrases = false;
|
bool _useLocationPhrases = false;
|
||||||
|
@ -153,7 +155,7 @@ Controller::Controller(
|
||||||
not_null<Ui::VerticalLayout*> container,
|
not_null<Ui::VerticalLayout*> container,
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
bool useLocationPhrases,
|
bool useLocationPhrases,
|
||||||
Privacy privacySavedValue,
|
std::optional<Privacy> privacySavedValue,
|
||||||
std::optional<QString> usernameSavedValue)
|
std::optional<QString> usernameSavedValue)
|
||||||
: _peer(peer)
|
: _peer(peer)
|
||||||
, _api(&_peer->session().mtp())
|
, _api(&_peer->session().mtp())
|
||||||
|
@ -172,10 +174,14 @@ void Controller::createContent() {
|
||||||
|
|
||||||
fillPrivaciesButtons(_wrap, _privacySavedValue);
|
fillPrivaciesButtons(_wrap, _privacySavedValue);
|
||||||
// Skip.
|
// Skip.
|
||||||
|
if (_privacySavedValue) {
|
||||||
_wrap->add(object_ptr<Ui::BoxContentDivider>(_wrap));
|
_wrap->add(object_ptr<Ui::BoxContentDivider>(_wrap));
|
||||||
|
}
|
||||||
//
|
//
|
||||||
_wrap->add(createInviteLinkBlock());
|
_wrap->add(createInviteLinkBlock());
|
||||||
|
if (_privacySavedValue) {
|
||||||
_wrap->add(createUsernameEdit());
|
_wrap->add(createUsernameEdit());
|
||||||
|
}
|
||||||
|
|
||||||
//using namespace Settings; // #TODO links
|
//using namespace Settings; // #TODO links
|
||||||
//AddSkip(_wrap.get());
|
//AddSkip(_wrap.get());
|
||||||
|
@ -192,15 +198,20 @@ void Controller::createContent() {
|
||||||
//AddSkip(_wrap.get());
|
//AddSkip(_wrap.get());
|
||||||
//AddDividerText(_wrap.get(), tr::lng_group_invite_manage_about());
|
//AddDividerText(_wrap.get(), tr::lng_group_invite_manage_about());
|
||||||
|
|
||||||
|
if (_controls.privacy) {
|
||||||
if (_controls.privacy->value() == Privacy::NoUsername) {
|
if (_controls.privacy->value() == Privacy::NoUsername) {
|
||||||
checkUsernameAvailability();
|
checkUsernameAvailability();
|
||||||
}
|
}
|
||||||
|
const auto forShowing = _privacySavedValue.value_or(Privacy::NoUsername);
|
||||||
_controls.inviteLinkWrap->toggle(
|
_controls.inviteLinkWrap->toggle(
|
||||||
(_privacySavedValue != Privacy::HasUsername),
|
(forShowing != Privacy::HasUsername),
|
||||||
anim::type::instant);
|
anim::type::instant);
|
||||||
_controls.usernameWrap->toggle(
|
_controls.usernameWrap->toggle(
|
||||||
(_privacySavedValue == Privacy::HasUsername),
|
(forShowing == Privacy::HasUsername),
|
||||||
anim::type::instant);
|
anim::type::instant);
|
||||||
|
} else {
|
||||||
|
_controls.inviteLinkWrap->show(anim::type::instant);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::addRoundButton(
|
void Controller::addRoundButton(
|
||||||
|
@ -228,7 +239,7 @@ void Controller::addRoundButton(
|
||||||
|
|
||||||
void Controller::fillPrivaciesButtons(
|
void Controller::fillPrivaciesButtons(
|
||||||
not_null<Ui::VerticalLayout*> parent,
|
not_null<Ui::VerticalLayout*> parent,
|
||||||
Privacy savedValue) {
|
std::optional<Privacy> savedValue) {
|
||||||
const auto canEditUsername = [&] {
|
const auto canEditUsername = [&] {
|
||||||
if (const auto chat = _peer->asChat()) {
|
if (const auto chat = _peer->asChat()) {
|
||||||
return chat->canEditUsername();
|
return chat->canEditUsername();
|
||||||
|
@ -251,7 +262,8 @@ void Controller::fillPrivaciesButtons(
|
||||||
const auto isPublic = _peer->isChannel()
|
const auto isPublic = _peer->isChannel()
|
||||||
&& _peer->asChannel()->hasUsername();
|
&& _peer->asChannel()->hasUsername();
|
||||||
_controls.privacy = std::make_shared<Ui::RadioenumGroup<Privacy>>(
|
_controls.privacy = std::make_shared<Ui::RadioenumGroup<Privacy>>(
|
||||||
savedValue);
|
savedValue.value_or(
|
||||||
|
isPublic ? Privacy::HasUsername : Privacy::NoUsername));
|
||||||
|
|
||||||
addRoundButton(
|
addRoundButton(
|
||||||
container,
|
container,
|
||||||
|
@ -546,9 +558,11 @@ object_ptr<Ui::RpWidget> Controller::createInviteLinkBlock() {
|
||||||
const auto container = result->entity();
|
const auto container = result->entity();
|
||||||
|
|
||||||
using namespace Settings;
|
using namespace Settings;
|
||||||
|
if (_privacySavedValue) {
|
||||||
AddSkip(container);
|
AddSkip(container);
|
||||||
|
|
||||||
AddSubsectionTitle(container, tr::lng_create_invite_link_title());
|
AddSubsectionTitle(container, tr::lng_create_invite_link_title());
|
||||||
|
}
|
||||||
// tr::lng_create_permanent_link_title()); // #TODO links
|
// tr::lng_create_permanent_link_title()); // #TODO links
|
||||||
AddPermanentLinkBlock(container, _peer);
|
AddPermanentLinkBlock(container, _peer);
|
||||||
|
|
||||||
|
@ -585,7 +599,7 @@ EditPeerTypeBox::EditPeerTypeBox(
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
bool useLocationPhrases,
|
bool useLocationPhrases,
|
||||||
std::optional<FnMut<void(Privacy, QString)>> savedCallback,
|
std::optional<FnMut<void(Privacy, QString)>> savedCallback,
|
||||||
Privacy privacySaved,
|
std::optional<Privacy> privacySaved,
|
||||||
std::optional<QString> usernameSaved,
|
std::optional<QString> usernameSaved,
|
||||||
std::optional<rpl::producer<QString>> usernameError)
|
std::optional<rpl::producer<QString>> usernameError)
|
||||||
: _peer(peer)
|
: _peer(peer)
|
||||||
|
@ -596,6 +610,12 @@ EditPeerTypeBox::EditPeerTypeBox(
|
||||||
, _usernameError(usernameError) {
|
, _usernameError(usernameError) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EditPeerTypeBox::EditPeerTypeBox(
|
||||||
|
QWidget*,
|
||||||
|
not_null<PeerData*> peer)
|
||||||
|
: EditPeerTypeBox(nullptr, peer, {}, {}, {}, {}, {}) {
|
||||||
|
}
|
||||||
|
|
||||||
void EditPeerTypeBox::setInnerFocus() {
|
void EditPeerTypeBox::setInnerFocus() {
|
||||||
_focusRequests.fire({});
|
_focusRequests.fire({});
|
||||||
}
|
}
|
||||||
|
@ -641,8 +661,10 @@ void EditPeerTypeBox::prepare() {
|
||||||
: QString()); // We don't need username with private type.
|
: QString()); // We don't need username with private type.
|
||||||
closeBox();
|
closeBox();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
||||||
|
} else {
|
||||||
|
addButton(tr::lng_close(), [=] { closeBox(); });
|
||||||
|
}
|
||||||
|
|
||||||
setDimensionsToContent(st::boxWideWidth, content.data());
|
setDimensionsToContent(st::boxWideWidth, content.data());
|
||||||
setInnerWidget(std::move(content));
|
setInnerWidget(std::move(content));
|
||||||
|
|
|
@ -37,10 +37,15 @@ public:
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
bool useLocationPhrases,
|
bool useLocationPhrases,
|
||||||
std::optional<FnMut<void(Privacy, QString)>> savedCallback,
|
std::optional<FnMut<void(Privacy, QString)>> savedCallback,
|
||||||
Privacy privacySaved,
|
std::optional<Privacy> privacySaved,
|
||||||
std::optional<QString> usernameSaved,
|
std::optional<QString> usernameSaved,
|
||||||
std::optional<rpl::producer<QString>> usernameError = {});
|
std::optional<rpl::producer<QString>> usernameError = {});
|
||||||
|
|
||||||
|
// For invite link only.
|
||||||
|
EditPeerTypeBox(
|
||||||
|
QWidget*,
|
||||||
|
not_null<PeerData*> peer);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void prepare() override;
|
void prepare() override;
|
||||||
void setInnerFocus() override;
|
void setInnerFocus() override;
|
||||||
|
@ -50,7 +55,7 @@ private:
|
||||||
bool _useLocationPhrases = false;
|
bool _useLocationPhrases = false;
|
||||||
std::optional<FnMut<void(Privacy, QString)>> _savedCallback;
|
std::optional<FnMut<void(Privacy, QString)>> _savedCallback;
|
||||||
|
|
||||||
Privacy _privacySavedValue = Privacy();
|
std::optional<Privacy> _privacySavedValue;
|
||||||
std::optional<QString> _usernameSavedValue;
|
std::optional<QString> _usernameSavedValue;
|
||||||
std::optional<rpl::producer<QString>> _usernameError;
|
std::optional<rpl::producer<QString>> _usernameError;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue