summary refs log tree commit diff
path: root/src/ChatPage.cc
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-04-21 21:18:57 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-04-21 21:18:57 +0300
commit29bd8b71d183e852c43c1bac7cd4c9020f1a4877 (patch)
treef03b3ea5188fa910c2bace502af68b88c3e46189 /src/ChatPage.cc
parentBump cache format version (diff)
downloadnheko-29bd8b71d183e852c43c1bac7cd4c9020f1a4877.tar.xz
Implement media cache
Diffstat (limited to 'src/ChatPage.cc')
-rw-r--r--src/ChatPage.cc40
1 files changed, 24 insertions, 16 deletions
diff --git a/src/ChatPage.cc b/src/ChatPage.cc

index a37cc9f0..280ae399 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc
@@ -399,8 +399,6 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, this, &ChatPage::setGroupViewState); - AvatarProvider::init(client); - connect(this, &ChatPage::continueSync, this, [this](const QString &next_batch) { syncTimeoutTimer_->start(SYNC_RETRY_TIMEOUT); client_->setNextBatchToken(next_batch); @@ -461,7 +459,6 @@ ChatPage::resetUI() top_bar_->reset(); user_info_widget_->reset(); view_manager_->clearAll(); - AvatarProvider::clear(); showUnreadMessageNotification(0); } @@ -497,6 +494,8 @@ ChatPage::bootstrap(QString userid, QString homeserver, QString token) room_list_->setCache(cache_); text_input_->setCache(cache_); + AvatarProvider::init(client_, cache_); + try { cache_->setup(); @@ -584,21 +583,30 @@ ChatPage::updateOwnProfileInfo(const QUrl &avatar_url, const QString &display_na user_info_widget_->setUserId(userid); user_info_widget_->setDisplayName(display_name); - if (avatar_url.isValid()) { - auto proxy = client_->fetchUserAvatar(avatar_url); + if (!avatar_url.isValid()) + return; - if (proxy.isNull()) + if (!cache_.isNull()) { + auto data = cache_->image(avatar_url.toString()); + if (!data.isNull()) { + user_info_widget_->setAvatar(QImage::fromData(data)); return; - - proxy->setParent(this); - connect(proxy.data(), - &DownloadMediaProxy::avatarDownloaded, - this, - [this, proxy](const QImage &img) { - proxy->deleteLater(); - user_info_widget_->setAvatar(img); - }); + } } + + auto proxy = client_->fetchUserAvatar(avatar_url); + + if (proxy.isNull()) + return; + + proxy->setParent(this); + connect(proxy.data(), + &DownloadMediaProxy::avatarDownloaded, + this, + [this, proxy](const QImage &img) { + proxy->deleteLater(); + user_info_widget_->setAvatar(img); + }); } void @@ -661,8 +669,8 @@ ChatPage::loadStateFromCache() try { cache_->populateMembers(); - emit initializeRoomList(cache_->roomInfo()); emit initializeEmptyViews(cache_->joinedRooms()); + emit initializeRoomList(cache_->roomInfo()); } catch (const lmdb::error &e) { std::cout << "load cache error:" << e.what() << '\n'; // TODO Clear cache and restart.