From 34f2c2dabcbaa9d2b0e2f75b0c6b7a2e0108c67c Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Tue, 15 Jul 2025 14:44:23 -0400 Subject: [PATCH] Stop a room's lastActiveTime from changing because of hidden events This was just a missed oversight during the refactoring, we need to pass the hidden filter into NeoChatRoom::lastEvent so it doesn't pick up on hidden events and push rooms to the top for no discernible reason. Also, I simplified the function to take out the cached event handling, because lastEvent is already doing that. The function is const now, too and has some nicer comments. --- src/libneochat/neochatroom.cpp | 19 +++++++++---------- src/libneochat/neochatroom.h | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/libneochat/neochatroom.cpp b/src/libneochat/neochatroom.cpp index c417af11a..e83848091 100644 --- a/src/libneochat/neochatroom.cpp +++ b/src/libneochat/neochatroom.cpp @@ -441,20 +441,19 @@ void NeoChatRoom::onRedaction(const RoomEvent &prevEvent, const RoomEvent & /*af } } -QDateTime NeoChatRoom::lastActiveTime() +QDateTime NeoChatRoom::lastActiveTime() const { - if (timelineSize() == 0) { - if (m_cachedEvent != nullptr) { - return m_cachedEvent->originTimestamp(); - } - return QDateTime(); - } - - if (auto event = lastEvent()) { + // Find the last relevant event: + if (const auto event = lastEvent(m_hiddenFilter)) { return event->originTimestamp(); } - // no message found, take last event + // If nothing is loaded yet, and there is no cached event: + if (timelineSize() == 0) { + return {}; + } + + // No message found, take last event: return messageEvents().rbegin()->get()->originTimestamp(); } diff --git a/src/libneochat/neochatroom.h b/src/libneochat/neochatroom.h index d65044501..f18553b5d 100644 --- a/src/libneochat/neochatroom.h +++ b/src/libneochat/neochatroom.h @@ -208,7 +208,7 @@ public: bool visible() const; void setVisible(bool visible); - [[nodiscard]] QDateTime lastActiveTime(); + [[nodiscard]] QDateTime lastActiveTime() const; /** * @brief Get the last interesting event.