mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-10 16:59:55 +00:00
Support theme document file origins.
This commit is contained in:
parent
51c1dc20e1
commit
9ff1fbcf47
@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "data/data_channel.h"
|
||||
#include "data/data_chat.h"
|
||||
#include "data/data_user.h"
|
||||
#include "data/data_cloud_themes.h"
|
||||
#include "dialogs/dialogs_key.h"
|
||||
#include "core/core_cloud_password.h"
|
||||
#include "core/application.h"
|
||||
@ -3063,6 +3064,13 @@ void ApiWrap::refreshFileReference(
|
||||
MTP_inputWallPaper(
|
||||
MTP_long(data.paperId),
|
||||
MTP_long(data.accessHash))));
|
||||
}, [&](Data::FileOriginTheme data) {
|
||||
request(MTPaccount_GetTheme(
|
||||
MTP_string(Data::CloudThemes::Format()),
|
||||
MTP_inputTheme(
|
||||
MTP_long(data.themeId),
|
||||
MTP_long(data.accessHash)),
|
||||
MTP_long(0)));
|
||||
}, [&](std::nullopt_t) {
|
||||
fail();
|
||||
});
|
||||
|
@ -182,7 +182,7 @@ void CloudThemes::showPreview(const CloudTheme &cloud) {
|
||||
void CloudThemes::updateFromDocument(
|
||||
const CloudTheme &cloud,
|
||||
not_null<DocumentData*> document) {
|
||||
loadDocumentAndInvoke(_updatingFrom, document, [=] {
|
||||
loadDocumentAndInvoke(_updatingFrom, cloud, document, [=] {
|
||||
auto preview = Window::Theme::PreviewFromFile(
|
||||
document->data(),
|
||||
document->location().name(),
|
||||
@ -197,13 +197,14 @@ void CloudThemes::updateFromDocument(
|
||||
void CloudThemes::previewFromDocument(
|
||||
const CloudTheme &cloud,
|
||||
not_null<DocumentData*> document) {
|
||||
loadDocumentAndInvoke(_previewFrom, document, [=] {
|
||||
loadDocumentAndInvoke(_previewFrom, cloud, document, [=] {
|
||||
Core::App().showTheme(document, cloud);
|
||||
});
|
||||
}
|
||||
|
||||
void CloudThemes::loadDocumentAndInvoke(
|
||||
LoadingDocument &value,
|
||||
const CloudTheme &cloud,
|
||||
not_null<DocumentData*> document,
|
||||
Fn<void()> callback) {
|
||||
const auto alreadyWaiting = (value.document != nullptr);
|
||||
@ -211,7 +212,9 @@ void CloudThemes::loadDocumentAndInvoke(
|
||||
value.document->cancel();
|
||||
}
|
||||
value.document = document;
|
||||
value.document->save(Data::FileOrigin(), QString()); // #TODO themes
|
||||
value.document->save(
|
||||
Data::FileOriginTheme(cloud.id, cloud.accessHash),
|
||||
QString());
|
||||
value.callback = std::move(callback);
|
||||
if (document->loaded()) {
|
||||
invokeForLoaded(value);
|
||||
|
@ -50,6 +50,7 @@ public:
|
||||
|
||||
private:
|
||||
struct LoadingDocument {
|
||||
CloudTheme theme;
|
||||
DocumentData *document = nullptr;
|
||||
rpl::lifetime subscription;
|
||||
Fn<void()> callback;
|
||||
@ -71,6 +72,7 @@ private:
|
||||
not_null<DocumentData*> document);
|
||||
void loadDocumentAndInvoke(
|
||||
LoadingDocument &value,
|
||||
const CloudTheme &cloud,
|
||||
not_null<DocumentData*> document,
|
||||
Fn<void()> callback);
|
||||
void invokeForLoaded(LoadingDocument &value);
|
||||
|
@ -38,6 +38,14 @@ struct FileReferenceAccumulator {
|
||||
push(data.vdocument());
|
||||
});
|
||||
}
|
||||
void push(const MTPTheme &data) {
|
||||
data.match([&](const MTPDtheme &data) {
|
||||
if (const auto document = data.vdocument()) {
|
||||
push(*document);
|
||||
}
|
||||
}, [&](const MTPDthemeDocumentNotModified &data) {
|
||||
});
|
||||
}
|
||||
void push(const MTPWebPage &data) {
|
||||
data.match([&](const MTPDwebPage &data) {
|
||||
if (const auto document = data.vdocument()) {
|
||||
@ -165,4 +173,8 @@ UpdatedFileReferences GetFileReferences(const MTPWallPaper &data) {
|
||||
return GetFileReferencesHelper(data);
|
||||
}
|
||||
|
||||
UpdatedFileReferences GetFileReferences(const MTPTheme &data) {
|
||||
return GetFileReferencesHelper(data);
|
||||
}
|
||||
|
||||
} // namespace Data
|
||||
|
@ -74,6 +74,20 @@ struct FileOriginWallpaper {
|
||||
}
|
||||
};
|
||||
|
||||
struct FileOriginTheme {
|
||||
FileOriginTheme(uint64 themeId, uint64 accessHash)
|
||||
: themeId(themeId)
|
||||
, accessHash(accessHash) {
|
||||
}
|
||||
|
||||
uint64 themeId = 0;
|
||||
uint64 accessHash = 0;
|
||||
|
||||
inline bool operator<(const FileOriginTheme &other) const {
|
||||
return themeId < other.themeId;
|
||||
}
|
||||
};
|
||||
|
||||
struct FileOrigin {
|
||||
using Variant = base::optional_variant<
|
||||
FileOriginMessage,
|
||||
@ -81,7 +95,8 @@ struct FileOrigin {
|
||||
FileOriginPeerPhoto,
|
||||
FileOriginStickerSet,
|
||||
FileOriginSavedGifs,
|
||||
FileOriginWallpaper>;
|
||||
FileOriginWallpaper,
|
||||
FileOriginTheme>;
|
||||
|
||||
FileOrigin() = default;
|
||||
FileOrigin(FileOriginMessage data) : data(data) {
|
||||
@ -96,6 +111,8 @@ struct FileOrigin {
|
||||
}
|
||||
FileOrigin(FileOriginWallpaper data) : data(data) {
|
||||
}
|
||||
FileOrigin(FileOriginTheme data) : data(data) {
|
||||
}
|
||||
|
||||
explicit operator bool() const {
|
||||
return data.has_value();
|
||||
@ -140,5 +157,6 @@ UpdatedFileReferences GetFileReferences(
|
||||
UpdatedFileReferences GetFileReferences(const MTPmessages_StickerSet &data);
|
||||
UpdatedFileReferences GetFileReferences(const MTPmessages_SavedGifs &data);
|
||||
UpdatedFileReferences GetFileReferences(const MTPWallPaper &data);
|
||||
UpdatedFileReferences GetFileReferences(const MTPTheme &data);
|
||||
|
||||
} // namespace Data
|
||||
|
@ -520,16 +520,18 @@ void CloudList::refreshElementUsing(
|
||||
|
||||
void CloudList::refreshColors(Element &element) {
|
||||
const auto currentId = Background()->themeObject().cloud.id;
|
||||
const auto documentId = element.theme.documentId;
|
||||
const auto document = documentId
|
||||
? _window->session().data().document(documentId).get()
|
||||
const auto &theme = element.theme;
|
||||
const auto document = theme.documentId
|
||||
? _window->session().data().document(theme.documentId).get()
|
||||
: nullptr;
|
||||
if (element.id() == kFakeCloudThemeId
|
||||
|| ((element.id() == currentId)
|
||||
&& (!document || !document->isTheme()))) {
|
||||
element.check->setColors(ColorsFromCurrentTheme());
|
||||
} else if (document) {
|
||||
document->save(Data::FileOrigin(), QString()); // #TODO themes
|
||||
document->save(
|
||||
Data::FileOriginTheme(theme.id, theme.accessHash),
|
||||
QString());
|
||||
if (document->loaded()) {
|
||||
refreshColorsFromDocument(element, document);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user