mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-31 13:22:46 +00:00
Add tests for UpdateRelations
(#2999)
This also fixes an issue regarding updates to relations for invalid events, which could result in us retrying said event over and over again, if we fail to unmarshal the event to `gomatrixserverlib.RelationContent`, this was discovered by `@sleroq:virto.community`
This commit is contained in:
parent
7fc839f751
commit
7d83f8b633
2 changed files with 93 additions and 4 deletions
|
@ -567,9 +567,14 @@ func (d *Database) ReIndex(ctx context.Context, limit, afterID int64) (map[int64
|
|||
}
|
||||
|
||||
func (d *Database) UpdateRelations(ctx context.Context, event *gomatrixserverlib.HeaderedEvent) error {
|
||||
// No need to unmarshal if the event is a redaction
|
||||
if event.Type() == gomatrixserverlib.MRoomRedaction {
|
||||
return nil
|
||||
}
|
||||
var content gomatrixserverlib.RelationContent
|
||||
if err := json.Unmarshal(event.Content(), &content); err != nil {
|
||||
return fmt.Errorf("json.Unmarshal: %w", err)
|
||||
logrus.WithError(err).Error("unable to unmarshal relation content")
|
||||
return nil
|
||||
}
|
||||
switch {
|
||||
case content.Relations == nil:
|
||||
|
@ -578,8 +583,6 @@ func (d *Database) UpdateRelations(ctx context.Context, event *gomatrixserverlib
|
|||
return nil
|
||||
case content.Relations.RelationType == "":
|
||||
return nil
|
||||
case event.Type() == gomatrixserverlib.MRoomRedaction:
|
||||
return nil
|
||||
default:
|
||||
return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||
return d.Relations.InsertRelation(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue