From 31d09dbd68f9fbc127c78fdedae9d446c5a8db60 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sun, 15 Jul 2018 20:32:22 +0300 Subject: [PATCH] De-duplicate the m.room.encryption event --- include/timeline/TimelineView.h | 7 +++++-- src/timeline/TimelineView.cc | 10 ++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/timeline/TimelineView.h b/include/timeline/TimelineView.h index 97bac51a..e6b80637 100644 --- a/include/timeline/TimelineView.h +++ b/include/timeline/TimelineView.h @@ -165,7 +165,7 @@ protected: private: using TimelineEvent = mtx::events::collections::TimelineEvents; - QWidget *relativeWidget(TimelineItem *item, int dt) const; + QWidget *relativeWidget(QWidget *item, int dt) const; DecryptionResult parseEncryptedEvent( const mtx::events::EncryptedEvent &e); @@ -265,6 +265,9 @@ private: QWidget *parseMessageEvent(const mtx::events::collections::TimelineEvents &event, TimelineDirection direction); + //! Store the event id associated with the given widget. + void saveEventId(QWidget *widget); + QVBoxLayout *top_layout_; QVBoxLayout *scroll_layout_; @@ -313,7 +316,7 @@ private: void renderTopEvents(const std::vector &events); // The events currently rendered. Used for duplicate detection. - QMap eventIds_; + QMap eventIds_; QQueue pending_msgs_; QList pending_sent_msgs_; }; diff --git a/src/timeline/TimelineView.cc b/src/timeline/TimelineView.cc index 0204bbd2..207844e4 100644 --- a/src/timeline/TimelineView.cc +++ b/src/timeline/TimelineView.cc @@ -221,9 +221,15 @@ TimelineView::parseMessageEvent(const mtx::events::collections::TimelineEvents & return nullptr; } else if (mpark::holds_alternative>(event)) { - auto msg = mpark::get>(event); + auto msg = mpark::get>(event); + auto event_id = QString::fromStdString(msg.event_id); + + if (eventIds_.contains(event_id)) + return nullptr; + auto item = new InfoMessage(tr("Encryption is enabled"), this); item->saveDatetime(QDateTime::fromMSecsSinceEpoch(msg.origin_server_ts)); + eventIds_[event_id] = item; return item; } else if (mpark::holds_alternative>(event)) { @@ -993,7 +999,7 @@ TimelineView::removeEvent(const QString &event_id) } QWidget * -TimelineView::relativeWidget(TimelineItem *item, int dt) const +TimelineView::relativeWidget(QWidget *item, int dt) const { int pos = scroll_layout_->indexOf(item);