From 160fe1d668d9c1fa8f089cec34df29c2ba31a56f Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sat, 21 Oct 2017 21:17:01 +0300 Subject: Remove cache updates from the main thread --- src/ChatPage.cc | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'src/ChatPage.cc') diff --git a/src/ChatPage.cc b/src/ChatPage.cc index 5df8dec2..65fef9de 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include "AvatarProvider.h" #include "ChatPage.h" @@ -196,6 +197,11 @@ ChatPage::ChatPage(QSharedPointer client, QWidget *parent) this, SLOT(initialSyncCompleted(const SyncResponse &))); connect(client_.data(), &MatrixClient::initialSyncFailed, this, [=](const QString &msg) { + if (client_->getHomeServer().isEmpty()) { + deleteConfigs(); + return; + } + initialSyncFailures += 1; if (initialSyncFailures >= MAX_INITIAL_SYNC_FAILURES) { @@ -426,14 +432,7 @@ ChatPage::syncCompleted(const SyncResponse &response) } } - try { - cache_->setState(response.nextBatch(), state_manager_); - } catch (const lmdb::error &e) { - qCritical() << "The cache couldn't be updated: " << e.what(); - // TODO: Notify the user. - cache_->unmount(); - cache_->deleteData(); - } + QtConcurrent::run(cache_.data(), &Cache::setState, response.nextBatch(), state_manager_); client_->setNextBatchToken(response.nextBatch()); @@ -479,16 +478,10 @@ ChatPage::initialSyncCompleted(const SyncResponse &response) QApplication::processEvents(); } - try { - cache_->setState(response.nextBatch(), state_manager_); - } catch (const lmdb::error &e) { - qCritical() << "The cache couldn't be initialized: " << e.what(); - cache_->unmount(); - cache_->deleteData(); - } - client_->setNextBatchToken(response.nextBatch()); + QtConcurrent::run(cache_.data(), &Cache::setState, response.nextBatch(), state_manager_); + // Populate timelines with messages. view_manager_->initialize(response.rooms()); -- cgit 1.5.1