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