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"
|
2021-08-25 16:16:50 +00:00
|
|
|
#include "data/data_wall_paper.h"
|
2019-09-06 13:35:26 +00:00
|
|
|
|
|
|
|
class DocumentData;
|
|
|
|
|
2019-09-03 15:24:51 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
2021-06-15 20:30:08 +00:00
|
|
|
namespace Window {
|
|
|
|
class Controller;
|
|
|
|
} // namespace Window
|
|
|
|
|
2019-09-03 15:24:51 +00:00
|
|
|
namespace Data {
|
|
|
|
|
2020-04-09 12:27:53 +00:00
|
|
|
class DocumentMedia;
|
|
|
|
|
2021-10-22 18:14:44 +00:00
|
|
|
enum class CloudThemeType {
|
|
|
|
Dark,
|
|
|
|
Light,
|
|
|
|
};
|
|
|
|
|
2019-09-03 15:24:51 +00:00
|
|
|
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;
|
2019-09-09 13:13:16 +00:00
|
|
|
int usersCount = 0;
|
2021-10-22 18:14:44 +00:00
|
|
|
QString emoticon;
|
2021-08-26 13:25:48 +00:00
|
|
|
|
2021-10-22 18:14:44 +00:00
|
|
|
using Type = CloudThemeType;
|
|
|
|
struct Settings {
|
|
|
|
std::optional<WallPaper> paper;
|
|
|
|
QColor accentColor;
|
|
|
|
std::optional<QColor> outgoingAccentColor;
|
|
|
|
std::vector<QColor> outgoingMessagesColors;
|
|
|
|
};
|
|
|
|
base::flat_map<Type, Settings> settings;
|
2019-09-03 18:04:38 +00:00
|
|
|
|
|
|
|
static CloudTheme Parse(
|
|
|
|
not_null<Main::Session*> session,
|
2021-08-25 16:16:50 +00:00
|
|
|
const MTPDtheme &data,
|
|
|
|
bool parseSettings = false);
|
|
|
|
static CloudTheme Parse(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
const MTPTheme &data,
|
|
|
|
bool parseSettings = false);
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2021-08-25 16:16:50 +00:00
|
|
|
void refreshChatThemes();
|
2021-10-22 18:14:44 +00:00
|
|
|
[[nodiscard]] const std::vector<CloudTheme> &chatThemes() const;
|
2021-08-25 16:16:50 +00:00
|
|
|
[[nodiscard]] rpl::producer<> chatThemesUpdated() const;
|
2021-10-22 18:14:44 +00:00
|
|
|
[[nodiscard]] std::optional<CloudTheme> themeForEmoji(
|
2021-09-24 15:10:25 +00:00
|
|
|
const QString &emoticon) const;
|
2021-10-22 18:14:44 +00:00
|
|
|
[[nodiscard]] auto themeForEmojiValue(const QString &emoticon)
|
|
|
|
-> rpl::producer<std::optional<CloudTheme>>;
|
2021-08-25 16:16:50 +00:00
|
|
|
|
2021-09-10 19:29:30 +00:00
|
|
|
[[nodiscard]] static bool TestingColors();
|
2021-09-10 21:02:15 +00:00
|
|
|
static void SetTestingColors(bool testing);
|
2021-09-19 08:39:38 +00:00
|
|
|
[[nodiscard]] QString prepareTestingLink(const CloudTheme &theme) const;
|
2021-09-10 19:29:30 +00:00
|
|
|
[[nodiscard]] std::optional<CloudTheme> updateThemeFromLink(
|
2021-09-24 15:10:25 +00:00
|
|
|
const QString &emoticon,
|
2021-09-10 19:29:30 +00:00
|
|
|
const QMap<QString, QString> ¶ms);
|
|
|
|
|
2019-09-06 13:35:26 +00:00
|
|
|
void applyUpdate(const MTPTheme &theme);
|
|
|
|
|
2021-06-15 20:30:08 +00:00
|
|
|
void resolve(
|
|
|
|
not_null<Window::Controller*> controller,
|
|
|
|
const QString &slug,
|
|
|
|
const FullMsgId &clickFromMessageId);
|
|
|
|
void showPreview(
|
|
|
|
not_null<Window::Controller*> controller,
|
|
|
|
const MTPTheme &data);
|
|
|
|
void showPreview(
|
|
|
|
not_null<Window::Controller*> controller,
|
|
|
|
const CloudTheme &cloud);
|
2019-09-09 09:13:07 +00:00
|
|
|
void applyFromDocument(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;
|
2020-04-09 12:27:53 +00:00
|
|
|
std::shared_ptr<Data::DocumentMedia> documentMedia;
|
2019-09-06 15:31:01 +00:00
|
|
|
rpl::lifetime subscription;
|
2020-04-09 12:27:53 +00:00
|
|
|
Fn<void(std::shared_ptr<Data::DocumentMedia>)> callback;
|
2019-09-06 15:31:01 +00:00
|
|
|
};
|
|
|
|
|
2019-09-03 15:24:51 +00:00
|
|
|
void parseThemes(const QVector<MTPTheme> &list);
|
2019-09-09 06:59:57 +00:00
|
|
|
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();
|
2021-06-15 20:30:08 +00:00
|
|
|
void previewFromDocument(
|
|
|
|
not_null<Window::Controller*> controller,
|
|
|
|
const CloudTheme &cloud);
|
2019-09-06 15:31:01 +00:00
|
|
|
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,
|
2020-04-09 12:27:53 +00:00
|
|
|
Fn<void(std::shared_ptr<Data::DocumentMedia>)> callback);
|
2019-09-06 15:31:01 +00:00
|
|
|
void invokeForLoaded(LoadingDocument &value);
|
2019-09-06 13:35:26 +00:00
|
|
|
|
2021-10-22 18:14:44 +00:00
|
|
|
void parseChatThemes(const QVector<MTPTheme> &list);
|
2021-08-25 16:16:50 +00:00
|
|
|
|
2019-09-03 15:24:51 +00:00
|
|
|
const not_null<Main::Session*> _session;
|
2021-08-25 08:15:05 +00:00
|
|
|
uint64 _hash = 0;
|
2021-08-25 16:16:50 +00:00
|
|
|
mtpRequestId _refreshRequestId = 0;
|
2019-09-06 14:24:22 +00:00
|
|
|
mtpRequestId _resolveRequestId = 0;
|
2019-09-03 15:24:51 +00:00
|
|
|
std::vector<CloudTheme> _list;
|
|
|
|
rpl::event_stream<> _updates;
|
|
|
|
|
2021-10-22 18:14:44 +00:00
|
|
|
uint64 _chatThemesHash = 0;
|
2021-08-25 16:16:50 +00:00
|
|
|
mtpRequestId _chatThemesRequestId = 0;
|
2021-10-22 18:14:44 +00:00
|
|
|
std::vector<CloudTheme> _chatThemes;
|
2021-08-25 16:16:50 +00:00
|
|
|
rpl::event_stream<> _chatThemesUpdates;
|
|
|
|
|
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
|