2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Use small userpic video in dialogs list / chat history.

This commit is contained in:
John Preston
2022-06-03 15:58:02 +04:00
parent 499923b6d3
commit 705753efb2
10 changed files with 186 additions and 94 deletions

View File

@@ -51,7 +51,7 @@ PhotoData::~PhotoData() {
for (auto &image : _images) {
base::take(image.loader).reset();
}
base::take(_video.loader).reset();
base::take(_videoSizes);
}
Data::Session &PhotoData::owner() const {
@@ -369,7 +369,8 @@ void PhotoData::updateImages(
const ImageWithLocation &small,
const ImageWithLocation &thumbnail,
const ImageWithLocation &large,
const ImageWithLocation &video,
const ImageWithLocation &videoSmall,
const ImageWithLocation &videoLarge,
crl::time videoStartTime) {
if (!inlineThumbnailBytes.isEmpty()
&& _inlineThumbnailBytes.isEmpty()) {
@@ -399,15 +400,28 @@ void PhotoData::updateImages(
update(PhotoSize::Thumbnail, thumbnail);
update(PhotoSize::Large, large);
if (video.location.valid()) {
_videoStartTime = videoStartTime;
if (!videoLarge.location.valid()) {
_videoSizes = nullptr;
} else {
if (!_videoSizes) {
_videoSizes = std::make_unique<VideoSizes>();
}
_videoSizes->startTime = videoStartTime;
constexpr auto large = PhotoSize::Large;
constexpr auto small = PhotoSize::Small;
Data::UpdateCloudFile(
_videoSizes->large,
videoLarge,
owner().cache(),
Data::kAnimationCacheTag,
[&](Data::FileOrigin origin) { loadVideo(large, origin); });
Data::UpdateCloudFile(
_videoSizes->small,
videoSmall,
owner().cache(),
Data::kAnimationCacheTag,
[&](Data::FileOrigin origin) { loadVideo(small, origin); });
}
Data::UpdateCloudFile(
_video,
video,
owner().cache(),
Data::kAnimationCacheTag,
[&](Data::FileOrigin origin) { loadVideo(origin); });
}
[[nodiscard]] bool PhotoData::hasAttachedStickers() const {
@@ -426,34 +440,55 @@ int PhotoData::height() const {
return _images[PhotoSizeIndex(PhotoSize::Large)].location.height();
}
Data::CloudFile &PhotoData::videoFile(PhotoSize size) {
Expects(_videoSizes != nullptr);
return (size == PhotoSize::Small)
? _videoSizes->small
: _videoSizes->large;
}
const Data::CloudFile &PhotoData::videoFile(PhotoSize size) const {
Expects(_videoSizes != nullptr);
return (size == PhotoSize::Small)
? _videoSizes->small
: _videoSizes->large;
}
bool PhotoData::hasVideo() const {
return _video.location.valid();
return _videoSizes != nullptr;
}
bool PhotoData::videoLoading() const {
return _video.loader != nullptr;
bool PhotoData::videoLoading(Data::PhotoSize size) const {
return _videoSizes && videoFile(size).loader != nullptr;
}
bool PhotoData::videoFailed() const {
return (_video.flags & Data::CloudFile::Flag::Failed);
bool PhotoData::videoFailed(Data::PhotoSize size) const {
return _videoSizes
&& (videoFile(size).flags & Data::CloudFile::Flag::Failed);
}
void PhotoData::loadVideo(Data::FileOrigin origin) {
void PhotoData::loadVideo(Data::PhotoSize size, Data::FileOrigin origin) {
if (!_videoSizes) {
return;
}
const auto autoLoading = false;
const auto finalCheck = [=] {
if (const auto active = activeMediaView()) {
return active->videoContent().isEmpty();
return active->videoContent(size).isEmpty();
}
return true;
};
const auto done = [=](QByteArray result) {
if (const auto active = activeMediaView()) {
active->setVideo(std::move(result));
active->setVideo(size, std::move(result));
}
};
Data::LoadCloudFile(
&session(),
_video,
videoFile(size),
origin,
LoadFromCloudOrLocal,
autoLoading,
@@ -462,12 +497,27 @@ void PhotoData::loadVideo(Data::FileOrigin origin) {
done);
}
const ImageLocation &PhotoData::videoLocation() const {
return _video.location;
const ImageLocation &PhotoData::videoLocation(Data::PhotoSize size) const {
static const auto empty = ImageLocation();
return _videoSizes ? videoFile(size).location : empty;
}
int PhotoData::videoByteSize() const {
return _video.byteSize;
int PhotoData::videoByteSize(Data::PhotoSize size) const {
return _videoSizes ? videoFile(size).byteSize : 0;
}
crl::time PhotoData::videoStartPosition() const {
return _videoSizes ? _videoSizes->startTime : crl::time(0);
}
void PhotoData::setVideoPlaybackFailed() {
if (_videoSizes) {
_videoSizes->playbackFailed = true;
}
}
bool PhotoData::videoPlaybackFailed() const {
return _videoSizes && _videoSizes->playbackFailed;
}
bool PhotoData::videoCanBePlayed() const {
@@ -481,17 +531,19 @@ auto PhotoData::createStreamingLoader(
if (!hasVideo()) {
return nullptr;
}
constexpr auto large = PhotoSize::Large;
if (!forceRemoteLoader) {
const auto media = activeMediaView();
if (media && !media->videoContent().isEmpty()) {
return Media::Streaming::MakeBytesLoader(media->videoContent());
const auto bytes = media ? media->videoContent(large) : QByteArray();
if (media && !bytes.isEmpty()) {
return Media::Streaming::MakeBytesLoader(bytes);
}
}
return v::is<StorageFileLocation>(videoLocation().file().data)
return v::is<StorageFileLocation>(videoLocation(large).file().data)
? std::make_unique<Media::Streaming::LoaderMtproto>(
&session().downloader(),
v::get<StorageFileLocation>(videoLocation().file().data),
videoByteSize(),
v::get<StorageFileLocation>(videoLocation(large).file().data),
videoByteSize(large),
origin)
: nullptr;
}