mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Support pre-defined channel wallpapers resolving.
This commit is contained in:
parent
b6c679449e
commit
cd5a6025f6
3 changed files with 57 additions and 3 deletions
|
@ -198,9 +198,14 @@ WallPaperId WallPaper::id() const {
|
||||||
return _id;
|
return _id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString WallPaper::emojiId() const {
|
||||||
|
return _emojiId;
|
||||||
|
}
|
||||||
|
|
||||||
bool WallPaper::equals(const WallPaper &paper) const {
|
bool WallPaper::equals(const WallPaper &paper) const {
|
||||||
return (_flags == paper._flags)
|
return (_flags == paper._flags)
|
||||||
&& (_slug == paper._slug)
|
&& (_slug == paper._slug)
|
||||||
|
&& (_emojiId == paper._emojiId)
|
||||||
&& (_backgroundColors == paper._backgroundColors)
|
&& (_backgroundColors == paper._backgroundColors)
|
||||||
&& (_rotation == paper._rotation)
|
&& (_rotation == paper._rotation)
|
||||||
&& (_intensity == paper._intensity)
|
&& (_intensity == paper._intensity)
|
||||||
|
@ -362,6 +367,7 @@ MTPWallPaperSettings WallPaper::mtpSettings() const {
|
||||||
MTP_flags((_blurred ? Flag::f_blur : Flag(0))
|
MTP_flags((_blurred ? Flag::f_blur : Flag(0))
|
||||||
| Flag::f_intensity
|
| Flag::f_intensity
|
||||||
| Flag::f_rotation
|
| Flag::f_rotation
|
||||||
|
| (_emojiId.isEmpty() ? Flag() : Flag::f_emoticon)
|
||||||
| flagForIndex(0)
|
| flagForIndex(0)
|
||||||
| flagForIndex(1)
|
| flagForIndex(1)
|
||||||
| flagForIndex(2)
|
| flagForIndex(2)
|
||||||
|
@ -372,7 +378,7 @@ MTPWallPaperSettings WallPaper::mtpSettings() const {
|
||||||
serializeForIndex(3),
|
serializeForIndex(3),
|
||||||
MTP_int(_intensity),
|
MTP_int(_intensity),
|
||||||
MTP_int(_rotation),
|
MTP_int(_rotation),
|
||||||
MTPstring()); // emoticon
|
MTP_string(_emojiId));
|
||||||
}
|
}
|
||||||
|
|
||||||
WallPaper WallPaper::withUrlParams(
|
WallPaper WallPaper::withUrlParams(
|
||||||
|
@ -520,6 +526,7 @@ std::optional<WallPaper> WallPaper::Create(const MTPDwallPaperNoFile &data) {
|
||||||
if (const auto rotation = data.vrotation()) {
|
if (const auto rotation = data.vrotation()) {
|
||||||
result._rotation = rotation->v;
|
result._rotation = rotation->v;
|
||||||
}
|
}
|
||||||
|
result._emojiId = qs(data.vemoticon().value_or_empty());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -45,6 +45,7 @@ public:
|
||||||
[[nodiscard]] bool equals(const WallPaper &paper) const;
|
[[nodiscard]] bool equals(const WallPaper &paper) const;
|
||||||
|
|
||||||
[[nodiscard]] WallPaperId id() const;
|
[[nodiscard]] WallPaperId id() const;
|
||||||
|
[[nodiscard]] QString emojiId() const;
|
||||||
[[nodiscard]] bool isNull() const;
|
[[nodiscard]] bool isNull() const;
|
||||||
[[nodiscard]] QString key() const;
|
[[nodiscard]] QString key() const;
|
||||||
[[nodiscard]] const std::vector<QColor> backgroundColors() const;
|
[[nodiscard]] const std::vector<QColor> backgroundColors() const;
|
||||||
|
@ -114,6 +115,7 @@ private:
|
||||||
UserId _ownerId = 0;
|
UserId _ownerId = 0;
|
||||||
WallPaperFlags _flags;
|
WallPaperFlags _flags;
|
||||||
QString _slug;
|
QString _slug;
|
||||||
|
QString _emojiId;
|
||||||
|
|
||||||
std::vector<QColor> _backgroundColors;
|
std::vector<QColor> _backgroundColors;
|
||||||
int _rotation = 0;
|
int _rotation = 0;
|
||||||
|
|
|
@ -50,13 +50,58 @@ struct ResolvedPaper {
|
||||||
std::shared_ptr<Data::DocumentMedia> media;
|
std::shared_ptr<Data::DocumentMedia> media;
|
||||||
};
|
};
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<std::optional<ResolvedPaper>> PeerWallPaperValue(
|
[[nodiscard]] rpl::producer<const Data::WallPaper*> PeerWallPaperMapped(
|
||||||
not_null<PeerData*> peer) {
|
not_null<PeerData*> peer) {
|
||||||
return peer->session().changes().peerFlagsValue(
|
return peer->session().changes().peerFlagsValue(
|
||||||
peer,
|
peer,
|
||||||
Data::PeerUpdate::Flag::ChatWallPaper
|
Data::PeerUpdate::Flag::ChatWallPaper
|
||||||
) | rpl::map([=]() -> rpl::producer<std::optional<ResolvedPaper>> {
|
) | rpl::map([=]() -> rpl::producer<const Data::WallPaper*> {
|
||||||
const auto paper = peer->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();
|
||||||
|
}) | rpl::flatten_latest();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] rpl::producer<std::optional<ResolvedPaper>> PeerWallPaperValue(
|
||||||
|
not_null<PeerData*> peer) {
|
||||||
|
return PeerWallPaperMapped(
|
||||||
|
peer
|
||||||
|
) | rpl::map([=](const Data::WallPaper *paper)
|
||||||
|
-> rpl::producer<std::optional<ResolvedPaper>> {
|
||||||
const auto single = [](std::optional<ResolvedPaper> value) {
|
const auto single = [](std::optional<ResolvedPaper> value) {
|
||||||
return rpl::single(std::move(value));
|
return rpl::single(std::move(value));
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue