2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Don't unload all media on switching between chats.

This commit is contained in:
John Preston
2018-10-23 16:57:43 +04:00
parent 959859f57c
commit 8e7117fa22
21 changed files with 61 additions and 83 deletions

View File

@@ -353,14 +353,14 @@ void Gif::clipCallback(Media::Clip::Notification notification) {
if (_gif) {
if (_gif->state() == State::Error) {
_gif.setBad();
getShownDocument()->forget();
getShownDocument()->unload();
} else if (_gif->ready() && !_gif->started()) {
auto height = st::inlineMediaHeight;
auto frame = countFrameSize();
_gif->start(frame.width(), frame.height(), _width, height, ImageRoundRadius::None, RectPart::None);
} else if (_gif->autoPausedGif() && !context()->inlineItemVisible(this)) {
_gif.reset();
getShownDocument()->forget();
getShownDocument()->unload();
}
}
@@ -1373,12 +1373,12 @@ void Game::clipCallback(Media::Clip::Notification notification) {
if (_gif) {
if (_gif->state() == State::Error) {
_gif.setBad();
getResultDocument()->forget();
getResultDocument()->unload();
} else if (_gif->ready() && !_gif->started()) {
_gif->start(_frameSize.width(), _frameSize.height(), st::inlineThumbSize, st::inlineThumbSize, ImageRoundRadius::None, RectPart::None);
} else if (_gif->autoPausedGif() && !context()->inlineItemVisible(this)) {
_gif.reset();
getResultDocument()->forget();
getResultDocument()->unload();
}
}

View File

@@ -279,13 +279,12 @@ bool Result::onChoose(Layout::ItemBase *layout) {
return true;
}
void Result::forget() {
_thumb->forget();
void Result::unload() {
if (_document) {
_document->forget();
_document->unload();
}
if (_photo) {
_photo->forget();
_photo->unload();
}
}

View File

@@ -45,7 +45,7 @@ public:
// inline bot result. If it returns true you need to send this result.
bool onChoose(Layout::ItemBase *layout);
void forget();
void unload();
void openFile();
void cancelFile();

View File

@@ -267,20 +267,20 @@ void Inner::clearSelection() {
void Inner::hideFinish(bool completely) {
if (completely) {
auto itemForget = [](auto &item) {
if (auto document = item->getDocument()) {
document->forget();
const auto unload = [](const auto &item) {
if (const auto document = item->getDocument()) {
document->unload();
}
if (auto photo = item->getPhoto()) {
photo->forget();
if (const auto photo = item->getPhoto()) {
photo->unload();
}
if (auto result = item->getResult()) {
result->forget();
if (const auto result = item->getResult()) {
result->unload();
}
};
clearInlineRows(false);
for_const (auto &item, _inlineLayouts) {
itemForget(item.second);
for (const auto &[result, layout] : _inlineLayouts) {
unload(layout);
}
}
}