about summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
m---------ArcaneLibs0
-rw-r--r--CONTRIBUTING.MD2
-rw-r--r--Docs/TWIM-TEMPLATE.MD15
-rw-r--r--LibMatrix.Federation/deps.json5
-rw-r--r--LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs5
-rw-r--r--LibMatrix/Homeservers/FederationClient.cs5
-rw-r--r--LibMatrix/Homeservers/RemoteHomeServer.cs80
-rw-r--r--LibMatrix/deps.json5
-rw-r--r--Utilities/LibMatrix.Utilities.Bot/deps.json5
-rw-r--r--flake.lock12
-rw-r--r--flake.nix18
11 files changed, 107 insertions, 45 deletions
diff --git a/ArcaneLibs b/ArcaneLibs
-Subproject 491a3c65481c4e5a41b4435106e3dc8ba81efdc
+Subproject 270012a7527345a914003c98bf97c7b221812cc
diff --git a/CONTRIBUTING.MD b/CONTRIBUTING.MD

index 50c5a4d..c660c6c 100644 --- a/CONTRIBUTING.MD +++ b/CONTRIBUTING.MD
@@ -4,7 +4,7 @@ Any contribution is welcome, even if it's just documentation or recommended git - Use spaces, not tabs - Use 4 spaces for indentation - Use the C# naming convention for variables, methods, etc. -- Wrap lines at 160 characters, though this value can be changed if it's too lean or strict +- Wrap lines at 180 characters, though this value can be changed if it's too lean or strict - Use the `#region` and `#endregion` directives to group code if you're adding utility functions ```sh diff --git a/Docs/TWIM-TEMPLATE.MD b/Docs/TWIM-TEMPLATE.MD new file mode 100644
index 0000000..7ab633a --- /dev/null +++ b/Docs/TWIM-TEMPLATE.MD
@@ -0,0 +1,15 @@ +[TWIM](https://matrix.to/#/%40this-week-in%3Amatrix.org) +### Rory&::LibMatrix ([website](https://cgit.rory.gay/matrix/LibMatrix.git/)) + +*<u>Your</u> friendly .NET 10 Matrix SDK* + +[Funny intro line] + +#### What's new: +- [changelog] + +#### *And, as always:* +- The code is available at [cgit.rory.gay](https://cgit.rory.gay/matrix/LibMatrix.git) or [GitHub](https://github.com/Rory-LibMatrix/LibMatrix)! + - All contributions are more than welcome, be it documentation, code, anything! Perhaps, example usecases, bots, ...? +- Discussion, suggestions and ideas are welcome in [#libmatrix:rory.gay](https://matrix.to/#/#libmatrix:rory.gay) (Space: [#libmatrix-space:rory.gay](https://matrix.to/#/#libmatrix-space:rory.gay)) +- Got a cool project that you're working on and want to share, using LibMatrix? Be sure to let us know, we'd love to hear all about it! \ No newline at end of file diff --git a/LibMatrix.Federation/deps.json b/LibMatrix.Federation/deps.json
index edecdc2..6c90cd1 100644 --- a/LibMatrix.Federation/deps.json +++ b/LibMatrix.Federation/deps.json
@@ -1,10 +1,5 @@ [ { - "pname": "ArcaneLibs", - "version": "1.0.0-preview.20251205-114150", - "hash": "sha256-OFH86NaYdaHhNjvwMzamKO6xz1HuXZAO0pVon8FFnzA=" - }, - { "pname": "BouncyCastle.Cryptography", "version": "2.6.2", "hash": "sha256-Yjk2+x/RcVeccGOQOQcRKCiYzyx1mlFnhS5auCII+Ms=" diff --git a/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs b/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs
index 916780e..b453d87 100644 --- a/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs +++ b/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs
@@ -669,5 +669,10 @@ public class AuthenticatedHomeserverGeneric : RemoteHomeserver { public required List<string> Aliases { get; set; } } + public async Task<HttpResponseMessage> SetRoomDirectoryVisibilityAsync(string roomId, RoomDirectoryVisibilityResponse.VisibilityValue visibility) + => await ClientHttpClient.PostAsJsonAsync($"/_matrix/client/v3/directory/list/room/{HttpUtility.UrlEncode(roomId)}", new RoomDirectoryVisibilityResponse { + Visibility = visibility + }); + #endregion } \ No newline at end of file diff --git a/LibMatrix/Homeservers/FederationClient.cs b/LibMatrix/Homeservers/FederationClient.cs
index 9760e20..310fa93 100644 --- a/LibMatrix/Homeservers/FederationClient.cs +++ b/LibMatrix/Homeservers/FederationClient.cs
@@ -10,7 +10,6 @@ public class FederationClient { BaseAddress = new Uri(proxy?.TrimEnd('/') ?? federationEndpoint.TrimEnd('/')), // Timeout = TimeSpan.FromSeconds(120) // TODO: Re-implement this }; - if (proxy is not null) HttpClient.DefaultRequestHeaders.Add("MXAE_UPSTREAM", federationEndpoint); } public MatrixHttpClient HttpClient { get; set; } @@ -18,6 +17,4 @@ public class FederationClient { public async Task<ServerVersionResponse> GetServerVersionAsync() => await HttpClient.GetFromJsonAsync<ServerVersionResponse>("/_matrix/federation/v1/version"); public async Task<SignedObject<ServerKeysResponse>> GetServerKeysAsync() => await HttpClient.GetFromJsonAsync<SignedObject<ServerKeysResponse>>("/_matrix/key/v2/server"); -} - - +} \ No newline at end of file diff --git a/LibMatrix/Homeservers/RemoteHomeServer.cs b/LibMatrix/Homeservers/RemoteHomeServer.cs
index af84be2..54f5937 100644 --- a/LibMatrix/Homeservers/RemoteHomeServer.cs +++ b/LibMatrix/Homeservers/RemoteHomeServer.cs
@@ -23,7 +23,6 @@ public class RemoteHomeserver { // Timeout = TimeSpan.FromSeconds(300) // TODO: Re-implement this }; - if (proxy is not null) ClientHttpClient.DefaultRequestHeaders.Add("MXAE_UPSTREAM", serverName); if (!string.IsNullOrWhiteSpace(wellKnownUris.Server)) FederationClient = new FederationClient(WellKnownUris.Server!, proxy); Auth = new(this); @@ -61,29 +60,54 @@ public class RemoteHomeserver { return data ?? throw new InvalidOperationException($"Could not resolve alias {alias}"); } - public Task<PublicRoomDirectoryResult> GetPublicRoomsAsync(int limit = 100, string? server = null, string? since = null) { - var url = $"/_matrix/client/v3/publicRooms?limit={limit}"; - if (!string.IsNullOrWhiteSpace(server)) { - url += $"&server={server}"; + public async Task<PublicRoomDirectoryResult> GetPublicRoomsAsync(int limit = 100, string? server = null, string? since = null, string? thirdPartyInstanceId = null, + bool? includeAllNetworks = null, RoomDirectoryFilter? filter = null) { + if (thirdPartyInstanceId is null && includeAllNetworks is null && filter is null) { + var url = $"/_matrix/client/v3/publicRooms?limit={limit}"; + if (!string.IsNullOrWhiteSpace(server)) { + url += $"&server={server}"; + } + + if (!string.IsNullOrWhiteSpace(since)) { + url += $"&since={since}"; + } + + return await ClientHttpClient.GetFromJsonAsync<PublicRoomDirectoryResult>(url); } - if (!string.IsNullOrWhiteSpace(since)) { - url += $"&since={since}"; + // this technically requires authentication... TODO: move to AuthenticatedHomeserver? + var postUrl = "/_matrix/client/v3/publicRooms"; + if (!string.IsNullOrWhiteSpace(server)) { + postUrl += $"?server={HttpUtility.UrlEncode(server)}"; } - return ClientHttpClient.GetFromJsonAsync<PublicRoomDirectoryResult>(url); + var postData = new RoomDirectoryFilteredRequest { + Limit = limit, + Since = since, + ThirdPartyInstanceId = thirdPartyInstanceId, + IncludeAllNetworks = includeAllNetworks, + Filter = filter + }; + + return await (await ClientHttpClient.PostAsJsonAsync(postUrl, postData)).EnsureSuccessStatusCode() + .Content.ReadFromJsonAsync<PublicRoomDirectoryResult>() ?? throw new InvalidOperationException(); } - public async IAsyncEnumerable<PublicRoomDirectoryResult> EnumeratePublicRoomsAsync(int limit = int.MaxValue, string? server = null, string? since = null, int chunkSize = 100) { + public async IAsyncEnumerable<PublicRoomDirectoryResult> EnumeratePublicRoomsAsync(int limit = int.MaxValue, string? server = null, string? since = null, + string? thirdPartyInstanceId = null, bool? includeAllNetworks = null, RoomDirectoryFilter? filter = null, int chunkSize = 100) { PublicRoomDirectoryResult res; do { - res = await GetPublicRoomsAsync(chunkSize, server, since); + res = await GetPublicRoomsAsync(chunkSize, server, since, thirdPartyInstanceId, includeAllNetworks, filter); yield return res; if (res.NextBatch is null || res.NextBatch == since || res.Chunk.Count == 0) break; since = res.NextBatch; } while (limit > 0 && limit-- > 0); } + public async Task<RoomDirectoryVisibilityResponse> GetRoomDirectoryVisibilityAsync(string roomId) + => await (await ClientHttpClient.GetAsync($"/_matrix/client/v3/directory/list/room/{HttpUtility.UrlEncode(roomId)}")).Content + .ReadFromJsonAsync<RoomDirectoryVisibilityResponse>() ?? throw new InvalidOperationException(); + #region Authentication public async Task<LoginResponse> LoginAsync(string username, string password, string? deviceName = null) { @@ -121,6 +145,42 @@ public class RemoteHomeserver { public UserInteractiveAuthClient Auth; } +public class RoomDirectoryFilteredRequest { + [JsonPropertyName("filter")] + public RoomDirectoryFilter? Filter { get; set; } + + [JsonPropertyName("include_all_networks")] + public bool? IncludeAllNetworks { get; set; } + + [JsonPropertyName("limit")] + public int Limit { get; set; } + + [JsonPropertyName("since")] + public string? Since { get; set; } + + [JsonPropertyName("third_party_instance_id")] + public string? ThirdPartyInstanceId { get; set; } +} + +public class RoomDirectoryFilter { + [JsonPropertyName("generic_search_term")] + public string? GenericSearchTerm { get; set; } + + [JsonPropertyName("room_types")] + public List<string?>? RoomTypes { get; set; } +} + +public class RoomDirectoryVisibilityResponse { + [JsonPropertyName("visibility")] + public VisibilityValue Visibility { get; set; } + + [JsonConverter(typeof(JsonStringEnumConverter))] + public enum VisibilityValue { + [JsonStringEnumMemberName("public")] Public, + [JsonStringEnumMemberName("private")] Private + } +} + public class PublicRoomDirectoryResult { [JsonPropertyName("chunk")] public List<PublicRoomListItem> Chunk { get; set; } diff --git a/LibMatrix/deps.json b/LibMatrix/deps.json
index 0fbc71d..ce0dfbf 100644 --- a/LibMatrix/deps.json +++ b/LibMatrix/deps.json
@@ -1,10 +1,5 @@ [ { - "pname": "ArcaneLibs", - "version": "1.0.0-preview.20251205-114150", - "hash": "sha256-OFH86NaYdaHhNjvwMzamKO6xz1HuXZAO0pVon8FFnzA=" - }, - { "pname": "Microsoft.Extensions.DependencyInjection.Abstractions", "version": "10.0.0", "hash": "sha256-9iodXP39YqgxomnOPOxd/mzbG0JfOSXzFoNU3omT2Ps=" diff --git a/Utilities/LibMatrix.Utilities.Bot/deps.json b/Utilities/LibMatrix.Utilities.Bot/deps.json
index 4d5a0c8..566f6a9 100644 --- a/Utilities/LibMatrix.Utilities.Bot/deps.json +++ b/Utilities/LibMatrix.Utilities.Bot/deps.json
@@ -1,10 +1,5 @@ [ { - "pname": "ArcaneLibs", - "version": "1.0.0-preview.20251205-114150", - "hash": "sha256-OFH86NaYdaHhNjvwMzamKO6xz1HuXZAO0pVon8FFnzA=" - }, - { "pname": "Microsoft.Extensions.Configuration", "version": "10.0.0", "hash": "sha256-MsLskVPpkCvov5+DWIaALCt1qfRRX4u228eHxvpE0dg=" diff --git a/flake.lock b/flake.lock
index 917a7a3..d70f9b9 100644 --- a/flake.lock +++ b/flake.lock
@@ -8,11 +8,11 @@ ] }, "locked": { - "lastModified": 1764934856, - "narHash": "sha256-ypuVuTHImU2JkzgkFmV4Z4AVNoz4yQAPkCbP5opo464=", + "lastModified": 1765126047, + "narHash": "sha256-c+IuteUQJI9Apm4z64XjEXZZyJS62THHmmceftYb6xk=", "owner": "TheArcaneBrony", "repo": "ArcaneLibs", - "rev": "491a3c65481c4e5a41b4435106e3dc8ba81efdc3", + "rev": "270012a7527345a914003c98bf97c7b221812cc1", "type": "github" }, "original": { @@ -59,11 +59,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1764667669, - "narHash": "sha256-7WUCZfmqLAssbDqwg9cUDAXrSoXN79eEEq17qhTNM/Y=", + "lastModified": 1764950072, + "narHash": "sha256-BmPWzogsG2GsXZtlT+MTcAWeDK5hkbGRZTeZNW42fwA=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "418468ac9527e799809c900eda37cbff999199b6", + "rev": "f61125a668a320878494449750330ca58b78c557", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix
index 45a0b4b..03becfa 100644 --- a/flake.nix +++ b/flake.nix
@@ -19,7 +19,7 @@ date = builtins.substring 0 8 self.sourceInfo.lastModifiedDate; time = builtins.substring 8 6 self.sourceInfo.lastModifiedDate; in - "preview.${date}-${time}+${rev}"; + "preview.${date}-${time}"; # +${rev}"; makeNupkg = { @@ -56,14 +56,14 @@ let # HACKHACK: trim version string until nuget learns to deal with semver properly # See: https://github.com/NuGet/Home/issues/14628 - ArcaneLibs = arcanelibs.packages."${pkgs.stdenv.hostPlatform.system}".ArcaneLibs.overrideAttrs (old: { - __intentionallyOverridingVersion = true; - version = builtins.substring 0 29 old.version; # "1.0.0-preview-20251106-123456"; - }); - LibMatrix = self.packages."${pkgs.stdenv.hostPlatform.system}".LibMatrix.overrideAttrs (old: { - __intentionallyOverridingVersion = true; - version = builtins.substring 0 29 old.version; # "1.0.0-preview-20251106-123456"; - }); + ArcaneLibs = arcanelibs.packages."${pkgs.stdenv.hostPlatform.system}".ArcaneLibs; #.overrideAttrs (old: { + # __intentionallyOverridingVersion = true; + # version = builtins.substring 0 29 old.version; # "1.0.0-preview-20251106-123456"; + #}); + LibMatrix = self.packages."${pkgs.stdenv.hostPlatform.system}".LibMatrix; #.overrideAttrs (old: { + # __intentionallyOverridingVersion = true; + # version = builtins.substring 0 29 old.version; # "1.0.0-preview-20251106-123456"; + # }); in { LibMatrix = makeNupkg {