Skip to content

feat: add flag to redactEvent with edits FM-732#2389

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

feat: add flag to redactEvent with edits FM-732#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 28.12500% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.56%. Comparing base (c8afef4) to head (592f594).

Files with missing lines Patch % Lines
...with_rel_types/msc_3912_redact_with_rel_types.dart 0.00% 14 Missing ⚠️
lib/src/room.dart 40.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2389      +/-   ##
==========================================
- Coverage   59.61%   59.56%   -0.06%     
==========================================
  Files         161      162       +1     
  Lines       20308    20338      +30     
==========================================
+ Hits        12107    12114       +7     
- Misses       8201     8224      +23     
Files with missing lines Coverage Δ
lib/src/event.dart 87.93% <100.00%> (+0.02%) ⬆️
lib/src/room.dart 75.82% <40.00%> (-0.47%) ⬇️
...with_rel_types/msc_3912_redact_with_rel_types.dart 0.00% <0.00%> (ø)

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 c8afef4...592f594. 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
Changes the redaction code path and can issue many redact requests on servers without MSC3912, which affects timeline content and server load.

Overview
Adds optional redactAllEdits on Event.redactEvent / Room.redactEvent so deleting a message can also remove its m.replace edit events, not just the root event.

When the flag is set, the client probes /versions for org.matrix.msc3912. Supported homeservers get a single redact via a new redactEventWithRelTypes API helper (MSC3912 with_rel_types). Otherwise the SDK loads related edits with getRelatingEventsWithRelType, redacts each edit (with rate-limit retry), then redacts the original event.

The MSC3912 extension is exported from matrix.dart. Timeline tests now exercise redactEvent(redactAllEdits: true) alongside aggregated edit display.

Reviewed by Cursor Bugbot for commit 592f594. 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.

Autofix Details

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.

Comment thread lib/src/room.dart
Comment thread lib/src/room.dart
@krille-chan
krille-chan force-pushed the krille/redact-edits-as-well branch from e261e44 to e499dd5 Compare July 9, 2026 10:59
@td-famedly td-famedly changed the title feat: add flag to redactEvent with edits feat: add flag to redactEvent with edits FM-732 Jul 9, 2026
@krille-chan
krille-chan force-pushed the krille/redact-edits-as-well branch from e499dd5 to 46ef708 Compare July 13, 2026 08:46
@krille-chan
krille-chan force-pushed the krille/redact-edits-as-well branch from 46ef708 to 592f594 Compare July 13, 2026 08:47
@td-famedly

Copy link
Copy Markdown
Member

@cursor review

Comment thread lib/src/event.dart
String? reason,
String? txid,
bool redactAllEdits = false,
}) async => await room.redactEvent(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

async => await you don't need async await with fat arrow

@td-famedly td-famedly left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

mostly lg

@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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 592f594. Configure here.

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.

2 participants