From 4701c5d6e354d7f82f6ce17139ecf4af3d0cf3ab Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 13 Jun 2021 06:47:56 +0300 Subject: [PATCH] Added ability to archive mask packs. --- Telegram/Resources/langs/lang.strings | 2 + .../SourceFiles/boxes/sticker_set_box.cpp | 81 +++++++++++-------- Telegram/SourceFiles/boxes/sticker_set_box.h | 1 - 3 files changed, 49 insertions(+), 35 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 3a3990e76..944c00b6e 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1419,6 +1419,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_stickers_remove_pack_confirm" = "Remove"; "lng_stickers_archive_pack" = "Archive Stickers"; "lng_stickers_has_been_archived" = "Sticker pack has been archived."; +"lng_masks_archive_pack" = "Archive Masks"; +"lng_masks_has_been_archived" = "Mask pack has been archived."; "lng_masks_installed" = "Mask pack has been installed."; "lng_in_dlg_photo" = "Photo"; diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index 4f805d0e5..814dc2b7f 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -73,6 +73,8 @@ public: [[nodiscard]] rpl::producer errors() const; + void archiveStickers(); + bool isMasksSet() const { return (_setFlags & MTPDstickerSet::Flag::f_masks); } @@ -228,38 +230,6 @@ void StickerSetBox::handleError(Error error) { } } -void StickerSetBox::archiveStickers() { - const auto weak = base::make_weak(_controller.get()); - const auto setId = _set.c_inputStickerSetID().vid().v; - _controller->session().api().request(MTPmessages_InstallStickerSet( - _set, - MTP_boolTrue() - )).done([=](const MTPmessages_StickerSetInstallResult &result) { - const auto controller = weak.get(); - if (!controller) { - return; - } - if (result.type() == mtpc_messages_stickerSetInstallResultSuccess) { - Ui::Toast::Show(tr::lng_stickers_has_been_archived(tr::now)); - - const auto &session = controller->session(); - auto &order = session.data().stickers().setsOrderRef(); - const auto index = order.indexOf(setId); - if (index == -1) { - return; - } - order.removeAt(index); - - session.local().writeInstalledStickers(); - session.local().writeArchivedStickers(); - - session.data().stickers().notifyUpdated(); - } - }).fail([](const MTP::Error &error) { - Ui::Toast::Show(Lang::Hard::ServerError()); - }).send(); -} - void StickerSetBox::updateTitleAndButtons() { setTitle(_inner->title()); updateButtons(); @@ -312,7 +282,7 @@ void StickerSetBox::updateButtons() { if (!_inner->shortName().isEmpty()) { const auto top = addTopButton(st::infoTopBarMenu); const auto archive = [=] { - archiveStickers(); + _inner->archiveStickers(); closeBox(); }; const auto menu = @@ -320,7 +290,9 @@ void StickerSetBox::updateButtons() { top->setClickedCallback([=] { *menu = base::make_unique_q(top); (*menu)->addAction( - tr::lng_stickers_archive_pack(tr::now), + isMasks + ? tr::lng_masks_archive_pack(tr::now) + : tr::lng_stickers_archive_pack(tr::now), archive); (*menu)->popup(QCursor::pos()); return true; @@ -883,4 +855,45 @@ void StickerSetBox::Inner::install() { }).send(); } +void StickerSetBox::Inner::archiveStickers() { + const auto isMasks = isMasksSet(); + const auto weak = base::make_weak(_controller.get()); + _controller->session().api().request(MTPmessages_InstallStickerSet( + _input, + MTP_boolTrue() + )).done([=](const MTPmessages_StickerSetInstallResult &result) { + const auto controller = weak.get(); + if (!controller) { + return; + } + if (result.type() == mtpc_messages_stickerSetInstallResultSuccess) { + Ui::Toast::Show(isMasks + ? tr::lng_masks_has_been_archived(tr::now) + : tr::lng_stickers_has_been_archived(tr::now)); + + const auto &session = controller->session(); + auto &order = isMasks + ? session.data().stickers().maskSetsOrderRef() + : session.data().stickers().setsOrderRef(); + const auto index = order.indexOf(_setId); + if (index == -1) { + return; + } + order.removeAt(index); + + if (isMasks) { + session.local().writeInstalledMasks(); + session.local().writeArchivedMasks(); + } else { + session.local().writeInstalledStickers(); + session.local().writeArchivedStickers(); + } + + session.data().stickers().notifyUpdated(); + } + }).fail([](const MTP::Error &error) { + Ui::Toast::Show(Lang::Hard::ServerError()); + }).send(); +} + StickerSetBox::Inner::~Inner() = default; diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.h b/Telegram/SourceFiles/boxes/sticker_set_box.h index 711415190..2bfe1633b 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.h +++ b/Telegram/SourceFiles/boxes/sticker_set_box.h @@ -46,7 +46,6 @@ private: void updateButtons(); void addStickers(); void copyStickersLink(); - void archiveStickers(); void handleError(Error error); const not_null _controller;