Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edited messages appear twice in fulltext search #3358

Closed
S7evinK opened this issue Apr 9, 2024 · 3 comments
Closed

Edited messages appear twice in fulltext search #3358

S7evinK opened this issue Apr 9, 2024 · 3 comments
Labels
good first issue Want to help with Dendrite? These are the issues to start with! T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.

Comments

@S7evinK
Copy link
Contributor

S7evinK commented Apr 9, 2024

When a message is edited, they appear twice in the results of /search.
While Element Web seems to aggregate the results and only returns one results, Element Android returns both. This may be a bit confusing.

IMO, Dendrite should only return the latest message.

The responsible code for this:

func (s *OutputRoomEventConsumer) writeFTS(ev *rstypes.HeaderedEvent, pduPosition types.StreamPosition) error {
if !s.cfg.Fulltext.Enabled {
return nil
}
e := fulltext.IndexElement{
EventID: ev.EventID(),
RoomID: ev.RoomID().String(),
StreamPosition: int64(pduPosition),
}
e.SetContentType(ev.Type())
switch ev.Type() {
case "m.room.message":
e.Content = gjson.GetBytes(ev.Content(), "body").String()
case spec.MRoomName:
e.Content = gjson.GetBytes(ev.Content(), "name").String()
case spec.MRoomTopic:
e.Content = gjson.GetBytes(ev.Content(), "topic").String()
case spec.MRoomRedaction:
log.Tracef("Redacting event: %s", ev.Redacts())
if err := s.fts.Delete(ev.Redacts()); err != nil {
return fmt.Errorf("failed to delete entry from fulltext index: %w", err)
}
return nil
default:
return nil
}
if e.Content != "" {
log.Tracef("Indexing element: %+v", e)
if err := s.fts.Index(e); err != nil {
return err
}
}
return nil
}

We'd need to check if m.relates.to in content contains a rel_type of m.replace and then delete the event_id from the fulltext index before indexing the new event.

@S7evinK S7evinK added good first issue Want to help with Dendrite? These are the issues to start with! T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues. labels Apr 9, 2024
@S7evinK S7evinK changed the title Edited messages appear twice in event search Edited messages appear twice in fulltext search Apr 9, 2024
@adnull
Copy link
Contributor

adnull commented Apr 17, 2024

Hi! I'd like to take this.

@S7evinK
Copy link
Contributor Author

S7evinK commented Apr 18, 2024

Sure, go for it! :)

S7evinK pushed a commit that referenced this issue Jul 27, 2024
As stated in #3358 the
search response contains both original and edited message.
This PR fixes it by removing of the original message from the fulltext
index after indexing the edit message event.
I also made some cosmetic changes/fixes i found in the code

Signed-off-by: `Alexander Dubovikov <[email protected]>`
@S7evinK
Copy link
Contributor Author

S7evinK commented Jul 27, 2024

Fixed with #3363.

@S7evinK S7evinK closed this as completed Jul 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Want to help with Dendrite? These are the issues to start with! T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.
Projects
None yet
Development

No branches or pull requests

2 participants