aboutsummaryrefslogtreecommitdiff
path: root/federationapi/consumers/roomserver.go
diff options
context:
space:
mode:
authorNeil <neilalexanderr@gmail.com>2023-01-19 20:02:32 +0000
committerGitHub <noreply@github.com>2023-01-19 21:02:32 +0100
commit738686ae686004c5efa9fe2096502cdc426c6dd8 (patch)
treee5c8e31aea47167be61aa326982ad9db1a00c15e /federationapi/consumers/roomserver.go
parent67f5c5bc1e837bbdee14d7d3388984ed8960528a (diff)
Add `/_dendrite/admin/purgeRoom/{roomID}` (#2662)
This adds a new admin endpoint `/_dendrite/admin/purgeRoom/{roomID}`. It completely erases all database entries for a given room ID. The roomserver will start by clearing all data for that room and then will generate an output event to notify downstream components (i.e. the sync API and federation API) to do the same. It does not currently clear media and it is currently not implemented for SQLite since it relies on SQL array operations right now. Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com> Co-authored-by: Till Faelligen <2353100+S7evinK@users.noreply.github.com>
Diffstat (limited to 'federationapi/consumers/roomserver.go')
-rw-r--r--federationapi/consumers/roomserver.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/federationapi/consumers/roomserver.go b/federationapi/consumers/roomserver.go
index 52b5744a..82a4db3f 100644
--- a/federationapi/consumers/roomserver.go
+++ b/federationapi/consumers/roomserver.go
@@ -25,6 +25,7 @@ import (
"github.com/matrix-org/gomatrixserverlib"
"github.com/nats-io/nats.go"
+ "github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
"github.com/matrix-org/dendrite/federationapi/queue"
@@ -90,8 +91,10 @@ func (s *OutputRoomEventConsumer) onMessage(ctx context.Context, msgs []*nats.Ms
msg := msgs[0] // Guaranteed to exist if onMessage is called
receivedType := api.OutputType(msg.Header.Get(jetstream.RoomEventType))
- // Only handle events we care about
- if receivedType != api.OutputTypeNewRoomEvent && receivedType != api.OutputTypeNewInboundPeek {
+ // Only handle events we care about, avoids unneeded unmarshalling
+ switch receivedType {
+ case api.OutputTypeNewRoomEvent, api.OutputTypeNewInboundPeek, api.OutputTypePurgeRoom:
+ default:
return true
}
@@ -126,6 +129,14 @@ func (s *OutputRoomEventConsumer) onMessage(ctx context.Context, msgs []*nats.Ms
return false
}
+ case api.OutputTypePurgeRoom:
+ log.WithField("room_id", output.PurgeRoom.RoomID).Warn("Purging room from federation API")
+ if err := s.db.PurgeRoom(ctx, output.PurgeRoom.RoomID); err != nil {
+ logrus.WithField("room_id", output.PurgeRoom.RoomID).WithError(err).Error("Failed to purge room from federation API")
+ } else {
+ logrus.WithField("room_id", output.PurgeRoom.RoomID).Warn("Room purged from federation API")
+ }
+
default:
log.WithField("type", output.Type).Debug(
"roomserver output log: ignoring unknown output type",