@baris said:
There is no chat message purge(hard delete) function, that's probably why reactions plugin doesn't have a function to remove reactions for chat messages.
That why I asked for this and test with create a plugin
Anyway. Thanks for the pointers, they were spot on.
I dug into messaging/create.js as you suggested and traced every write addMessage does, then built a plugin that undoes exactly those. Sharing the full key list in case it's useful for a potential core implementation, since you mentioned there's no hard-delete for chat right now.
For a given room, the purge removes:
Per message mid:
message:{mid} (the object)
mid:{mid}:replies (reply zset)
removes the mid from the global messages:mid index
reactions plugin leftovers: mid:{mid}:reactions + each mid:{mid}:reaction:{emoji} (the reactions plugin has no chat-side cleanup hook, so these orphan otherwise)
Per room roomId:
chat:room:{roomId}:mids (zset)
chat-read-receipts:room:{roomId}
resets chat:room:{roomId}.messageCount
removes roomId from chat:rooms:public:lastpost (public rooms)
Per member uid:
sortedSetRemove uid:{uid}:chat:rooms:unread (it's a sorted set)
deleteObjectField uid:{uid}:chat:rooms:read (it's a hash, so the field is deleted, not a zset member)
Global:
decrements global.messageCount by the number of messages purged
Deliberately kept: the room object, owners, members, settings, and uid:{uid}:chat:rooms, the room stays in everyone's chat list, since this empties the room rather than deleting it.
Two things worth flagging:
The read vs unread asymmetry tripped me up at first, unread is a sorted set but read is a hash keyed by roomId, so they need different removal calls. Easy to get wrong if you assume both are zsets.
Cleaning up the per-user read pointers across all room members is exactly the part that's painful via the mongo CLI (as you said), but trivial inside a plugin where I can iterate getUidsInRoom.
Does this look like it covers everything addMessage writes, or is there a key I'm still missing? And would a chat hard-delete like this be something core would consider, or is soft-delete-only intentional for chat?
Thanks again.