From 5db1a4d94b7f7a35f89bae78852ac31ab4bc29bf Mon Sep 17 00:00:00 2001 From: Rory& Date: Mon, 17 Nov 2025 12:10:28 +0100 Subject: Event content redaction (v12) --- LibMatrix/StateEvent.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'LibMatrix/StateEvent.cs') diff --git a/LibMatrix/StateEvent.cs b/LibMatrix/StateEvent.cs index 861b584..dfe393a 100644 --- a/LibMatrix/StateEvent.cs +++ b/LibMatrix/StateEvent.cs @@ -132,6 +132,27 @@ public class MatrixEvent { /// /// public static bool DeepEquals(MatrixEventResponse x, MatrixEventResponse y) => x.Type == y.Type && x.StateKey == y.StateKey && JsonNode.DeepEquals(x.RawContent, y.RawContent); + + public JsonObject GetRedactedContent(string roomVersion) { + JsonObject GetTopLevelKeys(string[] keys) { + var obj = new JsonObject(); + foreach (var key in keys) { + if (RawContent.ContainsKey(key)) + obj[key] = RawContent[key]!; + } + + return obj; + } + + return Type switch { + "m.room.create" => RawContent, // as of v11... TODO: implement older versions + "m.room.member" => GetTopLevelKeys(["membership", "join_authorised_via_users_server"]), // TODO: missing third_party_invite.signed + "m.room.join_rules" => GetTopLevelKeys(["join_rule", "allow"]), + "m.room.power_levels" => GetTopLevelKeys(["ban", "events", "events_default", "kick", "redact", "state_default", "users", "users_default"]), + "m.room.history_visibility" => GetTopLevelKeys(["history_visibility"]), + _ => new JsonObject() + }; + } } public class MatrixEventResponse : MatrixEvent { -- cgit 1.5.1