mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-11 01:10:13 +00:00
Handle t.me/addtheme links.
This commit is contained in:
parent
e38123cc48
commit
469c6770fb
@ -413,7 +413,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||||||
"lng_theme_reverting#other" = "Reverting to the old theme in {count} seconds.";
|
"lng_theme_reverting#other" = "Reverting to the old theme in {count} seconds.";
|
||||||
"lng_theme_keep_changes" = "Keep changes";
|
"lng_theme_keep_changes" = "Keep changes";
|
||||||
"lng_theme_revert" = "Revert";
|
"lng_theme_revert" = "Revert";
|
||||||
"lng_theme_no_desktop_version" = "Sorry, this theme doesn't include a version for Telegram Desktop.\n\n(Also, Telegram Desktop doesn't support cloud themes yet.)";
|
"lng_theme_no_desktop" = "Sorry, this theme doesn't include a version for Telegram Desktop.";
|
||||||
"lng_background_header" = "Background preview";
|
"lng_background_header" = "Background preview";
|
||||||
"lng_background_text1" = "Ah, you kids today with techno music! You should enjoy the classics, like Hasselhoff!";
|
"lng_background_text1" = "Ah, you kids today with techno music! You should enjoy the classics, like Hasselhoff!";
|
||||||
"lng_background_text2" = "I can't even take you seriously right now.";
|
"lng_background_text2" = "I can't even take you seriously right now.";
|
||||||
|
@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||||||
#include "passport/passport_form_controller.h"
|
#include "passport/passport_form_controller.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
#include "data/data_cloud_themes.h"
|
||||||
#include "data/data_channel.h"
|
#include "data/data_channel.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
@ -85,8 +86,11 @@ bool ShowTheme(
|
|||||||
if (!session) {
|
if (!session) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
const auto clickFromMessageId = context.value<FullMsgId>();
|
||||||
Core::App().hideMediaView();
|
Core::App().hideMediaView();
|
||||||
Ui::show(Box<InformBox>(tr::lng_theme_no_desktop_version(tr::now)));
|
session->data().cloudThemes().resolve(
|
||||||
|
match->captured(1),
|
||||||
|
clickFromMessageId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,11 +9,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||||||
|
|
||||||
#include "window/themes/window_theme.h"
|
#include "window/themes/window_theme.h"
|
||||||
#include "window/themes/window_theme_preview.h"
|
#include "window/themes/window_theme_preview.h"
|
||||||
|
#include "window/themes/window_theme_editor_box.h"
|
||||||
|
#include "window/window_controller.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/data_document.h"
|
#include "data/data_document.h"
|
||||||
#include "data/data_file_origin.h"
|
#include "data/data_file_origin.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
#include "boxes/confirm_box.h"
|
||||||
|
#include "lang/lang_keys.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
|
#include "mainwindow.h"
|
||||||
|
|
||||||
namespace Data {
|
namespace Data {
|
||||||
namespace {
|
namespace {
|
||||||
@ -121,19 +126,55 @@ void CloudThemes::applyUpdate(const MTPTheme &theme) {
|
|||||||
const auto cloud = CloudTheme::Parse(_session, data);
|
const auto cloud = CloudTheme::Parse(_session, data);
|
||||||
const auto &object = Window::Theme::Background()->themeObject();
|
const auto &object = Window::Theme::Background()->themeObject();
|
||||||
if ((cloud.id != object.cloud.id)
|
if ((cloud.id != object.cloud.id)
|
||||||
|| (cloud.documentId == object.cloud.documentId)) {
|
|| (cloud.documentId == object.cloud.documentId)
|
||||||
|
|| !cloud.documentId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (const auto updated = data.vdocument()) {
|
updateFromDocument(
|
||||||
updateFromDocument(
|
cloud,
|
||||||
cloud,
|
_session->data().document(cloud.documentId));
|
||||||
_session->data().processDocument(*updated));
|
|
||||||
}
|
|
||||||
}, [&](const MTPDthemeDocumentNotModified &data) {
|
}, [&](const MTPDthemeDocumentNotModified &data) {
|
||||||
});
|
});
|
||||||
scheduleReload();
|
scheduleReload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CloudThemes::resolve(
|
||||||
|
const QString &slug,
|
||||||
|
const FullMsgId &clickFromMessageId) {
|
||||||
|
_session->api().request(_resolveRequestId).cancel();
|
||||||
|
_resolveRequestId = _session->api().request(MTPaccount_GetTheme(
|
||||||
|
MTP_string(Format()),
|
||||||
|
MTP_inputThemeSlug(MTP_string(slug)),
|
||||||
|
MTP_long(0)
|
||||||
|
)).done([=](const MTPTheme &result) {
|
||||||
|
result.match([&](const MTPDtheme &data) {
|
||||||
|
const auto cloud = CloudTheme::Parse(_session, data);
|
||||||
|
if (cloud.documentId) {
|
||||||
|
const auto document = _session->data().document(
|
||||||
|
cloud.documentId);
|
||||||
|
DocumentOpenClickHandler::Open(
|
||||||
|
Data::FileOrigin(),
|
||||||
|
document,
|
||||||
|
_session->data().message(clickFromMessageId));
|
||||||
|
} else if (cloud.createdBy == _session->userId()) {
|
||||||
|
Ui::show(Box(
|
||||||
|
Window::Theme::CreateForExistingBox,
|
||||||
|
&App::wnd()->controller(),
|
||||||
|
cloud));
|
||||||
|
} else {
|
||||||
|
Ui::show(Box<InformBox>(
|
||||||
|
tr::lng_theme_no_desktop(tr::now)));
|
||||||
|
}
|
||||||
|
}, [&](const MTPDthemeDocumentNotModified &data) {
|
||||||
|
});
|
||||||
|
}).fail([=](const RPCError &error) {
|
||||||
|
if (error.type() == qstr("THEME_FORMAT_INVALID")) {
|
||||||
|
Ui::show(Box<InformBox>(
|
||||||
|
tr::lng_theme_no_desktop(tr::now)));
|
||||||
|
}
|
||||||
|
}).send();
|
||||||
|
}
|
||||||
|
|
||||||
void CloudThemes::updateFromDocument(
|
void CloudThemes::updateFromDocument(
|
||||||
const CloudTheme &cloud,
|
const CloudTheme &cloud,
|
||||||
not_null<DocumentData*> document) {
|
not_null<DocumentData*> document) {
|
||||||
@ -169,13 +210,14 @@ void CloudThemes::scheduleReload() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CloudThemes::refresh() {
|
void CloudThemes::refresh() {
|
||||||
if (_requestId) {
|
if (_refreshRquestId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_requestId = _session->api().request(MTPaccount_GetThemes(
|
_refreshRquestId = _session->api().request(MTPaccount_GetThemes(
|
||||||
MTP_string(Format()),
|
MTP_string(Format()),
|
||||||
MTP_int(_hash)
|
MTP_int(_hash)
|
||||||
)).done([=](const MTPaccount_Themes &result) {
|
)).done([=](const MTPaccount_Themes &result) {
|
||||||
|
_refreshRquestId = 0;
|
||||||
result.match([&](const MTPDaccount_themes &data) {
|
result.match([&](const MTPDaccount_themes &data) {
|
||||||
_hash = data.vhash().v;
|
_hash = data.vhash().v;
|
||||||
parseThemes(data.vthemes().v);
|
parseThemes(data.vthemes().v);
|
||||||
@ -183,7 +225,7 @@ void CloudThemes::refresh() {
|
|||||||
}, [](const MTPDaccount_themesNotModified &) {
|
}, [](const MTPDaccount_themesNotModified &) {
|
||||||
});
|
});
|
||||||
}).fail([=](const RPCError &error) {
|
}).fail([=](const RPCError &error) {
|
||||||
_requestId = 0;
|
_refreshRquestId = 0;
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,8 @@ public:
|
|||||||
|
|
||||||
void applyUpdate(const MTPTheme &theme);
|
void applyUpdate(const MTPTheme &theme);
|
||||||
|
|
||||||
|
void resolve(const QString &slug, const FullMsgId &clickFromMessageId);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void parseThemes(const QVector<MTPTheme> &list);
|
void parseThemes(const QVector<MTPTheme> &list);
|
||||||
|
|
||||||
@ -57,7 +59,8 @@ private:
|
|||||||
|
|
||||||
const not_null<Main::Session*> _session;
|
const not_null<Main::Session*> _session;
|
||||||
int32 _hash = 0;
|
int32 _hash = 0;
|
||||||
mtpRequestId _requestId = 0;
|
mtpRequestId _refreshRquestId = 0;
|
||||||
|
mtpRequestId _resolveRequestId = 0;
|
||||||
std::vector<CloudTheme> _list;
|
std::vector<CloudTheme> _list;
|
||||||
rpl::event_stream<> _updates;
|
rpl::event_stream<> _updates;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user