diff options
author | CH Chethan Reddy <40890937+Chethan2k1@users.noreply.github.com> | 2020-08-24 13:56:50 +0530 |
---|---|---|
committer | CH Chethan Reddy <40890937+Chethan2k1@users.noreply.github.com> | 2020-08-24 13:58:00 +0530 |
commit | 1d299951b61390c381013ca0503fb09df548c6ec (patch) | |
tree | 12a627382e339adb033143751a2d4f96fbabba48 /src/ChatPage.cpp | |
parent | [WIP] Room Verification Works! (diff) | |
download | nheko-1d299951b61390c381013ca0503fb09df548c6ec.tar.xz |
Cache Fix
Diffstat (limited to 'src/ChatPage.cpp')
-rw-r--r-- | src/ChatPage.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index b97b6b30..f8cb31a2 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -52,6 +52,8 @@ #include "blurhash.hpp" +#include <iostream> // only for debugging + // TODO: Needs to be updated with an actual secret. static const std::string STORAGE_SECRET_KEY("secret"); @@ -1446,3 +1448,36 @@ ChatPage::initiateLogout() emit showOverlayProgressBar(); } + +void +ChatPage::query_keys( + const mtx::requests::QueryKeys &req, + std::function<void(const mtx::responses::QueryKeys &, mtx::http::RequestErr)> cb) +{ + std::string user_id = req.device_keys.begin()->first; + auto cache_ = cache::getUserCache(user_id); + + if (cache_.has_value()) { + if (cache_.value().isUpdated) { + cb(cache_.value().keys, {}); + } else { + http::client()->query_keys( + req, + [cb, user_id](const mtx::responses::QueryKeys &res, + mtx::http::RequestErr err) { + if (err) { + nhlog::net()->warn("failed to query device keys: {},{}", + err->matrix_error.errcode, + static_cast<int>(err->status_code)); + return; + } + std::cout << "Over here " << user_id << std::endl; + cache::setUserCache(std::move(user_id), + std::move(UserCache{res, true})); + cb(res, err); + }); + } + } else { + http::client()->query_keys(req, cb); + } +} |