2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-23 19:07:25 +00:00

143 lines
3.5 KiB
C
Raw Normal View History

2019-09-03 18:24:51 +03: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 16:35:26 +03:00
#include "base/timer.h"
2021-08-25 19:16:50 +03:00
#include "data/data_wall_paper.h"
2019-09-06 16:35:26 +03:00
class DocumentData;
2019-09-03 18:24:51 +03:00
namespace Main {
class Session;
} // namespace Main
2021-06-15 23:30:08 +03:00
namespace Window {
class Controller;
} // namespace Window
2019-09-03 18:24:51 +03:00
namespace Data {
class DocumentMedia;
2019-09-03 18:24:51 +03:00
struct CloudTheme {
uint64 id = 0;
uint64 accessHash = 0;
QString slug;
QString title;
2019-09-03 21:04:38 +03:00
DocumentId documentId = 0;
UserId createdBy = 0;
int usersCount = 0;
2021-08-26 16:25:48 +03:00
2021-08-25 19:16:50 +03:00
std::optional<WallPaper> paper;
std::optional<QColor> accentColor;
std::vector<QColor> outgoingMessagesColors;
2021-08-26 16:25:48 +03:00
bool basedOnDark = false;
2019-09-03 21:04:38 +03:00
static CloudTheme Parse(
not_null<Main::Session*> session,
2021-08-25 19:16:50 +03:00
const MTPDtheme &data,
bool parseSettings = false);
static CloudTheme Parse(
not_null<Main::Session*> session,
const MTPTheme &data,
bool parseSettings = false);
};
struct ChatTheme {
QString emoji;
CloudTheme light;
CloudTheme dark;
2019-09-03 18:24:51 +03: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 21:01:45 +03:00
void savedFromEditor(const CloudTheme &data);
2019-09-08 20:05:26 +03:00
void remove(uint64 cloudThemeId);
2019-09-03 18:24:51 +03:00
2021-08-25 19:16:50 +03:00
void refreshChatThemes();
[[nodiscard]] const std::vector<ChatTheme> &chatThemes() const;
[[nodiscard]] rpl::producer<> chatThemesUpdated() const;
[[nodiscard]] std::optional<ChatTheme> themeForEmoji(
const QString &emoji) const;
2021-08-26 16:25:48 +03:00
[[nodiscard]] rpl::producer<std::optional<ChatTheme>> themeForEmojiValue(
const QString &emoji);
2021-08-25 19:16:50 +03:00
2019-09-06 16:35:26 +03:00
void applyUpdate(const MTPTheme &theme);
2021-06-15 23:30:08 +03: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);
void applyFromDocument(const CloudTheme &cloud);
2019-09-06 17:24:22 +03:00
2019-09-03 18:24:51 +03:00
private:
2019-09-06 18:31:01 +03:00
struct LoadingDocument {
2019-09-09 11:51:07 +03:00
CloudTheme theme;
2019-09-06 18:31:01 +03:00
DocumentData *document = nullptr;
std::shared_ptr<Data::DocumentMedia> documentMedia;
2019-09-06 18:31:01 +03:00
rpl::lifetime subscription;
Fn<void(std::shared_ptr<Data::DocumentMedia>)> callback;
2019-09-06 18:31:01 +03:00
};
2019-09-03 18:24:51 +03:00
void parseThemes(const QVector<MTPTheme> &list);
void checkCurrentTheme();
2019-09-03 18:24:51 +03:00
2019-09-06 16:52:16 +03:00
void install();
2019-09-06 16:35:26 +03:00
void setupReload();
[[nodiscard]] bool needReload() const;
void scheduleReload();
void reloadCurrent();
2021-06-15 23:30:08 +03:00
void previewFromDocument(
not_null<Window::Controller*> controller,
const CloudTheme &cloud);
2019-09-06 18:31:01 +03:00
void loadDocumentAndInvoke(
LoadingDocument &value,
2019-09-09 11:51:07 +03:00
const CloudTheme &cloud,
2019-09-06 18:31:01 +03:00
not_null<DocumentData*> document,
Fn<void(std::shared_ptr<Data::DocumentMedia>)> callback);
2019-09-06 18:31:01 +03:00
void invokeForLoaded(LoadingDocument &value);
2019-09-06 16:35:26 +03:00
2021-08-25 19:16:50 +03:00
void parseChatThemes(const QVector<MTPChatTheme> &list);
2019-09-03 18:24:51 +03:00
const not_null<Main::Session*> _session;
int32 _hash = 0;
2021-08-25 19:16:50 +03:00
mtpRequestId _refreshRequestId = 0;
2019-09-06 17:24:22 +03:00
mtpRequestId _resolveRequestId = 0;
2019-09-03 18:24:51 +03:00
std::vector<CloudTheme> _list;
rpl::event_stream<> _updates;
2021-08-25 19:16:50 +03:00
int32 _chatThemesHash = 0;
mtpRequestId _chatThemesRequestId = 0;
std::vector<ChatTheme> _chatThemes;
rpl::event_stream<> _chatThemesUpdates;
2019-09-06 16:35:26 +03:00
base::Timer _reloadCurrentTimer;
2019-09-06 18:31:01 +03:00
LoadingDocument _updatingFrom;
LoadingDocument _previewFrom;
2019-09-06 16:52:16 +03:00
uint64 _installedDayThemeId = 0;
uint64 _installedNightThemeId = 0;
2019-09-06 16:35:26 +03:00
rpl::lifetime _lifetime;
2019-09-03 18:24:51 +03:00
};
} // namespace Data