Improve PeerShortInfoBox cover updating.

This commit is contained in:
John Preston 2021-10-19 19:07:01 +04:00
parent 360a92c198
commit 05bdef041b
2 changed files with 15 additions and 8 deletions

View File

@ -345,8 +345,15 @@ void PeerShortInfoBox::applyUserpic(PeerShortInfoUserpic &&value) {
refreshBarImages();
update();
}
if (!value.photo.isNull()
&& _userpicImage.cacheKey() != value.photo.cacheKey()) {
if (value.photo.isNull()) {
const auto videoChanged = _videoInstance
? (_videoInstance->shared() != value.videoDocument)
: (value.videoDocument != nullptr);
const auto frame = videoChanged ? currentVideoFrame() : QImage();
if (!frame.isNull()) {
_userpicImage = frame;
}
} else if (_userpicImage.cacheKey() != value.photo.cacheKey()) {
_userpicImage = std::move(value.photo);
update();
}
@ -354,10 +361,6 @@ void PeerShortInfoBox::applyUserpic(PeerShortInfoUserpic &&value) {
_videoInstance = nullptr;
} else if (!_videoInstance
|| _videoInstance->shared() != value.videoDocument) {
const auto frame = currentVideoFrame();
if (!frame.isNull()) {
_userpicImage = frame;
}
using namespace Media::Streaming;
_videoInstance = std::make_unique<Instance>(
std::move(value.videoDocument),

View File

@ -129,6 +129,8 @@ void ProcessFullPhoto(
if (!current || state->current.photo.isNull()) {
if (const auto blurred = view->thumbnailInline()) {
GenerateImage(state, blurred, true);
} else {
state->current.photo = QImage();
}
}
}
@ -229,8 +231,10 @@ void ValidatePhotoId(
PhotoId oldUserpicPhotoId) {
if (state->userSlice) {
const auto count = state->userSlice->size();
const auto hasOld = state->userSlice->indexOf(oldUserpicPhotoId);
const auto hasNew = state->userSlice->indexOf(state->userpicPhotoId);
const auto hasOld = state->userSlice->indexOf(
oldUserpicPhotoId).has_value();
const auto hasNew = state->userSlice->indexOf(
state->userpicPhotoId).has_value();
const auto shift = (hasNew ? 0 : 1);
const auto fullCount = count + shift;
state->current.count = fullCount;