Add file size limit to autoplay settings.

This commit is contained in:
John Preston 2019-12-24 13:09:04 +03:00
parent 8a3506af89
commit 616957e46f
15 changed files with 290 additions and 200 deletions

View File

@ -415,8 +415,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_settings_system_integration" = "System integration";
"lng_settings_performance" = "Performance";
"lng_settings_enable_animations" = "Enable animations";
"lng_settings_autoplay_gifs" = "Autoplay GIFs";
"lng_settings_autoplay_videos" = "Autoplay Videos";
"lng_settings_sensitive_title" = "Sensitive content";
"lng_settings_sensitive_disable_filtering" = "Disable filtering";
"lng_settings_sensitive_about" = "Display sensitive media in public channels on all your Telegram devices.";
@ -1154,12 +1152,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_media_auto_in_groups" = "In groups";
"lng_media_auto_in_channels" = "In channels";
"lng_media_auto_title" = "Automatically download";
"lng_media_auto_play" = "Autoplay";
"lng_media_photo_title" = "Photos";
"lng_media_video_title" = "Video files";
"lng_media_audio_title" = "Voice messages";
"lng_media_video_messages_title" = "Round video messages";
"lng_media_file_title" = "Files";
"lng_media_music_title" = "Music";
"lng_media_animation_title" = "Animated GIFs";
"lng_media_size_limit" = "Limit by size";
"lng_media_size_up_to" = "up to {size}";

View File

