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"
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 = "" +
"SELECT id, room_id, child_event_id, rel_type FROM syncapi_relations" +
@ -103,11 +103,11 @@ func (s *relationsStatements) InsertRelation(
}
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 {
stmt := sqlutil.TxStmt(txn, s.deleteRelationStmt)
_, err := stmt.ExecContext(
ctx, roomID, eventID, childEventID, relType,
ctx, roomID, childEventID,
)
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 {
var err error
if event.Redacted() {
if event.Type() == gomatrixserverlib.MRoomRedaction {
err = d.Relations.DeleteRelation(
ctx, txn, event.RoomID(), content.Relations.EventID,
event.EventID(), content.Relations.RelationType,
ctx, txn, event.RoomID(), event.Redacts(),
)
} else {
_, err = d.Relations.InsertRelation(

View file

@ -209,7 +209,7 @@ type Presence interface {
type Relations interface {
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)
SelectMaxRelationID(ctx context.Context, txn *sql.Tx) (id int64, err error)
}