diff options
author | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2018-03-18 13:29:21 +0200 |
---|---|---|
committer | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2018-03-18 13:29:21 +0200 |
commit | fef7cd5b8378a73de686688eb136faeb6246feb0 (patch) | |
tree | 2ac62b77c3c915cc29ab35078c987cfbb3d21e5b /src/timeline | |
parent | Remove redacted events from other users (#171) (diff) | |
download | nheko-fef7cd5b8378a73de686688eb136faeb6246feb0.tar.xz |
Don't count m.room.member or m.room.reaction events as viewable
Diffstat (limited to 'src/timeline')
-rw-r--r-- | src/timeline/TimelineView.cc | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/timeline/TimelineView.cc b/src/timeline/TimelineView.cc index 2fef0952..16b57df4 100644 --- a/src/timeline/TimelineView.cc +++ b/src/timeline/TimelineView.cc @@ -170,7 +170,7 @@ TimelineView::addBackwardsEvents(const QString &room_id, const mtx::responses::M // is the first batch of messages received through /messages // i.e there are no other messages currently present. if (!topMessages_.empty() && scroll_layout_->count() == 1) - notifyForLastEvent(topMessages_.at(0)); + notifyForLastEvent(findFirstViewableEvent(topMessages_)); if (isVisible()) { renderTopEvents(topMessages_); @@ -313,7 +313,7 @@ TimelineView::addEvents(const mtx::responses::Timeline &timeline) bottomMessages_.push_back(e); if (!bottomMessages_.empty()) - notifyForLastEvent(bottomMessages_[bottomMessages_.size() - 1]); + notifyForLastEvent(findLastViewableEvent(bottomMessages_)); // If the current timeline is open and there are messages to be rendered. if (isVisible() && !bottomMessages_.empty()) { @@ -755,3 +755,29 @@ TimelineView::relativeWidget(TimelineItem *item, int dt) const return isOutOfBounds ? nullptr : scroll_layout_->itemAt(pos)->widget(); } + +TimelineEvent +TimelineView::findFirstViewableEvent(const std::vector<TimelineEvent> &events) +{ + auto it = std::find_if(events.begin(), events.end(), [this](const auto &event) { + return mtx::events::EventType::RoomMessage == getEventType(event); + }); + + return (it == std::end(events)) ? events.front() : *it; +} + +TimelineEvent +TimelineView::findLastViewableEvent(const std::vector<TimelineEvent> &events) +{ + auto it = std::find_if(events.rbegin(), events.rend(), [this](const auto &event) { + return mtx::events::EventType::RoomMessage == getEventType(event); + }); + + return (it == std::rend(events)) ? events.back() : *it; +} + +inline mtx::events::EventType +TimelineView::getEventType(const mtx::events::collections::TimelineEvents &event) const +{ + return mpark::visit([](auto msg) { return msg.type; }, event); +} |