Implement revoke of permanent link.

This commit is contained in:
John Preston 2021-01-15 20:13:45 +04:00
parent be1afb4781
commit c7b1a37722
3 changed files with 42 additions and 18 deletions

View file

@ -72,7 +72,10 @@ void InviteLinks::performCreate(
using Flag = MTPmessages_ExportChatInvite::Flag; using Flag = MTPmessages_ExportChatInvite::Flag;
_api->request(MTPmessages_ExportChatInvite( _api->request(MTPmessages_ExportChatInvite(
MTP_flags((expireDate ? Flag::f_expire_date : Flag(0)) MTP_flags((revokeLegacyPermanent
? Flag::f_legacy_revoke_permanent
: Flag(0))
| (expireDate ? Flag::f_expire_date : Flag(0))
| (usageLimit ? Flag::f_usage_limit : Flag(0))), | (usageLimit ? Flag::f_usage_limit : Flag(0))),
peer->input, peer->input,
MTP_int(expireDate), MTP_int(expireDate),
@ -118,14 +121,19 @@ auto InviteLinks::prepend(
i = _firstSlices.emplace(peer).first; i = _firstSlices.emplace(peer).first;
} }
auto &links = i->second; auto &links = i->second;
const auto permanent = lookupPermanent(links);
if (link.permanent) { if (link.permanent) {
if (const auto permanent = lookupPermanent(links)) { if (permanent) {
permanent->revoked = true; permanent->revoked = true;
} }
editPermanentLink(peer, link.link); editPermanentLink(peer, link.link);
} }
++links.count; ++links.count;
links.links.insert(begin(links.links), link); if (permanent && !link.permanent) {
links.links.insert(begin(links.links) + 1, link);
} else {
links.links.insert(begin(links.links), link);
}
notify(peer); notify(peer);
return link; return link;
} }
@ -153,10 +161,6 @@ void InviteLinks::performEdit(
} }
return; return;
} }
auto &callbacks = _editCallbacks[key];
if (done) {
callbacks.push_back(std::move(done));
}
if (const auto permanent = revoke ? lookupPermanent(peer) : nullptr) { if (const auto permanent = revoke ? lookupPermanent(peer) : nullptr) {
if (permanent->link == link) { if (permanent->link == link) {
@ -167,6 +171,11 @@ void InviteLinks::performEdit(
} }
} }
auto &callbacks = _editCallbacks[key];
if (done) {
callbacks.push_back(std::move(done));
}
using Flag = MTPmessages_EditExportedChatInvite::Flag; using Flag = MTPmessages_EditExportedChatInvite::Flag;
const auto requestId = _api->request(MTPmessages_EditExportedChatInvite( const auto requestId = _api->request(MTPmessages_EditExportedChatInvite(
MTP_flags((revoke ? Flag::f_revoked : Flag(0)) MTP_flags((revoke ? Flag::f_revoked : Flag(0))

View file

@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/toast/toast.h" #include "ui/toast/toast.h"
#include "history/view/history_view_group_call_tracker.h" // GenerateUs... #include "history/view/history_view_group_call_tracker.h" // GenerateUs...
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "boxes/confirm_box.h"
#include "apiwrap.h" #include "apiwrap.h"
#include "styles/style_info.h" #include "styles/style_info.h"
@ -45,24 +46,38 @@ void AddPermanentLinkBlock(
}) | rpl::distinct_until_changed( }) | rpl::distinct_until_changed(
) | rpl::start_spawning(container->lifetime()); ) | rpl::start_spawning(container->lifetime());
const auto copyLink = [=] { const auto weak = Ui::MakeWeak(container);
const auto copyLink = crl::guard(weak, [=] {
if (const auto link = computePermanentLink()) { if (const auto link = computePermanentLink()) {
QGuiApplication::clipboard()->setText(link->link); QGuiApplication::clipboard()->setText(link->link);
Ui::Toast::Show(tr::lng_group_invite_copied(tr::now)); Ui::Toast::Show(tr::lng_group_invite_copied(tr::now));
} }
}; });
const auto shareLink = [=] { const auto shareLink = crl::guard(weak, [=] {
if (const auto link = computePermanentLink()) { if (const auto link = computePermanentLink()) {
QGuiApplication::clipboard()->setText(link->link); QGuiApplication::clipboard()->setText(link->link);
Ui::Toast::Show(tr::lng_group_invite_copied(tr::now)); Ui::Toast::Show(tr::lng_group_invite_copied(tr::now));
} }
}; });
const auto revokeLink = [=] { const auto revokeLink = crl::guard(weak, [=] {
if (const auto link = computePermanentLink()) { const auto box = std::make_shared<QPointer<ConfirmBox>>();
QGuiApplication::clipboard()->setText(link->link); const auto done = crl::guard(weak, [=] {
Ui::Toast::Show(tr::lng_group_invite_copied(tr::now)); if (const auto link = computePermanentLink()) {
} const auto close = [=](auto&&) {
}; if (*box) {
(*box)->closeBox();
}
};
peer->session().api().inviteLinks().revoke(
peer,
link->link,
close);
}
});
*box = Ui::show(
Box<ConfirmBox>(tr::lng_group_invite_about_new(tr::now), done),
Ui::LayerOption::KeepOther);
});
auto link = rpl::duplicate( auto link = rpl::duplicate(
value value

View file

@ -874,4 +874,4 @@ inviteLinkUserpics: GroupCallUserpics {
} }
inviteLinkUserpicsSkip: 8px; inviteLinkUserpicsSkip: 8px;
inviteLinkJoinedFont: font(14px); inviteLinkJoinedFont: font(14px);
inviteLinkJoinedRowPadding: margins(0px, 18px, 0px, 0px); inviteLinkJoinedRowPadding: margins(0px, 18px, 0px, 8px);