mirror of https://github.com/procxx/kepka.git
Let [Photo|Document]Media outlive message view.
This commit is contained in:
parent
700d3db4cc
commit
dbb46ce9b0
|
@ -1601,13 +1601,9 @@ void DocumentData::collectLocalData(not_null<DocumentData*> local) {
|
|||
|
||||
_owner->cache().copyIfEmpty(local->cacheKey(), cacheKey());
|
||||
if (const auto localMedia = local->activeMediaView()) {
|
||||
const auto media = createMediaView();
|
||||
auto media = createMediaView();
|
||||
media->collectLocalData(localMedia.get());
|
||||
|
||||
// Keep DocumentMedia alive for some more time.
|
||||
// NB! This allows DocumentMedia to outlive Main::Session!
|
||||
// In case this is a problem this code should be rewritten.
|
||||
crl::on_main(&session(), [media] {});
|
||||
_owner->keepAlive(std::move(media));
|
||||
}
|
||||
if (!local->_location.inMediaCache() && !local->_location.isEmpty()) {
|
||||
_location = local->_location;
|
||||
|
|
|
@ -230,13 +230,9 @@ void PhotoData::collectLocalData(not_null<PhotoData*> local) {
|
|||
}
|
||||
}
|
||||
if (const auto localMedia = local->activeMediaView()) {
|
||||
const auto media = createMediaView();
|
||||
auto media = createMediaView();
|
||||
media->collectLocalData(localMedia.get());
|
||||
|
||||
// Keep DocumentMedia alive for some more time.
|
||||
// NB! This allows DocumentMedia to outlive Main::Session!
|
||||
// In case this is a problem this code should be rewritten.
|
||||
crl::on_main(&session(), [media] {});
|
||||
_owner->keepAlive(std::move(media));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ Image *ReplyPreview::image(Data::FileOrigin origin) {
|
|||
prepare(image, option | Images::Option::Blurred);
|
||||
}
|
||||
}
|
||||
if (thumbnail || !_document->hasThumbnail()) {
|
||||
if (_good || !_document->hasThumbnail()) {
|
||||
_checked = true;
|
||||
_documentMedia = nullptr;
|
||||
}
|
||||
|
@ -101,6 +101,10 @@ Image *ReplyPreview::image(Data::FileOrigin origin) {
|
|||
prepare(blurred, Images::Option::Blurred);
|
||||
}
|
||||
}
|
||||
if (_good) {
|
||||
_checked = true;
|
||||
_photoMedia = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
return _image.get();
|
||||
|
|
|
@ -268,6 +268,18 @@ void Session::clear() {
|
|||
_photos.clear();
|
||||
}
|
||||
|
||||
void Session::keepAlive(std::shared_ptr<PhotoMedia> media) {
|
||||
// NB! This allows PhotoMedia to outlive Main::Session!
|
||||
// In case this is a problem this code should be rewritten.
|
||||
crl::on_main(&session(), [media = std::move(media)]{});
|
||||
}
|
||||
|
||||
void Session::keepAlive(std::shared_ptr<DocumentMedia> media) {
|
||||
// NB! This allows DocumentMedia to outlive Main::Session!
|
||||
// In case this is a problem this code should be rewritten.
|
||||
crl::on_main(&session(), [media = std::move(media)] {});
|
||||
}
|
||||
|
||||
not_null<PeerData*> Session::peer(PeerId id) {
|
||||
const auto i = _peers.find(id);
|
||||
if (i != _peers.cend()) {
|
||||
|
@ -3335,6 +3347,9 @@ void Session::registerItemView(not_null<ViewElement*> view) {
|
|||
}
|
||||
|
||||
void Session::unregisterItemView(not_null<ViewElement*> view) {
|
||||
Expects(!_playingVideoFiles.contains(view));
|
||||
Expects(!_heavyViewParts.contains(view));
|
||||
|
||||
const auto i = _views.find(view->data());
|
||||
if (i != end(_views)) {
|
||||
auto &list = i->second;
|
||||
|
|
|
@ -63,6 +63,8 @@ class CloudThemes;
|
|||
class Streaming;
|
||||
class MediaRotation;
|
||||
class Histories;
|
||||
class DocumentMedia;
|
||||
class PhotoMedia;
|
||||
|
||||
class Session final {
|
||||
public:
|
||||
|
@ -110,6 +112,9 @@ public:
|
|||
|
||||
void clear();
|
||||
|
||||
void keepAlive(std::shared_ptr<PhotoMedia> media);
|
||||
void keepAlive(std::shared_ptr<DocumentMedia> media);
|
||||
|
||||
void startExport(PeerData *peer = nullptr);
|
||||
void startExport(const MTPInputPeer &singlePeer);
|
||||
void suggestStartExport(TimeId availableAt);
|
||||
|
|
|
@ -607,7 +607,7 @@ auto Element::verticalRepaintRange() const -> VerticalRepaintRange {
|
|||
}
|
||||
|
||||
void Element::checkHeavyPart() {
|
||||
if (_media && !_media->hasHeavyPart()) {
|
||||
if (!_media || !_media->hasHeavyPart()) {
|
||||
history()->owner().unregisterHeavyViewPart(this);
|
||||
}
|
||||
}
|
||||
|
@ -746,7 +746,7 @@ void Element::clickHandlerPressedChanged(
|
|||
|
||||
Element::~Element() {
|
||||
// Delete media while owner still exists.
|
||||
_media = nullptr;
|
||||
base::take(_media);
|
||||
if (_data->mainView() == this) {
|
||||
_data->clearMainView();
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ Document::Document(
|
|||
|
||||
Document::~Document() {
|
||||
if (_dataMedia) {
|
||||
_dataMedia = nullptr;
|
||||
_data->owner().keepAlive(base::take(_dataMedia));
|
||||
_parent->checkHeavyPart();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,7 +101,9 @@ Gif::~Gif() {
|
|||
_data->owner().streaming().keepAlive(_data);
|
||||
setStreamed(nullptr);
|
||||
}
|
||||
_dataMedia = nullptr;
|
||||
if (_dataMedia) {
|
||||
_data->owner().keepAlive(base::take(_dataMedia));
|
||||
}
|
||||
_parent->checkHeavyPart();
|
||||
}
|
||||
}
|
||||
|
@ -479,7 +481,8 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms
|
|||
auto over = _animation->a_thumbOver.value(1.);
|
||||
p.setBrush(anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, over));
|
||||
} else {
|
||||
auto over = ClickHandler::showAsActive(_data->loading() ? _cancell : _savel);
|
||||
const auto over = ClickHandler::showAsActive(
|
||||
(_data->loading() || _data->uploading()) ? _cancell : _savel);
|
||||
p.setBrush(over ? st::msgDateImgBgOver : st::msgDateImgBg);
|
||||
}
|
||||
p.setOpacity(radialOpacity * p.opacity());
|
||||
|
@ -1013,7 +1016,8 @@ void Gif::drawGrouped(
|
|||
auto over = _animation->a_thumbOver.value(1.);
|
||||
p.setBrush(anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, over));
|
||||
} else {
|
||||
auto over = ClickHandler::showAsActive(_data->loading() ? _cancell : _savel);
|
||||
auto over = ClickHandler::showAsActive(
|
||||
(_data->loading() || _data->uploading()) ? _cancell : _savel);
|
||||
p.setBrush(over ? st::msgDateImgBgOver : st::msgDateImgBg);
|
||||
}
|
||||
p.setOpacity(radialOpacity * p.opacity());
|
||||
|
|
|
@ -63,7 +63,7 @@ GroupedMedia::GroupedMedia(
|
|||
|
||||
GroupedMedia::~GroupedMedia() {
|
||||
// Destroy all parts while the media object is still not destroyed.
|
||||
base::take(_parts).clear();
|
||||
base::take(_parts);
|
||||
}
|
||||
|
||||
QSize GroupedMedia::countOptimalSize() {
|
||||
|
|
|
@ -24,8 +24,6 @@ constexpr auto kMaxForwardedBarLines = 4;
|
|||
|
||||
} // namespace
|
||||
|
||||
UnwrappedMedia::Content::~Content() = default;
|
||||
|
||||
UnwrappedMedia::UnwrappedMedia(
|
||||
not_null<Element*> parent,
|
||||
std::unique_ptr<Content> content)
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
[[nodiscard]] virtual bool alwaysShowOutTimestamp() {
|
||||
return false;
|
||||
}
|
||||
virtual ~Content() = 0;
|
||||
virtual ~Content() = default;
|
||||
};
|
||||
|
||||
UnwrappedMedia(
|
||||
|
|
|
@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/view/history_view_element.h"
|
||||
#include "history/view/history_view_cursor_state.h"
|
||||
#include "history/view/media/history_view_media_common.h"
|
||||
#include "main/main_session.h"
|
||||
#include "ui/image/image.h"
|
||||
#include "ui/grouped_layout.h"
|
||||
#include "data/data_session.h"
|
||||
|
@ -54,7 +55,7 @@ Photo::Photo(
|
|||
|
||||
Photo::~Photo() {
|
||||
if (_dataMedia) {
|
||||
_dataMedia = nullptr;
|
||||
_data->owner().keepAlive(base::take(_dataMedia));
|
||||
_parent->checkHeavyPart();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,9 @@ Sticker::Sticker(
|
|||
Sticker::~Sticker() {
|
||||
if (_lottie || _dataMedia) {
|
||||
unloadLottie();
|
||||
_dataMedia = nullptr;
|
||||
if (_dataMedia) {
|
||||
_data->owner().keepAlive(base::take(_dataMedia));
|
||||
}
|
||||
_parent->checkHeavyPart();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ ThemeDocument::ThemeDocument(
|
|||
|
||||
ThemeDocument::~ThemeDocument() {
|
||||
if (_dataMedia) {
|
||||
_dataMedia = nullptr;
|
||||
_data->owner().keepAlive(base::take(_dataMedia));
|
||||
_parent->checkHeavyPart();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -820,7 +820,7 @@ QString WebPage::displayedSiteName() const {
|
|||
WebPage::~WebPage() {
|
||||
history()->owner().unregisterWebPageView(_data, _parent);
|
||||
if (_photoMedia) {
|
||||
_photoMedia = nullptr;
|
||||
history()->owner().keepAlive(base::take(_photoMedia));
|
||||
_parent->checkHeavyPart();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue