Fix file origin in media viewer photo preloading.

It never worked correctly, but before somehow it got worked around.

Fixes #8043.
This commit is contained in:
John Preston 2020-06-23 16:10:56 +04:00
parent f6150d4d3e
commit bede709f6b
2 changed files with 25 additions and 8 deletions

View file

@ -1538,6 +1538,21 @@ Data::FileOrigin OverlayWidget::fileOrigin() const {
return Data::FileOrigin();
}
Data::FileOrigin OverlayWidget::fileOrigin(const Entity &entity) const {
if (const auto item = entity.item) {
return item->fullId();
} else if (!entity.data.is<not_null<PhotoData*>>()) {
return Data::FileOrigin();
}
const auto photo = entity.data.get_unchecked<not_null<PhotoData*>>();
if (_user) {
return Data::FileOriginUserPhoto(_user->bareId(), photo->id);
} else if (_peer && _peer->userpicPhotoId() == photo->id) {
return Data::FileOriginPeerPhoto(_peer->id);
}
return Data::FileOrigin();
}
bool OverlayWidget::validSharedMedia() const {
if (auto key = sharedMediaKey()) {
if (!_sharedMedia) {
@ -3413,16 +3428,17 @@ OverlayWidget::Entity OverlayWidget::entityByIndex(int index) const {
return { std::nullopt, nullptr };
}
void OverlayWidget::setContext(base::optional_variant<
void OverlayWidget::setContext(
base::optional_variant<
not_null<HistoryItem*>,
not_null<PeerData*>> context) {
if (auto item = base::get_if<not_null<HistoryItem*>>(&context)) {
if (const auto item = base::get_if<not_null<HistoryItem*>>(&context)) {
_msgid = (*item)->fullId();
_canForwardItem = (*item)->allowsForward();
_canDeleteItem = (*item)->canDelete();
_history = (*item)->history();
_peer = _history->peer;
} else if (auto peer = base::get_if<not_null<PeerData*>>(&context)) {
} else if (const auto peer = base::get_if<not_null<PeerData*>>(&context)) {
_msgid = FullMsgId();
_canForwardItem = _canDeleteItem = false;
_history = (*peer)->owner().history(*peer);
@ -3491,15 +3507,15 @@ void OverlayWidget::preloadData(int delta) {
auto entity = entityByIndex(index);
if (auto photo = base::get_if<not_null<PhotoData*>>(&entity.data)) {
const auto [i, ok] = photos.emplace((*photo)->createMediaView());
(*i)->wanted(Data::PhotoSize::Small, fileOrigin());
(*photo)->load(fileOrigin(), LoadFromCloudOrLocal, true);
(*i)->wanted(Data::PhotoSize::Small, fileOrigin(entity));
(*photo)->load(fileOrigin(entity), LoadFromCloudOrLocal, true);
} else if (auto document = base::get_if<not_null<DocumentData*>>(
&entity.data)) {
const auto [i, ok] = documents.emplace(
(*document)->createMediaView());
(*i)->thumbnailWanted(fileOrigin());
(*i)->thumbnailWanted(fileOrigin(entity));
if (!(*i)->canBePlayed()) {
(*i)->automaticLoad(fileOrigin(), entity.item);
(*i)->automaticLoad(fileOrigin(entity), entity.item);
}
}
}

View file

@ -239,7 +239,8 @@ private:
bool validCollage() const;
void validateCollage();
Data::FileOrigin fileOrigin() const;
[[nodiscard]] Data::FileOrigin fileOrigin() const;
[[nodiscard]] Data::FileOrigin fileOrigin(const Entity& entity) const;
void refreshFromLabel(HistoryItem *item);
void refreshCaption(HistoryItem *item);