From 1940c67a096d4bef3df9e0857748881cb8e0a4a3 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 1 Mar 2019 17:11:47 +0400 Subject: [PATCH] Disable music / video autodownload. --- .../SourceFiles/boxes/auto_download_box.cpp | 30 ++++++++++++------- .../SourceFiles/data/data_auto_download.cpp | 4 +++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Telegram/SourceFiles/boxes/auto_download_box.cpp b/Telegram/SourceFiles/boxes/auto_download_box.cpp index 21ac7a314..51ac639cd 100644 --- a/Telegram/SourceFiles/boxes/auto_download_box.cpp +++ b/Telegram/SourceFiles/boxes/auto_download_box.cpp @@ -56,8 +56,13 @@ void AutoDownloadBox::setupContent() { this, std::move(wrap))); + static const auto kHidden = { Type::Video, Type::Music }; + const auto values = Ui::CreateChild>(content); const auto add = [&](Type type, LangKey label) { + if (ranges::find(kHidden, type) != end(kHidden)) { + return; + } const auto value = settings->bytesLimit(_source, type); AddButton( content, @@ -111,16 +116,6 @@ void AutoDownloadBox::setupContent() { *limit = value; limits->fire_copy(value); }); - const auto save = [=]( - Type type, - std::pair pair) { - const auto limit = [](bool checked) { - return checked ? kMaxBytesLimit : 0; - }; - settings->setBytesLimit(Source::User, type, limit(pair.first)); - settings->setBytesLimit(Source::Group, type, limit(pair.second)); - settings->setBytesLimit(Source::Channel, type, limit(pair.second)); - }; addButton(langFactory(lng_connection_save), [=] { auto allowMore = ranges::view::all( @@ -143,11 +138,26 @@ void AutoDownloadBox::setupContent() { return settings->bytesLimit(_source, type) != value; }) != end(*values); + const auto hiddenChanged = ranges::find_if(kHidden, [&](Type type) { + const auto now = settings->bytesLimit(_source, type); + return (now > 0) && (now != *limit); + }) != end(kHidden); + if (changed) { for (const auto [type, enabled] : *values) { const auto value = enabled ? *limit : 0; settings->setBytesLimit(_source, type, value); } + } + if (hiddenChanged) { + for (const auto type : kHidden) { + const auto now = settings->bytesLimit(_source, type); + if (now > 0) { + settings->setBytesLimit(_source, type, *limit); + } + } + } + if (changed || hiddenChanged) { Local::writeUserSettings(); } if (allowMoreTypes.contains(Type::Photo)) { diff --git a/Telegram/SourceFiles/data/data_auto_download.cpp b/Telegram/SourceFiles/data/data_auto_download.cpp index 594798eab..66a75440f 100644 --- a/Telegram/SourceFiles/data/data_auto_download.cpp +++ b/Telegram/SourceFiles/data/data_auto_download.cpp @@ -181,6 +181,10 @@ void Full::setBytesLimit(Source source, Type type, int bytesLimit) { } bool Full::shouldDownload(Source source, Type type, int fileSize) const { + if (type == Type::Video || type == Type::Music) { + // With streaming we disable autodownload and hide them in Settings. + return false; + } return setOrDefault(source, type).shouldDownload(type, fileSize); }