Skip to content
This repository has been archived by the owner on Oct 17, 2019. It is now read-only.

Commit

Permalink
De-duplicate the m.room.encryption event
Browse files Browse the repository at this point in the history
  • Loading branch information
mujx committed Jul 15, 2018
1 parent a9f0212 commit 31d09db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 5 additions & 2 deletions include/timeline/TimelineView.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private slots:
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<mtx::events::msg::Encrypted> &e);
Expand Down Expand Up @@ -265,6 +265,9 @@ private slots:
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_;

Expand Down Expand Up @@ -313,7 +316,7 @@ private slots:
void renderTopEvents(const std::vector<TimelineEvent> &events);

// The events currently rendered. Used for duplicate detection.
QMap<QString, TimelineItem *> eventIds_;
QMap<QString, QWidget *> eventIds_;
QQueue<PendingMessage> pending_msgs_;
QList<PendingMessage> pending_sent_msgs_;
};
Expand Down
10 changes: 8 additions & 2 deletions src/timeline/TimelineView.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,15 @@ TimelineView::parseMessageEvent(const mtx::events::collections::TimelineEvents &

return nullptr;
} else if (mpark::holds_alternative<StateEvent<state::Encryption>>(event)) {
auto msg = mpark::get<StateEvent<state::Encryption>>(event);
auto msg = mpark::get<StateEvent<state::Encryption>>(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<RoomEvent<msg::Audio>>(event)) {
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 31d09db

Please sign in to comment.