tdesktop/Telegram/SourceFiles/data/data_cloud_themes.h

98 lines
2.2 KiB
C
Raw Normal View History

2019-09-03 15:24:51 +00:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
2019-09-06 13:35:26 +00:00
#include "base/timer.h"
class DocumentData;
2019-09-03 15:24:51 +00:00
namespace Main {
class Session;
} // namespace Main
namespace Data {
struct CloudTheme {
uint64 id = 0;
uint64 accessHash = 0;
QString slug;
QString title;
2019-09-03 18:04:38 +00:00
DocumentId documentId = 0;
UserId createdBy = 0;
static CloudTheme Parse(
not_null<Main::Session*> session,
const MTPDtheme &data);
2019-09-03 15:24:51 +00:00
};
class CloudThemes final {
public:
explicit CloudThemes(not_null<Main::Session*> session);
[[nodiscard]] static QString Format();
void refresh();
[[nodiscard]] rpl::producer<> updated() const;
[[nodiscard]] const std::vector<CloudTheme> &list() const;
2019-09-08 18:01:45 +00:00
void savedFromEditor(const CloudTheme &data);
2019-09-08 17:05:26 +00:00
void remove(uint64 cloudThemeId);
2019-09-03 15:24:51 +00:00
2019-09-06 13:35:26 +00:00
void applyUpdate(const MTPTheme &theme);
2019-09-06 14:24:22 +00:00
void resolve(const QString &slug, const FullMsgId &clickFromMessageId);
2019-09-06 15:31:01 +00:00
void showPreview(const MTPTheme &data);
void showPreview(const CloudTheme &cloud);
2019-09-06 14:24:22 +00:00
2019-09-03 15:24:51 +00:00
private:
2019-09-06 15:31:01 +00:00
struct LoadingDocument {
2019-09-09 08:51:07 +00:00
CloudTheme theme;
2019-09-06 15:31:01 +00:00
DocumentData *document = nullptr;
rpl::lifetime subscription;
Fn<void()> callback;
};
2019-09-03 15:24:51 +00:00
void parseThemes(const QVector<MTPTheme> &list);
void checkCurrentTheme();
2019-09-03 15:24:51 +00:00
2019-09-06 13:52:16 +00:00
void install();
2019-09-06 13:35:26 +00:00
void setupReload();
[[nodiscard]] bool needReload() const;
void scheduleReload();
void reloadCurrent();
void updateFromDocument(
const CloudTheme &cloud,
not_null<DocumentData*> document);
2019-09-06 15:31:01 +00:00
void previewFromDocument(
const CloudTheme &cloud,
not_null<DocumentData*> document);
void loadDocumentAndInvoke(
LoadingDocument &value,
2019-09-09 08:51:07 +00:00
const CloudTheme &cloud,
2019-09-06 15:31:01 +00:00
not_null<DocumentData*> document,
Fn<void()> callback);
void invokeForLoaded(LoadingDocument &value);
2019-09-06 13:35:26 +00:00
2019-09-03 15:24:51 +00:00
const not_null<Main::Session*> _session;
int32 _hash = 0;
2019-09-06 14:24:22 +00:00
mtpRequestId _refreshRquestId = 0;
mtpRequestId _resolveRequestId = 0;
2019-09-03 15:24:51 +00:00
std::vector<CloudTheme> _list;
rpl::event_stream<> _updates;
2019-09-06 13:35:26 +00:00
base::Timer _reloadCurrentTimer;
2019-09-06 15:31:01 +00:00
LoadingDocument _updatingFrom;
LoadingDocument _previewFrom;
2019-09-06 13:52:16 +00:00
uint64 _installedDayThemeId = 0;
uint64 _installedNightThemeId = 0;
2019-09-06 13:35:26 +00:00
rpl::lifetime _lifetime;
2019-09-03 15:24:51 +00:00
};
} // namespace Data