mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-14 05:07:10 +02:00
Moved bunch of arguments for creation of invite links to structure.
This commit is contained in:
parent
c8a3b0ab80
commit
75b26b1a85
7 changed files with 51 additions and 65 deletions
|
@ -69,41 +69,23 @@ JoinedByLinkSlice ParseJoinedByLinkSlice(
|
|||
InviteLinks::InviteLinks(not_null<ApiWrap*> api) : _api(api) {
|
||||
}
|
||||
|
||||
void InviteLinks::create(
|
||||
not_null<PeerData*> peer,
|
||||
Fn<void(Link)> done,
|
||||
const QString &label,
|
||||
TimeId expireDate,
|
||||
int usageLimit,
|
||||
bool requestApproval) {
|
||||
performCreate(
|
||||
peer,
|
||||
std::move(done),
|
||||
false,
|
||||
label,
|
||||
expireDate,
|
||||
usageLimit,
|
||||
requestApproval);
|
||||
void InviteLinks::create(const CreateInviteLinkArgs &args) {
|
||||
performCreate(args, false);
|
||||
}
|
||||
|
||||
void InviteLinks::performCreate(
|
||||
not_null<PeerData*> peer,
|
||||
Fn<void(Link)> done,
|
||||
bool revokeLegacyPermanent,
|
||||
const QString &label,
|
||||
TimeId expireDate,
|
||||
int usageLimit,
|
||||
bool requestApproval) {
|
||||
if (const auto i = _createCallbacks.find(peer)
|
||||
const CreateInviteLinkArgs &args,
|
||||
bool revokeLegacyPermanent) {
|
||||
if (const auto i = _createCallbacks.find(args.peer)
|
||||
; i != end(_createCallbacks)) {
|
||||
if (done) {
|
||||
i->second.push_back(std::move(done));
|
||||
if (args.done) {
|
||||
i->second.push_back(std::move(args.done));
|
||||
}
|
||||
return;
|
||||
}
|
||||
auto &callbacks = _createCallbacks[peer];
|
||||
if (done) {
|
||||
callbacks.push_back(std::move(done));
|
||||
auto &callbacks = _createCallbacks[args.peer];
|
||||
if (args.done) {
|
||||
callbacks.push_back(std::move(args.done));
|
||||
}
|
||||
|
||||
using Flag = MTPmessages_ExportChatInvite::Flag;
|
||||
|
@ -111,18 +93,18 @@ void InviteLinks::performCreate(
|
|||
MTP_flags((revokeLegacyPermanent
|
||||
? Flag::f_legacy_revoke_permanent
|
||||
: Flag(0))
|
||||
| (!label.isEmpty() ? Flag::f_title : Flag(0))
|
||||
| (expireDate ? Flag::f_expire_date : Flag(0))
|
||||
| ((!requestApproval && usageLimit)
|
||||
| (!args.label.isEmpty() ? Flag::f_title : Flag(0))
|
||||
| (args.expireDate ? Flag::f_expire_date : Flag(0))
|
||||
| ((!args.requestApproval && args.usageLimit)
|
||||
? Flag::f_usage_limit
|
||||
: Flag(0))
|
||||
| (requestApproval ? Flag::f_request_needed : Flag(0))),
|
||||
peer->input,
|
||||
MTP_int(expireDate),
|
||||
MTP_int(usageLimit),
|
||||
MTP_string(label),
|
||||
| (args.requestApproval ? Flag::f_request_needed : Flag(0))),
|
||||
args.peer->input,
|
||||
MTP_int(args.expireDate),
|
||||
MTP_int(args.usageLimit),
|
||||
MTP_string(args.label),
|
||||
MTPStarsSubscriptionPricing()
|
||||
)).done([=](const MTPExportedChatInvite &result) {
|
||||
)).done([=, peer = args.peer](const MTPExportedChatInvite &result) {
|
||||
const auto callbacks = _createCallbacks.take(peer);
|
||||
const auto link = prepend(peer, peer->session().user(), result);
|
||||
if (link && callbacks) {
|
||||
|
@ -130,7 +112,7 @@ void InviteLinks::performCreate(
|
|||
callback(*link);
|
||||
}
|
||||
}
|
||||
}).fail([=] {
|
||||
}).fail([=, peer = args.peer] {
|
||||
_createCallbacks.erase(peer);
|
||||
}).send();
|
||||
}
|
||||
|
@ -345,7 +327,7 @@ void InviteLinks::revokePermanent(
|
|||
} else if (!admin->isSelf()) {
|
||||
crl::on_main(&peer->session(), done);
|
||||
} else {
|
||||
performCreate(peer, callback, true);
|
||||
performCreate({ peer, callback }, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,15 @@ struct InviteLinkUpdate {
|
|||
not_null<PeerData*> peer,
|
||||
const MTPmessages_ChatInviteImporters &slice);
|
||||
|
||||
struct CreateInviteLinkArgs {
|
||||
not_null<PeerData*> peer;
|
||||
Fn<void(InviteLink)> done = nullptr;
|
||||
QString label;
|
||||
TimeId expireDate = 0;
|
||||
int usageLimit = 0;
|
||||
bool requestApproval = false;
|
||||
};
|
||||
|
||||
class InviteLinks final {
|
||||
public:
|
||||
explicit InviteLinks(not_null<ApiWrap*> api);
|
||||
|
@ -61,13 +70,7 @@ public:
|
|||
using Links = PeerInviteLinks;
|
||||
using Update = InviteLinkUpdate;
|
||||
|
||||
void create(
|
||||
not_null<PeerData*> peer,
|
||||
Fn<void(Link)> done = nullptr,
|
||||
const QString &label = QString(),
|
||||
TimeId expireDate = 0,
|
||||
int usageLimit = 0,
|
||||
bool requestApproval = false);
|
||||
void create(const CreateInviteLinkArgs &args);
|
||||
void edit(
|
||||
not_null<PeerData*> peer,
|
||||
not_null<UserData*> admin,
|
||||
|
@ -189,13 +192,8 @@ private:
|
|||
int usageLimit = 0,
|
||||
bool requestApproval = false);
|
||||
void performCreate(
|
||||
not_null<PeerData*> peer,
|
||||
Fn<void(Link)> done,
|
||||
bool revokeLegacyPermanent,
|
||||
const QString &label = QString(),
|
||||
TimeId expireDate = 0,
|
||||
int usageLimit = 0,
|
||||
bool requestApproval = false);
|
||||
const CreateInviteLinkArgs &args,
|
||||
bool revokeLegacyPermanent);
|
||||
|
||||
void requestJoinedFirstSlice(LinkKey key);
|
||||
[[nodiscard]] std::optional<JoinedByLinkSlice> lookupJoinedFirstSlice(
|
||||
|
|
|
@ -898,9 +898,10 @@ void GroupInfoBox::checkInviteLink() {
|
|||
channelReady();
|
||||
} else if (_createdChannel->isFullLoaded() && !_creatingInviteLink) {
|
||||
_creatingInviteLink = true;
|
||||
_createdChannel->session().api().inviteLinks().create(
|
||||
_createdChannel->session().api().inviteLinks().create({
|
||||
_createdChannel,
|
||||
crl::guard(this, [=](auto&&) { channelReady(); }));
|
||||
crl::guard(this, [=](auto&&) { channelReady(); }),
|
||||
});
|
||||
} else {
|
||||
_createdChannel->session().changes().peerUpdates(
|
||||
_createdChannel,
|
||||
|
@ -1243,7 +1244,7 @@ void SetupChannelBox::mousePressEvent(QMouseEvent *e) {
|
|||
showToast(tr::lng_create_channel_link_copied(tr::now));
|
||||
} else if (_channel->isFullLoaded() && !_creatingInviteLink) {
|
||||
_creatingInviteLink = true;
|
||||
_channel->session().api().inviteLinks().create(_channel);
|
||||
_channel->session().api().inviteLinks().create({ _channel });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ void MaxInviteBox::mousePressEvent(QMouseEvent *e) {
|
|||
showToast(tr::lng_create_channel_link_copied(tr::now));
|
||||
} else if (_channel->isFullLoaded() && !_creatingInviteLink) {
|
||||
_creatingInviteLink = true;
|
||||
_channel->session().api().inviteLinks().create(_channel);
|
||||
_channel->session().api().inviteLinks().create({ _channel });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -517,10 +517,13 @@ void InviteForbiddenController::send(
|
|||
};
|
||||
const auto sendForFull = [=] {
|
||||
if (!sendLink()) {
|
||||
_peer->session().api().inviteLinks().create(_peer, [=](auto) {
|
||||
if (!sendLink()) {
|
||||
close();
|
||||
}
|
||||
_peer->session().api().inviteLinks().create({
|
||||
_peer,
|
||||
[=](auto) {
|
||||
if (!sendLink()) {
|
||||
close();
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1266,13 +1266,14 @@ object_ptr<Ui::BoxContent> EditLinkBox(
|
|||
};
|
||||
if (creating) {
|
||||
Assert(data.admin->isSelf());
|
||||
peer->session().api().inviteLinks().create(
|
||||
peer->session().api().inviteLinks().create({
|
||||
peer,
|
||||
finish,
|
||||
result.label,
|
||||
result.expireDate,
|
||||
result.usageLimit,
|
||||
result.requestApproval);
|
||||
result.requestApproval,
|
||||
});
|
||||
} else {
|
||||
peer->session().api().inviteLinks().edit(
|
||||
peer,
|
||||
|
|
|
@ -645,9 +645,10 @@ void SettingsBox(
|
|||
shareLink = [=] {
|
||||
if (!copyLink() && !state->generatingLink) {
|
||||
state->generatingLink = true;
|
||||
peer->session().api().inviteLinks().create(
|
||||
peer->session().api().inviteLinks().create({
|
||||
peer,
|
||||
crl::guard(layout, [=](auto&&) { copyLink(); }));
|
||||
crl::guard(layout, [=](auto&&) { copyLink(); })
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue