From 5ca043ad87d56cfaa984f67b84c5e98f1900c61e Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 4 Jan 2021 15:10:53 +0100 Subject: [PATCH 1/2] Fix user status that got lost at some point --- resources/qml/MessageView.qml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/resources/qml/MessageView.qml b/resources/qml/MessageView.qml index 679c1f50..aa222ac5 100644 --- a/resources/qml/MessageView.qml +++ b/resources/qml/MessageView.qml @@ -140,6 +140,15 @@ ListView { } + Label { + color: colors.buttonText + text: TimelineManager.userStatus(modelData.userId) + textFormat: Text.PlainText + elide: Text.ElideRight + width: chat.delegateMaxWidth - parent.spacing * 2 - userName.implicitWidth - avatarSize + font.italic: true + } + } } From 3a41bb9fff45c7e87ee1ce647155a86ce4f227b1 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 5 Jan 2021 22:10:40 +0100 Subject: [PATCH 2/2] Fix typing notifications flickering sometimes --- CMakeLists.txt | 2 +- io.github.NhekoReborn.Nheko.json | 2 +- src/Cache.cpp | 77 ++++++++++++++++++---------- src/timeline/TimelineViewManager.cpp | 19 ++++--- 4 files changed, 66 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ead1c32b..6ba411ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -356,7 +356,7 @@ if(USE_BUNDLED_MTXCLIENT) FetchContent_Declare( MatrixClient GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git - GIT_TAG ce8bc9c3dd6bba432e716f55136133111b0186e7 + GIT_TAG cad81d1677a4845366b93112f8f2e267ee8c9ae0 ) set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "") set(BUILD_LIB_TESTS OFF CACHE INTERNAL "") diff --git a/io.github.NhekoReborn.Nheko.json b/io.github.NhekoReborn.Nheko.json index 352ca648..49e92311 100644 --- a/io.github.NhekoReborn.Nheko.json +++ b/io.github.NhekoReborn.Nheko.json @@ -162,7 +162,7 @@ "name": "mtxclient", "sources": [ { - "commit": "ce8bc9c3dd6bba432e716f55136133111b0186e7", + "commit": "cad81d1677a4845366b93112f8f2e267ee8c9ae0", "type": "git", "url": "https://github.com/Nheko-Reborn/mtxclient.git" } diff --git a/src/Cache.cpp b/src/Cache.cpp index dac0b23a..04046346 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -124,17 +124,15 @@ Cache::isHiddenEvent(lmdb::txn &txn, EventType::Reaction, EventType::CallCandidates, EventType::Unsupported}; if (auto temp = getAccountData(txn, mtx::events::EventType::NhekoHiddenEvents, "")) - hiddenEvents = std::move( - std::get< - mtx::events::Event>( - *temp) - .content); + hiddenEvents = + std::move(std::get>(*temp) + .content); if (auto temp = getAccountData(txn, mtx::events::EventType::NhekoHiddenEvents, room_id)) - hiddenEvents = std::move( - std::get< - mtx::events::Event>( - *temp) - .content); + hiddenEvents = + std::move(std::get>(*temp) + .content); return std::visit( [hiddenEvents](const auto &ev) { @@ -1197,7 +1195,7 @@ void Cache::saveState(const mtx::responses::Sync &res) { using namespace mtx::events; - auto user_id = this->localUserId_.toStdString(); + auto local_user_id = this->localUserId_.toStdString(); auto currentBatchToken = nextBatchToken(); @@ -1252,13 +1250,19 @@ Cache::saveState(const mtx::responses::Sync &res) evt); // for tag events - if (std::holds_alternative>(evt)) { - auto tags_evt = std::get>(evt); - has_new_tags = true; + if (std::holds_alternative>( + evt)) { + auto tags_evt = + std::get>(evt); + has_new_tags = true; for (const auto &tag : tags_evt.content.tags) { updatedInfo.tags.push_back(tag.first); } } + if (auto fr = std::get_if>(&evt)) { + nhlog::db()->debug("Fully read: {}", fr->content.event_id); + } } if (!has_new_tags) { // retrieve the old tags, they haven't changed @@ -1282,7 +1286,20 @@ 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); + for (const auto &e : room.second.ephemeral.events) { + if (auto receiptsEv = std::get_if< + mtx::events::EphemeralEvent>(&e)) { + Receipts receipts; + + for (const auto &[event_id, userReceipts] : + receiptsEv->content.receipts) { + for (const auto &[user_id, receipt] : userReceipts.users) { + receipts[event_id][user_id] = receipt.ts; + } + } + updateReadReceipt(txn, room.first, receipts); + } + } // Clean up non-valid invites. removeInvite(txn, room.first); @@ -1302,19 +1319,27 @@ Cache::saveState(const mtx::responses::Sync &res) std::map readStatus; for (const auto &room : res.rooms.join) { - if (!room.second.ephemeral.receipts.empty()) { - std::vector receipts; - for (const auto &receipt : room.second.ephemeral.receipts) { - for (const auto &receiptUsersTs : receipt.second) { - if (receiptUsersTs.first != user_id) { - receipts.push_back( - QString::fromStdString(receipt.first)); - break; + for (const auto &e : room.second.ephemeral.events) { + if (auto receiptsEv = std::get_if< + mtx::events::EphemeralEvent>(&e)) { + std::vector receipts; + + for (const auto &[event_id, userReceipts] : + receiptsEv->content.receipts) { + for (const auto &[user_id, receipt] : userReceipts.users) { + (void)receipt; + + if (user_id != local_user_id) { + receipts.push_back( + QString::fromStdString(event_id)); + break; + } } } + if (!receipts.empty()) + emit newReadReceipts(QString::fromStdString(room.first), + receipts); } - if (!receipts.empty()) - emit newReadReceipts(QString::fromStdString(room.first), receipts); } readStatus.emplace(QString::fromStdString(room.first), calculateRoomReadStatus(room.first)); @@ -1440,7 +1465,7 @@ Cache::roomsWithTagUpdates(const mtx::responses::Sync &res) for (const auto &room : res.rooms.join) { bool hasUpdates = false; for (const auto &evt : room.second.account_data.events) { - if (std::holds_alternative>(evt)) { + if (std::holds_alternative>(evt)) { hasUpdates = true; } } diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index 03eb53fc..f31b5ea5 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -297,13 +297,20 @@ TimelineViewManager::sync(const mtx::responses::Rooms &rooms) &CallManager::syncEvent); if (ChatPage::instance()->userSettings()->typingNotifications()) { - std::vector typing; - typing.reserve(room.ephemeral.typing.size()); - for (const auto &user : room.ephemeral.typing) { - if (user != http::client()->user_id().to_string()) - typing.push_back(QString::fromStdString(user)); + for (const auto &ev : room.ephemeral.events) { + if (auto t = std::get_if< + mtx::events::EphemeralEvent>( + &ev)) { + std::vector typing; + typing.reserve(t->content.user_ids.size()); + for (const auto &user : t->content.user_ids) { + if (user != http::client()->user_id().to_string()) + typing.push_back( + QString::fromStdString(user)); + } + room_model->updateTypingUsers(typing); + } } - room_model->updateTypingUsers(typing); } }