-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Expand file tree
/
Copy pathdata_cloud_themes.h
More file actions
177 lines (146 loc) · 4.72 KB
/
Copy pathdata_cloud_themes.h
File metadata and controls
177 lines (146 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
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
#include "base/timer.h"
#include "data/data_wall_paper.h"
class DocumentData;
namespace Main {
class Session;
} // namespace Main
namespace Window {
class Controller;
} // namespace Window
namespace Data {
struct UniqueGift;
class DocumentMedia;
enum class CloudThemeType {
Dark,
Light,
};
struct CloudTheme {
uint64 id = 0;
uint64 accessHash = 0;
QString slug;
QString title;
DocumentId documentId = 0;
UserId createdBy = 0;
int usersCount = 0;
QString emoticon;
std::shared_ptr<UniqueGift> unique;
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;
static CloudTheme Parse(
not_null<Main::Session*> session,
const MTPDtheme &data,
bool parseSettings = false);
static CloudTheme Parse(
not_null<Main::Session*> session,
const MTPDchatThemeUniqueGift &data,
bool parseSettings = false);
static CloudTheme Parse(
not_null<Main::Session*> session,
const MTPTheme &data,
bool parseSettings = false);
};
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;
void savedFromEditor(const CloudTheme &data);
void remove(uint64 cloudThemeId);
void refreshChatThemes();
[[nodiscard]] const std::vector<CloudTheme> &chatThemes() const;
[[nodiscard]] rpl::producer<> chatThemesUpdated() const;
void myGiftThemesLoadMore(bool reload = false);
[[nodiscard]] const std::vector<QString> &myGiftThemesTokens() const;
[[nodiscard]] rpl::producer<> myGiftThemesUpdated() const;
[[nodiscard]] QString processGiftThemeGetToken(
const MTPDchatThemeUniqueGift &data);
[[nodiscard]] bool myGiftThemesReady() const;
void refreshChatThemesFor(const QString &token);
[[nodiscard]] std::optional<CloudTheme> themeForToken(
const QString &token) const;
[[nodiscard]] auto themeForTokenValue(const QString &token)
-> rpl::producer<std::optional<CloudTheme>>;
[[nodiscard]] static bool TestingColors();
static void SetTestingColors(bool testing);
[[nodiscard]] QString prepareTestingLink(const CloudTheme &theme) const;
[[nodiscard]] std::optional<CloudTheme> updateThemeFromLink(
const QString &emoticon,
const QMap<QString, QString> ¶ms);
void applyUpdate(const MTPTheme &theme);
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);
private:
struct LoadingDocument {
CloudTheme theme;
DocumentData *document = nullptr;
std::shared_ptr<Data::DocumentMedia> documentMedia;
rpl::lifetime subscription;
Fn<void(std::shared_ptr<Data::DocumentMedia>)> callback;
};
void parseThemes(const QVector<MTPTheme> &list);
void checkCurrentTheme();
void checkAppliedChatTheme();
void install();
void setupReload();
[[nodiscard]] bool needReload() const;
void scheduleReload();
void reloadCurrent();
void previewFromDocument(
not_null<Window::Controller*> controller,
const CloudTheme &cloud);
void loadDocumentAndInvoke(
LoadingDocument &value,
const CloudTheme &cloud,
not_null<DocumentData*> document,
Fn<void(std::shared_ptr<Data::DocumentMedia>)> callback);
void invokeForLoaded(LoadingDocument &value);
void parseChatThemes(const QVector<MTPTheme> &list);
const not_null<Main::Session*> _session;
uint64 _hash = 0;
mtpRequestId _refreshRequestId = 0;
mtpRequestId _resolveRequestId = 0;
std::vector<CloudTheme> _list;
rpl::event_stream<> _updates;
uint64 _chatThemesHash = 0;
mtpRequestId _chatThemesRequestId = 0;
std::vector<CloudTheme> _chatThemes;
rpl::event_stream<> _chatThemesUpdates;
mtpRequestId _myGiftThemesRequestId = 0;
base::flat_map<uint64, CloudTheme> _giftThemes;
std::vector<QString> _myGiftThemesTokens;
rpl::event_stream<> _myGiftThemesUpdates;
uint64 _myGiftThemesHash = 0;
QString _myGiftThemesNextOffset;
bool _myGiftThemesLoaded = false;
base::Timer _reloadCurrentTimer;
LoadingDocument _updatingFrom;
LoadingDocument _previewFrom;
uint64 _installedDayThemeId = 0;
uint64 _installedNightThemeId = 0;
rpl::lifetime _lifetime;
};
} // namespace Data