1
0

Compare commits

...

2 Commits

Author SHA1 Message Date
Travis Ralston
5b2b2cedbc finish thinking 2025-06-04 09:33:45 -06:00
Travis Ralston
73b9b21bd5 Definitely not production ready code for MSC4293 2025-06-04 09:30:15 -06:00
3 changed files with 36 additions and 0 deletions

View File

@@ -2684,6 +2684,8 @@ class PersistEventsStore:
elif event.type == EventTypes.Retention:
# Update the room_retention table.
self._store_retention_policy_for_room_txn(txn, event)
elif event.type == EventTypes.Member and event.content.get("org.matrix.msc4293.redact_events", False) == True:
self._try_store_member_redaction_txn(txn, event)
self._handle_event_relations(txn, event)
@@ -2775,6 +2777,23 @@ class PersistEventsStore:
},
)
def _try_store_member_redaction_txn(self, txn: LoggingTransaction, event: EventBase) -> None:
# We only want to search for membership transitions which aren't kicks or bans
if event.membership != Membership.BAN and not (event.membership == Membership.LEAVE and event.sender != event.state_key):
# Not a membership event which is capable of redacting other events.
# See MSC4293 for details (as of May 28, 2025): https://github.com/matrix-org/matrix-spec-proposals/pull/4293
return
# We also want to filter out events where the sender can't actually redact (no permission to redact)
# TODO
# Find all the current events sent by this user
# TODO
# Insert them into the redactions table
# TODO
def insert_labels_for_event_txn(
self,
txn: LoggingTransaction,

View File

@@ -0,0 +1,8 @@
-- Create a unique index which *should* be fine because of the existing UNIQUE(event_id) preventing overlap
ALTER TABLE ONLY redactions ADD CONSTRAINT redactions_event_id_redacts_key UNIQUE (event_id, redacts);
-- Replace the index we're about to drop
CREATE INDEX redactions_event_id ON redactions USING btree (event_id);
-- Drop the old constraint
ALTER TABLE ONLY redactions DROP CONSTRAINT redactions_event_id_key;

View File

@@ -0,0 +1,9 @@
-- sqlite is awful and requires rebuilding the table to drop the UNIQUE(event_id) constraint, so let's do that
-- and build a new table with the constraints we want.
CREATE TABLE redactions2 (event_id TEXT NOT NULL, redacts TEXT NOT NULL, have_censored BOOL NOT NULL DEFAULT false, received_ts BIGINT, UNIQUE(event_id, redacts));
INSERT INTO redactions2 (event_id, redacts, have_censored, received_ts) SELECT r.event_id, r.redacts, r.have_censored, r.received_ts FROM redactions AS r;
DROP INDEX redactions_redacts;
DROP TABLE redactions;
ALTER TABLE redactions2 RENAME TO redactions;
CREATE INDEX redactions_redacts ON redactions(redacts);
CREATE INDEX redactions_event_id ON redactions(event_id); -- replace the index we dropped