From 514ced1d8efa10a3f91fd4d650c162baece1b47f Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 29 Nov 2023 18:00:50 +0400 Subject: [PATCH] Respect wallpaper_overriden flag. --- Telegram/SourceFiles/api/api_updates.cpp | 3 +- Telegram/SourceFiles/boxes/background_box.cpp | 2 +- Telegram/SourceFiles/data/data_peer.cpp | 32 +++++++++++++------ Telegram/SourceFiles/data/data_peer.h | 9 ++++-- Telegram/SourceFiles/data/data_user.cpp | 3 +- Telegram/SourceFiles/history/history.cpp | 3 +- .../media/history_view_theme_document.cpp | 17 ++++++---- 7 files changed, 47 insertions(+), 22 deletions(-) diff --git a/Telegram/SourceFiles/api/api_updates.cpp b/Telegram/SourceFiles/api/api_updates.cpp index d3cf44dd6..5f903a67d 100644 --- a/Telegram/SourceFiles/api/api_updates.cpp +++ b/Telegram/SourceFiles/api/api_updates.cpp @@ -1996,7 +1996,8 @@ void Updates::feedUpdate(const MTPUpdate &update) { if (const auto peer = session().data().peerLoaded(peerFromMTP(d.vpeer()))) { if (const auto paper = d.vwallpaper()) { peer->setWallPaper( - Data::WallPaper::Create(&session(), *paper)); + Data::WallPaper::Create(&session(), *paper), + d.is_wallpaper_overridden()); } else { peer->setWallPaper({}); } diff --git a/Telegram/SourceFiles/boxes/background_box.cpp b/Telegram/SourceFiles/boxes/background_box.cpp index 834d23f0a..0ae3023e0 100644 --- a/Telegram/SourceFiles/boxes/background_box.cpp +++ b/Telegram/SourceFiles/boxes/background_box.cpp @@ -310,7 +310,7 @@ void BackgroundBox::resetForPeer() { }).send(); const auto weak = Ui::MakeWeak(this); - _forPeer->setWallPaper(std::nullopt); + _forPeer->setWallPaper({}); if (weak) { _controller->finishChatThemeEdit(_forPeer); } diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index e86f36ea0..0f3472916 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -1227,16 +1227,30 @@ const QString &PeerData::themeEmoji() const { return _themeEmoticon; } -void PeerData::setWallPaper(std::optional paper) { - if (!paper && !_wallPaper) { - return; - } else if (paper && _wallPaper && _wallPaper->equals(*paper)) { - return; +void PeerData::setWallPaper( + std::optional paper, + bool overriden) { + const auto paperChanged = (paper || _wallPaper) + && (!paper || !_wallPaper || !_wallPaper->equals(*paper)); + if (paperChanged) { + _wallPaper = paper + ? std::make_unique(std::move(*paper)) + : nullptr; } - _wallPaper = paper - ? std::make_unique(std::move(*paper)) - : nullptr; - session().changes().peerUpdated(this, UpdateFlag::ChatWallPaper); + + const auto overridenValue = overriden ? 1 : 0; + const auto overridenChanged = (_wallPaperOverriden != overridenValue); + if (overridenChanged) { + _wallPaperOverriden = overridenValue; + } + + if (paperChanged || overridenChanged) { + session().changes().peerUpdated(this, UpdateFlag::ChatWallPaper); + } +} + +bool PeerData::wallPaperOverriden() const { + return _wallPaperOverriden != 0; } const Data::WallPaper *PeerData::wallPaper() const { diff --git a/Telegram/SourceFiles/data/data_peer.h b/Telegram/SourceFiles/data/data_peer.h index 5a2004b23..1ff2676d7 100644 --- a/Telegram/SourceFiles/data/data_peer.h +++ b/Telegram/SourceFiles/data/data_peer.h @@ -414,7 +414,10 @@ public: void setThemeEmoji(const QString &emoticon); [[nodiscard]] const QString &themeEmoji() const; - void setWallPaper(std::optional paper); + void setWallPaper( + std::optional paper, + bool overriden = false); + [[nodiscard]] bool wallPaperOverriden() const; [[nodiscard]] const Data::WallPaper *wallPaper() const; enum class StoriesState { @@ -467,7 +470,8 @@ private: crl::time _lastFullUpdate = 0; QString _name; - int _nameVersion = 1; + uint32 _nameVersion : 31 = 1; + uint32 _wallPaperOverriden : 1 = 0; TimeId _ttlPeriod = 0; @@ -475,6 +479,7 @@ private: TimeId _requestChatDate = 0; Settings _settings = PeerSettings(PeerSetting::Unknown); + BlockStatus _blockStatus = BlockStatus::Unknown; LoadedStatus _loadedStatus = LoadedStatus::Not; TranslationFlag _translationFlag = TranslationFlag::Unknown; diff --git a/Telegram/SourceFiles/data/data_user.cpp b/Telegram/SourceFiles/data/data_user.cpp index e16e4f13b..33dd42ca5 100644 --- a/Telegram/SourceFiles/data/data_user.cpp +++ b/Telegram/SourceFiles/data/data_user.cpp @@ -515,7 +515,8 @@ void ApplyUserUpdate(not_null user, const MTPDuserFull &update) { if (const auto paper = update.vwallpaper()) { user->setWallPaper( - Data::WallPaper::Create(&user->session(), *paper)); + Data::WallPaper::Create(&user->session(), *paper), + update.is_wallpaper_overridden()); } else { user->setWallPaper({}); } diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index ce6b8af95..13cdf046c 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -1195,7 +1195,8 @@ void History::applyServiceChanges( }, [&](const MTPDmessageActionSetChatWallPaper &data) { if (item->out() || data.is_for_both()) { peer->setWallPaper( - Data::WallPaper::Create(&session(), data.vwallpaper())); + Data::WallPaper::Create(&session(), data.vwallpaper()), + !item->out() && data.is_for_both()); } }, [&](const MTPDmessageActionChatJoinedByRequest &data) { processJoinedPeer(item->from()); diff --git a/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp index 2496417c2..002152c5b 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp @@ -40,22 +40,25 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace HistoryView { namespace { -[[nodiscard]] bool HasThatWallPaperForBoth( +[[nodiscard]] bool WallPaperRevertable( not_null peer, const Data::WallPaper &paper) { + if (!peer->wallPaperOverriden()) { + return false; + } const auto now = peer->wallPaper(); return now && now->equals(paper); } -[[nodiscard]] bool HasThatWallPaperForBoth(not_null item) { +[[nodiscard]] bool WallPaperRevertable(not_null item) { const auto media = item->media(); const auto paper = media ? media->paper() : nullptr; return paper && media->paperForBoth() - && HasThatWallPaperForBoth(item->history()->peer, *paper); + && WallPaperRevertable(item->history()->peer, *paper); } -[[nodiscard]] rpl::producer HasThatWallPaperForBothValue( +[[nodiscard]] rpl::producer WallPaperRevertableValue( not_null item) { const auto media = item->media(); const auto paper = media ? media->paper() : nullptr; @@ -67,7 +70,7 @@ namespace { peer, Data::PeerUpdate::Flag::ChatWallPaper ) | rpl::map([peer, paper = *paper] { - return HasThatWallPaperForBoth(peer, paper); + return WallPaperRevertable(peer, paper); }); } @@ -499,7 +502,7 @@ rpl::producer ThemeDocumentBox::button() { return _parent->data()->out() ? nullptr : rpl::conditional( - HasThatWallPaperForBothValue(_parent->data()), + WallPaperRevertableValue(_parent->data()), tr::lng_action_set_wallpaper_remove(), tr::lng_action_set_wallpaper_button()); } @@ -518,7 +521,7 @@ ClickHandlerPtr ThemeDocumentBox::createViewLink() { const auto view = weak.get(); if (view && !view->data()->out() - && HasThatWallPaperForBoth(view->data())) { + && WallPaperRevertable(view->data())) { const auto reset = crl::guard(weak, [=](Fn close) { const auto api = &controller->session().api(); api->request(MTPmessages_SetChatWallPaper(