Skip to content

Commit 498f217

Browse files
committed
policyeval/execute: set redact_events field on ban if applicable
See matrix-org/matrix-spec-proposals#4293
1 parent 45dd280 commit 498f217

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
go.mau.fi/zeroconfig v0.1.3
1313
gopkg.in/yaml.v3 v3.0.1
1414
maunium.net/go/mauflag v1.0.0
15-
maunium.net/go/mautrix v0.24.1-0.20250527150456-f5746ee0f68d
15+
maunium.net/go/mautrix v0.24.1-0.20250611161019-b8921397b82f
1616
)
1717

1818
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
9696
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
9797
maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
9898
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
99-
maunium.net/go/mautrix v0.24.1-0.20250527150456-f5746ee0f68d h1:xm5Dhdl+0kAPjh5olHfnvmsGUdIEsa9fYBNL8p5HXdA=
100-
maunium.net/go/mautrix v0.24.1-0.20250527150456-f5746ee0f68d/go.mod h1:HqA1HUutQYJkrYRPkK64itARDz79PCec1oWVEB72HVQ=
99+
maunium.net/go/mautrix v0.24.1-0.20250611161019-b8921397b82f h1:fBWlmxu8ehizMNxGXr85FPM4fym38aaWJgr5hALSduI=
100+
maunium.net/go/mautrix v0.24.1-0.20250611161019-b8921397b82f/go.mod h1:HqA1HUutQYJkrYRPkK64itARDz79PCec1oWVEB72HVQ=

policyeval/execute.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ func (pe *PolicyEvaluator) ApplyPolicy(ctx context.Context, userID id.UserID, po
4848
Any("matches", policy).
4949
Msg("Applying ban recommendation")
5050
pe.policyServer.UpdateRecommendation(userID, pe.GetProtectedRooms(), PSRecommendationSpam)
51-
for _, room := range rooms {
52-
pe.ApplyBan(ctx, userID, room, recs.BanOrUnban)
53-
}
5451
shouldRedact := recs.BanOrUnban.Recommendation == event.PolicyRecommendationUnstableTakedown
5552
if !shouldRedact && recs.BanOrUnban.Reason != "" {
5653
for _, pattern := range pe.autoRedactPatterns {
@@ -60,6 +57,9 @@ func (pe *PolicyEvaluator) ApplyPolicy(ctx context.Context, userID id.UserID, po
6057
}
6158
}
6259
}
60+
for _, room := range rooms {
61+
pe.ApplyBan(ctx, userID, room, recs.BanOrUnban, shouldRedact)
62+
}
6363
if shouldRedact {
6464
go pe.RedactUser(context.WithoutCancel(ctx), userID, recs.BanOrUnban.Reason, true)
6565
}
@@ -149,7 +149,13 @@ func (pe *PolicyEvaluator) maybeApplySuspend(ctx context.Context, userID id.User
149149
}
150150
}
151151

152-
func (pe *PolicyEvaluator) ApplyBan(ctx context.Context, userID id.UserID, roomID id.RoomID, policy *policylist.Policy) {
152+
func (pe *PolicyEvaluator) ApplyBan(
153+
ctx context.Context,
154+
userID id.UserID,
155+
roomID id.RoomID,
156+
policy *policylist.Policy,
157+
shouldRedact bool,
158+
) {
153159
ta := &database.TakenAction{
154160
TargetUser: userID,
155161
InRoomID: roomID,
@@ -164,6 +170,8 @@ func (pe *PolicyEvaluator) ApplyBan(ctx context.Context, userID id.UserID, roomI
164170
_, err = pe.Bot.BanUser(ctx, roomID, &mautrix.ReqBanUser{
165171
Reason: filterReason(policy.Reason),
166172
UserID: userID,
173+
174+
MSC4293RedactEvents: shouldRedact,
167175
})
168176
}
169177
if err != nil {

0 commit comments

Comments
 (0)