Added ability to archive mask packs.

This commit is contained in:
23rd 2021-06-13 06:47:56 +03:00
parent 8420b7dc17
commit 4701c5d6e3
3 changed files with 49 additions and 35 deletions
Telegram
Resources/langs
SourceFiles/boxes

View file

@ -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";

View file

@ -73,6 +73,8 @@ public:
[[nodiscard]] rpl::producer<Error> 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<Ui::PopupMenu>(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;

View file

@ -46,7 +46,6 @@ private:
void updateButtons();
void addStickers();
void copyStickersLink();
void archiveStickers();
void handleError(Error error);
const not_null<Window::SessionController*> _controller;