mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added ability to edit invite links with subscription.
This commit is contained in:
parent
8158c52e82
commit
7ed715b01c
4 changed files with 59 additions and 32 deletions
|
@ -225,6 +225,15 @@ void InviteLinks::edit(
|
||||||
requestApproval);
|
requestApproval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InviteLinks::editTitle(
|
||||||
|
not_null<PeerData*> peer,
|
||||||
|
not_null<UserData*> admin,
|
||||||
|
const QString &link,
|
||||||
|
const QString &label,
|
||||||
|
Fn<void(Link)> done) {
|
||||||
|
performEdit(peer, admin, link, done, false, label, 0, 0, false, true);
|
||||||
|
}
|
||||||
|
|
||||||
void InviteLinks::performEdit(
|
void InviteLinks::performEdit(
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
not_null<UserData*> admin,
|
not_null<UserData*> admin,
|
||||||
|
@ -234,7 +243,8 @@ void InviteLinks::performEdit(
|
||||||
const QString &label,
|
const QString &label,
|
||||||
TimeId expireDate,
|
TimeId expireDate,
|
||||||
int usageLimit,
|
int usageLimit,
|
||||||
bool requestApproval) {
|
bool requestApproval,
|
||||||
|
bool editOnlyTitle) {
|
||||||
const auto key = LinkKey{ peer, link };
|
const auto key = LinkKey{ peer, link };
|
||||||
if (_deleteCallbacks.contains(key)) {
|
if (_deleteCallbacks.contains(key)) {
|
||||||
return;
|
return;
|
||||||
|
@ -259,7 +269,7 @@ void InviteLinks::performEdit(
|
||||||
? Flag::f_request_needed
|
? Flag::f_request_needed
|
||||||
: Flag(0));
|
: Flag(0));
|
||||||
_api->request(MTPmessages_EditExportedChatInvite(
|
_api->request(MTPmessages_EditExportedChatInvite(
|
||||||
MTP_flags(flags),
|
MTP_flags(editOnlyTitle ? Flag::f_title : flags),
|
||||||
peer->input,
|
peer->input,
|
||||||
MTP_string(link),
|
MTP_string(link),
|
||||||
MTP_int(expireDate),
|
MTP_int(expireDate),
|
||||||
|
|
|
@ -84,6 +84,12 @@ public:
|
||||||
int usageLimit,
|
int usageLimit,
|
||||||
bool requestApproval,
|
bool requestApproval,
|
||||||
Fn<void(Link)> done = nullptr);
|
Fn<void(Link)> done = nullptr);
|
||||||
|
void editTitle(
|
||||||
|
not_null<PeerData*> peer,
|
||||||
|
not_null<UserData*> admin,
|
||||||
|
const QString &link,
|
||||||
|
const QString &label,
|
||||||
|
Fn<void(Link)> done = nullptr);
|
||||||
void revoke(
|
void revoke(
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
not_null<UserData*> admin,
|
not_null<UserData*> admin,
|
||||||
|
@ -194,7 +200,8 @@ private:
|
||||||
const QString &label = QString(),
|
const QString &label = QString(),
|
||||||
TimeId expireDate = 0,
|
TimeId expireDate = 0,
|
||||||
int usageLimit = 0,
|
int usageLimit = 0,
|
||||||
bool requestApproval = false);
|
bool requestApproval = false,
|
||||||
|
bool editOnlyTitle = false);
|
||||||
void performCreate(
|
void performCreate(
|
||||||
const CreateInviteLinkArgs &args,
|
const CreateInviteLinkArgs &args,
|
||||||
bool revokeLegacyPermanent);
|
bool revokeLegacyPermanent);
|
||||||
|
|
|
@ -1281,6 +1281,13 @@ object_ptr<Ui::BoxContent> EditLinkBox(
|
||||||
result.requestApproval,
|
result.requestApproval,
|
||||||
{ uint64(result.subscriptionCredits), period },
|
{ uint64(result.subscriptionCredits), period },
|
||||||
});
|
});
|
||||||
|
} else if (result.subscriptionCredits) {
|
||||||
|
peer->session().api().inviteLinks().editTitle(
|
||||||
|
peer,
|
||||||
|
data.admin,
|
||||||
|
result.link,
|
||||||
|
result.label,
|
||||||
|
finish);
|
||||||
} else {
|
} else {
|
||||||
peer->session().api().inviteLinks().edit(
|
peer->session().api().inviteLinks().edit(
|
||||||
peer,
|
peer,
|
||||||
|
|
|
@ -55,6 +55,7 @@ void EditInviteLinkBox(
|
||||||
const auto link = data.link;
|
const auto link = data.link;
|
||||||
const auto isGroup = data.isGroup;
|
const auto isGroup = data.isGroup;
|
||||||
const auto isPublic = data.isPublic;
|
const auto isPublic = data.isPublic;
|
||||||
|
const auto subscriptionLocked = data.subscriptionCredits > 0;
|
||||||
box->setTitle(link.isEmpty()
|
box->setTitle(link.isEmpty()
|
||||||
? tr::lng_group_invite_new_title()
|
? tr::lng_group_invite_new_title()
|
||||||
: tr::lng_group_invite_edit_title());
|
: tr::lng_group_invite_edit_title());
|
||||||
|
@ -108,7 +109,6 @@ void EditInviteLinkBox(
|
||||||
.subscription = false,
|
.subscription = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto subscriptionLocked = data.subscriptionCredits > 0;
|
|
||||||
const auto requestApproval = (isPublic || subscriptionLocked)
|
const auto requestApproval = (isPublic || subscriptionLocked)
|
||||||
? nullptr
|
? nullptr
|
||||||
: container->add(
|
: container->add(
|
||||||
|
@ -171,6 +171,37 @@ void EditInviteLinkBox(
|
||||||
labelField->setMaxLength(kMaxLabelLength);
|
labelField->setMaxLength(kMaxLabelLength);
|
||||||
addDivider(container, tr::lng_group_invite_label_about());
|
addDivider(container, tr::lng_group_invite_label_about());
|
||||||
|
|
||||||
|
const auto &saveLabel = link.isEmpty()
|
||||||
|
? tr::lng_formatting_link_create
|
||||||
|
: tr::lng_settings_save;
|
||||||
|
box->addButton(saveLabel(), [=] {
|
||||||
|
const auto label = labelField->getLastText();
|
||||||
|
const auto expireDate = (state->expireValue == kMaxLimit)
|
||||||
|
? 0
|
||||||
|
: (state->expireValue < 0)
|
||||||
|
? (base::unixtime::now() - state->expireValue)
|
||||||
|
: state->expireValue;
|
||||||
|
const auto usageLimit = (state->usageValue == kMaxLimit)
|
||||||
|
? 0
|
||||||
|
: state->usageValue;
|
||||||
|
done(InviteLinkFields{
|
||||||
|
.link = link,
|
||||||
|
.label = label,
|
||||||
|
.expireDate = expireDate,
|
||||||
|
.usageLimit = usageLimit,
|
||||||
|
.subscriptionCredits = credits
|
||||||
|
? credits->getLastText().toInt()
|
||||||
|
: 0,
|
||||||
|
.requestApproval = state->requestApproval.current(),
|
||||||
|
.isGroup = isGroup,
|
||||||
|
.isPublic = isPublic,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
||||||
|
|
||||||
|
if (subscriptionLocked) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
addTitle(container, tr::lng_group_invite_expire_title());
|
addTitle(container, tr::lng_group_invite_expire_title());
|
||||||
const auto expiresWrap = container->add(
|
const auto expiresWrap = container->add(
|
||||||
object_ptr<VerticalLayout>(container),
|
object_ptr<VerticalLayout>(container),
|
||||||
|
@ -342,34 +373,6 @@ void EditInviteLinkBox(
|
||||||
|
|
||||||
usagesSlide->toggleOn(state->requestApproval.value() | rpl::map(!_1));
|
usagesSlide->toggleOn(state->requestApproval.value() | rpl::map(!_1));
|
||||||
usagesSlide->finishAnimating();
|
usagesSlide->finishAnimating();
|
||||||
|
|
||||||
const auto &saveLabel = link.isEmpty()
|
|
||||||
? tr::lng_formatting_link_create
|
|
||||||
: tr::lng_settings_save;
|
|
||||||
box->addButton(saveLabel(), [=] {
|
|
||||||
const auto label = labelField->getLastText();
|
|
||||||
const auto expireDate = (state->expireValue == kMaxLimit)
|
|
||||||
? 0
|
|
||||||
: (state->expireValue < 0)
|
|
||||||
? (base::unixtime::now() - state->expireValue)
|
|
||||||
: state->expireValue;
|
|
||||||
const auto usageLimit = (state->usageValue == kMaxLimit)
|
|
||||||
? 0
|
|
||||||
: state->usageValue;
|
|
||||||
done(InviteLinkFields{
|
|
||||||
.link = link,
|
|
||||||
.label = label,
|
|
||||||
.expireDate = expireDate,
|
|
||||||
.usageLimit = usageLimit,
|
|
||||||
.subscriptionCredits = credits
|
|
||||||
? credits->getLastText().toInt()
|
|
||||||
: 0,
|
|
||||||
.requestApproval = state->requestApproval.current(),
|
|
||||||
.isGroup = isGroup,
|
|
||||||
.isPublic = isPublic,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateInviteLinkBox(
|
void CreateInviteLinkBox(
|
||||||
|
|
Loading…
Add table
Reference in a new issue