diff --git a/MatrixRoomUtils.Core/AuthenticatedHomeServer.cs b/MatrixRoomUtils.Core/AuthenticatedHomeServer.cs
index ee6be72..7e5650f 100644
--- a/MatrixRoomUtils.Core/AuthenticatedHomeServer.cs
+++ b/MatrixRoomUtils.Core/AuthenticatedHomeServer.cs
@@ -3,6 +3,7 @@ using System.Net.Http.Json;
using System.Text.Json;
using System.Text.Json.Nodes;
using MatrixRoomUtils.Core.Extensions;
+using MatrixRoomUtils.Core.Filters;
using MatrixRoomUtils.Core.Interfaces;
using MatrixRoomUtils.Core.Responses;
using MatrixRoomUtils.Core.Responses.Admin;
@@ -73,7 +74,7 @@ public class AuthenticatedHomeServer : IHomeServer {
public HomeserverAdminApi(AuthenticatedHomeServer authenticatedHomeServer) => _authenticatedHomeServer = authenticatedHomeServer;
- public async IAsyncEnumerable<AdminRoomListingResult.AdminRoomListingResultRoom> SearchRoomsAsync(int limit = int.MaxValue, string orderBy = "name", string dir = "f", string? searchTerm = null, string? contentSearch = null) {
+ public async IAsyncEnumerable<AdminRoomListingResult.AdminRoomListingResultRoom> SearchRoomsAsync(int limit = int.MaxValue, string orderBy = "name", string dir = "f", string? searchTerm = null, LocalRoomQueryFilter? localFilter = null) {
AdminRoomListingResult? res = null;
var i = 0;
int? totalRooms = null;
@@ -89,16 +90,72 @@ public class AuthenticatedHomeServer : IHomeServer {
totalRooms ??= res?.TotalRooms;
Console.WriteLine(res.ToJson(false));
foreach (var room in res.Rooms) {
- if (contentSearch != null && !string.IsNullOrEmpty(contentSearch) &&
- !(
- room.Name?.Contains(contentSearch, StringComparison.InvariantCultureIgnoreCase) == true ||
- room.CanonicalAlias?.Contains(contentSearch, StringComparison.InvariantCultureIgnoreCase) == true ||
- room.Creator?.Contains(contentSearch, StringComparison.InvariantCultureIgnoreCase) == true
- )
- ) {
- totalRooms--;
- continue;
+ if (localFilter != null) {
+ if (!room.RoomId.Contains(localFilter.RoomIdContains)) {
+ totalRooms--;
+ continue;
+ }
+ if (!room.Name?.Contains(localFilter.NameContains) == true) {
+ totalRooms--;
+ continue;
+ }
+ if (!room.CanonicalAlias?.Contains(localFilter.CanonicalAliasContains) == true) {
+ totalRooms--;
+ continue;
+ }
+ if (!room.Version.Contains(localFilter.VersionContains)) {
+ totalRooms--;
+ continue;
+ }
+ if (!room.Creator.Contains(localFilter.CreatorContains)) {
+ totalRooms--;
+ continue;
+ }
+ if (!room.Encryption?.Contains(localFilter.EncryptionContains) == true) {
+ totalRooms--;
+ continue;
+ }
+ if (!room.JoinRules?.Contains(localFilter.JoinRulesContains) == true) {
+ totalRooms--;
+ continue;
+ }
+ if(!room.GuestAccess?.Contains(localFilter.GuestAccessContains) == true) {
+ totalRooms--;
+ continue;
+ }
+ if(!room.HistoryVisibility?.Contains(localFilter.HistoryVisibilityContains) == true) {
+ totalRooms--;
+ continue;
+ }
+
+ if(localFilter.CheckFederation && room.Federatable != localFilter.Federatable) {
+ totalRooms--;
+ continue;
+ }
+ if(localFilter.CheckPublic && room.Public != localFilter.Public) {
+ totalRooms--;
+ continue;
+ }
+
+ if(room.JoinedMembers < localFilter.JoinedMembersGreaterThan || room.JoinedMembers > localFilter.JoinedMembersLessThan) {
+ totalRooms--;
+ continue;
+ }
+ if(room.JoinedLocalMembers < localFilter.JoinedLocalMembersGreaterThan || room.JoinedLocalMembers > localFilter.JoinedLocalMembersLessThan) {
+ totalRooms--;
+ continue;
+ }
}
+ // if (contentSearch != null && !string.IsNullOrEmpty(contentSearch) &&
+ // !(
+ // room.Name?.Contains(contentSearch, StringComparison.InvariantCultureIgnoreCase) == true ||
+ // room.CanonicalAlias?.Contains(contentSearch, StringComparison.InvariantCultureIgnoreCase) == true ||
+ // room.Creator?.Contains(contentSearch, StringComparison.InvariantCultureIgnoreCase) == true
+ // )
+ // ) {
+ // totalRooms--;
+ // continue;
+ // }
i++;
yield return room;
diff --git a/MatrixRoomUtils.Core/Filters/LocalRoomQueryFilter.cs b/MatrixRoomUtils.Core/Filters/LocalRoomQueryFilter.cs
new file mode 100644
index 0000000..65c7baa
--- /dev/null
+++ b/MatrixRoomUtils.Core/Filters/LocalRoomQueryFilter.cs
@@ -0,0 +1,28 @@
+namespace MatrixRoomUtils.Core.Filters;
+
+public class LocalRoomQueryFilter {
+ public string RoomIdContains { get; set; } = "";
+ public string NameContains { get; set; } = "";
+ public string CanonicalAliasContains { get; set; } = "";
+ public string VersionContains { get; set; } = "";
+ public string CreatorContains { get; set; } = "";
+ public string EncryptionContains { get; set; } = "";
+ public string JoinRulesContains { get; set; } = "";
+ public string GuestAccessContains { get; set; } = "";
+ public string HistoryVisibilityContains { get; set; } = "";
+
+ public bool Federatable { get; set; } = true;
+ public bool Public { get; set; } = true;
+
+ public int JoinedMembersGreaterThan { get; set; } = 0;
+ public int JoinedMembersLessThan { get; set; } = int.MaxValue;
+
+ public int JoinedLocalMembersGreaterThan { get; set; } = 0;
+ public int JoinedLocalMembersLessThan { get; set; } = int.MaxValue;
+ public int StateEventsGreaterThan { get; set; } = 0;
+ public int StateEventsLessThan { get; set; } = int.MaxValue;
+
+
+ public bool CheckFederation { get; set; }
+ public bool CheckPublic { get; set; }
+}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Core/Interfaces/IHomeServer.cs b/MatrixRoomUtils.Core/Interfaces/IHomeServer.cs
index 9a9ba7a..a808c3d 100644
--- a/MatrixRoomUtils.Core/Interfaces/IHomeServer.cs
+++ b/MatrixRoomUtils.Core/Interfaces/IHomeServer.cs
@@ -21,7 +21,7 @@ public class IHomeServer {
private async Task<string> _resolveHomeserverFromWellKnown(string homeserver) {
if (RuntimeCache.HomeserverResolutionCache.Count == 0) {
- Console.WriteLine("No cached homeservers, resolving...");
+ // Console.WriteLine("No cached homeservers, resolving...");
await Task.Delay(Random.Shared.Next(1000, 5000));
}
diff --git a/MatrixRoomUtils.Core/Interfaces/IStorageProvider.cs b/MatrixRoomUtils.Core/Interfaces/IStorageProvider.cs
new file mode 100644
index 0000000..e1a066e
--- /dev/null
+++ b/MatrixRoomUtils.Core/Interfaces/IStorageProvider.cs
@@ -0,0 +1,15 @@
+public interface IStorageProvider {
+ // save
+ public async Task SaveAll() {
+ Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement Save()!");
+ }
+
+ public async Task SaveObject<T>(string key, T value) {
+ Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement SaveObject<T>(key, value)!");
+ }
+
+ // delete
+ public async Task DeleteObject(string key) {
+ Console.WriteLine($"StorageProvider<{GetType().Name}> does not implement DeleteObject(key)!");
+ }
+}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Core/Responses/Admin/AdminRoomDeleteRequest.cs b/MatrixRoomUtils.Core/Responses/Admin/AdminRoomDeleteRequest.cs
new file mode 100644
index 0000000..5605329
--- /dev/null
+++ b/MatrixRoomUtils.Core/Responses/Admin/AdminRoomDeleteRequest.cs
@@ -0,0 +1,18 @@
+using System.Text.Json.Serialization;
+
+namespace MatrixRoomUtils.Core.Responses.Admin;
+
+public class AdminRoomDeleteRequest {
+ [JsonPropertyName("new_room_user_id")]
+ public string? NewRoomUserId { get; set; }
+ [JsonPropertyName("room_name")]
+ public string? RoomName { get; set; }
+ [JsonPropertyName("block")]
+ public bool Block { get; set; }
+ [JsonPropertyName("purge")]
+ public bool Purge { get; set; }
+ [JsonPropertyName("message")]
+ public string? Message { get; set; }
+ [JsonPropertyName("force_purge")]
+ public bool ForcePurge { get; set; }
+}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Core/Responses/Admin/AdminRoomListingResult.cs b/MatrixRoomUtils.Core/Responses/Admin/AdminRoomListingResult.cs
index 37bb3ba..d6da859 100644
--- a/MatrixRoomUtils.Core/Responses/Admin/AdminRoomListingResult.cs
+++ b/MatrixRoomUtils.Core/Responses/Admin/AdminRoomListingResult.cs
@@ -23,10 +23,10 @@ public class AdminRoomListingResult {
public string RoomId { get; set; }
[JsonPropertyName("name")]
- public string Name { get; set; }
+ public string? Name { get; set; }
[JsonPropertyName("canonical_alias")]
- public string CanonicalAlias { get; set; }
+ public string? CanonicalAlias { get; set; }
[JsonPropertyName("joined_members")]
public int JoinedMembers { get; set; }
@@ -41,7 +41,7 @@ public class AdminRoomListingResult {
public string Creator { get; set; }
[JsonPropertyName("encryption")]
- public string Encryption { get; set; }
+ public string? Encryption { get; set; }
[JsonPropertyName("federatable")]
public bool Federatable { get; set; }
@@ -50,13 +50,13 @@ public class AdminRoomListingResult {
public bool Public { get; set; }
[JsonPropertyName("join_rules")]
- public string JoinRules { get; set; }
+ public string? JoinRules { get; set; }
[JsonPropertyName("guest_access")]
- public string GuestAccess { get; set; }
+ public string? GuestAccess { get; set; }
[JsonPropertyName("history_visibility")]
- public string HistoryVisibility { get; set; }
+ public string? HistoryVisibility { get; set; }
[JsonPropertyName("state_events")]
public int StateEvents { get; set; }
diff --git a/MatrixRoomUtils.Core/RuntimeCache.cs b/MatrixRoomUtils.Core/RuntimeCache.cs
index a2fcf40..db71ee5 100644
--- a/MatrixRoomUtils.Core/RuntimeCache.cs
+++ b/MatrixRoomUtils.Core/RuntimeCache.cs
@@ -27,7 +27,7 @@ public class RuntimeCache {
public static Dictionary<string, ObjectCache<object>> GenericResponseCache { get; set; } = new();
- public static Action Save { get; set; } = () => { Console.WriteLine("RuntimeCache.Save() was called, but no callback was set!"); };
+ public static Task Save { get; set; } = new Task(() => { Console.WriteLine("RuntimeCache.Save() was called, but no callback was set!"); });
public static Action<string, object> SaveObject { get; set; } = (key, value) => { Console.WriteLine($"RuntimeCache.SaveObject({key}, {value}) was called, but no callback was set!"); };
public static Action<string> RemoveObject { get; set; } = key => { Console.WriteLine($"RuntimeCache.RemoveObject({key}) was called, but no callback was set!"); };
}
|