about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-05-09 07:09:57 +0200
committerRory& <root@rory.gay>2025-05-09 07:09:57 +0200
commit51ff4a3b95ab38dd46c88f4e5482bf78449bb88c (patch)
treee25789fdf98248b22da3e0a498a262c9f31c86d5
parentVerbosity (diff)
downloadLibMatrix-51ff4a3b95ab38dd46c88f4e5482bf78449bb88c.tar.xz
msc4222 fixes
-rw-r--r--LibMatrix.EventTypes/Spec/IgnoredUserListEventContent.cs10
-rw-r--r--LibMatrix/Helpers/SyncProcessors/Msc4222EmulationSyncProcessor.cs6
-rw-r--r--LibMatrix/Helpers/SyncProcessors/SimpleSyncProcessors.cs4
3 files changed, 17 insertions, 3 deletions
diff --git a/LibMatrix.EventTypes/Spec/IgnoredUserListEventContent.cs b/LibMatrix.EventTypes/Spec/IgnoredUserListEventContent.cs

index 3643b8c..59e17c9 100644 --- a/LibMatrix.EventTypes/Spec/IgnoredUserListEventContent.cs +++ b/LibMatrix.EventTypes/Spec/IgnoredUserListEventContent.cs
@@ -16,12 +16,16 @@ public class IgnoredUserListEventContent : EventContent { [JsonExtensionData] public Dictionary<string, object>? AdditionalData { get; set; } = []; - public T GetAdditionalData<T>(string key) { + public T? GetAdditionalData<T>(string key) where T : class { if (AdditionalData == null || !AdditionalData.TryGetValue(key, out var value)) - throw new KeyNotFoundException($"Key '{key}' not found in AdditionalData."); + return null; + if (value is T tValue) return tValue; - throw new InvalidCastException($"Value for key '{key}' cannot be cast to type '{typeof(T)}'. Cannot continue."); + if (value is JsonElement jsonElement) + return jsonElement.Deserialize<T>(); + + throw new InvalidCastException($"Value for key '{key}' ({value.GetType()}) cannot be cast to type '{typeof(T)}'. Cannot continue."); } } } \ No newline at end of file diff --git a/LibMatrix/Helpers/SyncProcessors/Msc4222EmulationSyncProcessor.cs b/LibMatrix/Helpers/SyncProcessors/Msc4222EmulationSyncProcessor.cs
index 9baeaa4..6cb42ca 100644 --- a/LibMatrix/Helpers/SyncProcessors/Msc4222EmulationSyncProcessor.cs +++ b/LibMatrix/Helpers/SyncProcessors/Msc4222EmulationSyncProcessor.cs
@@ -26,6 +26,12 @@ public class Msc4222EmulationSyncProcessor(AuthenticatedHomeserverGeneric homese return resp; } + resp = await EmulateMsc4222Internal(resp, sw); + + return SimpleSyncProcessors.FillRoomIds(resp); + } + + private async Task<SyncResponse?> EmulateMsc4222Internal(SyncResponse? resp, Stopwatch sw) { var modified = false; List<Task<bool>> tasks = []; if (resp.Rooms is { Join.Count: > 0 }) { diff --git a/LibMatrix/Helpers/SyncProcessors/SimpleSyncProcessors.cs b/LibMatrix/Helpers/SyncProcessors/SimpleSyncProcessors.cs
index 5cf5c36..5981cb5 100644 --- a/LibMatrix/Helpers/SyncProcessors/SimpleSyncProcessors.cs +++ b/LibMatrix/Helpers/SyncProcessors/SimpleSyncProcessors.cs
@@ -18,6 +18,8 @@ public class SimpleSyncProcessors { Parallel.ForEach(data.Timeline.Events, evt => evt.RoomId = id); if (data.State is { Events.Count: > 0 }) Parallel.ForEach(data.State.Events, evt => evt.RoomId = id); + if (data.StateAfter is { Events.Count: > 0 }) + Parallel.ForEach(data.StateAfter.Events, evt => evt.RoomId = id); }); if (resp.Rooms.Leave is { Count: > 0 }) Parallel.ForEach(resp.Rooms.Leave, (roomEntry) => { @@ -28,6 +30,8 @@ public class SimpleSyncProcessors { Parallel.ForEach(data.Timeline.Events, evt => evt.RoomId = id); if (data.State is { Events.Count: > 0 }) Parallel.ForEach(data.State.Events, evt => evt.RoomId = id); + if (data.StateAfter is { Events.Count: > 0 }) + Parallel.ForEach(data.StateAfter.Events, evt => evt.RoomId = id); }); if (resp.Rooms.Invite is { Count: > 0 }) Parallel.ForEach(resp.Rooms.Invite, (roomEntry) => {