mirror of
https://github.com/matrix-org/dendrite
synced 2024-11-10 15:14:36 +00:00
MSC2946: Allow redactions/updates for space state events (#1712)
This commit is contained in:
parent
ef24ea2678
commit
2626525c65
3 changed files with 27 additions and 3 deletions
|
@ -333,7 +333,12 @@ func (w *walker) references(roomID string) (eventLookup, error) {
|
|||
}
|
||||
el := make(eventLookup)
|
||||
for _, ev := range events {
|
||||
el.set(ev)
|
||||
// only return events that have a `via` key as per MSC1772
|
||||
// else we'll incorrectly walk redacted events (as the link
|
||||
// is in the state_key)
|
||||
if gjson.GetBytes(ev.Content(), "via").Exists() {
|
||||
el.set(ev)
|
||||
}
|
||||
}
|
||||
return el, nil
|
||||
}
|
||||
|
|
|
@ -254,7 +254,26 @@ func TestMSC2946(t *testing.T) {
|
|||
if len(res.Rooms) != len(allRooms) {
|
||||
t.Errorf("got %d rooms, want %d", len(res.Rooms), len(allRooms))
|
||||
}
|
||||
})
|
||||
t.Run("can update the graph", func(t *testing.T) {
|
||||
// remove R3 from the graph
|
||||
rmS1ToR3 := mustCreateEvent(t, fledglingEvent{
|
||||
RoomID: subSpaceS1,
|
||||
Sender: alice,
|
||||
Type: msc2946.ConstSpaceChildEventType,
|
||||
StateKey: &room3,
|
||||
Content: map[string]interface{}{}, // redacted
|
||||
})
|
||||
nopRsAPI.events[rmS1ToR3.EventID()] = rmS1ToR3
|
||||
hooks.Run(hooks.KindNewEventPersisted, rmS1ToR3)
|
||||
|
||||
res := postSpaces(t, 200, "alice", rootSpace, newReq(t, map[string]interface{}{}))
|
||||
if len(res.Events) != 6 { // one less since we don't return redacted events
|
||||
t.Errorf("got %d events, want 6", len(res.Events))
|
||||
}
|
||||
if len(res.Rooms) != (len(allRooms) - 1) { // one less due to lack of R3
|
||||
t.Errorf("got %d rooms, want %d", len(res.Rooms), len(allRooms)-1)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ func newPostgresDatabase(dbOpts *config.DatabaseOptions) (Database, error) {
|
|||
if d.insertEdgeStmt, err = d.db.Prepare(`
|
||||
INSERT INTO msc2946_edges(room_version, source_room_id, dest_room_id, rel_type, event_json)
|
||||
VALUES($1, $2, $3, $4, $5)
|
||||
ON CONFLICT DO NOTHING
|
||||
ON CONFLICT ON CONSTRAINT msc2946_edges_uniq DO UPDATE SET event_json = $5
|
||||
`); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ func newSQLiteDatabase(dbOpts *config.DatabaseOptions) (Database, error) {
|
|||
if d.insertEdgeStmt, err = d.db.Prepare(`
|
||||
INSERT INTO msc2946_edges(room_version, source_room_id, dest_room_id, rel_type, event_json)
|
||||
VALUES($1, $2, $3, $4, $5)
|
||||
ON CONFLICT DO NOTHING
|
||||
ON CONFLICT (source_room_id, dest_room_id, rel_type) DO UPDATE SET event_json = $5
|
||||
`); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue