diff options
author | Kegsay <kegan@matrix.org> | 2020-07-07 12:51:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-07 12:51:55 +0100 |
commit | 99ea1f9b4875e9458e640daa3358c3e9ad4fe065 (patch) | |
tree | fab2f5ccf12241cdfa4323525590957276e23c8c /internal/eventutil/events.go | |
parent | d7a8bbff72194ea41d33aba49bfa3caf9a40e721 (diff) |
Emit redacted_event from the roomserver when redactions are validated (#1186)
* Emit redacted_event from the roomserver when redactions are validated
- Consume them in the currentstateserver and act accordingly.
- Add integration test for the roomserver to check that injecting
`m.room.redaction` events result in `redacted_event` being emitted.
* Linting
* Ignore events that redact themselves
Diffstat (limited to 'internal/eventutil/events.go')
-rw-r--r-- | internal/eventutil/events.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/internal/eventutil/events.go b/internal/eventutil/events.go index d56f5be8..e3b8f3d3 100644 --- a/internal/eventutil/events.go +++ b/internal/eventutil/events.go @@ -149,3 +149,18 @@ func truncateAuthAndPrevEvents(auth, prev []gomatrixserverlib.EventReference) ( } return } + +// RedactEvent redacts the given event and sets the unsigned field appropriately. This should be used by +// downstream components to the roomserver when an OutputTypeRedactedEvent occurs. +func RedactEvent(redactionEvent, redactedEvent *gomatrixserverlib.Event) (*gomatrixserverlib.Event, error) { + // sanity check + if redactionEvent.Type() != gomatrixserverlib.MRoomRedaction { + return nil, fmt.Errorf("RedactEvent: redactionEvent isn't a redaction event, is '%s'", redactionEvent.Type()) + } + r := redactedEvent.Redact() + err := r.SetUnsignedField("redacted_because", redactionEvent) + if err != nil { + return nil, err + } + return &r, nil +} |