mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 05:07:10 +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);
|
||||
}
|
||||
|
||||
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(
|
||||
not_null<PeerData*> peer,
|
||||
not_null<UserData*> admin,
|
||||
|
@ -234,7 +243,8 @@ void InviteLinks::performEdit(
|
|||
const QString &label,
|
||||
TimeId expireDate,
|
||||
int usageLimit,
|
||||
bool requestApproval) {
|
||||
bool requestApproval,
|
||||
bool editOnlyTitle) {
|
||||
const auto key = LinkKey{ peer, link };
|
||||
if (_deleteCallbacks.contains(key)) {
|
||||
return;
|
||||
|
@ -259,7 +269,7 @@ void InviteLinks::performEdit(
|
|||
? Flag::f_request_needed
|
||||
: Flag(0));
|
||||
_api->request(MTPmessages_EditExportedChatInvite(
|
||||
MTP_flags(flags),
|
||||
MTP_flags(editOnlyTitle ? Flag::f_title : flags),
|
||||
peer->input,
|
||||
MTP_string(link),
|
||||
MTP_int(expireDate),
|
||||
|
|
|
@ -84,6 +84,12 @@ public:
|
|||
int usageLimit,
|
||||
bool requestApproval,
|
||||
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(
|
||||
not_null<PeerData*> peer,
|
||||
not_null<UserData*> admin,
|
||||
|
@ -194,7 +200,8 @@ private:
|
|||
const QString &label = QString(),
|
||||
TimeId expireDate = 0,
|
||||
int usageLimit = 0,
|
||||
bool requestApproval = false);
|
||||
bool requestApproval = false,
|
||||
bool editOnlyTitle = false);
|
||||
void performCreate(
|
||||
const CreateInviteLinkArgs &args,
|
||||
bool revokeLegacyPermanent);
|
||||
|
|
|
@ -1281,6 +1281,13 @@ object_ptr<Ui::BoxContent> EditLinkBox(
|
|||
result.requestApproval,
|
||||
{ uint64(result.subscriptionCredits), period },
|
||||
});
|
||||
} else if (result.subscriptionCredits) {
|
||||
peer->session().api().inviteLinks().editTitle(
|
||||
peer,
|
||||
data.admin,
|
||||
result.link,
|
||||
result.label,
|
||||
finish);
|
||||
} else {
|
||||
peer->session().api().inviteLinks().edit(
|
||||
peer,
|
||||
|
|
|
@ -55,6 +55,7 @@ void EditInviteLinkBox(
|
|||
const auto link = data.link;
|
||||
const auto isGroup = data.isGroup;
|
||||
const auto isPublic = data.isPublic;
|
||||
const auto subscriptionLocked = data.subscriptionCredits > 0;
|
||||
box->setTitle(link.isEmpty()
|
||||
? tr::lng_group_invite_new_title()
|
||||
: tr::lng_group_invite_edit_title());
|
||||
|
@ -108,7 +109,6 @@ void EditInviteLinkBox(
|
|||
.subscription = false,
|
||||
});
|
||||
|
||||
const auto subscriptionLocked = data.subscriptionCredits > 0;
|
||||
const auto requestApproval = (isPublic || subscriptionLocked)
|
||||
? nullptr
|
||||
: container->add(
|
||||
|
@ -171,6 +171,37 @@ void EditInviteLinkBox(
|
|||
labelField->setMaxLength(kMaxLabelLength);
|
||||
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());
|
||||
const auto expiresWrap = container->add(
|
||||
object_ptr<VerticalLayout>(container),
|
||||
|
@ -342,34 +373,6 @@ void EditInviteLinkBox(
|
|||
|
||||
usagesSlide->toggleOn(state->requestApproval.value() | rpl::map(!_1));
|
||||
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(
|
||||
|
|
Loading…
Add table
Reference in a new issue