diff --git a/src/models/roomlistmodel.cpp b/src/models/roomlistmodel.cpp index b53d5348a..9acf9f34b 100644 --- a/src/models/roomlistmodel.cpp +++ b/src/models/roomlistmodel.cpp @@ -3,7 +3,10 @@ #include "roomlistmodel.h" +#include + #include "eventhandler.h" +#include "neochatconfig.h" #include "neochatconnection.h" #include "neochatroom.h" #include "roommanager.h" @@ -239,10 +242,26 @@ QVariant RoomListModel::data(const QModelIndex &index, int role) const return QVariant::fromValue(room); } if (role == SubtitleTextRole) { - if (room->lastEvent() == nullptr || room->lastEventIsSpoiler()) { + const auto lastEvent = room->lastEvent([](const RoomEvent *event) -> bool { + if (event->isStateEvent() && !NeoChatConfig::showStateEvent()) { + return true; + } + if (auto roomMemberEvent = eventCast(event)) { + if ((roomMemberEvent->isJoin() || roomMemberEvent->isLeave()) && !NeoChatConfig::showLeaveJoinEvent()) { + return true; + } else if (roomMemberEvent->isRename() && !roomMemberEvent->isJoin() && !roomMemberEvent->isLeave() && !NeoChatConfig::showRename()) { + return true; + } else if (roomMemberEvent->isAvatarUpdate() && !roomMemberEvent->isJoin() && !roomMemberEvent->isLeave() + && !NeoChatConfig::showAvatarUpdate()) { + return true; + } + } + return false; + }); + if (lastEvent == nullptr || room->lastEventIsSpoiler()) { return QString(); } - return EventHandler::subtitleText(room, room->lastEvent()); + return EventHandler::subtitleText(room, lastEvent); } if (role == AvatarImageRole) { return room->avatar(128); diff --git a/src/models/roomtreemodel.cpp b/src/models/roomtreemodel.cpp index c605de7a9..52030f1b0 100644 --- a/src/models/roomtreemodel.cpp +++ b/src/models/roomtreemodel.cpp @@ -3,9 +3,11 @@ #include "roomtreemodel.h" +#include #include #include "eventhandler.h" +#include "neochatconfig.h" #include "neochatconnection.h" #include "neochatroomtype.h" #include "spacehierarchycache.h" @@ -354,10 +356,26 @@ QVariant RoomTreeModel::data(const QModelIndex &index, int role) const } return i18nc("@info:label", "%1 invited you", room->member(room->invitingUserId()).displayName()); } - if (room->lastEvent() == nullptr || room->lastEventIsSpoiler()) { + const auto lastEvent = room->lastEvent([](const RoomEvent *event) -> bool { + if (event->isStateEvent() && !NeoChatConfig::showStateEvent()) { + return true; + } + if (auto roomMemberEvent = eventCast(event)) { + if ((roomMemberEvent->isJoin() || roomMemberEvent->isLeave()) && !NeoChatConfig::showLeaveJoinEvent()) { + return true; + } else if (roomMemberEvent->isRename() && !roomMemberEvent->isJoin() && !roomMemberEvent->isLeave() && !NeoChatConfig::showRename()) { + return true; + } else if (roomMemberEvent->isAvatarUpdate() && !roomMemberEvent->isJoin() && !roomMemberEvent->isLeave() + && !NeoChatConfig::showAvatarUpdate()) { + return true; + } + } + return false; + }); + if (lastEvent == nullptr || room->lastEventIsSpoiler()) { return QString(); } - return EventHandler::subtitleText(room, room->lastEvent()); + return EventHandler::subtitleText(room, lastEvent); } if (role == AvatarImageRole) { return room->avatar(128); diff --git a/src/neochatroom.cpp b/src/neochatroom.cpp index 84d86e488..4655ff073 100644 --- a/src/neochatroom.cpp +++ b/src/neochatroom.cpp @@ -42,7 +42,6 @@ #include "eventhandler.h" #include "events/pollevent.h" #include "filetransferpseudojob.h" -#include "neochatconfig.h" #include "neochatconnection.h" #include "neochatroommember.h" #include "roomlastmessageprovider.h" @@ -314,11 +313,17 @@ void NeoChatRoom::sendTypingNotification(bool isTyping) connection()->callApi(BackgroundRequest, localMember().id(), id(), isTyping, 10000); } -const RoomEvent *NeoChatRoom::lastEvent() const +const RoomEvent *NeoChatRoom::lastEvent(std::function filter) const { for (auto timelineItem = messageEvents().rbegin(); timelineItem < messageEvents().rend(); timelineItem++) { const RoomEvent *event = timelineItem->get(); + if (filter) { + if (filter(event)) { + continue; + } + } + if (is(*event) || is(*event)) { continue; } @@ -326,19 +331,6 @@ const RoomEvent *NeoChatRoom::lastEvent() const continue; } - if (event->isStateEvent() && !NeoChatConfig::showStateEvent()) { - continue; - } - - if (auto roomMemberEvent = eventCast(event)) { - if ((roomMemberEvent->isJoin() || roomMemberEvent->isLeave()) && !NeoChatConfig::showLeaveJoinEvent()) { - continue; - } else if (roomMemberEvent->isRename() && !roomMemberEvent->isJoin() && !roomMemberEvent->isLeave() && !NeoChatConfig::showRename()) { - continue; - } else if (roomMemberEvent->isAvatarUpdate() && !roomMemberEvent->isJoin() && !roomMemberEvent->isLeave() && !NeoChatConfig::showAvatarUpdate()) { - continue; - } - } if (event->isStateEvent() && static_cast(*event).repeatsState()) { continue; } diff --git a/src/neochatroom.h b/src/neochatroom.h index 79dc6751a..a2a218cff 100644 --- a/src/neochatroom.h +++ b/src/neochatroom.h @@ -211,7 +211,7 @@ public: * @warning This function can return an empty pointer if the room does not have * any RoomMessageEvents loaded. */ - [[nodiscard]] const Quotient::RoomEvent *lastEvent() const; + [[nodiscard]] const Quotient::RoomEvent *lastEvent(std::function filter = {}) const; /** * @brief Convenient way to check if the last event looks like it has spoilers.