summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-04-22 14:19:05 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-04-22 14:19:05 +0300
commit1642f3cf40154e6183b7eae031a40d89c7eba948 (patch)
treea45add2aa5bb43625ced920c37c4573209ae5a05 /src
parentProperly clean stale invites (diff)
downloadnheko-1642f3cf40154e6183b7eae031a40d89c7eba948.tar.xz
Update invites in the UI after sync
Diffstat (limited to 'src')
-rw-r--r--src/Cache.cc19
-rw-r--r--src/ChatPage.cc8
-rw-r--r--src/RoomList.cc14
3 files changed, 40 insertions, 1 deletions
diff --git a/src/Cache.cc b/src/Cache.cc

index 2e210f6b..129b6696 100644 --- a/src/Cache.cc +++ b/src/Cache.cc
@@ -579,6 +579,25 @@ Cache::roomInfo(bool withInvites) return result; } +std::map<QString, bool> +Cache::invites() +{ + std::map<QString, bool> result; + + auto txn = lmdb::txn::begin(env_, nullptr, MDB_RDONLY); + auto cursor = lmdb::cursor::open(txn, invitesDb_); + + std::string room_id, unused; + + while (cursor.get(room_id, unused, MDB_NEXT)) + result.emplace(QString::fromStdString(std::move(room_id)), true); + + cursor.close(); + txn.commit(); + + return result; +} + QString Cache::getRoomAvatarUrl(lmdb::txn &txn, lmdb::dbi &statesdb, diff --git a/src/ChatPage.cc b/src/ChatPage.cc
index ae3079a3..110b8131 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc
@@ -420,6 +420,12 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, this, [this](const std::vector<std::string> &rooms) { view_manager_->initialize(rooms); }); connect(this, &ChatPage::syncUI, this, [this](const mtx::responses::Rooms &rooms) { + try { + room_list_->cleanupInvites(cache_->invites()); + } catch (const lmdb::error &e) { + qWarning() << "failed to retrieve invites" << e.what(); + } + view_manager_->initialize(rooms); removeLeftRooms(rooms.leave); @@ -528,6 +534,7 @@ ChatPage::syncCompleted(const mtx::responses::Sync &response) auto promise = QtConcurrent::run([this, res = std::move(response)]() { try { cache_->saveState(res); + emit syncUI(res.rooms); emit syncRoomlist(cache_->roomUpdates(res)); } catch (const lmdb::error &e) { std::cout << "save cache error:" << e.what() << '\n'; @@ -535,7 +542,6 @@ ChatPage::syncCompleted(const mtx::responses::Sync &response) return; } - emit syncUI(std::move(res.rooms)); emit continueSync(cache_->nextBatchToken()); }); } diff --git a/src/RoomList.cc b/src/RoomList.cc
index caa4adae..cfc8fecc 100644 --- a/src/RoomList.cc +++ b/src/RoomList.cc
@@ -181,6 +181,20 @@ RoomList::initialize(const QMap<QString, RoomInfo> &info) } void +RoomList::cleanupInvites(const std::map<QString, bool> &invites) +{ + if (invites.empty()) + return; + + for (auto it = rooms_.begin(); it != rooms_.end();) { + if (it->second->isInvite() && (invites.find(it->first) == invites.end())) + it = rooms_.erase(it); + else + ++it; + } +} + +void RoomList::sync(const std::map<QString, RoomInfo> &info) {