diff --git a/src/libneochat/models/roomlistmodel.cpp b/src/libneochat/models/roomlistmodel.cpp index e9084c4ab..648275359 100644 --- a/src/libneochat/models/roomlistmodel.cpp +++ b/src/libneochat/models/roomlistmodel.cpp @@ -248,7 +248,7 @@ QVariant RoomListModel::data(const QModelIndex &index, int role) const } if (role == SubtitleTextRole) { const auto lastEvent = room->lastEvent(m_hiddenFilter); - if (lastEvent == nullptr || room->lastEventIsSpoiler()) { + if (lastEvent == nullptr || room->isEventSpoiler(lastEvent)) { return QString(); } return EventHandler::subtitleText(room, lastEvent); diff --git a/src/libneochat/neochatroom.cpp b/src/libneochat/neochatroom.cpp index 60325613a..20389350e 100644 --- a/src/libneochat/neochatroom.cpp +++ b/src/libneochat/neochatroom.cpp @@ -379,14 +379,12 @@ void NeoChatRoom::cacheLastEvent() } } -bool NeoChatRoom::lastEventIsSpoiler() const +bool NeoChatRoom::isEventSpoiler(const RoomEvent *e) const { - if (auto event = lastEvent()) { - if (auto e = eventCast(event)) { - if (e->has() && e->content() && e->mimeType().name() == "text/html"_L1) { - auto htmlBody = e->get()->body; - return htmlBody.contains("data-mx-spoiler"_L1); - } + if (const auto message = eventCast(e)) { + if (message->has() && message->content() && message->mimeType().name() == "text/html"_L1) { + const auto htmlBody = message->get()->body; + return htmlBody.contains("data-mx-spoiler"_L1); } } return false; diff --git a/src/libneochat/neochatroom.h b/src/libneochat/neochatroom.h index ab20ead77..8eff6fef8 100644 --- a/src/libneochat/neochatroom.h +++ b/src/libneochat/neochatroom.h @@ -212,7 +212,7 @@ public: [[nodiscard]] const Quotient::RoomEvent *lastEvent(std::function filter = {}) const; /** - * @brief Convenient way to check if the last event looks like it has spoilers. + * @brief Convenient way to check if the event looks like it has spoilers. * * This does a basic check to see if the message contains a data-mx-spoiler * attribute within the text which makes it likely that the message has a spoiler @@ -222,7 +222,7 @@ public: * * @sa lastEvent() */ - [[nodiscard]] bool lastEventIsSpoiler() const; + [[nodiscard]] bool isEventSpoiler(const Quotient::RoomEvent *e) const; /** * @brief Return the notification count for the room accounting for tags and notification state. diff --git a/src/rooms/models/roomtreemodel.cpp b/src/rooms/models/roomtreemodel.cpp index ad5657c23..03cf48aca 100644 --- a/src/rooms/models/roomtreemodel.cpp +++ b/src/rooms/models/roomtreemodel.cpp @@ -360,7 +360,7 @@ QVariant RoomTreeModel::data(const QModelIndex &index, int role) const return i18nc("@info:label", "%1 invited you", room->member(room->invitingUserId()).displayName()); } const auto lastEvent = room->lastEvent(m_hiddenFilter); - if (lastEvent == nullptr || room->lastEventIsSpoiler()) { + if (lastEvent == nullptr || room->isEventSpoiler(lastEvent)) { return QString(); } return EventHandler::subtitleText(room, lastEvent);