diff options
author | Kegsay <kegan@matrix.org> | 2021-01-15 11:44:36 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-15 11:44:36 +0000 |
commit | 2626525c65e5e7f3cf446d7ab23c26c6c345320a (patch) | |
tree | 44856b271ef3a17ab3f2142813b9b48b815415fe /setup | |
parent | ef24ea26784a025d6c59d688a66859b51a0f1166 (diff) |
MSC2946: Allow redactions/updates for space state events (#1712)
Diffstat (limited to 'setup')
-rw-r--r-- | setup/mscs/msc2946/msc2946.go | 7 | ||||
-rw-r--r-- | setup/mscs/msc2946/msc2946_test.go | 19 | ||||
-rw-r--r-- | setup/mscs/msc2946/storage.go | 4 |
3 files changed, 27 insertions, 3 deletions
diff --git a/setup/mscs/msc2946/msc2946.go b/setup/mscs/msc2946/msc2946.go index a2d801e4..accdbd39 100644 --- a/setup/mscs/msc2946/msc2946.go +++ b/setup/mscs/msc2946/msc2946.go @@ -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 } diff --git a/setup/mscs/msc2946/msc2946_test.go b/setup/mscs/msc2946/msc2946_test.go index 017319dc..a7650f0b 100644 --- a/setup/mscs/msc2946/msc2946_test.go +++ b/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) + } }) } diff --git a/setup/mscs/msc2946/storage.go b/setup/mscs/msc2946/storage.go index eb4a5efb..5798310a 100644 --- a/setup/mscs/msc2946/storage.go +++ b/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 } |