MSC2946: Allow redactions/updates for space state events
MODIFY
setup/mscs/msc2946/msc2946.go
setup/mscs/msc2946/msc2946.go
@@ -333,8 +333,13 @@ func (w *walker) references(roomID string) (eventLookup, error) {
}
el := make(eventLookup)
for _, ev := range events {
+ // 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
}

MODIFY
setup/mscs/msc2946/msc2946_test.go
setup/mscs/msc2946/msc2946_test.go
@@ -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)
+ }
})
}

MODIFY
setup/mscs/msc2946/storage.go
setup/mscs/msc2946/storage.go
@@ -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
}

MSC2946: Allow redactions/updates for space state events (#1712)