From 67458dd2f86d0e74fa14730827f1475d12a4dd6b Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sat, 7 Jul 2018 12:35:29 +0300 Subject: [PATCH] Mark all decrypted messages with a padlock fixes #351 --- include/timeline/TimelineView.h | 10 +++++++++- src/timeline/TimelineView.cc | 24 ++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/include/timeline/TimelineView.h b/include/timeline/TimelineView.h index 7f1912ea..81212c27 100644 --- a/include/timeline/TimelineView.h +++ b/include/timeline/TimelineView.h @@ -46,6 +46,14 @@ private: std::function fn_; }; +struct DecryptionResult +{ + //! The decrypted content as a normal plaintext event. + utils::TimelineEvent event; + //! Whether or not the decryption was successful. + bool isDecrypted = false; +}; + class FloatingButton; struct DescInfo; @@ -192,7 +200,7 @@ private: QWidget *relativeWidget(TimelineItem *item, int dt) const; - TimelineEvent parseEncryptedEvent( + DecryptionResult parseEncryptedEvent( const mtx::events::EncryptedEvent &e); void handleClaimedKeys(std::shared_ptr keeper, diff --git a/src/timeline/TimelineView.cc b/src/timeline/TimelineView.cc index 114c52df..e9c5b017 100644 --- a/src/timeline/TimelineView.cc +++ b/src/timeline/TimelineView.cc @@ -280,15 +280,19 @@ TimelineView::parseMessageEvent(const mtx::events::collections::TimelineEvents & return processMessageEvent(mpark::get(event), direction); } else if (mpark::holds_alternative>(event)) { - auto decrypted = - parseEncryptedEvent(mpark::get>(event)); - return parseMessageEvent(decrypted, direction); + auto res = parseEncryptedEvent(mpark::get>(event)); + auto item = parseMessageEvent(res.event, direction); + + if (item != nullptr && res.isDecrypted) + item->markReceived(true); + + return item; } return nullptr; } -TimelineEvent +DecryptionResult TimelineView::parseEncryptedEvent(const mtx::events::EncryptedEvent &e) { MegolmSessionIndex index; @@ -309,12 +313,12 @@ TimelineView::parseEncryptedEvent(const mtx::events::EncryptedEventcritical("failed to check megolm session's existence: {}", e.what()); dummy.content.body = "-- Decryption Error (failed to communicate with DB) --"; - return dummy; + return {dummy, false}; } std::string msg_str; @@ -330,7 +334,7 @@ TimelineView::parseEncryptedEvent(const mtx::events::EncryptedEventcritical("failed to decrypt message with index ({}, {}, {}): {}", index.room_id, @@ -338,7 +342,7 @@ TimelineView::parseEncryptedEvent(const mtx::events::EncryptedEvent