about summary refs log tree commit diff
path: root/LibMatrix/StateEvent.cs
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-11-17 12:10:28 +0100
committerRory& <root@rory.gay>2025-11-17 12:10:28 +0100
commit5db1a4d94b7f7a35f89bae78852ac31ab4bc29bf (patch)
tree678554eabd09e9322b25280b48e7f7ddadfe8b37 /LibMatrix/StateEvent.cs
parentnix: fix builds (diff)
downloadLibMatrix-5db1a4d94b7f7a35f89bae78852ac31ab4bc29bf.tar.xz
Event content redaction (v12)
Diffstat (limited to 'LibMatrix/StateEvent.cs')
-rw-r--r--LibMatrix/StateEvent.cs21
1 files changed, 21 insertions, 0 deletions
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 { /// <param name="y"></param> /// <returns></returns> 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 {