From 81d3bd8ce6d08c99793cb3a5d60b185701cd5e5c Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sun, 18 Mar 2018 12:47:35 +0200 Subject: Remove redacted events from other users (#171) --- cmake/MatrixStructs.cmake | 2 +- include/timeline/TimelineView.h | 6 ---- src/timeline/TimelineView.cc | 61 +++++++++++------------------------------ 3 files changed, 17 insertions(+), 52 deletions(-) diff --git a/cmake/MatrixStructs.cmake b/cmake/MatrixStructs.cmake index 4b1a3c12..9252f128 100644 --- a/cmake/MatrixStructs.cmake +++ b/cmake/MatrixStructs.cmake @@ -23,7 +23,7 @@ ExternalProject_Add( MatrixStructs GIT_REPOSITORY https://github.com/mujx/matrix-structs - GIT_TAG 701eb5b06c370c23bca35a957f5a208c2115b52f + GIT_TAG e503c4ff27cd8159c377d9a7d2e6e91698a5517b BUILD_IN_SOURCE 1 SOURCE_DIR ${MATRIX_STRUCTS_ROOT} diff --git a/include/timeline/TimelineView.h b/include/timeline/TimelineView.h index 78e092b3..78000a16 100644 --- a/include/timeline/TimelineView.h +++ b/include/timeline/TimelineView.h @@ -230,12 +230,6 @@ private: //! Render the given timeline events to the top of the timeline. void renderTopEvents(const std::vector &events); - //! Decide if the given timeline event can be rendered. - inline bool isViewable(const TimelineEvent &event) const; - - //! Decide if the given event should trigger a notification. - inline bool isNotifiable(const TimelineEvent &event) const; - // The events currently rendered. Used for duplicate detection. QMap eventIds_; QQueue pending_msgs_; diff --git a/src/timeline/TimelineView.cc b/src/timeline/TimelineView.cc index ded5ad2c..2fef0952 100644 --- a/src/timeline/TimelineView.cc +++ b/src/timeline/TimelineView.cc @@ -163,10 +163,8 @@ TimelineView::addBackwardsEvents(const QString &room_id, const mtx::responses::M isTimelineFinished = false; // Queue incoming messages to be rendered later. - for (auto const &e : msgs.chunk) { - if (isViewable(e)) - topMessages_.emplace_back(e); - } + for (auto const &e : msgs.chunk) + topMessages_.emplace_back(e); // The RoomList message preview will be updated only if this // is the first batch of messages received through /messages @@ -202,7 +200,18 @@ TimelineView::parseMessageEvent(const mtx::events::collections::TimelineEvents & using TextEvent = mtx::events::RoomEvent; using VideoEvent = mtx::events::RoomEvent; - if (mpark::holds_alternative>(event)) { + if (mpark::holds_alternative>(event)) { + auto redaction_event = + mpark::get>(event); + const auto event_id = QString::fromStdString(redaction_event.redacts); + + QTimer::singleShot(0, this, [event_id, this]() { + if (eventIds_.contains(event_id)) + removeEvent(event_id); + }); + + return nullptr; + } else if (mpark::holds_alternative>(event)) { auto audio = mpark::get>(event); return processMessageEvent(audio, direction); } else if (mpark::holds_alternative>(event)) { @@ -300,15 +309,8 @@ TimelineView::addEvents(const mtx::responses::Timeline &timeline) isInitialSync = false; } - for (const auto &e : timeline.events) { - // Save the message if it can be rendered. - if (isViewable(e)) - bottomMessages_.push_back(e); - - // Calculate notifications. - /* if (isNotifiable(e)) */ - /* sendNotification() */ - } + for (const auto &e : timeline.events) + bottomMessages_.push_back(e); if (!bottomMessages_.empty()) notifyForLastEvent(bottomMessages_[bottomMessages_.size() - 1]); @@ -326,37 +328,6 @@ TimelineView::addEvents(const mtx::responses::Timeline &timeline) } } -inline bool -TimelineView::isViewable(const TimelineEvent &event) const -{ - namespace msg = mtx::events::msg; - - return mpark::holds_alternative>(event) || - mpark::holds_alternative>(event) || - mpark::holds_alternative>(event) || - mpark::holds_alternative>(event) || - mpark::holds_alternative>(event) || - mpark::holds_alternative>(event) || - mpark::holds_alternative>(event); -} - -inline bool -TimelineView::isNotifiable(const TimelineEvent &event) const -{ - namespace msg = mtx::events::msg; - - if (local_user_ == getEventSender(event)) - return false; - - return mpark::holds_alternative>(event) || - mpark::holds_alternative>(event) || - mpark::holds_alternative>(event) || - mpark::holds_alternative>(event) || - mpark::holds_alternative>(event) || - mpark::holds_alternative>(event) || - mpark::holds_alternative>(event); -} - void TimelineView::init() { -- cgit v1.2.3