From 0a09ce0f7546a040c6c69a0cfe3b2221ed5a9685 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Tue, 27 Mar 2018 21:07:39 +0300 Subject: [PATCH] Update first & last sender after message deletion fixes #282 --- include/timeline/TimelineView.h | 3 +++ src/timeline/TimelineView.cc | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/timeline/TimelineView.h b/include/timeline/TimelineView.h index bec23cca..b38d6a7d 100644 --- a/include/timeline/TimelineView.h +++ b/include/timeline/TimelineView.h @@ -154,8 +154,11 @@ private: TimelineEvent findFirstViewableEvent(const std::vector &events); TimelineEvent findLastViewableEvent(const std::vector &events); + //! Mark the last event as read. void readLastEvent() const; + //! Whether or not the scrollbar is visible (non-zero height). bool isScrollbarActivated() { return scroll_area_->verticalScrollBar()->value() != 0; } + //! Retrieve the event id of the last item. QString getLastEventId() const; QString getEventSender(const mtx::events::collections::TimelineEvents &event) const; mtx::events::EventType getEventType( diff --git a/src/timeline/TimelineView.cc b/src/timeline/TimelineView.cc index ce6b061a..a00f4df5 100644 --- a/src/timeline/TimelineView.cc +++ b/src/timeline/TimelineView.cc @@ -753,6 +753,20 @@ TimelineView::removeEvent(const QString &event_id) prevLabel->deleteLater(); } + // If we deleted the last item in the timeline... + if (!nextItem && prevItem) + lastSender_ = prevItem->descriptionMessage().userid; + + // If we deleted the first item in the timeline... + if (!prevItem && nextItem) + firstSender_ = nextItem->descriptionMessage().userid; + + // If we deleted the only item in the timeline... + if (!prevItem && !nextItem) { + firstSender_.clear(); + lastSender_.clear(); + } + // Finally remove the event. removedItem->deleteLater(); eventIds_.remove(event_id);