From 75b26b1a8526e8f4625a67c0a9d6f68b7ff53188 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 6 Aug 2024 12:56:45 +0300 Subject: [PATCH] Moved bunch of arguments for creation of invite links to structure. --- Telegram/SourceFiles/api/api_invite_links.cpp | 60 +++++++------------ Telegram/SourceFiles/api/api_invite_links.h | 26 ++++---- .../SourceFiles/boxes/add_contact_box.cpp | 7 ++- Telegram/SourceFiles/boxes/max_invite_box.cpp | 2 +- .../boxes/peers/add_participants_box.cpp | 11 ++-- .../boxes/peers/edit_peer_invite_link.cpp | 5 +- .../calls/group/calls_group_settings.cpp | 5 +- 7 files changed, 51 insertions(+), 65 deletions(-) diff --git a/Telegram/SourceFiles/api/api_invite_links.cpp b/Telegram/SourceFiles/api/api_invite_links.cpp index 79fab14d5..3f9296f52 100644 --- a/Telegram/SourceFiles/api/api_invite_links.cpp +++ b/Telegram/SourceFiles/api/api_invite_links.cpp @@ -69,41 +69,23 @@ JoinedByLinkSlice ParseJoinedByLinkSlice( InviteLinks::InviteLinks(not_null api) : _api(api) { } -void InviteLinks::create( - not_null peer, - Fn 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 peer, - Fn 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); } } diff --git a/Telegram/SourceFiles/api/api_invite_links.h b/Telegram/SourceFiles/api/api_invite_links.h index 09b43c086..a69e229ec 100644 --- a/Telegram/SourceFiles/api/api_invite_links.h +++ b/Telegram/SourceFiles/api/api_invite_links.h @@ -53,6 +53,15 @@ struct InviteLinkUpdate { not_null peer, const MTPmessages_ChatInviteImporters &slice); +struct CreateInviteLinkArgs { + not_null peer; + Fn done = nullptr; + QString label; + TimeId expireDate = 0; + int usageLimit = 0; + bool requestApproval = false; +}; + class InviteLinks final { public: explicit InviteLinks(not_null api); @@ -61,13 +70,7 @@ public: using Links = PeerInviteLinks; using Update = InviteLinkUpdate; - void create( - not_null peer, - Fn done = nullptr, - const QString &label = QString(), - TimeId expireDate = 0, - int usageLimit = 0, - bool requestApproval = false); + void create(const CreateInviteLinkArgs &args); void edit( not_null peer, not_null admin, @@ -189,13 +192,8 @@ private: int usageLimit = 0, bool requestApproval = false); void performCreate( - not_null peer, - Fn 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 lookupJoinedFirstSlice( diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index 6b9a0852c..d8dd581a3 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -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 }); } } diff --git a/Telegram/SourceFiles/boxes/max_invite_box.cpp b/Telegram/SourceFiles/boxes/max_invite_box.cpp index a7c1f8408..3159285f4 100644 --- a/Telegram/SourceFiles/boxes/max_invite_box.cpp +++ b/Telegram/SourceFiles/boxes/max_invite_box.cpp @@ -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 }); } } } diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index 04ef17276..bd66b859e 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -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(); + } + }, }); } }; diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp index 8f67b6ba4..e6173c1d1 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_invite_link.cpp @@ -1266,13 +1266,14 @@ object_ptr 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, diff --git a/Telegram/SourceFiles/calls/group/calls_group_settings.cpp b/Telegram/SourceFiles/calls/group/calls_group_settings.cpp index a34bd5cb3..4c60a3f88 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_settings.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_settings.cpp @@ -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(); }) + }); } }; }