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 {
|
|
|
|
|
2020-07-06 08:18:11 +00:00
|
|
|
constexpr auto kMaxBytesLimit = 4000 * 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:
|
|
|
|
void setBytesLimit(int bytesLimit);
|
|
|
|
|
|
|
|
bool hasValue() const;
|
|
|
|
bool shouldDownload(int fileSize) const;
|
|
|
|
int bytesLimit() const;
|
|
|
|
|
|
|
|
qint32 serialize() const;
|
|
|
|
bool setFromSerialized(qint32 serialized);
|
|
|
|
|
|
|
|
private:
|
|
|
|
int _limit = -1;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class Set {
|
|
|
|
public:
|
|
|
|
void setBytesLimit(Type type, int bytesLimit);
|
|
|
|
|
|
|
|
bool hasValue(Type type) const;
|
|
|
|
bool shouldDownload(Type type, int fileSize) const;
|
|
|
|
int bytesLimit(Type type) const;
|
|
|
|
|
|
|
|
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:
|
|
|
|
void setBytesLimit(Source source, Type type, int bytesLimit);
|
|
|
|
|
2019-12-24 10:09:04 +00:00
|
|
|
[[nodiscard]] bool shouldDownload(
|
|
|
|
Source source,
|
|
|
|
Type type,
|
|
|
|
int fileSize) const;
|
|
|
|
[[nodiscard]] int 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);
|
|
|
|
|
|
|
|
[[nodiscard]] Full WithDisabledAutoPlay(const Full &data);
|
|
|
|
|
2018-11-30 12:49:30 +00:00
|
|
|
} // namespace AutoDownload
|
|
|
|
} // namespace Data
|