Automatically load and apply old emoji set by id.

This commit is contained in:
John Preston 2020-05-07 19:06:44 +04:00
parent 942fcb9aae
commit 36997f084a
7 changed files with 43 additions and 14 deletions

View file

@ -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<Loader>(
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<Loader>(
App::main(),
id,
GetDownloadLocation(id),
internal::SetDataPath(id),
GetDownloadSize(id)));
}
} // namespace Emoji
} // namespace Ui

View file

@ -21,5 +21,7 @@ protected:
};
void LoadAndSwitchTo(int id);
} // namespace Emoji
} // namespace Ui

View file

@ -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()) {

View file

@ -40,9 +40,9 @@ bool ExtractZipFile(zlib::FileToRead &zip, const QString path) {
} // namespace
bool UnpackBlob(
const QString &path,
const QString &folder,
Fn<bool(const QString &)> checkNameCallback) {
const QString &path,
const QString &folder,
Fn<bool(const QString &)> checkNameCallback) {
const auto bytes = ReadFinalFile(path);
if (bytes.isEmpty()) {
return false;

View file

@ -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() {

@ -1 +1 @@
Subproject commit f9947fe4972408baa20b144b442eb4011444587c
Subproject commit 8b4686f24d80f1f8d6a4ad0d6a55bf1bb701f35a

@ -1 +1 @@
Subproject commit 2e82e7a3c9b0c8f0f533c2728e73a9f5a60993ab
Subproject commit ab5a2260562078b7e5abcda8bb0eb2a61984bfd5