2018-11-30 12:49:30 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
namespace AutoDownload {
|
|
|
|
|
2022-05-10 14:22:28 +00:00
|
|
|
constexpr auto kMaxBytesLimit = 8000 * int64(512 * 1024);
|
2018-11-30 12:49:30 +00:00
|
|
|
|
|
|
|
enum class Source {
|
|
|
|
User = 0x00,
|
|
|
|
Group = 0x01,
|
|
|
|
Channel = 0x02,
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr auto kSourcesCount = 3;
|
|
|
|
|
|
|
|
enum class Type {
|
2019-12-24 10:09:04 +00:00
|
|
|
Photo = 0x00,
|
|
|
|
AutoPlayVideo = 0x01,
|
|
|
|
VoiceMessage = 0x02,
|
|
|
|
AutoPlayVideoMessage = 0x03,
|
|
|
|
Music = 0x04,
|
|
|
|
AutoPlayGIF = 0x05,
|
|
|
|
File = 0x06,
|
|
|
|
};
|
|
|
|
|
|
|
|
inline constexpr auto kAutoPlayTypes = {
|
|
|
|
Type::AutoPlayVideo,
|
|
|
|
Type::AutoPlayVideoMessage,
|
|
|
|
Type::AutoPlayGIF,
|
2018-11-30 12:49:30 +00:00
|
|
|
};
|
|
|
|
|
2019-12-20 12:56:39 +00:00
|
|
|
inline constexpr auto kStreamedTypes = {
|
|
|
|
Type::VoiceMessage,
|
2019-12-24 10:09:04 +00:00
|
|
|
Type::Music,
|
2019-12-20 12:56:39 +00:00
|
|
|
};
|
|
|
|
|
2018-11-30 12:49:30 +00:00
|
|
|
constexpr auto kTypesCount = 7;
|
|
|
|
|
|
|
|
class Single {
|
|
|
|
public:
|
2022-05-10 14:22:28 +00:00
|
|
|
void setBytesLimit(int64 bytesLimit);
|
2018-11-30 12:49:30 +00:00
|
|
|
|
|
|
|
bool hasValue() const;
|
2022-05-10 14:22:28 +00:00
|
|
|
bool shouldDownload(int64 fileSize) const;
|
|
|
|
int64 bytesLimit() const;
|
2018-11-30 12:49:30 +00:00
|
|
|
|
|
|
|
qint32 serialize() const;
|
|
|
|
bool setFromSerialized(qint32 serialized);
|
|
|
|
|
|
|
|
private:
|
2022-05-10 14:22:28 +00:00
|
|
|
int _limit = -1; // FileSize: Right now any file size fits 32 bit.
|
2018-11-30 12:49:30 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class Set {
|
|
|
|
public:
|
2022-05-10 14:22:28 +00:00
|
|
|
void setBytesLimit(Type type, int64 bytesLimit);
|
2018-11-30 12:49:30 +00:00
|
|
|
|
|
|
|
bool hasValue(Type type) const;
|
2022-05-10 14:22:28 +00:00
|
|
|
bool shouldDownload(Type type, int64 fileSize) const;
|
|
|
|
int64 bytesLimit(Type type) const;
|
2018-11-30 12:49:30 +00:00
|
|
|
|
|
|
|
qint32 serialize(Type type) const;
|
|
|
|
bool setFromSerialized(Type type, qint32 serialized);
|
|
|
|
|
|
|
|
private:
|
|
|
|
const Single &single(Type type) const;
|
|
|
|
Single &single(Type type);
|
|
|
|
|
|
|
|
std::array<Single, kTypesCount> _data;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class Full {
|
|
|
|
public:
|
2022-05-10 14:22:28 +00:00
|
|
|
void setBytesLimit(Source source, Type type, int64 bytesLimit);
|
2018-11-30 12:49:30 +00:00
|
|
|
|
2019-12-24 10:09:04 +00:00
|
|
|
[[nodiscard]] bool shouldDownload(
|
|
|
|
Source source,
|
|
|
|
Type type,
|
2022-05-10 14:22:28 +00:00
|
|
|
int64 fileSize) const;
|
|
|
|
[[nodiscard]] int64 bytesLimit(Source source, Type type) const;
|
2018-11-30 12:49:30 +00:00
|
|
|
|
2019-12-24 10:09:04 +00:00
|
|
|
[[nodiscard]] QByteArray serialize() const;
|
2018-11-30 12:49:30 +00:00
|
|
|
bool setFromSerialized(const QByteArray &serialized);
|
|
|
|
|
2019-12-24 10:09:04 +00:00
|
|
|
[[nodiscard]] static Full FullDisabled();
|
2018-11-30 12:49:30 +00:00
|
|
|
|
|
|
|
private:
|
2019-12-24 10:09:04 +00:00
|
|
|
[[nodiscard]] const Set &set(Source source) const;
|
|
|
|
[[nodiscard]] Set &set(Source source);
|
|
|
|
[[nodiscard]] const Set &setOrDefault(Source source, Type type) const;
|
2018-11-30 12:49:30 +00:00
|
|
|
|
|
|
|
std::array<Set, kSourcesCount> _data;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-12-24 10:09:04 +00:00
|
|
|
[[nodiscard]] bool Should(
|
2018-11-30 12:49:30 +00:00
|
|
|
const Full &data,
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
not_null<DocumentData*> document);
|
2019-12-24 10:09:04 +00:00
|
|
|
[[nodiscard]] bool Should(
|
2018-11-30 12:49:30 +00:00
|
|
|
const Full &data,
|
|
|
|
not_null<DocumentData*> document);
|
2019-12-24 10:09:04 +00:00
|
|
|
[[nodiscard]] bool Should(
|
2018-11-30 12:49:30 +00:00
|
|
|
const Full &data,
|
|
|
|
not_null<PeerData*> peer,
|
2020-05-25 14:16:04 +00:00
|
|
|
not_null<PhotoData*> photo);
|
2018-11-30 12:49:30 +00:00
|
|
|
|
2019-12-24 10:09:04 +00:00
|
|
|
[[nodiscard]] bool ShouldAutoPlay(
|
|
|
|
const Full &data,
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
not_null<DocumentData*> document);
|
2020-07-03 18:57:30 +00:00
|
|
|
[[nodiscard]] bool ShouldAutoPlay(
|
|
|
|
const Full &data,
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
not_null<PhotoData*> photo);
|
2019-12-24 10:09:04 +00:00
|
|
|
|
|
|
|
[[nodiscard]] Full WithDisabledAutoPlay(const Full &data);
|
|
|
|
|
2018-11-30 12:49:30 +00:00
|
|
|
} // namespace AutoDownload
|
|
|
|
} // namespace Data
|