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 --- 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 +++++----- 13 files changed, 148 insertions(+), 284 deletions(-) delete mode 100644 LibMatrix/Extensions/JsonElementExtensions.cs create mode 100644 LibMatrix/Filters/MatrixFilter.cs delete mode 100644 LibMatrix/Filters/SyncFilter.cs (limited to 'LibMatrix') 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, -- cgit 1.4.1