diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-04-07 17:15:42 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-18 23:38:23 +0200 |
commit | 983be4253f2ea3827d78db97afcc666664ae75ed (patch) | |
tree | 058174a46ebe3eac15467f0c9f2d0ca58cecdb2d /src | |
parent | 18c27df9d7efe087c9196b46a47867af9a111b3e (diff) |
Update cache signature, update odhtdb
Diffstat (limited to 'src')
-rw-r--r-- | src/Cache.cpp | 14 | ||||
-rw-r--r-- | src/Gif.cpp | 2 | ||||
-rw-r--r-- | src/Room.cpp | 4 |
3 files changed, 12 insertions, 8 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(); diff --git a/src/Gif.cpp b/src/Gif.cpp index e98718f..a35b6c2 100644 --- a/src/Gif.cpp +++ b/src/Gif.cpp @@ -139,7 +139,7 @@ namespace dchat if(!created) { created = true; - if(!createTexture(gif.width, gif.height)) + if(!createTexture()) throw GifLoadException("Failed to create texture for gif"); } diff --git a/src/Room.cpp b/src/Room.cpp index b526833..b558f87 100644 --- a/src/Room.cpp +++ b/src/Room.cpp @@ -101,10 +101,11 @@ namespace dchat publicKeyToKeyPairMap[user->publicKey] = keyPair; odhtdb::Log::debug("Local user set to %s for room %s", user->publicKey.toString().c_str(), id->toString().c_str()); - // Room id + room encryption key + invite key checksum (to verify invite key is not types incorrectly) + // Room id + room encryption key + invite key checksum (to verify invite key is not typed incorrectly) inviteKey = id->toString() + odhtdb::bin2hex((const char*)encryptionKey->data, encryptionKey->size); inviteKey += getInviteKeyChecksum(inviteKey); odhtdb::InfoHash inviteInfoHash = odhtdb::InfoHash::generateHash((const u8*)inviteKey.data(), inviteKey.size()); + // TODO: Use database instead of custom message. Then both parties dont have to be online to add user to room rooms->database->receiveCustomMessage(inviteInfoHash, [this](const void *data, usize size) { sibs::SafeSerializer serializer; @@ -464,6 +465,7 @@ namespace dchat }, address, port, callbackFuncs).detach(); } + // TODO: Add logout void Rooms::loginUser(const std::string &username, const std::string &password) { std::lock_guard<std::recursive_mutex> lock(roomModifyMutex); |