diff options
Diffstat (limited to 'src/Cache.cpp')
-rw-r--r-- | src/Cache.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp index 0d5dd05..82f31b9 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -67,7 +67,7 @@ namespace dchat return success; } - static ContentByUrlResult loadImageFromFile(const boost::filesystem::path &filepath, bool loadFromCache, CreateGifFunc createGifFunc, CreateStaticImageFunc createStaticImageFunc) + ContentByUrlResult Cache::loadImageFromFile(const boost::filesystem::path &filepath, bool loadFromCache) { StringView fileContent; try @@ -126,7 +126,7 @@ namespace dchat if(foundHtmlContent) { - WebPagePreview *webPagePreview = new WebPagePreview { webPageTitle, webPageDescription }; + WebPagePreview *webPagePreview = createWebPagePreviewFunc(webPageTitle, webPageDescription); return { webPagePreview, ContentByUrlResult::Type::CACHED }; } } @@ -137,13 +137,15 @@ namespace dchat return { (StaticImage*)nullptr, ContentByUrlResult::Type::FAILED_DOWNLOAD }; } - Cache::Cache(CreateGifFunc _createGifFunc, CreateStaticImageFunc _createStaticImageFunc) : + Cache::Cache(CreateGifFunc _createGifFunc, CreateStaticImageFunc _createStaticImageFunc, CreateWebPagePreviewFunc _createWebPagePreviewFunc) : alive(true), createGifFunc(_createGifFunc), - createStaticImageFunc(_createStaticImageFunc) + createStaticImageFunc(_createStaticImageFunc), + createWebPagePreviewFunc(_createWebPagePreviewFunc) { assert(createGifFunc); assert(createStaticImageFunc); + assert(createWebPagePreviewFunc); downloadWaitThread = thread([this] { while(alive) @@ -165,7 +167,7 @@ namespace dchat } else { - contentByUrlResult = loadImageFromFile(filepath, false, createGifFunc, createStaticImageFunc); + contentByUrlResult = loadImageFromFile(filepath, false); contentByUrlResult.lastAccessed = chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now().time_since_epoch()).count(); if(contentByUrlResult.type == ContentByUrlResult::Type::CACHED) { @@ -328,7 +330,7 @@ namespace dchat } // TODO: Do not load content in this thread. Return LOADING status and load it in another thread, because with a lot of images, chat can freeze - ContentByUrlResult contentByUrlResult = loadImageFromFile(filepath, true, createGifFunc, createStaticImageFunc); + ContentByUrlResult contentByUrlResult = loadImageFromFile(filepath, true); if(contentByUrlResult.type == ContentByUrlResult::Type::CACHED) { contentByUrlResult.lastAccessed = chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now().time_since_epoch()).count(); |