Skip to content

feat: add flag to redactEvent with edits#2389

Open
krille-chan wants to merge 1 commit into
mainfrom
krille/redact-edits-as-well
Open

feat: add flag to redactEvent with edits#2389
krille-chan wants to merge 1 commit into
mainfrom
krille/redact-edits-as-well

Conversation

@krille-chan

@krille-chan krille-chan commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

@krille-chan krille-chan force-pushed the krille/redact-edits-as-well branch 2 times, most recently from af153c0 to 4097e9d Compare June 29, 2026 09:37
@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 12.50000% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.21%. Comparing base (f9e6b68) to head (e261e44).

Files with missing lines Patch % Lines
...with_rel_types/msc_3912_redact_with_rel_types.dart 0.00% 14 Missing ⚠️
lib/src/room.dart 6.66% 14 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2389      +/-   ##
==========================================
- Coverage   59.29%   59.21%   -0.09%     
==========================================
  Files         161      162       +1     
  Lines       20300    20330      +30     
==========================================
+ Hits        12037    12038       +1     
- Misses       8263     8292      +29     
Files with missing lines Coverage Δ
lib/src/event.dart 87.93% <100.00%> (+0.02%) ⬆️
...with_rel_types/msc_3912_redact_with_rel_types.dart 0.00% <0.00%> (ø)
lib/src/room.dart 75.29% <6.66%> (-0.98%) ⬇️

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f9e6b68...e261e44. Read the comment docs.

@krille-chan krille-chan force-pushed the krille/redact-edits-as-well branch from 4097e9d to 0964378 Compare July 7, 2026 06:22
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Opt-in redaction can issue many server requests and change timeline state when the MSC3912 fallback path runs; default behavior is unchanged.

Overview
Adds an opt-in redactAllEdits flag on Event.redactEvent / Room.redactEvent so redacting a message can also remove related m.replace edit events, not only the target event.

When redactAllEdits is true, the client calls /versions: if org.matrix.msc3912 is advertised, it uses a new redactEventWithRelTypes API helper (MSC3912 with_rel_types) in one request; otherwise it loads relating edits via getRelatingEventsWithRelType, redacts each edit (with MatrixException rate-limit retry), then redacts the original event. Default false preserves the previous single-redact behavior.

The MSC3912 extension is exported from matrix.dart for SDK consumers.

Reviewed by Cursor Bugbot for commit e261e44. Bugbot is set up for automated code reviews on this repo. Configure here.

@krille-chan krille-chan force-pushed the krille/redact-edits-as-well branch from 0964378 to e261e44 Compare July 7, 2026 06:23

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix prepared fixes for both issues found in the latest run.

  • ✅ Fixed: Edit fetch ignores pagination tokens
    • Manual edit redaction now paginates related m.replace events with from/nextBatch until all pages are processed.
  • ✅ Fixed: Main redact lacks rate retry
    • The primary event redaction now uses the same retryAfterMs rate-limit retry path as edit redactions.

Create PR

Or push these changes by commenting:

@cursor push ed4d881c74
Preview (ed4d881c74)
diff --git a/lib/src/room.dart b/lib/src/room.dart
--- a/lib/src/room.dart
+++ b/lib/src/room.dart
@@ -2491,24 +2491,47 @@
       );
     }
 
-    final edits = await client.getRelatingEventsWithRelType(
-      id,
-      eventId,
-      RelationshipTypes.edit,
-    );
-    for (final edit in edits.chunk) {
-      final txnid = client.generateUniqueTransactionId();
+    Future<String?> redactWithRateLimitRetry(
+      String redactionEventId,
+      String txid,
+    ) async {
       try {
-        await client.redactEvent(id, edit.eventId, txnid, reason: reason);
+        return await client.redactEvent(
+          id,
+          redactionEventId,
+          txid,
+          reason: reason,
+        );
       } on MatrixException catch (e) {
         final retryAfterMs = e.retryAfterMs;
         if (retryAfterMs == null) rethrow;
         await Future.delayed(Duration(milliseconds: retryAfterMs));
-        await client.redactEvent(id, edit.eventId, txnid, reason: reason);
+        return await client.redactEvent(
+          id,
+          redactionEventId,
+          txid,
+          reason: reason,
+        );
       }
     }
 
-    return await client.redactEvent(id, eventId, messageID, reason: reason);
+    String? nextBatch;
+    do {
+      final edits = await client.getRelatingEventsWithRelType(
+        id,
+        eventId,
+        RelationshipTypes.edit,
+        from: nextBatch,
+        limit: 50,
+      );
+      for (final edit in edits.chunk) {
+        final txnid = client.generateUniqueTransactionId();
+        await redactWithRateLimitRetry(edit.eventId, txnid);
+      }
+      nextBatch = edits.nextBatch;
+    } while (nextBatch != null);
+
+    return await redactWithRateLimitRetry(eventId, messageID);
   }
 
   /// This tells the server that the user is typing for the next N milliseconds

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit e261e44. Configure here.

Comment thread lib/src/room.dart
Comment thread lib/src/room.dart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant