From cf90f02e1f9c9f7d037976cace2b9c49119c741c Mon Sep 17 00:00:00 2001 From: Rory& Date: Thu, 30 May 2024 19:07:09 +0000 Subject: Start implementing new event system --- ConsoleApp1/ConsoleApp1.csproj | 14 ++ ConsoleApp1/Program.cs | 25 ++++ ExampleBots/ModerationBot | 2 +- .../Events/RoomMembershipEventContent.cs | 10 ++ LibMatrix.EventTypes/MatrixEvent.cs | 9 ++ LibMatrix.EventTypes/MatrixEventCollection.cs | 71 ++++++++++ LibMatrix.EventTypes/MatrixEventContent.cs | 26 ++++ LibMatrix.EventTypes/temp/Temp.cs | 17 +++ LibMatrix.sln | 6 + LibMatrix.sln.DotSettings.user | 6 +- LibMatrix/Extensions/EnumerableExtensions.cs | 2 + LibMatrix/Extensions/JsonElementExtensions.cs | 147 --------------------- LibMatrix/Filters/MatrixFilter.cs | 87 ++++++++++++ LibMatrix/Filters/SyncFilter.cs | 87 ------------ LibMatrix/Helpers/MessageBuilder.cs | 5 +- LibMatrix/Helpers/SyncHelper.cs | 4 +- LibMatrix/Helpers/SyncStateResolver.cs | 2 +- .../Homeservers/AuthenticatedHomeserverGeneric.cs | 12 +- .../Extensions/NamedCaches/NamedFilterCache.cs | 2 +- LibMatrix/LegacyMatrixEvent.cs | 4 +- LibMatrix/LibMatrix.csproj | 4 + LibMatrix/RoomTypes/GenericRoom.cs | 8 +- LibMatrix/Utilities/CommonSyncFilters.cs | 68 +++++----- .../JsonElementExtensions.cs | 147 +++++++++++++++++++++ .../LibMatrix.DebugDataValidationApi.csproj | 4 +- .../Services/CommandListenerHostedService.cs | 16 +-- .../Services/InviteListenerHostedService.cs | 16 +-- 27 files changed, 498 insertions(+), 303 deletions(-) create mode 100644 ConsoleApp1/ConsoleApp1.csproj create mode 100644 ConsoleApp1/Program.cs create mode 100644 LibMatrix.EventTypes/Events/RoomMembershipEventContent.cs create mode 100644 LibMatrix.EventTypes/MatrixEvent.cs create mode 100644 LibMatrix.EventTypes/MatrixEventCollection.cs create mode 100644 LibMatrix.EventTypes/MatrixEventContent.cs create mode 100644 LibMatrix.EventTypes/temp/Temp.cs delete mode 100644 LibMatrix/Extensions/JsonElementExtensions.cs create mode 100644 LibMatrix/Filters/MatrixFilter.cs delete mode 100644 LibMatrix/Filters/SyncFilter.cs create mode 100644 Utilities/LibMatrix.DebugDataValidationApi/JsonElementExtensions.cs diff --git a/ConsoleApp1/ConsoleApp1.csproj b/ConsoleApp1/ConsoleApp1.csproj new file mode 100644 index 0000000..f30d408 --- /dev/null +++ b/ConsoleApp1/ConsoleApp1.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + diff --git a/ConsoleApp1/Program.cs b/ConsoleApp1/Program.cs new file mode 100644 index 0000000..7831ce8 --- /dev/null +++ b/ConsoleApp1/Program.cs @@ -0,0 +1,25 @@ +// See https://aka.ms/new-console-template for more information + +using LibMatrix.EventTypes; +using LibMatrix.EventTypes.Events; + +Console.WriteLine("Hello, World!"); + +MatrixEventCollection collection = new(); +collection.Add(new MatrixEvent() { + Content = new RoomMembershipEventContent() { + Membership = "yes" + } +}); + +List> collection2 = new(); +collection2.Add(new MatrixEvent() { + Content = new RoomMembershipEventContent() { + Membership = "yes" + } +}); + +List collection3 = new(); +collection3.Add(new RoomMembershipEventContent() { + Membership = "yes" +}); \ No newline at end of file diff --git a/ExampleBots/ModerationBot b/ExampleBots/ModerationBot index c137f94..b5db509 160000 --- a/ExampleBots/ModerationBot +++ b/ExampleBots/ModerationBot @@ -1 +1 @@ -Subproject commit c137f94aeb122c636629fb9361dd73626594f690 +Subproject commit b5db50961eeedf24f0c969799e6f24830c973b0c diff --git a/LibMatrix.EventTypes/Events/RoomMembershipEventContent.cs b/LibMatrix.EventTypes/Events/RoomMembershipEventContent.cs new file mode 100644 index 0000000..dac7094 --- /dev/null +++ b/LibMatrix.EventTypes/Events/RoomMembershipEventContent.cs @@ -0,0 +1,10 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Events; + +public class RoomMembershipEventContent : MatrixEventContent { + public string Membership { + get => _json["membership"]!.GetValue(); + set => Console.WriteLine(value); + } +} \ No newline at end of file diff --git a/LibMatrix.EventTypes/MatrixEvent.cs b/LibMatrix.EventTypes/MatrixEvent.cs new file mode 100644 index 0000000..63f1e75 --- /dev/null +++ b/LibMatrix.EventTypes/MatrixEvent.cs @@ -0,0 +1,9 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes; + +public interface IMatrixEvent where T : MatrixEventContent; +public class MatrixEvent : IMatrixEvent where T : MatrixEventContent { + [JsonPropertyName("content")] + public T? Content { get; set; } +} \ No newline at end of file diff --git a/LibMatrix.EventTypes/MatrixEventCollection.cs b/LibMatrix.EventTypes/MatrixEventCollection.cs new file mode 100644 index 0000000..35afd2b --- /dev/null +++ b/LibMatrix.EventTypes/MatrixEventCollection.cs @@ -0,0 +1,71 @@ +using System.Collections; + +namespace LibMatrix.EventTypes; + +public interface IMatrixEventCollection : IEnumerable> where T : MatrixEventContent { + +} +public class MatrixEventCollection : IMatrixEventCollection, IList { + private IList> _listImplementation; + public IEnumerator> GetEnumerator() => _listImplementation.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)_listImplementation).GetEnumerator(); + + public void Add(MatrixEvent item) => _listImplementation.Add(item); + + public void Clear() => _listImplementation.Clear(); + + public bool Contains(MatrixEvent item) => _listImplementation.Contains(item); + + public void CopyTo(MatrixEvent[] array, int arrayIndex) => _listImplementation.CopyTo(array, arrayIndex); + + public bool Remove(MatrixEvent item) => _listImplementation.Remove(item); + + public int Count => _listImplementation.Count; + + public bool IsReadOnly => _listImplementation.IsReadOnly; + + public int IndexOf(MatrixEvent item) => _listImplementation.IndexOf(item); + + public void Insert(int index, MatrixEvent item) => _listImplementation.Insert(index, item); + + public void RemoveAt(int index) => _listImplementation.RemoveAt(index); + + public MatrixEvent this[int index] { + get => _listImplementation[index]; + set => _listImplementation[index] = value; + } +} +public class MatrixEventCollection : IMatrixEventCollection, IList> where T : MatrixEventContent { + //TODO: implement + + private IList> _listImplementation = new List>(); + public IEnumerator> GetEnumerator() => _listImplementation.GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)_listImplementation).GetEnumerator(); + + public void Add(MatrixEvent item) => _listImplementation.Add(item); + + public void Clear() => _listImplementation.Clear(); + + public bool Contains(MatrixEvent item) => _listImplementation.Contains(item); + + public void CopyTo(MatrixEvent[] array, int arrayIndex) => _listImplementation.CopyTo(array, arrayIndex); + + public bool Remove(MatrixEvent item) => _listImplementation.Remove(item); + + public int Count => _listImplementation.Count; + + public bool IsReadOnly => _listImplementation.IsReadOnly; + + public int IndexOf(MatrixEvent item) => _listImplementation.IndexOf(item); + + public void Insert(int index, MatrixEvent item) => _listImplementation.Insert(index, item); + + public void RemoveAt(int index) => _listImplementation.RemoveAt(index); + + public MatrixEvent this[int index] { + get => _listImplementation[index]; + set => _listImplementation[index] = value; + } +} \ No newline at end of file diff --git a/LibMatrix.EventTypes/MatrixEventContent.cs b/LibMatrix.EventTypes/MatrixEventContent.cs new file mode 100644 index 0000000..c30ebb0 --- /dev/null +++ b/LibMatrix.EventTypes/MatrixEventContent.cs @@ -0,0 +1,26 @@ +using System.Text.Json; +using System.Text.Json.Nodes; +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes; + +/// +/// Extensible Event Content, aims to provide an API similar to JsonNode/JsonObject +/// +/// +/// +public class MatrixEventContent { + // : MatrixEventContent where T : MatrixEventContent, new() { + internal JsonNode _json = new JsonObject(); + + public static implicit operator MatrixEventContent(JsonNode json) => new(json); + + [JsonConstructor] + public MatrixEventContent(JsonNode json) { + _json = json; + } + + public MatrixEventContent() { } + + public JsonNode? this[string key] => _json[key]; +} \ No newline at end of file diff --git a/LibMatrix.EventTypes/temp/Temp.cs b/LibMatrix.EventTypes/temp/Temp.cs new file mode 100644 index 0000000..3fbb401 --- /dev/null +++ b/LibMatrix.EventTypes/temp/Temp.cs @@ -0,0 +1,17 @@ +using LibMatrix.EventTypes.Events; + +namespace LibMatrix.EventTypes.temp; + +// public class Temp { +// public MatrixEventCollection Members = [ +// new MatrixEvent() { +// Content = new() { +// Membership = "join" +// } +// } +// ]; +// +// public void a() { +// +// } +// } \ No newline at end of file diff --git a/LibMatrix.sln b/LibMatrix.sln index 257a8f2..df24832 100644 --- a/LibMatrix.sln +++ b/LibMatrix.sln @@ -39,6 +39,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibMatrix.HomeserverEmulato EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibMatrix.EventTypes", "LibMatrix.EventTypes\LibMatrix.EventTypes.csproj", "{E9E9567D-58F4-4E17-BBC1-D4746C2526DB}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{6254A2BA-279F-49F7-B3F3-675397F0F644}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -104,6 +106,10 @@ Global {E9E9567D-58F4-4E17-BBC1-D4746C2526DB}.Debug|Any CPU.Build.0 = Debug|Any CPU {E9E9567D-58F4-4E17-BBC1-D4746C2526DB}.Release|Any CPU.ActiveCfg = Release|Any CPU {E9E9567D-58F4-4E17-BBC1-D4746C2526DB}.Release|Any CPU.Build.0 = Release|Any CPU + {6254A2BA-279F-49F7-B3F3-675397F0F644}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6254A2BA-279F-49F7-B3F3-675397F0F644}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6254A2BA-279F-49F7-B3F3-675397F0F644}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6254A2BA-279F-49F7-B3F3-675397F0F644}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {1B1B2197-61FB-416F-B6C8-845F2E5A0442} = {840309F0-435B-43A7-8471-8C2BE643889D} diff --git a/LibMatrix.sln.DotSettings.user b/LibMatrix.sln.DotSettings.user index ec6bdc7..c5570e2 100644 --- a/LibMatrix.sln.DotSettings.user +++ b/LibMatrix.sln.DotSettings.user @@ -4,5 +4,9 @@ <AssemblyExplorer> <Assembly Path="/home/root@Rory/.cache/NuGetPackages/microsoft.extensions.hosting.abstractions/7.0.0/lib/net7.0/Microsoft.Extensions.Hosting.Abstractions.dll" /> </AssemblyExplorer> + True True - True \ No newline at end of file + True + True + True + True \ No newline at end of file diff --git a/LibMatrix/Extensions/EnumerableExtensions.cs b/LibMatrix/Extensions/EnumerableExtensions.cs index b5193ab..7a810ac 100644 --- a/LibMatrix/Extensions/EnumerableExtensions.cs +++ b/LibMatrix/Extensions/EnumerableExtensions.cs @@ -1,6 +1,7 @@ namespace LibMatrix.Extensions; public static class EnumerableExtensions { +#if !DISABLE_LEGACY_EVENTS public static void MergeStateEventLists(this IList oldState, IList newState) { foreach (var stateEvent in newState) { var old = oldState.FirstOrDefault(x => x.Type == stateEvent.Type && x.StateKey == stateEvent.StateKey); @@ -26,4 +27,5 @@ public static class EnumerableExtensions { oldState.Add(stateEvent); } } +#endif } \ No newline at end of file diff --git a/LibMatrix/Extensions/JsonElementExtensions.cs b/LibMatrix/Extensions/JsonElementExtensions.cs deleted file mode 100644 index a2faddc..0000000 --- a/LibMatrix/Extensions/JsonElementExtensions.cs +++ /dev/null @@ -1,147 +0,0 @@ -using System.Reflection; -using System.Text.Json; -using System.Text.Json.Nodes; -using System.Text.Json.Serialization; - -namespace LibMatrix.Extensions; - -public static class JsonElementExtensions { - public static bool FindExtraJsonElementFields(this JsonElement obj, Type objectType, string objectPropertyName) { - if (objectPropertyName == "content" && objectType == typeof(JsonObject)) - objectType = typeof(LegacyMatrixEventResponse); - // if (t == typeof(JsonNode)) - // return false; - - Console.WriteLine($"{objectType.Name} {objectPropertyName}"); - var unknownPropertyFound = false; - var mappedPropsDict = objectType.GetProperties() - .Where(x => x.GetCustomAttribute() is not null) - .ToDictionary(x => x.GetCustomAttribute()!.Name, x => x); - objectType.GetProperties().Where(x => !mappedPropsDict.ContainsKey(x.Name)) - .ToList().ForEach(x => mappedPropsDict.TryAdd(x.Name, x)); - - foreach (var field in obj.EnumerateObject()) { - if (mappedPropsDict.TryGetValue(field.Name, out var mappedProperty)) { - //dictionary - if (mappedProperty.PropertyType.IsGenericType && - mappedProperty.PropertyType.GetGenericTypeDefinition() == typeof(Dictionary<,>)) { - unknownPropertyFound |= _checkDictionary(field, objectType, mappedProperty.PropertyType); - continue; - } - - if (mappedProperty.PropertyType.IsGenericType && - mappedProperty.PropertyType.GetGenericTypeDefinition() == typeof(List<>)) { - unknownPropertyFound |= _checkList(field, objectType, mappedProperty.PropertyType); - continue; - } - - if (field.Name == "content" && (objectType == typeof(LegacyMatrixEventResponse) || objectType == typeof(LegacyMatrixEvent))) { - unknownPropertyFound |= field.FindExtraJsonPropertyFieldsByValueKind( - LegacyMatrixEvent.GetStateEventType(obj.GetProperty("type").GetString()!), // We expect type to always be present - mappedProperty.PropertyType); - continue; - } - - unknownPropertyFound |= - field.FindExtraJsonPropertyFieldsByValueKind(objectType, mappedProperty.PropertyType); - continue; - } - - Console.WriteLine($"[!!] Unknown property {field.Name} in {objectType.Name}!"); - unknownPropertyFound = true; - } - - return unknownPropertyFound; - } - - private static bool FindExtraJsonPropertyFieldsByValueKind(this JsonProperty field, Type containerType, - Type propertyType) { - if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable<>)) propertyType = propertyType.GetGenericArguments()[0]; - - var switchResult = false; - switch (field.Value.ValueKind) { - case JsonValueKind.Array: - switchResult = field.Value.EnumerateArray().Aggregate(switchResult, - (current, element) => current | element.FindExtraJsonElementFields(propertyType, field.Name)); - break; - case JsonValueKind.Object: - switchResult |= field.Value.FindExtraJsonElementFields(propertyType, field.Name); - break; - case JsonValueKind.True: - case JsonValueKind.False: - return _checkBool(field, containerType, propertyType); - case JsonValueKind.String: - return _checkString(field, containerType, propertyType); - case JsonValueKind.Number: - return _checkNumber(field, containerType, propertyType); - case JsonValueKind.Undefined: - case JsonValueKind.Null: - break; - default: - throw new ArgumentOutOfRangeException(); - } - - return switchResult; - } - - private static bool _checkBool(this JsonProperty field, Type containerType, Type propertyType) { - if (propertyType == typeof(bool)) return true; - Console.WriteLine( - $"[!!] Encountered bool for {field.Name} in {containerType.Name}, the class defines {propertyType.Name}!"); - return false; - } - - private static bool _checkString(this JsonProperty field, Type containerType, Type propertyType) { - if (propertyType == typeof(string)) return true; - // ReSharper disable once BuiltInTypeReferenceStyle - if (propertyType == typeof(String)) return true; - Console.WriteLine( - $"[!!] Encountered string for {field.Name} in {containerType.Name}, the class defines {propertyType.Name}!"); - return false; - } - - private static bool _checkNumber(this JsonProperty field, Type containerType, Type propertyType) { - if (propertyType == typeof(int) || - propertyType == typeof(double) || - propertyType == typeof(float) || - propertyType == typeof(decimal) || - propertyType == typeof(long) || - propertyType == typeof(short) || - propertyType == typeof(uint) || - propertyType == typeof(ulong) || - propertyType == typeof(ushort) || - propertyType == typeof(byte) || - propertyType == typeof(sbyte)) - return true; - Console.WriteLine( - $"[!!] Encountered number for {field.Name} in {containerType.Name}, the class defines {propertyType.Name}!"); - return false; - } - - private static bool _checkDictionary(this JsonProperty field, Type containerType, Type propertyType) { - var keyType = propertyType.GetGenericArguments()[0]; - var valueType = propertyType.GetGenericArguments()[1]; - valueType = Nullable.GetUnderlyingType(valueType) ?? valueType; - Console.WriteLine( - $"Encountered dictionary {field.Name} with key type {keyType.Name} and value type {valueType.Name}!"); - - return field.Value.EnumerateObject() - .Where(key => !valueType.IsPrimitive && valueType != typeof(string)) - .Aggregate(false, (current, key) => - current | key.FindExtraJsonPropertyFieldsByValueKind(containerType, valueType) - ); - } - - private static bool _checkList(this JsonProperty field, Type containerType, Type propertyType) { - var valueType = propertyType.GetGenericArguments()[0]; - valueType = Nullable.GetUnderlyingType(valueType) ?? valueType; - Console.WriteLine( - $"Encountered list {field.Name} with value type {valueType.Name}!"); - - return field.Value.EnumerateArray() - .Where(key => !valueType.IsPrimitive && valueType != typeof(string)) - .Aggregate(false, (current, key) => - current | key.FindExtraJsonElementFields(valueType, field.Name) - ); - } -} \ No newline at end of file diff --git a/LibMatrix/Filters/MatrixFilter.cs b/LibMatrix/Filters/MatrixFilter.cs new file mode 100644 index 0000000..08dc2fc --- /dev/null +++ b/LibMatrix/Filters/MatrixFilter.cs @@ -0,0 +1,87 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.Filters; + +public class MatrixFilter { + [JsonPropertyName("account_data")] + public EventFilter? AccountData { get; set; } + + [JsonPropertyName("presence")] + public EventFilter? Presence { get; set; } + + [JsonPropertyName("room")] + public RoomFilter? Room { get; set; } + + public class RoomFilter { + [JsonPropertyName("account_data")] + public StateFilter? AccountData { get; set; } + + [JsonPropertyName("ephemeral")] + public StateFilter? Ephemeral { get; set; } + + [JsonPropertyName("state")] + public StateFilter? State { get; set; } + + [JsonPropertyName("timeline")] + public StateFilter? Timeline { get; set; } + + [JsonPropertyName("rooms")] + public List? Rooms { get; set; } + + [JsonPropertyName("not_rooms")] + public List? NotRooms { get; set; } + + [JsonPropertyName("include_leave")] + public bool? IncludeLeave { get; set; } + + public class StateFilter( + bool? containsUrl = null, + bool? includeRedundantMembers = null, + bool? lazyLoadMembers = null, + List? rooms = null, + List? notRooms = null, + bool? unreadThreadNotifications = null, + //base ctor + int? limit = null, + List? types = null, + List? notTypes = null, + List? senders = null, + List? notSenders = null + ) : EventFilter(limit, types, notTypes, senders, notSenders) { + [JsonPropertyName("contains_url")] + public bool? ContainsUrl { get; set; } = containsUrl; + + [JsonPropertyName("include_redundant_members")] + public bool? IncludeRedundantMembers { get; set; } = includeRedundantMembers; + + [JsonPropertyName("lazy_load_members")] + public bool? LazyLoadMembers { get; set; } = lazyLoadMembers; + + [JsonPropertyName("rooms")] + public List? Rooms { get; set; } = rooms; + + [JsonPropertyName("not_rooms")] + public List? NotRooms { get; set; } = notRooms; + + [JsonPropertyName("unread_thread_notifications")] + public bool? UnreadThreadNotifications { get; set; } = unreadThreadNotifications; + } + } + + public class EventFilter(int? limit = null, List? types = null, List? notTypes = null, List? senders = null, List? notSenders = null) { + [JsonPropertyName("limit")] + public int? Limit { get; set; } = limit; + + [JsonPropertyName("types")] + public List? Types { get; set; } = types; + + [JsonPropertyName("not_types")] + public List? NotTypes { get; set; } = notTypes; + + [JsonPropertyName("senders")] + public List? Senders { get; set; } = senders; + + [JsonPropertyName("not_senders")] + public List? NotSenders { get; set; } = notSenders; + } +} \ No newline at end of file diff --git a/LibMatrix/Filters/SyncFilter.cs b/LibMatrix/Filters/SyncFilter.cs deleted file mode 100644 index 787ffa7..0000000 --- a/LibMatrix/Filters/SyncFilter.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.Filters; - -public class SyncFilter { - [JsonPropertyName("account_data")] - public EventFilter? AccountData { get; set; } - - [JsonPropertyName("presence")] - public EventFilter? Presence { get; set; } - - [JsonPropertyName("room")] - public RoomFilter? Room { get; set; } - - public class RoomFilter { - [JsonPropertyName("account_data")] - public StateFilter? AccountData { get; set; } - - [JsonPropertyName("ephemeral")] - public StateFilter? Ephemeral { get; set; } - - [JsonPropertyName("state")] - public StateFilter? State { get; set; } - - [JsonPropertyName("timeline")] - public StateFilter? Timeline { get; set; } - - [JsonPropertyName("rooms")] - public List? Rooms { get; set; } - - [JsonPropertyName("not_rooms")] - public List? NotRooms { get; set; } - - [JsonPropertyName("include_leave")] - public bool? IncludeLeave { get; set; } - - public class StateFilter( - bool? containsUrl = null, - bool? includeRedundantMembers = null, - bool? lazyLoadMembers = null, - List? rooms = null, - List? notRooms = null, - bool? unreadThreadNotifications = null, - //base ctor - int? limit = null, - List? types = null, - List? notTypes = null, - List? senders = null, - List? notSenders = null - ) : EventFilter(limit, types, notTypes, senders, notSenders) { - [JsonPropertyName("contains_url")] - public bool? ContainsUrl { get; set; } = containsUrl; - - [JsonPropertyName("include_redundant_members")] - public bool? IncludeRedundantMembers { get; set; } = includeRedundantMembers; - - [JsonPropertyName("lazy_load_members")] - public bool? LazyLoadMembers { get; set; } = lazyLoadMembers; - - [JsonPropertyName("rooms")] - public List? Rooms { get; set; } = rooms; - - [JsonPropertyName("not_rooms")] - public List? NotRooms { get; set; } = notRooms; - - [JsonPropertyName("unread_thread_notifications")] - public bool? UnreadThreadNotifications { get; set; } = unreadThreadNotifications; - } - } - - public class EventFilter(int? limit = null, List? types = null, List? notTypes = null, List? senders = null, List? notSenders = null) { - [JsonPropertyName("limit")] - public int? Limit { get; set; } = limit; - - [JsonPropertyName("types")] - public List? Types { get; set; } = types; - - [JsonPropertyName("not_types")] - public List? NotTypes { get; set; } = notTypes; - - [JsonPropertyName("senders")] - public List? Senders { get; set; } = senders; - - [JsonPropertyName("not_senders")] - public List? NotSenders { get; set; } = notSenders; - } -} \ No newline at end of file diff --git a/LibMatrix/Helpers/MessageBuilder.cs b/LibMatrix/Helpers/MessageBuilder.cs index 0ed0339..43999b3 100644 --- a/LibMatrix/Helpers/MessageBuilder.cs +++ b/LibMatrix/Helpers/MessageBuilder.cs @@ -1,3 +1,4 @@ +#if !DISABLE_LEGACY_EVENTS using LibMatrix.LegacyEvents.EventTypes.Spec; namespace LibMatrix.Helpers; @@ -118,4 +119,6 @@ public class MessageBuilder(string msgType = "m.text", string format = "org.matr } } } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/LibMatrix/Helpers/SyncHelper.cs b/LibMatrix/Helpers/SyncHelper.cs index 5635955..09bcf8e 100644 --- a/LibMatrix/Helpers/SyncHelper.cs +++ b/LibMatrix/Helpers/SyncHelper.cs @@ -9,7 +9,7 @@ using Microsoft.Extensions.Logging; namespace LibMatrix.Helpers; public class SyncHelper(AuthenticatedHomeserverGeneric homeserver, ILogger? logger = null) { - private SyncFilter? _filter; + private MatrixFilter? _filter; private string? _namedFilterName; private bool _filterIsDirty = false; private string? _filterId = null; @@ -36,7 +36,7 @@ public class SyncHelper(AuthenticatedHomeserverGeneric homeserver, ILogger? logg } } - public SyncFilter? Filter { + public MatrixFilter? Filter { get => _filter; set { _filter = value; diff --git a/LibMatrix/Helpers/SyncStateResolver.cs b/LibMatrix/Helpers/SyncStateResolver.cs index b1f83ff..511819a 100644 --- a/LibMatrix/Helpers/SyncStateResolver.cs +++ b/LibMatrix/Helpers/SyncStateResolver.cs @@ -10,7 +10,7 @@ public class SyncStateResolver(AuthenticatedHomeserverGeneric homeserver, ILogge public string? Since { get; set; } public int Timeout { get; set; } = 30000; public string? SetPresence { get; set; } = "online"; - public SyncFilter? Filter { get; set; } + public MatrixFilter? Filter { get; set; } public bool FullState { get; set; } = false; public SyncResponse? MergedState { get; set; } diff --git a/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs b/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs index db76985..96e20e0 100644 --- a/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs +++ b/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs @@ -192,8 +192,8 @@ public class AuthenticatedHomeserverGeneric : RemoteHomeserver { var oldProfile = await GetProfileAsync(WhoAmI.UserId!); Dictionary expectedRoomProfiles = new(); var syncHelper = new SyncHelper(this) { - Filter = new SyncFilter { - AccountData = new SyncFilter.EventFilter() { + Filter = new MatrixFilter { + AccountData = new MatrixFilter.EventFilter() { Types = new List { "m.room.member" } @@ -312,7 +312,7 @@ public class AuthenticatedHomeserverGeneric : RemoteHomeserver { /// /// /// - public async Task UploadFilterAsync(SyncFilter filter) { + public async Task UploadFilterAsync(MatrixFilter filter) { List?> senderLists = [ filter.AccountData?.Senders, filter.AccountData?.NotSenders, @@ -338,10 +338,10 @@ public class AuthenticatedHomeserverGeneric : RemoteHomeserver { return await resp.Content.ReadFromJsonAsync() ?? throw new Exception("Failed to upload filter?"); } - public async Task GetFilterAsync(string filterId) { + public async Task GetFilterAsync(string filterId) { if (_filterCache.TryGetValue(filterId, out var filter)) return filter; var resp = await ClientHttpClient.GetAsync("/_matrix/client/v3/user/" + UserId + "/filter/" + filterId); - return _filterCache[filterId] = await resp.Content.ReadFromJsonAsync() ?? throw new Exception("Failed to get filter?"); + return _filterCache[filterId] = await resp.Content.ReadFromJsonAsync() ?? throw new Exception("Failed to get filter?"); } public class FilterIdResponse { @@ -385,7 +385,7 @@ public class AuthenticatedHomeserverGeneric : RemoteHomeserver { } private Dictionary? _namedFilterCache; - private Dictionary _filterCache = new(); + private Dictionary _filterCache = new(); public async Task GetCapabilitiesAsync() { var res = await ClientHttpClient.GetAsync("/_matrix/client/v3/capabilities"); diff --git a/LibMatrix/Homeservers/Extensions/NamedCaches/NamedFilterCache.cs b/LibMatrix/Homeservers/Extensions/NamedCaches/NamedFilterCache.cs index 76533a4..551ac39 100644 --- a/LibMatrix/Homeservers/Extensions/NamedCaches/NamedFilterCache.cs +++ b/LibMatrix/Homeservers/Extensions/NamedCaches/NamedFilterCache.cs @@ -13,7 +13,7 @@ public class NamedFilterCache(AuthenticatedHomeserverGeneric hs) : NamedCacheFilter to upload if not cached, otherwise defaults to common filters if that exists. /// /// - public async Task GetOrSetValueAsync(string key, SyncFilter? filter = null) { + public async Task GetOrSetValueAsync(string key, MatrixFilter? filter = null) { var existingValue = await GetValueAsync(key); if (existingValue != null) { return existingValue; diff --git a/LibMatrix/LegacyMatrixEvent.cs b/LibMatrix/LegacyMatrixEvent.cs index 5433da3..a1ac5db 100644 --- a/LibMatrix/LegacyMatrixEvent.cs +++ b/LibMatrix/LegacyMatrixEvent.cs @@ -1,3 +1,4 @@ +#if !DISABLE_LEGACY_EVENTS using System.Collections.Frozen; using System.Diagnostics.CodeAnalysis; using System.Reflection; @@ -222,4 +223,5 @@ public class StateEventContentPolymorphicTypeInfoResolver : DefaultJsonTypeInfoR } */ -#endregion \ No newline at end of file +#endregion +#endif \ No newline at end of file diff --git a/LibMatrix/LibMatrix.csproj b/LibMatrix/LibMatrix.csproj index 42ef17d..69f2bf4 100644 --- a/LibMatrix/LibMatrix.csproj +++ b/LibMatrix/LibMatrix.csproj @@ -8,6 +8,10 @@ true true + + + $(DefineConstants);DISABLE_LEGACY_EVENTS + $(DefineConstants);$(ExtraDefineConstants) diff --git a/LibMatrix/RoomTypes/GenericRoom.cs b/LibMatrix/RoomTypes/GenericRoom.cs index 8fa46d3..aafe29f 100644 --- a/LibMatrix/RoomTypes/GenericRoom.cs +++ b/LibMatrix/RoomTypes/GenericRoom.cs @@ -105,16 +105,16 @@ public class GenericRoom { if (!fallbackToSync) throw; Console.WriteLine("WARNING: Homeserver does not support getting event ID from state events, falling back to sync"); var sh = new SyncHelper(Homeserver); - var emptyFilter = new SyncFilter.EventFilter(types: [], limit: 1, senders: [], notTypes: ["*"]); - var emptyStateFilter = new SyncFilter.RoomFilter.StateFilter(types: [], limit: 1, senders: [], notTypes: ["*"], rooms:[]); + var emptyFilter = new MatrixFilter.EventFilter(types: [], limit: 1, senders: [], notTypes: ["*"]); + var emptyStateFilter = new MatrixFilter.RoomFilter.StateFilter(types: [], limit: 1, senders: [], notTypes: ["*"], rooms:[]); sh.Filter = new() { Presence = emptyFilter, AccountData = emptyFilter, - Room = new SyncFilter.RoomFilter() { + Room = new MatrixFilter.RoomFilter() { AccountData = emptyStateFilter, Timeline = emptyStateFilter, Ephemeral = emptyStateFilter, - State = new SyncFilter.RoomFilter.StateFilter(), + State = new MatrixFilter.RoomFilter.StateFilter(), Rooms = [RoomId] } }; diff --git a/LibMatrix/Utilities/CommonSyncFilters.cs b/LibMatrix/Utilities/CommonSyncFilters.cs index d07c225..68836f5 100644 --- a/LibMatrix/Utilities/CommonSyncFilters.cs +++ b/LibMatrix/Utilities/CommonSyncFilters.cs @@ -13,29 +13,29 @@ public static class CommonSyncFilters { public const string GetSpaceRelations = "gay.rory.matrixutils.get_space_relations.v0"; public const string GetOwnMemberEvents = "gay.rory.matrixutils.get_own_member_events.v0"; - public static SyncFilter GetAccountDataFilter => new() { - Presence = new SyncFilter.EventFilter(notTypes: ["*"]), - Room = new SyncFilter.RoomFilter() { + public static MatrixFilter GetAccountDataFilter => new() { + Presence = new MatrixFilter.EventFilter(notTypes: ["*"]), + Room = new MatrixFilter.RoomFilter() { Rooms = [] } }; - public static SyncFilter GetAccountDataWithRoomsFilter => new() { - Presence = new SyncFilter.EventFilter(notTypes: ["*"]), - Room = new SyncFilter.RoomFilter() { - State = new SyncFilter.RoomFilter.StateFilter(notTypes: ["*"]), - Ephemeral = new SyncFilter.RoomFilter.StateFilter(notTypes: ["*"]), - Timeline = new SyncFilter.RoomFilter.StateFilter(notTypes: ["*"]) + public static MatrixFilter GetAccountDataWithRoomsFilter => new() { + Presence = new MatrixFilter.EventFilter(notTypes: ["*"]), + Room = new MatrixFilter.RoomFilter() { + State = new MatrixFilter.RoomFilter.StateFilter(notTypes: ["*"]), + Ephemeral = new MatrixFilter.RoomFilter.StateFilter(notTypes: ["*"]), + Timeline = new MatrixFilter.RoomFilter.StateFilter(notTypes: ["*"]) } }; - public static SyncFilter GetBasicRoomDataFilter => new() { - AccountData = new SyncFilter.EventFilter(notTypes: ["*"], limit: 1), - Presence = new SyncFilter.EventFilter(notTypes: ["*"], limit: 1), - Room = new SyncFilter.RoomFilter { - AccountData = new SyncFilter.RoomFilter.StateFilter(rooms: []), - Ephemeral = new SyncFilter.RoomFilter.StateFilter(rooms: []), - State = new SyncFilter.RoomFilter.StateFilter { + public static MatrixFilter GetBasicRoomDataFilter => new() { + AccountData = new MatrixFilter.EventFilter(notTypes: ["*"], limit: 1), + Presence = new MatrixFilter.EventFilter(notTypes: ["*"], limit: 1), + Room = new MatrixFilter.RoomFilter { + AccountData = new MatrixFilter.RoomFilter.StateFilter(rooms: []), + Ephemeral = new MatrixFilter.RoomFilter.StateFilter(rooms: []), + State = new MatrixFilter.RoomFilter.StateFilter { Types = new List { RoomCreateLegacyEventContent.EventId, RoomNameLegacyEventContent.EventId, @@ -45,46 +45,46 @@ public static class CommonSyncFilters { }, LazyLoadMembers = true, IncludeRedundantMembers = false }, - Timeline = new SyncFilter.RoomFilter.StateFilter(rooms: []) + Timeline = new MatrixFilter.RoomFilter.StateFilter(rooms: []) } }; - public static SyncFilter GetSpaceRelationsFilter => new() { - AccountData = new SyncFilter.EventFilter(notTypes: ["*"], limit: 1), - Presence = new SyncFilter.EventFilter(notTypes: ["*"], limit: 1), - Room = new SyncFilter.RoomFilter { - AccountData = new SyncFilter.RoomFilter.StateFilter(rooms: []), - Ephemeral = new SyncFilter.RoomFilter.StateFilter(rooms: []), - State = new SyncFilter.RoomFilter.StateFilter { + public static MatrixFilter GetSpaceRelationsFilter => new() { + AccountData = new MatrixFilter.EventFilter(notTypes: ["*"], limit: 1), + Presence = new MatrixFilter.EventFilter(notTypes: ["*"], limit: 1), + Room = new MatrixFilter.RoomFilter { + AccountData = new MatrixFilter.RoomFilter.StateFilter(rooms: []), + Ephemeral = new MatrixFilter.RoomFilter.StateFilter(rooms: []), + State = new MatrixFilter.RoomFilter.StateFilter { Types = new List { SpaceChildLegacyEventContent.EventId, SpaceParentLegacyEventContent.EventId }, LazyLoadMembers = true, IncludeRedundantMembers = false }, - Timeline = new SyncFilter.RoomFilter.StateFilter(rooms: []) + Timeline = new MatrixFilter.RoomFilter.StateFilter(rooms: []) } }; - public static SyncFilter GetOwnMemberEventsFilter => new() { - AccountData = new SyncFilter.EventFilter(types: ["m.room.member"], limit: 1), - Presence = new SyncFilter.EventFilter(notTypes: ["*"], limit: 1), - Room = new SyncFilter.RoomFilter { - AccountData = new SyncFilter.RoomFilter.StateFilter(rooms: []), - Ephemeral = new SyncFilter.RoomFilter.StateFilter(rooms: []), - State = new SyncFilter.RoomFilter.StateFilter { + public static MatrixFilter GetOwnMemberEventsFilter => new() { + AccountData = new MatrixFilter.EventFilter(types: ["m.room.member"], limit: 1), + Presence = new MatrixFilter.EventFilter(notTypes: ["*"], limit: 1), + Room = new MatrixFilter.RoomFilter { + AccountData = new MatrixFilter.RoomFilter.StateFilter(rooms: []), + Ephemeral = new MatrixFilter.RoomFilter.StateFilter(rooms: []), + State = new MatrixFilter.RoomFilter.StateFilter { Types = new List { RoomMemberLegacyEventContent.EventId }, LazyLoadMembers = true, IncludeRedundantMembers = false, Senders = ["@me"] }, - Timeline = new SyncFilter.RoomFilter.StateFilter(rooms: []) + Timeline = new MatrixFilter.RoomFilter.StateFilter(rooms: []) } }; // This must be down here, due to statics load order - public static FrozenDictionary FilterMap => new Dictionary() { + public static FrozenDictionary FilterMap => new Dictionary() { [GetAccountData] = GetAccountDataFilter, [GetAccountDataWithRooms] = GetAccountDataWithRoomsFilter, [GetBasicRoomInfo] = GetBasicRoomDataFilter, diff --git a/Utilities/LibMatrix.DebugDataValidationApi/JsonElementExtensions.cs b/Utilities/LibMatrix.DebugDataValidationApi/JsonElementExtensions.cs new file mode 100644 index 0000000..a2faddc --- /dev/null +++ b/Utilities/LibMatrix.DebugDataValidationApi/JsonElementExtensions.cs @@ -0,0 +1,147 @@ +using System.Reflection; +using System.Text.Json; +using System.Text.Json.Nodes; +using System.Text.Json.Serialization; + +namespace LibMatrix.Extensions; + +public static class JsonElementExtensions { + public static bool FindExtraJsonElementFields(this JsonElement obj, Type objectType, string objectPropertyName) { + if (objectPropertyName == "content" && objectType == typeof(JsonObject)) + objectType = typeof(LegacyMatrixEventResponse); + // if (t == typeof(JsonNode)) + // return false; + + Console.WriteLine($"{objectType.Name} {objectPropertyName}"); + var unknownPropertyFound = false; + var mappedPropsDict = objectType.GetProperties() + .Where(x => x.GetCustomAttribute() is not null) + .ToDictionary(x => x.GetCustomAttribute()!.Name, x => x); + objectType.GetProperties().Where(x => !mappedPropsDict.ContainsKey(x.Name)) + .ToList().ForEach(x => mappedPropsDict.TryAdd(x.Name, x)); + + foreach (var field in obj.EnumerateObject()) { + if (mappedPropsDict.TryGetValue(field.Name, out var mappedProperty)) { + //dictionary + if (mappedProperty.PropertyType.IsGenericType && + mappedProperty.PropertyType.GetGenericTypeDefinition() == typeof(Dictionary<,>)) { + unknownPropertyFound |= _checkDictionary(field, objectType, mappedProperty.PropertyType); + continue; + } + + if (mappedProperty.PropertyType.IsGenericType && + mappedProperty.PropertyType.GetGenericTypeDefinition() == typeof(List<>)) { + unknownPropertyFound |= _checkList(field, objectType, mappedProperty.PropertyType); + continue; + } + + if (field.Name == "content" && (objectType == typeof(LegacyMatrixEventResponse) || objectType == typeof(LegacyMatrixEvent))) { + unknownPropertyFound |= field.FindExtraJsonPropertyFieldsByValueKind( + LegacyMatrixEvent.GetStateEventType(obj.GetProperty("type").GetString()!), // We expect type to always be present + mappedProperty.PropertyType); + continue; + } + + unknownPropertyFound |= + field.FindExtraJsonPropertyFieldsByValueKind(objectType, mappedProperty.PropertyType); + continue; + } + + Console.WriteLine($"[!!] Unknown property {field.Name} in {objectType.Name}!"); + unknownPropertyFound = true; + } + + return unknownPropertyFound; + } + + private static bool FindExtraJsonPropertyFieldsByValueKind(this JsonProperty field, Type containerType, + Type propertyType) { + if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable<>)) propertyType = propertyType.GetGenericArguments()[0]; + + var switchResult = false; + switch (field.Value.ValueKind) { + case JsonValueKind.Array: + switchResult = field.Value.EnumerateArray().Aggregate(switchResult, + (current, element) => current | element.FindExtraJsonElementFields(propertyType, field.Name)); + break; + case JsonValueKind.Object: + switchResult |= field.Value.FindExtraJsonElementFields(propertyType, field.Name); + break; + case JsonValueKind.True: + case JsonValueKind.False: + return _checkBool(field, containerType, propertyType); + case JsonValueKind.String: + return _checkString(field, containerType, propertyType); + case JsonValueKind.Number: + return _checkNumber(field, containerType, propertyType); + case JsonValueKind.Undefined: + case JsonValueKind.Null: + break; + default: + throw new ArgumentOutOfRangeException(); + } + + return switchResult; + } + + private static bool _checkBool(this JsonProperty field, Type containerType, Type propertyType) { + if (propertyType == typeof(bool)) return true; + Console.WriteLine( + $"[!!] Encountered bool for {field.Name} in {containerType.Name}, the class defines {propertyType.Name}!"); + return false; + } + + private static bool _checkString(this JsonProperty field, Type containerType, Type propertyType) { + if (propertyType == typeof(string)) return true; + // ReSharper disable once BuiltInTypeReferenceStyle + if (propertyType == typeof(String)) return true; + Console.WriteLine( + $"[!!] Encountered string for {field.Name} in {containerType.Name}, the class defines {propertyType.Name}!"); + return false; + } + + private static bool _checkNumber(this JsonProperty field, Type containerType, Type propertyType) { + if (propertyType == typeof(int) || + propertyType == typeof(double) || + propertyType == typeof(float) || + propertyType == typeof(decimal) || + propertyType == typeof(long) || + propertyType == typeof(short) || + propertyType == typeof(uint) || + propertyType == typeof(ulong) || + propertyType == typeof(ushort) || + propertyType == typeof(byte) || + propertyType == typeof(sbyte)) + return true; + Console.WriteLine( + $"[!!] Encountered number for {field.Name} in {containerType.Name}, the class defines {propertyType.Name}!"); + return false; + } + + private static bool _checkDictionary(this JsonProperty field, Type containerType, Type propertyType) { + var keyType = propertyType.GetGenericArguments()[0]; + var valueType = propertyType.GetGenericArguments()[1]; + valueType = Nullable.GetUnderlyingType(valueType) ?? valueType; + Console.WriteLine( + $"Encountered dictionary {field.Name} with key type {keyType.Name} and value type {valueType.Name}!"); + + return field.Value.EnumerateObject() + .Where(key => !valueType.IsPrimitive && valueType != typeof(string)) + .Aggregate(false, (current, key) => + current | key.FindExtraJsonPropertyFieldsByValueKind(containerType, valueType) + ); + } + + private static bool _checkList(this JsonProperty field, Type containerType, Type propertyType) { + var valueType = propertyType.GetGenericArguments()[0]; + valueType = Nullable.GetUnderlyingType(valueType) ?? valueType; + Console.WriteLine( + $"Encountered list {field.Name} with value type {valueType.Name}!"); + + return field.Value.EnumerateArray() + .Where(key => !valueType.IsPrimitive && valueType != typeof(string)) + .Aggregate(false, (current, key) => + current | key.FindExtraJsonElementFields(valueType, field.Name) + ); + } +} \ No newline at end of file diff --git a/Utilities/LibMatrix.DebugDataValidationApi/LibMatrix.DebugDataValidationApi.csproj b/Utilities/LibMatrix.DebugDataValidationApi/LibMatrix.DebugDataValidationApi.csproj index 24fd617..ef8f443 100644 --- a/Utilities/LibMatrix.DebugDataValidationApi/LibMatrix.DebugDataValidationApi.csproj +++ b/Utilities/LibMatrix.DebugDataValidationApi/LibMatrix.DebugDataValidationApi.csproj @@ -14,7 +14,9 @@ - + + ExtraDefineConstants=WITH_LEGACY_EVENTS + diff --git a/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs b/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs index 46638e4..45118b3 100644 --- a/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs +++ b/Utilities/LibMatrix.Utilities.Bot/Services/CommandListenerHostedService.cs @@ -41,14 +41,14 @@ public class CommandListenerHostedService : IHostedService { private async Task? Run(CancellationToken cancellationToken) { _logger.LogInformation("Starting command listener!"); - var filter = await _hs.NamedCaches.FilterCache.GetOrSetValueAsync("gay.rory.libmatrix.utilities.bot.command_listener_syncfilter.dev2", new SyncFilter() { - AccountData = new SyncFilter.EventFilter(notTypes: ["*"], limit: 1), - Presence = new SyncFilter.EventFilter(notTypes: ["*"]), - Room = new SyncFilter.RoomFilter() { - AccountData = new SyncFilter.RoomFilter.StateFilter(notTypes: ["*"]), - Ephemeral = new SyncFilter.RoomFilter.StateFilter(notTypes: ["*"]), - State = new SyncFilter.RoomFilter.StateFilter(notTypes: ["*"]), - Timeline = new SyncFilter.RoomFilter.StateFilter(types: ["m.room.message"], notSenders: [_hs.WhoAmI.UserId]), + var filter = await _hs.NamedCaches.FilterCache.GetOrSetValueAsync("gay.rory.libmatrix.utilities.bot.command_listener_syncfilter.dev2", new MatrixFilter() { + AccountData = new MatrixFilter.EventFilter(notTypes: ["*"], limit: 1), + Presence = new MatrixFilter.EventFilter(notTypes: ["*"]), + Room = new MatrixFilter.RoomFilter() { + AccountData = new MatrixFilter.RoomFilter.StateFilter(notTypes: ["*"]), + Ephemeral = new MatrixFilter.RoomFilter.StateFilter(notTypes: ["*"]), + State = new MatrixFilter.RoomFilter.StateFilter(notTypes: ["*"]), + Timeline = new MatrixFilter.RoomFilter.StateFilter(types: ["m.room.message"], notSenders: [_hs.WhoAmI.UserId]), } }); diff --git a/Utilities/LibMatrix.Utilities.Bot/Services/InviteListenerHostedService.cs b/Utilities/LibMatrix.Utilities.Bot/Services/InviteListenerHostedService.cs index c2aed04..b49a8e3 100644 --- a/Utilities/LibMatrix.Utilities.Bot/Services/InviteListenerHostedService.cs +++ b/Utilities/LibMatrix.Utilities.Bot/Services/InviteListenerHostedService.cs @@ -31,14 +31,14 @@ public class InviteHandlerHostedService : IHostedService { private async Task? Run(CancellationToken cancellationToken) { _logger.LogInformation("Starting invite listener!"); - var filter = await _hs.NamedCaches.FilterCache.GetOrSetValueAsync("gay.rory.libmatrix.utilities.bot.command_listener_syncfilter.dev2", new SyncFilter() { - AccountData = new SyncFilter.EventFilter(notTypes: ["*"], limit: 1), - Presence = new SyncFilter.EventFilter(notTypes: ["*"]), - Room = new SyncFilter.RoomFilter() { - AccountData = new SyncFilter.RoomFilter.StateFilter(notTypes: ["*"]), - Ephemeral = new SyncFilter.RoomFilter.StateFilter(notTypes: ["*"]), - State = new SyncFilter.RoomFilter.StateFilter(notTypes: ["*"]), - Timeline = new SyncFilter.RoomFilter.StateFilter(types: ["m.room.message"], notSenders: [_hs.WhoAmI.UserId]), + var filter = await _hs.NamedCaches.FilterCache.GetOrSetValueAsync("gay.rory.libmatrix.utilities.bot.command_listener_syncfilter.dev2", new MatrixFilter() { + AccountData = new MatrixFilter.EventFilter(notTypes: ["*"], limit: 1), + Presence = new MatrixFilter.EventFilter(notTypes: ["*"]), + Room = new MatrixFilter.RoomFilter() { + AccountData = new MatrixFilter.RoomFilter.StateFilter(notTypes: ["*"]), + Ephemeral = new MatrixFilter.RoomFilter.StateFilter(notTypes: ["*"]), + State = new MatrixFilter.RoomFilter.StateFilter(notTypes: ["*"]), + Timeline = new MatrixFilter.RoomFilter.StateFilter(types: ["m.room.message"], notSenders: [_hs.WhoAmI.UserId]), } }); -- cgit 1.4.1