@ -25,8 +25,53 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace {
constexpr auto kMegabyte = 1024 * 1024;
constexpr auto kDefaultLimit = 10 * kMegabyte;
constexpr auto kDefaultDownloadLimit = 10 * kMegabyte;
constexpr auto kDefaultAutoPlayLimit = 50 * kMegabyte;
using Type = Data::AutoDownload::Type;
not_null<int*> AddSizeLimitSlider(
not_null<Ui::VerticalLayout*> container,
const base::flat_map<Type, int> &values,
int defaultValue) {
using namespace Settings;
using Pair = base::flat_map<Type, int>::value_type;
const auto limits = Ui::CreateChild<rpl::event_stream<int>>(
container.get());
const auto currentLimit = ranges::max_element(
values,
std::less<>(),
[](Pair pair) { return pair.second; })->second;
const auto initialLimit = currentLimit ? currentLimit : defaultValue;
const auto result = Ui::CreateChild<int>(container.get(), initialLimit);
AddButtonWithLabel(
container,
tr::lng_media_size_limit(),
limits->events_starting_with_copy(
initialLimit
) | rpl::map([](int value) {
return tr::lng_media_size_up_to(
tr::now,
lt_size,
QString::number(value / kMegabyte) + " MB");
}),
st::autoDownloadLimitButton
)->setAttribute(Qt::WA_TransparentForMouseEvents);
const auto slider = container->add(
object_ptr<Ui::MediaSlider>(container, st::autoDownloadLimitSlider),
st::autoDownloadLimitPadding);
slider->resize(st::autoDownloadLimitSlider.seekSize);
slider->setPseudoDiscrete(
Export::View::kSizeValueCount,
Export::View::SizeLimitByIndex,
*result,
[=](int value) {
*result = value;
limits->fire_copy(value);
});
return result;
}
} // namespace
AutoDownloadBox::AutoDownloadBox(
@ -42,12 +87,13 @@ void AutoDownloadBox::prepare() {
}
void AutoDownloadBox::setupContent() {
using namespace rpl::mappers;
using namespace Settings;
using namespace Data::AutoDownload;
using namespace rpl::mappers;
using Type = Data::AutoDownload::Type;
using Pair = base::flat_map<Type, int>::value_type;
setTitle(tr::lng_media_auto_title());
setTitle(tr::lng_profile_settings_section());
const auto settings = &_session->settings().autoDownload();
const auto checked = [=](Source source, Type type) {
@ -60,11 +106,10 @@ void AutoDownloadBox::setupContent() {
this,
std::move(wrap)));
const auto values = Ui::CreateChild<base::flat_map<Type, int>>(content);
const auto add = [&](Type type, rpl::producer<QString> label) {
if (ranges::find(kStreamedTypes, type) != end(kStreamedTypes)) {
return;
}
const auto add = [&](
not_null<base::flat_map<Type, int>*> values,
Type type,
rpl::producer<QString> label) {
const auto value = settings->bytesLimit(_source, type);
AddButton(
content,
@ -78,78 +123,78 @@ void AutoDownloadBox::setupContent() {
}, content->lifetime());
values->emplace(type, value);
};
add(Type::Photo, tr::lng_media_photo_title());
add(Type::VoiceMessage, tr::lng_media_audio_title());
add(Type::VideoMessage, tr::lng_media_video_messages_title());
add(Type::Video, tr::lng_media_video_title());
add(Type::File, tr::lng_media_file_title());
add(Type::Music, tr::lng_media_music_title());
add(Type::GIF, tr::lng_media_animation_title());
const auto limits = Ui::CreateChild<rpl::event_stream<int>>(content);
using Pair = base::flat_map<Type, int>::value_type;
const auto settingsLimit = ranges::max_element(
*values,
std::less<>(),
[](Pair pair) { return pair.second; })->second;
const auto initialLimit = settingsLimit ? settingsLimit : kDefaultLimit;
const auto limit = Ui::CreateChild<int>(content, initialLimit);
AddButtonWithLabel(
AddSubsectionTitle(content, tr::lng_media_auto_title());
const auto downloadValues = Ui::CreateChild<base::flat_map<Type, int>>(
content);
add(downloadValues, Type::Photo, tr::lng_media_photo_title());
add(downloadValues, Type::File, tr::lng_media_file_title());
const auto downloadLimit = AddSizeLimitSlider(
content,
tr::lng_media_size_limit(),
limits->events_starting_with_copy(
initialLimit
) | rpl::map([](int value) {
return tr::lng_media_size_up_to(
tr::now,
lt_size,
QString::number(value / kMegabyte) + " MB");
}),
st::autoDownloadLimitButton
)->setAttribute(Qt::WA_TransparentForMouseEvents);
const auto slider = content->add(
object_ptr<Ui::MediaSlider>(content, st::autoDownloadLimitSlider),
st::autoDownloadLimitPadding);
slider->resize(st::autoDownloadLimitSlider.seekSize);
slider->setPseudoDiscrete(
Export::View::kSizeValueCount,
Export::View::SizeLimitByIndex,
*limit,
[=](int value) {
*limit = value;
limits->fire_copy(value);
});
*downloadValues,
kDefaultDownloadLimit);
AddSkip(content);
AddSubsectionTitle(content, tr::lng_media_auto_play());
const auto autoPlayValues = Ui::CreateChild<base::flat_map<Type, int>>(
content);
add(
autoPlayValues,
Type::AutoPlayVideoMessage,
tr::lng_media_video_messages_title());
add(autoPlayValues, Type::AutoPlayVideo, tr::lng_media_video_title());
add(autoPlayValues, Type::AutoPlayGIF, tr::lng_media_animation_title());
const auto autoPlayLimit = AddSizeLimitSlider(
content,
*autoPlayValues,
kDefaultAutoPlayLimit);
const auto limitByType = [=](Type type) {
return (ranges::find(kAutoPlayTypes, type) != end(kAutoPlayTypes))
? *autoPlayLimit
: *downloadLimit;
};
addButton(tr::lng_connection_save(), [=] {
auto allowMore = ranges::view::all(
*values
) | ranges::view::filter([&](Pair pair) {
auto &&values = ranges::view::concat(
*downloadValues,
*autoPlayValues);
auto allowMore = values | ranges::view::filter([&](Pair pair) {
const auto [type, enabled] = pair;
const auto value = enabled ? *limit : 0;
const auto value = enabled ? limitByType(type) : 0;
const auto old = settings->bytesLimit(_source, type);
return (old < value);
}) | ranges::view::transform([](Pair pair) {
return pair.first;
});
const auto less = ranges::find_if(*autoPlayValues, [&](Pair pair) {
const auto [type, enabled] = pair;
const auto value = enabled ? limitByType(type) : 0;
return value < settings->bytesLimit(_source, type);
}) != end(*autoPlayValues);
const auto allowMoreTypes = base::flat_set<Type>(
allowMore.begin(),
allowMore.end());
const auto changed = ranges::find_if(*values, [&](Pair pair) {
const auto changed = ranges::find_if(values, [&](Pair pair) {
const auto [type, enabled] = pair;
const auto value = enabled ? *limit : 0;
return settings->bytesLimit(_source, type) != value;
}) != end(*values);
const auto value = enabled ? limitByType(type) : 0;
return value != settings->bytesLimit(_source, type);
}) != end(values);
const auto &kHidden = kStreamedTypes;
const auto hiddenChanged = ranges::find_if(kHidden, [&](Type type) {
const auto now = settings->bytesLimit(_source, type);
return (now > 0) && (now != *limit);
return (now > 0) && (now != limitByType(type));
}) != end(kHidden);
if (changed) {
for (const auto [type, enabled] : *values) {
const auto value = enabled ? *limit : 0;
for (const auto [type, enabled] : values) {
const auto value = enabled ? limitByType(type) : 0;
settings->setBytesLimit(_source, type, value);
}
}
@ -157,7 +202,10 @@ void AutoDownloadBox::setupContent() {
for (const auto type : kHidden) {
const auto now = settings->bytesLimit(_source, type);
if (now > 0) {
settings->setBytesLimit(_source, type, *limit);
settings->setBytesLimit(
_source,
type,
limitByType(type));
}
}
}
@ -171,6 +219,9 @@ void AutoDownloadBox::setupContent() {
!= allowMoreTypes.end()) {
_session->data().documentLoadSettingsChanged();
}
if (less) {
_session->data().checkPlayingVideoFiles();
}
closeBox();
});
addButton(tr::lng_cancel(), [=] { closeBox(); });

View File

@ -20,7 +20,9 @@ namespace AutoDownload {
namespace {
constexpr auto kDefaultMaxSize = 8 * 1024 * 1024;
constexpr auto kVersion = char(1);
constexpr auto kDefaultAutoPlaySize = 50 * 1024 * 1024;
constexpr auto kVersion1 = char(1);
constexpr auto kVersion = char(2);
template <typename Enum>
auto enums_view(int from, int till) {
@ -38,13 +40,16 @@ auto enums_view(int till) {
void SetDefaultsForSource(Full &data, Source source) {
data.setBytesLimit(source, Type::Photo, kDefaultMaxSize);
data.setBytesLimit(source, Type::VoiceMessage, kDefaultMaxSize);
data.setBytesLimit(source, Type::VideoMessage, kDefaultMaxSize);
data.setBytesLimit(source, Type::GIF, kDefaultMaxSize);
data.setBytesLimit(
source,
Type::AutoPlayVideoMessage,
kDefaultAutoPlaySize);
data.setBytesLimit(source, Type::AutoPlayGIF, kDefaultAutoPlaySize);
const auto channelsFileLimit = (source == Source::Channel)
? 0
: kDefaultMaxSize;
data.setBytesLimit(source, Type::File, channelsFileLimit);
data.setBytesLimit(source, Type::Video, channelsFileLimit);
data.setBytesLimit(source, Type::AutoPlayVideo, kDefaultAutoPlaySize);
data.setBytesLimit(source, Type::Music, channelsFileLimit);
}
@ -69,19 +74,12 @@ Source SourceFromPeer(not_null<PeerData*> peer) {
}
}
Type TypeFromDocument(not_null<DocumentData*> document) {
if (document->isSong()) {
return Type::Music;
} else if (document->isVoiceMessage()) {
return Type::VoiceMessage;
} else if (document->isVideoMessage()) {
return Type::VideoMessage;
} else if (document->isAnimation()) {
return Type::GIF;
} else if (document->isVideoFile()) {
return Type::Video;
}
return Type::File;
Type AutoPlayTypeFromDocument(not_null<DocumentData*> document) {
return document->isVideoFile()
? Type::AutoPlayVideo
: document->isVideoMessage()
? Type::AutoPlayVideoMessage
: Type::AutoPlayGIF;
}
} // namespace
@ -223,7 +221,7 @@ bool Full::setFromSerialized(const QByteArray &serialized) {
stream >> version;
if (stream.status() != QDataStream::Ok) {
return false;
} else if (version != kVersion) {
} else if (version != kVersion && version != kVersion1) {
return false;
}
auto temp = Full();
@ -236,6 +234,15 @@ bool Full::setFromSerialized(const QByteArray &serialized) {
}
}
}
if (version == kVersion1) {
for (const auto source : enums_view<Source>(kSourcesCount)) {
for (const auto type : kAutoPlayTypes) {
temp.setBytesLimit(source, type, std::max(
temp.bytesLimit(source, type),
kDefaultAutoPlaySize));
}
}
}
_data = temp._data;
return true;
}
@ -259,7 +266,7 @@ bool Should(
}
return data.shouldDownload(
SourceFromPeer(peer),
TypeFromDocument(document),
Type::File,
document->size);
}
@ -269,11 +276,10 @@ bool Should(
if (document->sticker()) {
return true;
}
const auto type = TypeFromDocument(document);
const auto size = document->size;
return data.shouldDownload(Source::User, type, size)
|| data.shouldDownload(Source::Group, type, size)
|| data.shouldDownload(Source::Channel, type, size);
return data.shouldDownload(Source::User, Type::File, size)
|| data.shouldDownload(Source::Group, Type::File, size)
|| data.shouldDownload(Source::Channel, Type::File, size);
}
bool Should(
@ -286,5 +292,25 @@ bool Should(
image->bytesSize());
}
bool ShouldAutoPlay(
const Full &data,
not_null<PeerData*> peer,
not_null<DocumentData*> document) {
return data.shouldDownload(
SourceFromPeer(peer),
AutoPlayTypeFromDocument(document),
document->size);
}
Full WithDisabledAutoPlay(const Full &data) {
auto result = data;
for (const auto source : enums_view<Source>(kSourcesCount)) {
for (const auto type : kAutoPlayTypes) {
result.setBytesLimit(source, type, 0);
}
}
return result;
}
} // namespace AutoDownload
} // namespace Data

View File

@ -27,21 +27,24 @@ enum class Source {
constexpr auto kSourcesCount = 3;
enum class Type {
Photo = 0x00,
Video = 0x01,
VoiceMessage = 0x02,
VideoMessage = 0x03,
Music = 0x04,
GIF = 0x05,
File = 0x06,
Photo = 0x00,
AutoPlayVideo = 0x01,
VoiceMessage = 0x02,
AutoPlayVideoMessage = 0x03,
Music = 0x04,
AutoPlayGIF = 0x05,
File = 0x06,
};
inline constexpr auto kAutoPlayTypes = {
Type::AutoPlayVideo,
Type::AutoPlayVideoMessage,
Type::AutoPlayGIF,
};
inline constexpr auto kStreamedTypes = {
Type::Video,
Type::Music,
Type::VoiceMessage,
Type::VideoMessage,
Type::GIF,
Type::Music,
};
constexpr auto kTypesCount = 7;
@ -85,34 +88,44 @@ class Full {
public:
void setBytesLimit(Source source, Type type, int bytesLimit);
bool shouldDownload(Source source, Type type, int fileSize) const;
int bytesLimit(Source source, Type type) const;
[[nodiscard]] bool shouldDownload(
Source source,
Type type,
int fileSize) const;
[[nodiscard]] int bytesLimit(Source source, Type type) const;
QByteArray serialize() const;
[[nodiscard]] QByteArray serialize() const;
bool setFromSerialized(const QByteArray &serialized);
static Full FullDisabled();
[[nodiscard]] static Full FullDisabled();
private:
const Set &set(Source source) const;
Set &set(Source source);
const Set &setOrDefault(Source source, Type type) const;
[[nodiscard]] const Set &set(Source source) const;
[[nodiscard]] Set &set(Source source);
[[nodiscard]] const Set &setOrDefault(Source source, Type type) const;
std::array<Set, kSourcesCount> _data;
};
bool Should(
[[nodiscard]] bool Should(
const Full &data,
not_null<PeerData*> peer,
not_null<DocumentData*> document);
bool Should(
[[nodiscard]] bool Should(
const Full &data,
not_null<DocumentData*> document);
bool Should(
[[nodiscard]] bool Should(
const Full &data,
not_null<PeerData*> peer,
not_null<Images::Source*> image);
[[nodiscard]] bool ShouldAutoPlay(
const Full &data,
not_null<PeerData*> peer,
not_null<DocumentData*> document);
[[nodiscard]] Full WithDisabledAutoPlay(const Full &data);
} // namespace AutoDownload
} // namespace Data

View File

@ -1046,15 +1046,22 @@ void InnerWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
cancelContextDownload(document);
});
} else {
if (document->loaded()
&& document->isGifv()
&& !document->session().settings().autoplayGifs()) {
const auto itemId = view
? view->data()->fullId()
: FullMsgId();
_menu->addAction(tr::lng_context_open_gif(tr::now), [=] {
openContextGif(itemId);
});
const auto itemId = view
? view->data()->fullId()
: FullMsgId();
if (const auto item = document->session().data().message(itemId)) {
const auto notAutoplayedGif = [&] {
return document->isGifv()
&& Data::AutoDownload::ShouldAutoPlay(
document->session().settings().autoDownload(),
item->history()->peer,
document);
}();
if (notAutoplayedGif) {
_menu->addAction(tr::lng_context_open_gif(tr::now), [=] {
openContextGif(itemId);
});
}
}
if (!document->filepath(DocumentData::FilePathResolve::Checked).isEmpty()) {
_menu->addAction(Platform::IsMac() ? tr::lng_context_show_in_finder(tr::now) : tr::lng_context_show_in_folder(tr::now), [=] {

View File

@ -1568,8 +1568,16 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
const auto lnkIsVideo = document->isVideoFile();
const auto lnkIsVoice = document->isVoiceMessage();
const auto lnkIsAudio = document->isAudioFile();
if (document->loaded() && document->isGifv()) {
if (!document->session().settings().autoplayGifs()) {
if (document->isGifv()) {
const auto notAutoplayedGif = [&] {
return item
&& document->isGifv()
&& Data::AutoDownload::ShouldAutoPlay(
document->session().settings().autoDownload(),
item->history()->peer,
document);
}();
if (notAutoplayedGif) {
_menu->addAction(tr::lng_context_open_gif(tr::now), [=] {
openContextGif(itemId);
});

View File

@ -168,12 +168,19 @@ void AddDocumentActions(
});
return;
}
if (document->loaded()
&& document->isGifv()
&& !document->session().settings().autoplayGifs()) {
menu->addAction(tr::lng_context_open_gif(tr::now), [=] {
OpenGif(contextId);
});
if (const auto item = document->session().data().message(contextId)) {
const auto notAutoplayedGif = [&] {
return document->isGifv()
&& Data::AutoDownload::ShouldAutoPlay(
document->session().settings().autoDownload(),
item->history()->peer,
document);
}();
if (notAutoplayedGif) {
menu->addAction(tr::lng_context_open_gif(tr::now), [=] {
OpenGif(contextId);
});
}
}
if (document->sticker()
&& document->sticker()->set.type() != mtpc_inputStickerSetEmpty) {

View File

@ -211,7 +211,9 @@ void Document::draw(Painter &p, const QRect &r, TextSelection selection, crl::ti
const auto cornerDownload = downloadInCorner();
_data->automaticLoad(_realParent->fullId(), _parent->data());
if (!_data->canBePlayed()) {
_data->automaticLoad(_realParent->fullId(), _parent->data());
}
bool loaded = _data->loaded(), displayLoading = _data->displayLoading();
bool selected = (selection == FullSelection);

View File

@ -238,9 +238,10 @@ bool Gif::downloadInCorner() const {
}
bool Gif::autoplayEnabled() const {
return _data->isVideoFile()
? history()->session().settings().autoplayVideos()
: history()->session().settings().autoplayGifs();
return Data::AutoDownload::ShouldAutoPlay(
_data->session().settings().autoDownload(),
_realParent->history()->peer,
_data);
}
void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms) const {
@ -415,8 +416,7 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms
if (radial
|| (!streamingMode
&& ((!_data->loaded() && !_data->loading())
|| !autoplayEnabled()))) {
&& ((!_data->loaded() && !_data->loading()) || !autoplay))) {
const auto radialOpacity = item->isSending()
? 1.
: streamed
@ -923,8 +923,7 @@ void Gif::drawGrouped(
if (radial
|| (!streamingMode
&& ((!_data->loaded() && !_data->loading())
|| !autoplayEnabled()))) {
&& ((!_data->loaded() && !_data->loading()) || !autoplay))) {
const auto radialOpacity = item->isSending()
? 1.
: streamed

View File

@ -19,6 +19,8 @@ namespace {
constexpr auto kAutoLockTimeoutLateMs = crl::time(3000);
constexpr auto kLegacyCallsPeerToPeerNobody = 4;
constexpr auto kVersionTag = -1;
constexpr auto kVersion = 1;
} // namespace
@ -45,6 +47,7 @@ QByteArray Settings::serialize() const {
{
QDataStream stream(&result, QIODevice::WriteOnly);
stream.setVersion(QDataStream::Qt_5_1);
stream << qint32(kVersionTag) << qint32(kVersion);
stream << static_cast<qint32>(_variables.selectorTab);
stream << qint32(_variables.lastSeenWarningSeen ? 1 : 0);
stream << qint32(_variables.tabbedSelectorSectionEnabled ? 1 : 0);
@ -83,14 +86,13 @@ QByteArray Settings::serialize() const {
stream << qint32(_variables.notifyAboutPinned.current() ? 1 : 0);
stream << qint32(_variables.archiveInMainMenu.current() ? 1 : 0);
stream << qint32(_variables.skipArchiveInSearch.current() ? 1 : 0);
stream << qint32(_variables.autoplayGifs ? 1 : 0);
stream << qint32(0);// LEGACY _variables.autoplayGifs ? 1 : 0);
stream << qint32(_variables.loopAnimatedStickers ? 1 : 0);
stream << qint32(_variables.largeEmoji.current() ? 1 : 0);
stream << qint32(_variables.replaceEmoji.current() ? 1 : 0);
stream << qint32(_variables.suggestEmoji ? 1 : 0);
stream << qint32(_variables.suggestStickersByEmoji ? 1 : 0);
stream << qint32(_variables.spellcheckerEnabled.current() ? 1 : 0);
stream << qint32(_variables.autoplayVideos ? 1 : 0);
}
return result;
}
@ -102,6 +104,8 @@ void Settings::constructFromSerialized(const QByteArray &serialized) {
QDataStream stream(serialized);
stream.setVersion(QDataStream::Qt_5_1);
qint32 versionTag = 0;
qint32 version = 0;
qint32 selectorTab = static_cast<qint32>(ChatHelpers::SelectorTab::Emoji);
qint32 lastSeenWarningSeen = 0;
qint32 tabbedSelectorSectionEnabled = 1;
@ -131,16 +135,21 @@ void Settings::constructFromSerialized(const QByteArray &serialized) {
qint32 notifyAboutPinned = _variables.notifyAboutPinned.current() ? 1 : 0;
qint32 archiveInMainMenu = _variables.archiveInMainMenu.current() ? 1 : 0;
qint32 skipArchiveInSearch = _variables.skipArchiveInSearch.current() ? 1 : 0;
qint32 autoplayGifs = _variables.autoplayGifs ? 1 : 0;
qint32 autoplayGifs = 1;
qint32 loopAnimatedStickers = _variables.loopAnimatedStickers ? 1 : 0;
qint32 largeEmoji = _variables.largeEmoji.current() ? 1 : 0;
qint32 replaceEmoji = _variables.replaceEmoji.current() ? 1 : 0;
qint32 suggestEmoji = _variables.suggestEmoji ? 1 : 0;
qint32 suggestStickersByEmoji = _variables.suggestStickersByEmoji ? 1 : 0;
qint32 spellcheckerEnabled = _variables.spellcheckerEnabled.current() ? 1 : 0;
qint32 autoplayVideos = _variables.autoplayVideos ? 1 : 0;
stream >> selectorTab;
stream >> versionTag;
if (versionTag == kVersionTag) {
stream >> version;
stream >> selectorTab;
} else {
selectorTab = versionTag;
}
stream >> lastSeenWarningSeen;
if (!stream.atEnd()) {
stream >> tabbedSelectorSectionEnabled;
@ -241,9 +250,6 @@ void Settings::constructFromSerialized(const QByteArray &serialized) {
if (!stream.atEnd()) {
stream >> spellcheckerEnabled;
}
if (!stream.atEnd()) {
stream >> autoplayVideos;
}
if (stream.status() != QDataStream::Ok) {
LOG(("App Error: "
"Bad data for Main::Settings::constructFromSerialized()"));
@ -253,6 +259,13 @@ void Settings::constructFromSerialized(const QByteArray &serialized) {
&& !_variables.autoDownload.setFromSerialized(autoDownload)) {
return;
}
if (!version) {
if (!autoplayGifs) {
using namespace Data::AutoDownload;
_variables.autoDownload = WithDisabledAutoPlay(
_variables.autoDownload);
}
}
auto uncheckedTab = static_cast<ChatHelpers::SelectorTab>(selectorTab);
switch (uncheckedTab) {
@ -317,14 +330,12 @@ void Settings::constructFromSerialized(const QByteArray &serialized) {
_variables.notifyAboutPinned = (notifyAboutPinned == 1);
_variables.archiveInMainMenu = (archiveInMainMenu == 1);
_variables.skipArchiveInSearch = (skipArchiveInSearch == 1);
_variables.autoplayGifs = (autoplayGifs == 1);
_variables.loopAnimatedStickers = (loopAnimatedStickers == 1);
_variables.largeEmoji = (largeEmoji == 1);
_variables.replaceEmoji = (replaceEmoji == 1);
_variables.suggestEmoji = (suggestEmoji == 1);
_variables.suggestStickersByEmoji = (suggestStickersByEmoji == 1);
_variables.spellcheckerEnabled = (spellcheckerEnabled == 1);
_variables.autoplayVideos = (autoplayVideos == 1);
}
void Settings::setSupportChatsTimeSlice(int slice) {

View File

@ -198,18 +198,6 @@ public:
void setExeLaunchWarning(bool warning) {
_variables.exeLaunchWarning = warning;
}
[[nodiscard]] bool autoplayGifs() const {
return _variables.autoplayGifs;
}
void setAutoplayGifs(bool value) {
_variables.autoplayGifs = value;
}
[[nodiscard]] bool autoplayVideos() const {
return _variables.autoplayVideos;
}
void setAutoplayVideos(bool value) {
_variables.autoplayVideos = value;
}
[[nodiscard]] bool loopAnimatedStickers() const {
return _variables.loopAnimatedStickers;
}
@ -283,8 +271,6 @@ private:
rpl::variable<bool> archiveInMainMenu = false;
rpl::variable<bool> notifyAboutPinned = true;
rpl::variable<bool> skipArchiveInSearch = false;
bool autoplayGifs = true;
bool autoplayVideos = true;
bool loopAnimatedStickers = true;
rpl::variable<bool> largeEmoji = true;
rpl::variable<bool> replaceEmoji = true;

View File

@ -1856,14 +1856,15 @@ void OverlayWidget::displayDocument(
_doc->dimensions.height());
}
} else {
_doc->automaticLoad(fileOrigin(), item);
if (_doc->canBePlayed() && initStreaming()) {
} else if (_doc->isVideoFile()) {
_doc->automaticLoad(fileOrigin(), item);
initStreamingThumbnail();
} else if (_doc->isTheme()) {
_doc->automaticLoad(fileOrigin(), item);
initThemePreview();
} else {
_doc->automaticLoad(fileOrigin(), item);
auto &location = _doc->location(true);
if (location.accessEnable()) {
const auto &path = location.name();
@ -3216,7 +3217,9 @@ void OverlayWidget::preloadData(int delta) {
image->load(fileOrigin());
} else {
(*document)->loadThumbnail(fileOrigin());
(*document)->automaticLoad(fileOrigin(), entity.item);
if (!(*document)->canBePlayed()) {
(*document)->automaticLoad(fileOrigin(), entity.item);
}
}
}
}

View File

@ -429,7 +429,6 @@ void Video::paint(Painter &p, const QRect &clip, TextSelection selection, const
const auto thumbLoaded = _data->hasThumbnail()
&& _data->thumbnail()->loaded();
_data->automaticLoad(parent()->fullId(), parent());
bool loaded = _data->loaded(), displayLoading = _data->displayLoading();
if (displayLoading) {
ensureRadial();
@ -621,8 +620,6 @@ void Voice::initDimensions() {
void Voice::paint(Painter &p, const QRect &clip, TextSelection selection, const PaintContext *context) {
bool selected = (selection == FullSelection);
_data->automaticLoad(parent()->fullId(), parent());
bool loaded = _data->loaded(), displayLoading = _data->displayLoading();
if (displayLoading) {

View File

@ -452,41 +452,6 @@ void SetupPerformance(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container) {
SetupAnimations(container);
const auto session = &controller->session();
AddButton(
container,
tr::lng_settings_autoplay_gifs(),
st::settingsButton
)->toggleOn(
rpl::single(session->settings().autoplayGifs())
)->toggledValue(
) | rpl::filter([=](bool enabled) {
return (enabled != session->settings().autoplayGifs());
}) | rpl::start_with_next([=](bool enabled) {
session->settings().setAutoplayGifs(enabled);
if (!enabled) {
session->data().checkPlayingVideoFiles();
}
session->saveSettingsDelayed();
}, container->lifetime());
AddButton(
container,
tr::lng_settings_autoplay_videos(),
st::settingsButton
)->toggleOn(
rpl::single(session->settings().autoplayVideos())
)->toggledValue(
) | rpl::filter([=](bool enabled) {
return (enabled != session->settings().autoplayVideos());
}) | rpl::start_with_next([=](bool enabled) {
session->settings().setAutoplayVideos(enabled);
if (!enabled) {
session->data().checkPlayingVideoFiles();
}
session->saveSettingsDelayed();
}, container->lifetime());
}
void SetupSystemIntegration(

View File

@ -1117,8 +1117,8 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting
};
set(Type::Photo, photo);
set(Type::VoiceMessage, audio);
set(Type::GIF, gif);
set(Type::VideoMessage, gif);
set(Type::AutoPlayGIF, gif);
set(Type::AutoPlayVideoMessage, gif);
} break;
case dbiAutoPlayOld: {
@ -1126,7 +1126,25 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting
stream >> gif;
if (!_checkStreamStatus(stream)) return false;
GetStoredSessionSettings().setAutoplayGifs(gif == 1);
if (!gif) {
using namespace Data::AutoDownload;
auto &settings = GetStoredSessionSettings().autoDownload();
const auto types = {
Type::AutoPlayGIF,
Type::AutoPlayVideo,
Type::AutoPlayVideoMessage,
};
const auto sources = {
Source::User,
Source::Group,
Source::Channel
};
for (const auto source : sources) {
for (const auto type : types) {
settings.setBytesLimit(source, type, 0);
}
}
}
} break;
case dbiDialogsMode: {