2017-09-26 11:49:16 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-09-26 11:49:16 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-09-26 11:49:16 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "data/data_types.h"
|
2020-05-26 11:59:45 +00:00
|
|
|
#include "data/data_cloud_file.h"
|
2017-09-26 11:49:16 +00:00
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
2019-01-25 14:37:28 +00:00
|
|
|
|
2020-07-03 10:48:55 +00:00
|
|
|
namespace Media {
|
|
|
|
namespace Streaming {
|
|
|
|
class Loader;
|
|
|
|
} // namespace Streaming
|
|
|
|
} // namespace Media
|
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
namespace Data {
|
2020-05-25 14:16:04 +00:00
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
class Session;
|
2020-04-08 15:09:29 +00:00
|
|
|
class ReplyPreview;
|
2020-05-25 14:16:04 +00:00
|
|
|
class PhotoMedia;
|
|
|
|
|
|
|
|
inline constexpr auto kPhotoSizeCount = 3;
|
|
|
|
|
|
|
|
enum class PhotoSize : uchar {
|
|
|
|
Small,
|
|
|
|
Thumbnail,
|
|
|
|
Large,
|
|
|
|
};
|
|
|
|
|
|
|
|
[[nodiscard]] inline int PhotoSizeIndex(PhotoSize size) {
|
2020-05-29 18:06:40 +00:00
|
|
|
Expects(static_cast<int>(size) < kPhotoSizeCount);
|
2020-05-25 14:16:04 +00:00
|
|
|
|
|
|
|
return static_cast<int>(size);
|
|
|
|
}
|
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
} // namespace Data
|
|
|
|
|
2020-04-08 15:09:29 +00:00
|
|
|
class PhotoData final {
|
2017-09-26 11:49:16 +00:00
|
|
|
public:
|
2019-01-25 14:37:28 +00:00
|
|
|
PhotoData(not_null<Data::Session*> owner, PhotoId id);
|
2020-04-08 15:09:29 +00:00
|
|
|
~PhotoData();
|
2019-01-25 14:37:28 +00:00
|
|
|
|
|
|
|
[[nodiscard]] Data::Session &owner() const;
|
2019-07-24 11:45:24 +00:00
|
|
|
[[nodiscard]] Main::Session &session() const;
|
2020-05-25 14:16:04 +00:00
|
|
|
[[nodiscard]] bool isNull() const;
|
2017-09-26 11:49:16 +00:00
|
|
|
|
|
|
|
void automaticLoadSettingsChanged();
|
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
[[nodiscard]] bool loading() const;
|
|
|
|
[[nodiscard]] bool displayLoading() const;
|
2017-09-26 11:49:16 +00:00
|
|
|
void cancel();
|
2019-01-25 14:37:28 +00:00
|
|
|
[[nodiscard]] float64 progress() const;
|
|
|
|
[[nodiscard]] int32 loadOffset() const;
|
|
|
|
[[nodiscard]] bool uploading() const;
|
2020-05-25 14:16:04 +00:00
|
|
|
[[nodiscard]] bool cancelled() const;
|
2017-09-26 11:49:16 +00:00
|
|
|
|
2017-12-25 14:17:00 +00:00
|
|
|
void setWaitingForAlbum();
|
2019-01-25 14:37:28 +00:00
|
|
|
[[nodiscard]] bool waitingForAlbum() const;
|
2017-12-25 14:17:00 +00:00
|
|
|
|
2021-12-03 10:59:08 +00:00
|
|
|
[[nodiscard]] Image *getReplyPreview(
|
|
|
|
Data::FileOrigin origin,
|
2022-12-30 09:37:34 +00:00
|
|
|
not_null<PeerData*> context,
|
|
|
|
bool spoiler);
|
2021-12-03 10:59:08 +00:00
|
|
|
[[nodiscard]] Image *getReplyPreview(not_null<HistoryItem*> item);
|
2022-12-30 09:37:34 +00:00
|
|
|
[[nodiscard]] bool replyPreviewLoaded(bool spoiler) const;
|
2017-09-26 11:49:16 +00:00
|
|
|
|
2019-03-22 14:19:43 +00:00
|
|
|
void setRemoteLocation(
|
|
|
|
int32 dc,
|
|
|
|
uint64 access,
|
|
|
|
const QByteArray &fileReference);
|
2019-01-25 14:37:28 +00:00
|
|
|
[[nodiscard]] MTPInputPhoto mtpInput() const;
|
2019-03-22 14:19:43 +00:00
|
|
|
[[nodiscard]] QByteArray fileReference() const;
|
|
|
|
void refreshFileReference(const QByteArray &value);
|
2018-07-13 16:49:46 +00:00
|
|
|
|
2018-08-27 11:35:58 +00:00
|
|
|
// When we have some client-side generated photo
|
|
|
|
// (for example for displaying an external inline bot result)
|
|
|
|
// and it has downloaded full image, we can collect image from it
|
|
|
|
// to (this) received from the server "same" photo.
|
2019-01-25 14:37:28 +00:00
|
|
|
void collectLocalData(not_null<PhotoData*> local);
|
|
|
|
|
2020-05-25 14:16:04 +00:00
|
|
|
[[nodiscard]] std::shared_ptr<Data::PhotoMedia> createMediaView();
|
|
|
|
[[nodiscard]] auto activeMediaView() const
|
|
|
|
-> std::shared_ptr<Data::PhotoMedia>;
|
2019-01-25 14:37:28 +00:00
|
|
|
|
2020-05-25 14:16:04 +00:00
|
|
|
void updateImages(
|
|
|
|
const QByteArray &inlineThumbnailBytes,
|
|
|
|
const ImageWithLocation &small,
|
|
|
|
const ImageWithLocation &thumbnail,
|
2020-07-03 08:42:09 +00:00
|
|
|
const ImageWithLocation &large,
|
2022-06-03 11:58:02 +00:00
|
|
|
const ImageWithLocation &videoSmall,
|
|
|
|
const ImageWithLocation &videoLarge,
|
2020-07-03 10:48:55 +00:00
|
|
|
crl::time videoStartTime);
|
2020-05-26 10:13:32 +00:00
|
|
|
[[nodiscard]] int validSizeIndex(Data::PhotoSize size) const;
|
2020-08-25 18:03:41 +00:00
|
|
|
[[nodiscard]] int existingSizeIndex(Data::PhotoSize size) const;
|
2019-01-25 14:37:28 +00:00
|
|
|
|
2020-05-25 14:16:04 +00:00
|
|
|
[[nodiscard]] QByteArray inlineThumbnailBytes() const {
|
|
|
|
return _inlineThumbnailBytes;
|
|
|
|
}
|
2020-05-30 18:37:03 +00:00
|
|
|
void clearInlineThumbnailBytes() {
|
|
|
|
_inlineThumbnailBytes = QByteArray();
|
|
|
|
}
|
2020-05-25 14:16:04 +00:00
|
|
|
|
|
|
|
void load(
|
|
|
|
Data::FileOrigin origin,
|
|
|
|
LoadFromCloudSetting fromCloud = LoadFromCloudOrLocal,
|
|
|
|
bool autoLoading = false);
|
|
|
|
|
2020-05-26 10:13:32 +00:00
|
|
|
[[nodiscard]] static int SideLimit();
|
|
|
|
|
|
|
|
[[nodiscard]] bool hasExact(Data::PhotoSize size) const;
|
2020-05-25 14:16:04 +00:00
|
|
|
[[nodiscard]] bool loading(Data::PhotoSize size) const;
|
|
|
|
[[nodiscard]] bool failed(Data::PhotoSize size) const;
|
2020-08-26 13:28:56 +00:00
|
|
|
void clearFailed(Data::PhotoSize size);
|
2020-05-25 14:16:04 +00:00
|
|
|
void load(
|
|
|
|
Data::PhotoSize size,
|
|
|
|
Data::FileOrigin origin,
|
|
|
|
LoadFromCloudSetting fromCloud = LoadFromCloudOrLocal,
|
|
|
|
bool autoLoading = false);
|
|
|
|
[[nodiscard]] const ImageLocation &location(Data::PhotoSize size) const;
|
2020-05-26 10:13:32 +00:00
|
|
|
[[nodiscard]] std::optional<QSize> size(Data::PhotoSize size) const;
|
2020-05-25 14:16:04 +00:00
|
|
|
[[nodiscard]] int imageByteSize(Data::PhotoSize size) const;
|
2019-01-25 14:37:28 +00:00
|
|
|
|
2020-07-03 08:42:09 +00:00
|
|
|
[[nodiscard]] bool hasVideo() const;
|
2022-06-15 12:50:53 +00:00
|
|
|
[[nodiscard]] bool hasVideoSmall() const;
|
2022-06-03 11:58:02 +00:00
|
|
|
[[nodiscard]] bool videoLoading(Data::PhotoSize size) const;
|
|
|
|
[[nodiscard]] bool videoFailed(Data::PhotoSize size) const;
|
|
|
|
void loadVideo(Data::PhotoSize size, Data::FileOrigin origin);
|
|
|
|
[[nodiscard]] const ImageLocation &videoLocation(
|
|
|
|
Data::PhotoSize size) const;
|
|
|
|
[[nodiscard]] int videoByteSize(Data::PhotoSize size) const;
|
|
|
|
[[nodiscard]] crl::time videoStartPosition() const;
|
|
|
|
void setVideoPlaybackFailed();
|
|
|
|
[[nodiscard]] bool videoPlaybackFailed() const;
|
2020-07-03 10:48:55 +00:00
|
|
|
[[nodiscard]] bool videoCanBePlayed() const;
|
|
|
|
[[nodiscard]] auto createStreamingLoader(
|
|
|
|
Data::FileOrigin origin,
|
|
|
|
bool forceRemoteLoader) const
|
|
|
|
-> std::unique_ptr<Media::Streaming::Loader>;
|
2020-07-03 08:42:09 +00:00
|
|
|
|
2020-10-30 00:07:59 +00:00
|
|
|
[[nodiscard]] bool hasAttachedStickers() const;
|
|
|
|
void setHasAttachedStickers(bool value);
|
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
// For now they return size of the 'large' image.
|
|
|
|
int width() const;
|
|
|
|
int height() const;
|
|
|
|
|
2018-07-13 16:49:46 +00:00
|
|
|
PhotoId id = 0;
|
|
|
|
TimeId date = 0;
|
2017-09-26 11:49:16 +00:00
|
|
|
|
|
|
|
PeerData *peer = nullptr; // for chat and channel photos connection
|
|
|
|
// geo, caption
|
|
|
|
|
2017-12-25 14:17:00 +00:00
|
|
|
std::unique_ptr<Data::UploadState> uploadingData;
|
2017-09-26 11:49:16 +00:00
|
|
|
|
2018-11-09 15:03:38 +00:00
|
|
|
private:
|
2022-06-03 11:58:02 +00:00
|
|
|
[[nodiscard]] Data::CloudFile &videoFile(Data::PhotoSize size);
|
|
|
|
[[nodiscard]] const Data::CloudFile &videoFile(
|
|
|
|
Data::PhotoSize size) const;
|
|
|
|
|
|
|
|
struct VideoSizes {
|
|
|
|
Data::CloudFile small;
|
|
|
|
Data::CloudFile large;
|
|
|
|
crl::time startTime = 0;
|
|
|
|
bool playbackFailed = false;
|
|
|
|
};
|
2020-05-25 14:16:04 +00:00
|
|
|
QByteArray _inlineThumbnailBytes;
|
2020-05-26 11:59:45 +00:00
|
|
|
std::array<Data::CloudFile, Data::kPhotoSizeCount> _images;
|
2022-06-03 11:58:02 +00:00
|
|
|
std::unique_ptr<VideoSizes> _videoSizes;
|
2019-01-25 14:37:28 +00:00
|
|
|
|
2019-03-22 14:19:43 +00:00
|
|
|
int32 _dc = 0;
|
|
|
|
uint64 _access = 0;
|
2020-10-30 00:07:59 +00:00
|
|
|
bool _hasStickers = false;
|
2019-03-22 14:19:43 +00:00
|
|
|
QByteArray _fileReference;
|
2020-04-08 15:09:29 +00:00
|
|
|
std::unique_ptr<Data::ReplyPreview> _replyPreview;
|
2020-05-25 14:16:04 +00:00
|
|
|
std::weak_ptr<Data::PhotoMedia> _media;
|
2019-01-25 14:37:28 +00:00
|
|
|
|
|
|
|
not_null<Data::Session*> _owner;
|
2018-11-09 15:03:38 +00:00
|
|
|
|
2017-09-26 11:49:16 +00:00
|
|
|
};
|