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
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
[[nodiscard]] Image *getReplyPreview(Data::FileOrigin origin);
|
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,
|
2020-07-03 10:48:55 +00:00
|
|
|
const ImageWithLocation &video,
|
|
|
|
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;
|
|
|
|
[[nodiscard]] bool videoLoading() const;
|
|
|
|
[[nodiscard]] bool videoFailed() const;
|
|
|
|
void loadVideo(Data::FileOrigin origin);
|
|
|
|
[[nodiscard]] const ImageLocation &videoLocation() const;
|
|
|
|
[[nodiscard]] int videoByteSize() const;
|
2020-07-03 10:48:55 +00:00
|
|
|
[[nodiscard]] crl::time videoStartPosition() const {
|
|
|
|
return _videoStartTime;
|
|
|
|
}
|
|
|
|
void setVideoPlaybackFailed() {
|
|
|
|
_videoPlaybackFailed = true;
|
|
|
|
}
|
|
|
|
[[nodiscard]] bool videoPlaybackFailed() const {
|
|
|
|
return _videoPlaybackFailed;
|
|
|
|
}
|
|
|
|
[[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:
|
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;
|
2020-07-03 08:42:09 +00:00
|
|
|
Data::CloudFile _video;
|
2020-07-03 10:48:55 +00:00
|
|
|
crl::time _videoStartTime = 0;
|
|
|
|
bool _videoPlaybackFailed = false;
|
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
|
|
|
};
|
|
|
|
|
2017-12-18 13:13:41 +00:00
|
|
|
class PhotoClickHandler : public FileClickHandler {
|
2017-09-26 11:49:16 +00:00
|
|
|
public:
|
|
|
|
PhotoClickHandler(
|
|
|
|
not_null<PhotoData*> photo,
|
2017-12-15 16:25:47 +00:00
|
|
|
FullMsgId context = FullMsgId(),
|
2020-05-04 13:38:49 +00:00
|
|
|
PeerData *peer = nullptr);
|
|
|
|
|
|
|
|
[[nodiscard]] not_null<PhotoData*> photo() const {
|
2017-09-26 11:49:16 +00:00
|
|
|
return _photo;
|
|
|
|
}
|
2020-05-04 13:38:49 +00:00
|
|
|
[[nodiscard]] PeerData *peer() const {
|
2017-09-26 11:49:16 +00:00
|
|
|
return _peer;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-05-04 13:38:49 +00:00
|
|
|
const not_null<PhotoData*> _photo;
|
|
|
|
PeerData * const _peer = nullptr;
|
2017-09-26 11:49:16 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class PhotoOpenClickHandler : public PhotoClickHandler {
|
|
|
|
public:
|
|
|
|
using PhotoClickHandler::PhotoClickHandler;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void onClickImpl() const override;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class PhotoSaveClickHandler : public PhotoClickHandler {
|
|
|
|
public:
|
|
|
|
using PhotoClickHandler::PhotoClickHandler;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void onClickImpl() const override;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class PhotoCancelClickHandler : public PhotoClickHandler {
|
|
|
|
public:
|
|
|
|
using PhotoClickHandler::PhotoClickHandler;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void onClickImpl() const override;
|
|
|
|
|
|
|
|
};
|