mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added ability to instantly delete account in test DC.
This commit is contained in:
parent
2ab725e5e1
commit
1b6a7fafa8
1 changed files with 76 additions and 5 deletions
|
@ -7,20 +7,89 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "boxes/self_destruction_box.h"
|
#include "boxes/self_destruction_box.h"
|
||||||
|
|
||||||
|
#include "api/api_authorizations.h"
|
||||||
|
#include "api/api_cloud_password.h"
|
||||||
|
#include "api/api_self_destruct.h"
|
||||||
|
#include "apiwrap.h"
|
||||||
|
#include "boxes/passcode_box.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
|
#include "main/main_session.h"
|
||||||
#include "ui/widgets/checkbox.h"
|
#include "ui/widgets/checkbox.h"
|
||||||
#include "ui/widgets/labels.h"
|
#include "ui/widgets/labels.h"
|
||||||
#include "apiwrap.h"
|
#include "ui/text/text_utilities.h"
|
||||||
#include "api/api_self_destruct.h"
|
#include "ui/widgets/menu/menu_add_action_callback.h"
|
||||||
#include "api/api_authorizations.h"
|
#include "ui/widgets/menu/menu_add_action_callback_factory.h"
|
||||||
#include "main/main_session.h"
|
#include "ui/widgets/popup_menu.h"
|
||||||
#include "styles/style_layers.h"
|
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
|
#include "styles/style_info.h"
|
||||||
|
#include "styles/style_layers.h"
|
||||||
|
#include "styles/style_menu_icons.h"
|
||||||
|
#include "styles/style_widgets.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using Type = SelfDestructionBox::Type;
|
using Type = SelfDestructionBox::Type;
|
||||||
|
|
||||||
|
void AddDeleteAccount(
|
||||||
|
not_null<Ui::BoxContent*> box,
|
||||||
|
not_null<Main::Session*> session) {
|
||||||
|
if (!session->isTestMode()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto maybeState = session->api().cloudPassword().stateCurrent();
|
||||||
|
if (!maybeState || !maybeState->hasPassword) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto top = box->addTopButton(st::infoTopBarMenu);
|
||||||
|
const auto menu
|
||||||
|
= top->lifetime().make_state<base::unique_qptr<Ui::PopupMenu>>();
|
||||||
|
const auto handler = [=] {
|
||||||
|
session->api().cloudPassword().state(
|
||||||
|
) | rpl::take(
|
||||||
|
1
|
||||||
|
) | rpl::start_with_next([=](const Core::CloudPasswordState &state) {
|
||||||
|
auto fields = PasscodeBox::CloudFields::From(state);
|
||||||
|
fields.customTitle = tr::lng_settings_destroy_title();
|
||||||
|
fields.customDescription = tr::lng_context_mark_read_all_sure_2(
|
||||||
|
tr::now,
|
||||||
|
Ui::Text::RichLangValue).text;
|
||||||
|
fields.customSubmitButton = tr::lng_theme_delete();
|
||||||
|
fields.customCheckCallback = [=](
|
||||||
|
const Core::CloudPasswordResult &result,
|
||||||
|
QPointer<PasscodeBox> box) {
|
||||||
|
session->api().request(MTPaccount_DeleteAccount(
|
||||||
|
MTP_flags(MTPaccount_DeleteAccount::Flag::f_password),
|
||||||
|
MTP_string("Manual"),
|
||||||
|
result.result
|
||||||
|
)).done([=] {
|
||||||
|
if (box) {
|
||||||
|
box->uiShow()->hideLayer();
|
||||||
|
}
|
||||||
|
}).fail([=](const MTP::Error &error) {
|
||||||
|
if (box) {
|
||||||
|
box->handleCustomCheckError(error.type());
|
||||||
|
}
|
||||||
|
}).send();
|
||||||
|
};
|
||||||
|
box->uiShow()->showBox(Box<PasscodeBox>(session, fields));
|
||||||
|
}, top->lifetime());
|
||||||
|
};
|
||||||
|
top->setClickedCallback([=] {
|
||||||
|
*menu = base::make_unique_q<Ui::PopupMenu>(
|
||||||
|
top,
|
||||||
|
st::popupMenuWithIcons);
|
||||||
|
|
||||||
|
const auto addAction = Ui::Menu::CreateAddActionCallback(menu->get());
|
||||||
|
addAction({
|
||||||
|
.text = tr::lng_settings_destroy_title(tr::now),
|
||||||
|
.handler = handler,
|
||||||
|
.icon = &st::menuIconDeleteAttention,
|
||||||
|
.isAttention = true,
|
||||||
|
});
|
||||||
|
(*menu)->popup(QCursor::pos());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] std::vector<int> Values(Type type) {
|
[[nodiscard]] std::vector<int> Values(Type type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Type::Account: return { 30, 90, 180, 365, 548, 720 };
|
case Type::Account: return { 30, 90, 180, 365, 548, 720 };
|
||||||
|
@ -151,4 +220,6 @@ void SelfDestructionBox::prepare() {
|
||||||
} else {
|
} else {
|
||||||
showContent();
|
showContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AddDeleteAccount(this, _session);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue