Don't count m.room.member or m.room.reaction events as viewable

This commit is contained in:
Konstantinos Sideris 2018-03-18 13:29:21 +02:00
parent 81d3bd8ce6
commit fef7cd5b83
2 changed files with 34 additions and 2 deletions

View File

@ -150,10 +150,16 @@ private:
void updateLastSender(const QString &user_id, TimelineDirection direction);
void notifyForLastEvent();
void notifyForLastEvent(const TimelineEvent &event);
TimelineEvent findFirstViewableEvent(const std::vector<TimelineEvent> &events);
TimelineEvent findLastViewableEvent(const std::vector<TimelineEvent> &events);
void readLastEvent() const;
bool isScrollbarActivated() { return scroll_area_->verticalScrollBar()->value() != 0; }
QString getLastEventId() const;
QString getEventSender(const mtx::events::collections::TimelineEvents &event) const;
mtx::events::EventType getEventType(
const mtx::events::collections::TimelineEvents &event) const;
template<class Event, class Widget>
TimelineItem *processMessageEvent(const Event &event, TimelineDirection direction);

View File

@ -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);
}