Store NeochatRoomMember objects in the room

Store NeochatRoomMember objects in the room so we don't duplicate them unnecessarily. This also adds a visible property for a room which is set true when shown by MessageEventModel and false when not, triggering the deletion of member objects. This mechanism will be used for other object types in the future.
This commit is contained in:
James Graham
2025-01-05 11:06:42 +00:00
parent 3dbe605de8
commit c21e9f2114
5 changed files with 74 additions and 18 deletions

View File

@@ -44,6 +44,7 @@
#include "events/pollevent.h"
#include "filetransferpseudojob.h"
#include "neochatconfig.h"
#include "neochatroommember.h"
#include "roomlastmessageprovider.h"
#include "spacehierarchycache.h"
#include "texthandler.h"
@@ -161,6 +162,20 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS
});
}
bool NeoChatRoom::visible() const
{
return m_visible;
}
void NeoChatRoom::setVisible(bool visible)
{
m_visible = visible;
if (!visible) {
m_memberObjects.clear();
}
}
int NeoChatRoom::contextAwareNotificationCount() const
{
// DOn't include spaces, rooms that the user hasn't joined and rooms where the user has joined the successor.
@@ -1726,4 +1741,13 @@ void NeoChatRoom::setRoomState(const QString &type, const QString &stateKey, con
setState(type, stateKey, QJsonDocument::fromJson(content).object());
}
NeochatRoomMember *NeoChatRoom::qmlSafeMember(const QString &memberId)
{
if (!m_memberObjects.contains(memberId)) {
return m_memberObjects.emplace(memberId, std::make_unique<NeochatRoomMember>(this, memberId)).first->second.get();
}
return m_memberObjects[memberId].get();
}
#include "moc_neochatroom.cpp"