From 36997f084a0ccdcbae1cbfa4eb966c5d5a52dd10 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 7 May 2020 19:06:44 +0400 Subject: [PATCH] Automatically load and apply old emoji set by id. --- .../chat_helpers/emoji_sets_manager.cpp | 36 ++++++++++++++----- .../chat_helpers/emoji_sets_manager.h | 2 ++ Telegram/SourceFiles/intro/intro_step.cpp | 3 +- .../storage/storage_cloud_blob.cpp | 6 ++-- .../SourceFiles/window/window_controller.cpp | 6 ++++ Telegram/codegen | 2 +- Telegram/lib_ui | 2 +- 7 files changed, 43 insertions(+), 14 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp index 833f1d641..ea94dcb54 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp @@ -48,7 +48,7 @@ const auto kSets = { using Loading = MTP::DedicatedLoader::Progress; using SetState = BlobState; -class Loader : public BlobLoader { +class Loader final : public BlobLoader { public: Loader( QObject *parent, @@ -60,6 +60,9 @@ public: void destroy() override; void unpack(const QString &path) override; +private: + void fail() override; + }; class Inner : public Ui::RpWidget { @@ -155,12 +158,14 @@ bool UnpackSet(const QString &path, const QString &folder) { return UnpackBlob(path, folder, GoodSetPartName); } + Loader::Loader( QObject *parent, int id, MTP::DedicatedLoader::Location location, const QString &folder, - int size) : BlobLoader(parent, id, location, folder, size) { + int size) +: BlobLoader(parent, id, location, folder, size) { } void Loader::unpack(const QString &path) { @@ -190,6 +195,11 @@ void Loader::destroy() { SetGlobalLoader(nullptr); } +void Loader::fail() { + ClearNeedSwitchToId(); + BlobLoader::fail(); +} + Inner::Inner(QWidget *parent) : RpWidget(parent) { setupContent(); } @@ -401,12 +411,7 @@ void Row::setupHandler() { } void Row::load() { - SetGlobalLoader(base::make_unique_q( - App::main(), - _id, - GetDownloadLocation(_id), - internal::SetDataPath(_id), - GetDownloadSize(_id))); + LoadAndSwitchTo(_id); } void Row::setupLabels(const Set &set) { @@ -538,5 +543,20 @@ void ManageSetsBox::prepare() { setDimensionsToContent(st::boxWidth, inner); } +void LoadAndSwitchTo(int id) { + Expects(App::main() != nullptr); + + if (!ranges::contains(kSets, id, &Set::id)) { + ClearNeedSwitchToId(); + return; + } + SetGlobalLoader(base::make_unique_q( + App::main(), + id, + GetDownloadLocation(id), + internal::SetDataPath(id), + GetDownloadSize(id))); +} + } // namespace Emoji } // namespace Ui diff --git a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.h b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.h index 316b06100..39ea5fd35 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.h +++ b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.h @@ -21,5 +21,7 @@ protected: }; +void LoadAndSwitchTo(int id); + } // namespace Emoji } // namespace Ui diff --git a/Telegram/SourceFiles/intro/intro_step.cpp b/Telegram/SourceFiles/intro/intro_step.cpp index 0ad9d7da5..a749e6395 100644 --- a/Telegram/SourceFiles/intro/intro_step.cpp +++ b/Telegram/SourceFiles/intro/intro_step.cpp @@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/slide_animation.h" #include "data/data_user.h" #include "data/data_auto_download.h" +#include "window/window_controller.h" #include "window/themes/window_theme.h" #include "facades.h" #include "app.h" @@ -140,7 +141,7 @@ void Step::finish(const MTPUser &user, QImage &&photo) { const auto weak = base::make_weak(account.get()); account->createSession(user); Local::writeMtpData(); - App::wnd()->setupMain(); + App::wnd()->controller().setupMain(); // "this" is already deleted here by creating the main widget. if (weak && account->sessionExists()) { diff --git a/Telegram/SourceFiles/storage/storage_cloud_blob.cpp b/Telegram/SourceFiles/storage/storage_cloud_blob.cpp index 41d7d1c9d..300dffd91 100644 --- a/Telegram/SourceFiles/storage/storage_cloud_blob.cpp +++ b/Telegram/SourceFiles/storage/storage_cloud_blob.cpp @@ -40,9 +40,9 @@ bool ExtractZipFile(zlib::FileToRead &zip, const QString path) { } // namespace bool UnpackBlob( - const QString &path, - const QString &folder, - Fn checkNameCallback) { + const QString &path, + const QString &folder, + Fn checkNameCallback) { const auto bytes = ReadFinalFile(path); if (bytes.isEmpty()) { return false; diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index a89616730..8252f175d 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -13,6 +13,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/layers/box_content.h" #include "ui/layers/layer_widget.h" #include "ui/toast/toast.h" +#include "ui/emoji_config.h" +#include "chat_helpers/emoji_sets_manager.h" #include "window/window_session_controller.h" #include "window/themes/window_theme.h" #include "window/themes/window_theme_editor.h" @@ -82,6 +84,10 @@ void Controller::setupIntro() { void Controller::setupMain() { _widget.setupMain(); + + if (const auto id = Ui::Emoji::NeedToSwitchBackToId()) { + Ui::Emoji::LoadAndSwitchTo(id); + } } void Controller::showSettings() { diff --git a/Telegram/codegen b/Telegram/codegen index f9947fe49..8b4686f24 160000 --- a/Telegram/codegen +++ b/Telegram/codegen @@ -1 +1 @@ -Subproject commit f9947fe4972408baa20b144b442eb4011444587c +Subproject commit 8b4686f24d80f1f8d6a4ad0d6a55bf1bb701f35a diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 2e82e7a3c..ab5a22605 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 2e82e7a3c9b0c8f0f533c2728e73a9f5a60993ab +Subproject commit ab5a2260562078b7e5abcda8bb0eb2a61984bfd5