mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
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:
parent
f6150d4d3e
commit
bede709f6b
2 changed files with 25 additions and 8 deletions
|
@ -1538,6 +1538,21 @@ Data::FileOrigin OverlayWidget::fileOrigin() const {
|
||||||
return Data::FileOrigin();
|
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 {
|
bool OverlayWidget::validSharedMedia() const {
|
||||||
if (auto key = sharedMediaKey()) {
|
if (auto key = sharedMediaKey()) {
|
||||||
if (!_sharedMedia) {
|
if (!_sharedMedia) {
|
||||||
|
@ -3413,16 +3428,17 @@ OverlayWidget::Entity OverlayWidget::entityByIndex(int index) const {
|
||||||
return { std::nullopt, nullptr };
|
return { std::nullopt, nullptr };
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverlayWidget::setContext(base::optional_variant<
|
void OverlayWidget::setContext(
|
||||||
|
base::optional_variant<
|
||||||
not_null<HistoryItem*>,
|
not_null<HistoryItem*>,
|
||||||
not_null<PeerData*>> context) {
|
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();
|
_msgid = (*item)->fullId();
|
||||||
_canForwardItem = (*item)->allowsForward();
|
_canForwardItem = (*item)->allowsForward();
|
||||||
_canDeleteItem = (*item)->canDelete();
|
_canDeleteItem = (*item)->canDelete();
|
||||||
_history = (*item)->history();
|
_history = (*item)->history();
|
||||||
_peer = _history->peer;
|
_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();
|
_msgid = FullMsgId();
|
||||||
_canForwardItem = _canDeleteItem = false;
|
_canForwardItem = _canDeleteItem = false;
|
||||||
_history = (*peer)->owner().history(*peer);
|
_history = (*peer)->owner().history(*peer);
|
||||||
|
@ -3491,15 +3507,15 @@ void OverlayWidget::preloadData(int delta) {
|
||||||
auto entity = entityByIndex(index);
|
auto entity = entityByIndex(index);
|
||||||
if (auto photo = base::get_if<not_null<PhotoData*>>(&entity.data)) {
|
if (auto photo = base::get_if<not_null<PhotoData*>>(&entity.data)) {
|
||||||
const auto [i, ok] = photos.emplace((*photo)->createMediaView());
|
const auto [i, ok] = photos.emplace((*photo)->createMediaView());
|
||||||
(*i)->wanted(Data::PhotoSize::Small, fileOrigin());
|
(*i)->wanted(Data::PhotoSize::Small, fileOrigin(entity));
|
||||||
(*photo)->load(fileOrigin(), LoadFromCloudOrLocal, true);
|
(*photo)->load(fileOrigin(entity), LoadFromCloudOrLocal, true);
|
||||||
} else if (auto document = base::get_if<not_null<DocumentData*>>(
|
} else if (auto document = base::get_if<not_null<DocumentData*>>(
|
||||||
&entity.data)) {
|
&entity.data)) {
|
||||||
const auto [i, ok] = documents.emplace(
|
const auto [i, ok] = documents.emplace(
|
||||||
(*document)->createMediaView());
|
(*document)->createMediaView());
|
||||||
(*i)->thumbnailWanted(fileOrigin());
|
(*i)->thumbnailWanted(fileOrigin(entity));
|
||||||
if (!(*i)->canBePlayed()) {
|
if (!(*i)->canBePlayed()) {
|
||||||
(*i)->automaticLoad(fileOrigin(), entity.item);
|
(*i)->automaticLoad(fileOrigin(entity), entity.item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -239,7 +239,8 @@ private:
|
||||||
bool validCollage() const;
|
bool validCollage() const;
|
||||||
void validateCollage();
|
void validateCollage();
|
||||||
|
|
||||||
Data::FileOrigin fileOrigin() const;
|
[[nodiscard]] Data::FileOrigin fileOrigin() const;
|
||||||
|
[[nodiscard]] Data::FileOrigin fileOrigin(const Entity& entity) const;
|
||||||
|
|
||||||
void refreshFromLabel(HistoryItem *item);
|
void refreshFromLabel(HistoryItem *item);
|
||||||
void refreshCaption(HistoryItem *item);
|
void refreshCaption(HistoryItem *item);
|
||||||
|
|
Loading…
Add table
Reference in a new issue