2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-09-05 08:55:59 +00:00

Support by-emoji background resolve in preview.

This commit is contained in:
John Preston
2023-12-20 21:44:34 -04:00
parent 41ae1f56ed
commit d5a1c354d0
4 changed files with 86 additions and 49 deletions

View File

@@ -56,43 +56,7 @@ struct ResolvedPaper {
peer,
Data::PeerUpdate::Flag::ChatWallPaper
) | rpl::map([=]() -> rpl::producer<const Data::WallPaper*> {
const auto paper = peer->wallPaper();
const auto id = paper ? paper->emojiId() : QString();
if (id.isEmpty()) {
return rpl::single(paper);
}
const auto themes = &peer->owner().cloudThemes();
auto fromThemes = [=](bool force)
-> rpl::producer<const Data::WallPaper*> {
if (themes->chatThemes().empty() && !force) {
return nullptr;
}
return Window::Theme::IsNightModeValue(
) | rpl::map([=](bool dark) -> const Data::WallPaper* {
const auto &list = themes->chatThemes();
const auto i = ranges::find(
list,
id,
&Data::CloudTheme::emoticon);
if (i != end(list)) {
using Type = Data::CloudThemeType;
const auto type = dark ? Type::Dark : Type::Light;
const auto j = i->settings.find(type);
if (j != end(i->settings) && j->second.paper) {
return &*j->second.paper;
}
}
return nullptr;
});
};
if (auto result = fromThemes(false)) {
return result;
}
themes->refreshChatThemes();
return themes->chatThemesUpdated(
) | rpl::take(1) | rpl::map([=] {
return fromThemes(true);
}) | rpl::flatten_latest();
return WallPaperResolved(&peer->owner(), peer->wallPaper());
}) | rpl::flatten_latest();
}
@@ -202,6 +166,47 @@ struct ResolvedTheme {
} // namespace
rpl::producer<const Data::WallPaper*> WallPaperResolved(
not_null<Data::Session*> owner,
const Data::WallPaper *paper) {
const auto id = paper ? paper->emojiId() : QString();
if (id.isEmpty()) {
return rpl::single(paper);
}
const auto themes = &owner->cloudThemes();
auto fromThemes = [=](bool force)
-> rpl::producer<const Data::WallPaper*> {
if (themes->chatThemes().empty() && !force) {
return nullptr;
}
return Window::Theme::IsNightModeValue(
) | rpl::map([=](bool dark) -> const Data::WallPaper* {
const auto &list = themes->chatThemes();
const auto i = ranges::find(
list,
id,
&Data::CloudTheme::emoticon);
if (i != end(list)) {
using Type = Data::CloudThemeType;
const auto type = dark ? Type::Dark : Type::Light;
const auto j = i->settings.find(type);
if (j != end(i->settings) && j->second.paper) {
return &*j->second.paper;
}
}
return nullptr;
});
};
if (auto result = fromThemes(false)) {
return result;
}
themes->refreshChatThemes();
return themes->chatThemesUpdated(
) | rpl::take(1) | rpl::map([=] {
return fromThemes(true);
}) | rpl::flatten_latest();
}
AbstractSectionWidget::AbstractSectionWidget(
QWidget *parent,
not_null<SessionController*> controller,