diff --git a/include/Cache.h b/include/Cache.h index b3bc085b..cc5f7065 100644 --- a/include/Cache.h +++ b/include/Cache.h @@ -170,7 +170,9 @@ public: //! There should be only one user id present in a receipt list per room. //! The user id should be removed from any other lists. using Receipts = std::map>; - void updateReadReceipt(const std::string &room_id, const Receipts &receipts); + void updateReadReceipt(lmdb::txn &txn, + const std::string &room_id, + const Receipts &receipts); //! Retrieve all the read receipts for the given event id and room. //! diff --git a/src/Cache.cc b/src/Cache.cc index eca13635..18e4d8ef 100644 --- a/src/Cache.cc +++ b/src/Cache.cc @@ -310,7 +310,7 @@ Cache::readReceipts(const QString &event_id, const QString &room_id) } void -Cache::updateReadReceipt(const std::string &room_id, const Receipts &receipts) +Cache::updateReadReceipt(lmdb::txn &txn, const std::string &room_id, const Receipts &receipts) { for (const auto &receipt : receipts) { const auto event_id = receipt.first; @@ -320,15 +320,12 @@ Cache::updateReadReceipt(const std::string &room_id, const Receipts &receipts) nlohmann::json json_key = receipt_key; try { - auto read_txn = lmdb::txn::begin(env_, nullptr, MDB_RDONLY); const auto key = json_key.dump(); lmdb::val prev_value; bool exists = lmdb::dbi_get( - read_txn, readReceiptsDb_, lmdb::val(key.data(), key.size()), prev_value); - - read_txn.commit(); + txn, readReceiptsDb_, lmdb::val(key.data(), key.size()), prev_value); std::map saved_receipts; @@ -350,14 +347,11 @@ Cache::updateReadReceipt(const std::string &room_id, const Receipts &receipts) nlohmann::json json_updated_value = saved_receipts; std::string merged_receipts = json_updated_value.dump(); - auto txn = lmdb::txn::begin(env_); - lmdb::dbi_put(txn, readReceiptsDb_, lmdb::val(key.data(), key.size()), lmdb::val(merged_receipts.data(), merged_receipts.size())); - txn.commit(); } catch (const lmdb::error &e) { qCritical() << "updateReadReceipts:" << e.what(); } @@ -388,6 +382,8 @@ Cache::saveState(const mtx::responses::Sync &res) lmdb::dbi_put( txn, roomsDb_, lmdb::val(room.first), lmdb::val(json(updatedInfo).dump())); + + updateReadReceipt(txn, room.first, room.second.ephemeral.receipts); } saveInvites(txn, res.rooms.invite); diff --git a/src/ChatPage.cc b/src/ChatPage.cc index aa21a98e..673f7b08 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -424,6 +425,14 @@ ChatPage::ChatPage(QSharedPointer client, connect(this, &ChatPage::syncUI, this, [this](const mtx::responses::Rooms &rooms) { view_manager_->initialize(rooms); removeLeftRooms(rooms.leave); + + for (const auto &room : rooms.join) { + auto room_id = QString::fromStdString(room.first); + + updateTypingUsers(room_id, room.second.ephemeral.typing); + updateRoomNotificationCount( + room_id, room.second.unread_notifications.notification_count); + } }); connect(this, &ChatPage::syncRoomlist, room_list_, &RoomList::sync); @@ -518,16 +527,7 @@ ChatPage::syncCompleted(const mtx::responses::Sync &response) { syncTimeoutTimer_->stop(); - // Process ephemeral data per room. - for (const auto &room : response.rooms.join) { - auto room_id = QString::fromStdString(room.first); - - updateTypingUsers(room_id, room.second.ephemeral.typing); - updateRoomNotificationCount(room_id, - room.second.unread_notifications.notification_count); - } - - QtConcurrent::run([this, res = std::move(response)]() { + auto promise = QtConcurrent::run([this, res = std::move(response)]() { try { cache_->saveState(res); emit syncRoomlist(cache_->roomUpdates(res)); diff --git a/src/RoomList.cc b/src/RoomList.cc index 7d17585c..bb3e7505 100644 --- a/src/RoomList.cc +++ b/src/RoomList.cc @@ -352,8 +352,6 @@ RoomList::paintEvent(QPaintEvent *) void RoomList::updateRoom(const QString &room_id, const RoomInfo &info) { - qDebug() << "updateRoom" << QString::fromStdString(info.name) << room_id; - if (!roomExists(room_id)) { if (info.is_invite) addInvitedRoom(room_id, info);