Update deletion/redaction

This commit is contained in:
Neil Alexander 2022-10-11 14:21:15 +01:00
parent c9ef9a6106
commit 1f06794904
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
3 changed files with 6 additions and 7 deletions

View file

@ -46,7 +46,7 @@ const insertRelationSQL = "" +
" RETURNING id" " RETURNING id"
const deleteRelationSQL = "" + const deleteRelationSQL = "" +
"DELETE FROM syncapi_relations WHERE event_id = $1" "DELETE FROM syncapi_relations WHERE room_id = $1 AND child_event_id = $2"
const selectRelationsInRangeSQL = "" + const selectRelationsInRangeSQL = "" +
"SELECT id, room_id, child_event_id, rel_type FROM syncapi_relations" + "SELECT id, room_id, child_event_id, rel_type FROM syncapi_relations" +
@ -103,11 +103,11 @@ func (s *relationsStatements) InsertRelation(
} }
func (s *relationsStatements) DeleteRelation( func (s *relationsStatements) DeleteRelation(
ctx context.Context, txn *sql.Tx, roomID, eventID, childEventID, relType string, ctx context.Context, txn *sql.Tx, roomID, childEventID string,
) error { ) error {
stmt := sqlutil.TxStmt(txn, s.deleteRelationStmt) stmt := sqlutil.TxStmt(txn, s.deleteRelationStmt)
_, err := stmt.ExecContext( _, err := stmt.ExecContext(
ctx, roomID, eventID, childEventID, relType, ctx, roomID, childEventID,
) )
return err return err
} }

View file

@ -598,10 +598,9 @@ func (d *Database) UpdateRelations(ctx context.Context, event *gomatrixserverlib
} }
return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error { return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
var err error var err error
if event.Redacted() { if event.Type() == gomatrixserverlib.MRoomRedaction {
err = d.Relations.DeleteRelation( err = d.Relations.DeleteRelation(
ctx, txn, event.RoomID(), content.Relations.EventID, ctx, txn, event.RoomID(), event.Redacts(),
event.EventID(), content.Relations.RelationType,
) )
} else { } else {
_, err = d.Relations.InsertRelation( _, err = d.Relations.InsertRelation(

View file

@ -209,7 +209,7 @@ type Presence interface {
type Relations interface { type Relations interface {
InsertRelation(ctx context.Context, txn *sql.Tx, roomID, eventID, childEventID, relType string) (streamPos types.StreamPosition, err error) InsertRelation(ctx context.Context, txn *sql.Tx, roomID, eventID, childEventID, relType string) (streamPos types.StreamPosition, err error)
DeleteRelation(ctx context.Context, txn *sql.Tx, roomID, eventID, childEventID, relType string) error DeleteRelation(ctx context.Context, txn *sql.Tx, roomID, childEventID string) error
SelectRelationsInRange(ctx context.Context, txn *sql.Tx, roomID, eventID, relType string, r types.Range) (map[string][]string, types.StreamPosition, error) SelectRelationsInRange(ctx context.Context, txn *sql.Tx, roomID, eventID, relType string, r types.Range) (map[string][]string, types.StreamPosition, error)
SelectMaxRelationID(ctx context.Context, txn *sql.Tx) (id int64, err error) SelectMaxRelationID(ctx context.Context, txn *sql.Tx) (id int64, err error)
} }