fix: Delete original event from index when message is edited
Fix: Delete original event from index when message is edited
Summary
When a message is edited (m.replace relation), the original event remained in the Seshat search index, causing inconsistent search results. This PR deletes the original event from the index before adding the edited version.
Changes
- In
EventIndex.addLiveEventToIndex(), detect edit events (RelationType.Replace) and delete the original event from the index before processing the edit
Testing
- Verified that editing a message updates the search index correctly
- Original message content no longer appears in search results after editing
Files Changed
-
src/indexing/EventIndex.ts -
test/unit-tests/indexing/EventIndex-test.ts
Related Issues
Part of a fix for displaying edited messages correctly in Seshat search results.
Checklist
- [x] I have read through review guidelines and CONTRIBUTING.md.
- [x] Tests written for new code (and old code if feasible).
- [x] New or updated
public/exportedsymbols have accurate TSDoc documentation. - [x] Linter and other CI checks pass.
- [x] I have licensed the changes to Element by completing the Contributor License Agreement (CLA)
I assume this won't really be a complete solution since if it's only processing live events, it will miss other cases, eg. if we're scrolling back and see and edit, then the original event. However, if we don't have any handling for edits in search at all, this is better than nothing. It might be worth commenting this.
I see. A complete solution would require introducing getEventsByRelation(targetId, relType) to the Seshat API (and modifying the database structure).
I will add a comment for now.
(I am going to make another PR to Seshat later, but not now)
It may be possible to remove such "old messages" internally in Seshat when loading a database. In addition, we could remove the corresponding old one when a new edited message is registered to the database. This would approach only updating the internal logic of Seshat.
Do you think this makes sense?
I have created a PR to seshat. I will close this PR in favor of the new PR once the PR is merged.
https://github.com/matrix-org/seshat/pull/151
Thanks - yeah, it could make sense to solve this by making seshat aware of message edits.