diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index f1d4e37ba41b50..c80fdc901f1530 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -946,6 +946,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_power_chat_effects" = "Effects in messages"; "lng_settings_power_calls" = "Animations in Calls"; "lng_settings_power_ui" = "Interface animations"; +"lng_settings_power_animated_avatars" = "Animated avatars"; "lng_settings_power_auto" = "Save Power on Low Battery"; "lng_settings_power_auto_about" = "Automatically disable all animations when your laptop is in a battery saving mode."; "lng_settings_power_turn_off" = "Please turn off Save Power on Low Battery to change these settings."; diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 943361e05a17f9..9c0c532827b891 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -33,6 +33,7 @@ For license and copyright information please follow this link: #include "ui/dynamic_thumbnails.h" #include "ui/vertical_list.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "ui/rect.h" #include "ui/screen_reader_mode.h" #include "ui/ui_utility.h" @@ -319,6 +320,11 @@ InnerWidget::InnerWidget( update(); }, lifetime()); + PowerSaving::OnValue(PowerSaving::kAnimatedUserpics) | rpl::on_next([=] { + _videoUserpics.clear(); + update(); + }, lifetime()); + Core::App().notifications().settingsChanged( ) | rpl::on_next([=](Window::Notifications::ChangeType change) { if (change == Window::Notifications::ChangeType::CountMessages) { @@ -1434,7 +1440,8 @@ Ui::VideoUserpic *InnerWidget::validateVideoUserpic(not_null row) { Ui::VideoUserpic *InnerWidget::validateVideoUserpic( not_null history) { const auto peer = history->peer; - if (!peer->isPremium() + if (PowerSaving::On(PowerSaving::kAnimatedUserpics) + || !peer->isPremium() || peer->userpicPhotoUnknown() || !peer->userpicHasVideo()) { _videoUserpics.remove(peer); diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_video_userpic.cpp b/Telegram/SourceFiles/dialogs/ui/dialogs_video_userpic.cpp index 9f970a30d9c6c7..be82e8a4903221 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_video_userpic.cpp +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_video_userpic.cpp @@ -16,6 +16,7 @@ For license and copyright information please follow this link: #include "dialogs/dialogs_entry.h" #include "dialogs/ui/dialogs_layout.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "styles/style_dialogs.h" namespace Dialogs::Ui { @@ -165,7 +166,7 @@ void PaintUserpic( int outerWidth, int size, bool paused) { - if (videoUserpic) { + if (videoUserpic && !PowerSaving::On(PowerSaving::kAnimatedUserpics)) { videoUserpic->paintLeft(p, view, x, y, outerWidth, size, paused); } else { peer->paintUserpicLeft(p, view, x, y, outerWidth, size); diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 639bf40b93e80f..1cffdb638794c9 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -56,6 +56,7 @@ For license and copyright information please follow this link: #include "ui/controls/swipe_handler.h" #include "ui/inactive_press.h" #include "ui/painter.h" +#include "ui/power_saving.h" #include "ui/rect.h" #include "ui/screen_reader_mode.h" #include "ui/ui_utility.h" @@ -418,6 +419,10 @@ HistoryInner::HistoryInner( update(); } }, lifetime()); + PowerSaving::OnValue(PowerSaving::kAnimatedUserpics) | rpl::on_next([=] { + _videoUserpics.clear(); + update(); + }, lifetime()); using PlayRequest = ChatHelpers::EmojiInteractionPlayRequest; _controller->emojiInteractions().playRequests( @@ -1788,7 +1793,8 @@ int HistoryInner::SelectionViewOffset( HistoryInner::VideoUserpic *HistoryInner::validateVideoUserpic( not_null peer) { - if (!peer->isPremium() + if (PowerSaving::On(PowerSaving::kAnimatedUserpics) + || !peer->isPremium() || peer->userpicPhotoUnknown() || !peer->userpicHasVideo()) { _videoUserpics.remove(peer); diff --git a/Telegram/SourceFiles/info/profile/info_profile_top_bar.cpp b/Telegram/SourceFiles/info/profile/info_profile_top_bar.cpp index 1dc78f8412552c..8778160fb5bcc0 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_top_bar.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_top_bar.cpp @@ -79,6 +79,7 @@ For license and copyright information please follow this link: #include "ui/layers/generic_box.h" #include "ui/painter.h" #include "ui/peer/video_userpic_player.h" +#include "ui/power_saving.h" #include "ui/rect.h" #include "ui/text/text_utilities.h" #include "ui/top_background_gradient.h" @@ -451,6 +452,10 @@ TopBar::TopBar( [=] { update(); }); } else { updateVideoUserpic(); + PowerSaving::OnValue(PowerSaving::kAnimatedUserpics) | rpl::on_next([=] { + updateVideoUserpic(); + update(); + }, lifetime()); } rpl::merge( @@ -1803,7 +1808,9 @@ void TopBar::paintUserpic(QPainter &p, const QRect &geometry) { _topicIconView->paintInRect(p, geometry); return; } - if (_videoUserpicPlayer && _videoUserpicPlayer->ready()) { + if (_videoUserpicPlayer + && _videoUserpicPlayer->ready() + && !PowerSaving::On(PowerSaving::kAnimatedUserpics)) { const auto size = st::infoProfileTopBarPhotoSize; const auto frame = _videoUserpicPlayer->frame(Size(size), _peer); if (!frame.isNull()) { @@ -2102,6 +2109,9 @@ void TopBar::fillTopBarMenu( void TopBar::updateVideoUserpic() { if (width() <= 0) { return; + } else if (PowerSaving::On(PowerSaving::kAnimatedUserpics)) { + _videoUserpicPlayer = nullptr; + return; } const auto id = _peer->userpicPhotoId(); if (!id) { diff --git a/Telegram/SourceFiles/settings/settings_power_saving.cpp b/Telegram/SourceFiles/settings/settings_power_saving.cpp index d026fb9231912e..61b8e03907b2c2 100644 --- a/Telegram/SourceFiles/settings/settings_power_saving.cpp +++ b/Telegram/SourceFiles/settings/settings_power_saving.cpp @@ -179,6 +179,11 @@ EditFlagsDescriptor PowerSavingLabels() { tr::lng_settings_power_ui(tr::now), &st::menuIconStartStream, }, + { + kAnimatedUserpics, + tr::lng_settings_power_animated_avatars(tr::now), + &st::menuIconProfile, + }, }; return { .labels = { { tr::lng_settings_power_stickers(), std::move(stickers) }, diff --git a/Telegram/SourceFiles/ui/power_saving.h b/Telegram/SourceFiles/ui/power_saving.h index 6a25e379633c7b..2fca896e03f2df 100644 --- a/Telegram/SourceFiles/ui/power_saving.h +++ b/Telegram/SourceFiles/ui/power_saving.h @@ -21,8 +21,9 @@ enum Flag : uint32 { kCalls = (1U << 8), kEmojiStatus = (1U << 9), kChatEffects = (1U << 10), + kAnimatedUserpics = (1U << 11), - kAll = (1U << 11) - 1, + kAll = (1U << 12) - 1, }; inline constexpr bool is_flag_type(Flag) { return true; } using Flags = base::flags;