From 442fc29582b5581111e3ffd286f4f3d282877f3c Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 16 Dec 2022 21:13:38 +0100 Subject: Fix bug where image are not removed from loading when not visible Matrix: fix invites not showing notification --- src/AsyncImageLoader.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/AsyncImageLoader.cpp') diff --git a/src/AsyncImageLoader.cpp b/src/AsyncImageLoader.cpp index 4021c55..8613cf9 100644 --- a/src/AsyncImageLoader.cpp +++ b/src/AsyncImageLoader.cpp @@ -312,15 +312,19 @@ namespace QuickMedia { } std::shared_ptr AsyncImageLoader::get_thumbnail(const std::string &url, bool local, mgl::vec2i resize_target_size) { - // TODO: Instead of generating a new hash everytime to access thumbnail, cache the hash of the thumbnail url - auto &thumbnail_data = thumbnails[url + "_" + std::to_string(resize_target_size.x) + "x" + std::to_string(resize_target_size.y)]; - if(!thumbnail_data) + // TODO: Instead of generating a new hash everytime to access thumbnail, cache the hash of the thumbnail url. + // TODO: Cache this resize_url + std::string resize_url = url + "_" + std::to_string(resize_target_size.x) + "x" + std::to_string(resize_target_size.y); + auto &thumbnail_data = thumbnails[resize_url]; + if(!thumbnail_data) { thumbnail_data = std::make_shared(); + thumbnail_data->url = url; + } thumbnail_data->counter = counter; if(thumbnail_data->thumbnail_path.data.empty()) { SHA256 sha256; - sha256.add(url.data(), url.size()); + sha256.add(resize_url.data(), resize_url.size()); thumbnail_data->thumbnail_path = get_cache_dir().join("thumbnails").join(sha256.getHash()); } @@ -358,7 +362,7 @@ namespace QuickMedia { if(download.read_program.pid == -1) continue; - if(download.url == it->first) { + if(download.url == it->second->url) { reset_download(download); break; } @@ -366,7 +370,7 @@ namespace QuickMedia { } image_thumbnail_create_queue.erase_if([&it](ThumbnailLoadData &load_data) { - return load_data.path.data == it->first; + return load_data.path.data == it->second->url; }); it = thumbnails.erase(it); -- cgit v1.2.3