From 9b8ef93483150d5ad6c534052ec79f8aa4b5d0d8 Mon Sep 17 00:00:00 2001 From: "Richard T. Carback III" Date: Mon, 25 Nov 2024 10:06:17 -0500 Subject: [PATCH 1/4] Add OutputTypeRedactedEvent to the OutputRoomEventConsumer --- appservice/consumers/roomserver.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/appservice/consumers/roomserver.go b/appservice/consumers/roomserver.go index 862dde49..cb353c90 100644 --- a/appservice/consumers/roomserver.go +++ b/appservice/consumers/roomserver.go @@ -111,7 +111,7 @@ func (s *OutputRoomEventConsumer) onMessage( for _, msg := range msgs { // Only handle events we care about receivedType := api.OutputType(msg.Header.Get(jetstream.RoomEventType)) - if receivedType != api.OutputTypeNewRoomEvent && receivedType != api.OutputTypeNewInviteEvent { + if receivedType != api.OutputTypeNewRoomEvent && receivedType != api.OutputTypeNewInviteEvent && receivedType != api.OutputTypeRedactedEvent { continue } // Parse out the event JSON @@ -147,7 +147,11 @@ func (s *OutputRoomEventConsumer) onMessage( events = append(events, eventsRes.Events...) } } - + case api.OutputTypeRedactedEvent: + if output.RedactedEvent == nil || !s.appserviceIsInterestedInEvent(ctx, output.RedactedEvent.RedactedBecause, state.ApplicationService) { + continue + } + events = append(events, output.RedactedEvent.RedactedBecause) default: continue } From 4c55d5356f9a30e260180be307c60ac766e959f1 Mon Sep 17 00:00:00 2001 From: "Richard T. Carback III" Date: Mon, 25 Nov 2024 10:29:36 -0500 Subject: [PATCH 2/4] Send event using the PDU, not just e. Add a log event so we can see when it is sent --- clientapi/routing/redaction.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/clientapi/routing/redaction.go b/clientapi/routing/redaction.go index 795b311b..b868d333 100644 --- a/clientapi/routing/redaction.go +++ b/clientapi/routing/redaction.go @@ -15,6 +15,7 @@ import ( "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib/spec" "github.com/matrix-org/util" + "github.com/sirupsen/logrus" "github.com/element-hq/dendrite/clientapi/httputil" "github.com/element-hq/dendrite/internal/eventutil" @@ -40,6 +41,13 @@ func SendRedaction( txnID *string, txnCache *transactions.Cache, ) util.JSONResponse { + roomVersion, err := rsAPI.QueryRoomVersionForRoom(req.Context(), roomID) + if err != nil { + return util.JSONResponse{ + Code: http.StatusBadRequest, + JSON: spec.UnsupportedRoomVersion(err.Error()), + } + } deviceUserID, userIDErr := spec.NewUserID(device.UserID, true) if userIDErr != nil { return util.JSONResponse{ @@ -175,7 +183,7 @@ func SendRedaction( } } domain := device.UserDomain() - if err = roomserverAPI.SendEvents(context.Background(), rsAPI, roomserverAPI.KindNew, []*types.HeaderedEvent{e}, device.UserDomain(), domain, domain, nil, false); err != nil { + if err = roomserverAPI.SendEvents(context.Background(), rsAPI, roomserverAPI.KindNew, []*types.HeaderedEvent{{PDU: e.PDU}}, device.UserDomain(), domain, domain, nil, false); err != nil { util.GetLogger(req.Context()).WithError(err).Errorf("failed to SendEvents") return util.JSONResponse{ Code: http.StatusInternalServerError, @@ -183,6 +191,12 @@ func SendRedaction( } } + util.GetLogger(req.Context()).WithFields(logrus.Fields{ + "event_id": e.PDU.EventID(), + "room_id": roomID, + "room_version": roomVersion, + }).Info("Sent redaction to roomserver") + res := util.JSONResponse{ Code: 200, JSON: redactionResponse{ From 8dd5e50ed1c1cbdc3c41af88314450c0497fb801 Mon Sep 17 00:00:00 2001 From: "Richard T. Carback III" Date: Mon, 25 Nov 2024 10:42:18 -0500 Subject: [PATCH 3/4] When there is no error, produce a RoomEvent for appservices --- syncapi/consumers/roomserver.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/syncapi/consumers/roomserver.go b/syncapi/consumers/roomserver.go index 75afa1c9..b3d3a7ae 100644 --- a/syncapi/consumers/roomserver.go +++ b/syncapi/consumers/roomserver.go @@ -132,6 +132,11 @@ func (s *OutputRoomEventConsumer) onMessage(ctx context.Context, msgs []*nats.Ms s.onRetirePeek(s.ctx, *output.RetirePeek) case api.OutputTypeRedactedEvent: err = s.onRedactEvent(s.ctx, *output.RedactedEvent) + if err == nil && s.asProducer != nil { + if err = s.asProducer.ProduceRoomEvents(msg); err != nil { + log.WithError(err).Warn("failed to produce OutputAppserviceEvent") + } + } case api.OutputTypePurgeRoom: err = s.onPurgeRoom(s.ctx, *output.PurgeRoom) if err != nil { From 253d7a9599aef5567413fe2015225795d9e38911 Mon Sep 17 00:00:00 2001 From: Richard Carback Date: Tue, 3 Dec 2024 14:57:51 +0000 Subject: [PATCH 4/4] Revert "Send event using the PDU, not just e. Add a log event so we can see when it is sent" This reverts commit 4c55d5356f9a30e260180be307c60ac766e959f1. --- clientapi/routing/redaction.go | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/clientapi/routing/redaction.go b/clientapi/routing/redaction.go index b868d333..795b311b 100644 --- a/clientapi/routing/redaction.go +++ b/clientapi/routing/redaction.go @@ -15,7 +15,6 @@ import ( "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib/spec" "github.com/matrix-org/util" - "github.com/sirupsen/logrus" "github.com/element-hq/dendrite/clientapi/httputil" "github.com/element-hq/dendrite/internal/eventutil" @@ -41,13 +40,6 @@ func SendRedaction( txnID *string, txnCache *transactions.Cache, ) util.JSONResponse { - roomVersion, err := rsAPI.QueryRoomVersionForRoom(req.Context(), roomID) - if err != nil { - return util.JSONResponse{ - Code: http.StatusBadRequest, - JSON: spec.UnsupportedRoomVersion(err.Error()), - } - } deviceUserID, userIDErr := spec.NewUserID(device.UserID, true) if userIDErr != nil { return util.JSONResponse{ @@ -183,7 +175,7 @@ func SendRedaction( } } domain := device.UserDomain() - if err = roomserverAPI.SendEvents(context.Background(), rsAPI, roomserverAPI.KindNew, []*types.HeaderedEvent{{PDU: e.PDU}}, device.UserDomain(), domain, domain, nil, false); err != nil { + if err = roomserverAPI.SendEvents(context.Background(), rsAPI, roomserverAPI.KindNew, []*types.HeaderedEvent{e}, device.UserDomain(), domain, domain, nil, false); err != nil { util.GetLogger(req.Context()).WithError(err).Errorf("failed to SendEvents") return util.JSONResponse{ Code: http.StatusInternalServerError, @@ -191,12 +183,6 @@ func SendRedaction( } } - util.GetLogger(req.Context()).WithFields(logrus.Fields{ - "event_id": e.PDU.EventID(), - "room_id": roomID, - "room_version": roomVersion, - }).Info("Sent redaction to roomserver") - res := util.JSONResponse{ Code: 200, JSON: redactionResponse{