about summary refs log tree commit diff
path: root/LibMatrix/Utilities
diff options
context:
space:
mode:
authorEmma [it/its]@Rory& <root@rory.gay>2024-01-31 12:09:28 +0100
committerEmma [it/its]@Rory& <root@rory.gay>2024-01-31 12:09:28 +0100
commit9f8d0c85c54b4715974994aea52562072d6f1751 (patch)
treece5eaf47b02fb82bc99236b926eb9948322745f7 /LibMatrix/Utilities
parentGet full state event (diff)
downloadLibMatrix-9f8d0c85c54b4715974994aea52562072d6f1751.tar.xz
Better sync filter support, named filters, error handling
Diffstat (limited to 'LibMatrix/Utilities')
-rw-r--r--LibMatrix/Utilities/CommonSyncFilters.cs73
1 files changed, 73 insertions, 0 deletions
diff --git a/LibMatrix/Utilities/CommonSyncFilters.cs b/LibMatrix/Utilities/CommonSyncFilters.cs
new file mode 100644
index 0000000..7cf1b41
--- /dev/null
+++ b/LibMatrix/Utilities/CommonSyncFilters.cs
@@ -0,0 +1,73 @@
+using System.Collections.Frozen;
+using LibMatrix.EventTypes.Spec.State;
+using LibMatrix.Filters;
+
+namespace LibMatrix.Utilities;
+
+public static class CommonSyncFilters {
+    public const string GetAccountData = "gay.rory.libmatrix.get_account_data.v0";
+    public const string GetAccountDataWithRooms = "gay.rory.libmatrix.get_account_data_with_rooms.v0";
+    public const string GetBasicRoomInfo = "gay.rory.matrixutils.get_basic_room_info.v0";
+    public const string GetSpaceRelations = "gay.rory.matrixutils.get_space_relations.v0";
+
+    public static readonly SyncFilter GetAccountDataFilter = new() {
+        Presence = new SyncFilter.EventFilter(notTypes: ["*"]),
+        Room = new SyncFilter.RoomFilter() {
+            Rooms = []
+        }
+    };
+
+    public static readonly 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 readonly 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 {
+                Types = new List<string> {
+                    "m.room.create",
+                    "m.room.name",
+                    "m.room.avatar",
+                    "org.matrix.mjolnir.shortcode",
+                    "m.room.power_levels",
+                },
+                LazyLoadMembers = true, IncludeRedundantMembers = false
+            },
+            Timeline = new SyncFilter.RoomFilter.StateFilter(rooms: []),
+        }
+    };
+    
+    public static readonly 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 {
+                Types = new List<string> {
+                    "m.space.child",
+                    "m.space.parent"
+                },
+                LazyLoadMembers = true, IncludeRedundantMembers = false
+            },
+            Timeline = new SyncFilter.RoomFilter.StateFilter(rooms: []),
+        }
+    };
+
+    // This must be down here, due to statics load order
+    public static readonly FrozenDictionary<string, SyncFilter> FilterMap = new Dictionary<string, SyncFilter>() {
+        [GetAccountData] = GetAccountDataFilter,
+        [GetAccountDataWithRooms] = GetAccountDataWithRoomsFilter,
+        [GetBasicRoomInfo] = GetBasicRoomDataFilter,
+        [GetSpaceRelations] = GetSpaceRelationsFilter
+    }.ToFrozenDictionary();
+}
\ No newline at end of file