Make lastEvent() take a filter function

Make `lastEvent()` take a filter function so we can remove any dependence on `NeochatConfig` from `NeoChatRoom`.
This commit is contained in:
James Graham
2025-04-04 09:27:04 +00:00
parent 88eb2223c5
commit 913b4ea923
4 changed files with 49 additions and 20 deletions

View File

@@ -3,7 +3,10 @@
#include "roomlistmodel.h"
#include <Quotient/events/roommemberevent.h>
#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<const RoomMemberEvent>(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);

View File

@@ -3,9 +3,11 @@
#include "roomtreemodel.h"
#include <Quotient/events/roommemberevent.h>
#include <Quotient/room.h>
#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<const RoomMemberEvent>(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);