summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-04-21 17:14:16 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-04-21 17:14:16 +0300
commit4a2f1af0907905829917ceddd828d5706aeff294 (patch)
tree9c2d65a64d1901556640814952abfee1710fd256 /src
parentCache refactoring (diff)
downloadnheko-4a2f1af0907905829917ceddd828d5706aeff294.tar.xz
Save read receipts
Diffstat (limited to 'src')
-rw-r--r--src/Cache.cc12
-rw-r--r--src/ChatPage.cc20
-rw-r--r--src/RoomList.cc2
3 files changed, 14 insertions, 20 deletions
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<std::string, uint64_t> 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 <QApplication> #include <QDebug> +#include <QFuture> #include <QSettings> #include <QtConcurrent> @@ -424,6 +425,14 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> 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);