diff options
author | Rory& <root@rory.gay> | 2024-09-08 23:53:27 +0200 |
---|---|---|
committer | Rory& <root@rory.gay> | 2024-09-08 23:53:27 +0200 |
commit | 5b394ea44ea0bf3f1c5bd4d5a0a13d8be2018582 (patch) | |
tree | 39ab019b65ec9f17037290c1bfd53377de50bef9 | |
parent | Clean up dev stuff a little bit (diff) | |
download | LibMatrix-5b394ea44ea0bf3f1c5bd4d5a0a13d8be2018582.tar.xz |
meow
-rw-r--r-- | LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs | 19 | ||||
-rw-r--r-- | LibMatrix/Homeservers/RemoteHomeServer.cs | 2 | ||||
-rw-r--r-- | LibMatrix/Responses/UserProfileResponse.cs | 15 |
3 files changed, 34 insertions, 2 deletions
diff --git a/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs b/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs index c729a44..f2b3292 100644 --- a/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs +++ b/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs @@ -48,7 +48,6 @@ public class AuthenticatedHomeserverGeneric : RemoteHomeserver { public HsNamedCaches NamedCaches { get; set; } = null!; public GenericRoom GetRoom(string roomId) { - if (roomId is null || !roomId.StartsWith("!")) throw new ArgumentException("Room ID must start with !", nameof(roomId)); return new GenericRoom(this, roomId); } @@ -186,6 +185,17 @@ public class AuthenticatedHomeserverGeneric : RemoteHomeserver { #endregion +#region MSC 4133 + + public async Task UpdateProfilePropertyAsync(string name, object? value) { + var caps = await GetCapabilitiesAsync(); + if(caps is null) throw new Exception("Failed to get capabilities"); + + } + +#endregion + + [Obsolete("This method assumes no support for MSC 4069 and MSC 4133")] public async Task UpdateProfileAsync(UserProfileResponse? newProfile, bool preserveCustomRoomProfile = true) { if (newProfile is null) return; Console.WriteLine($"Updating profile for {WhoAmI.UserId} to {newProfile.ToJson(ignoreNull: true)} (preserving room profiles: {preserveCustomRoomProfile})"); @@ -393,7 +403,7 @@ public class AuthenticatedHomeserverGeneric : RemoteHomeserver { Console.WriteLine($"Failed to get capabilities: {await res.Content.ReadAsStringAsync()}"); throw new InvalidDataException($"Failed to get capabilities: {await res.Content.ReadAsStringAsync()}"); } - + return await res.Content.ReadFromJsonAsync<JsonObject>(); } @@ -406,4 +416,9 @@ public class AuthenticatedHomeserverGeneric : RemoteHomeserver { public NamedFilterCache FilterCache { get; init; } public NamedFileCache FileCache { get; init; } } + + private class CapabilitiesResponse { + [JsonPropertyName("capabilities")] + public Dictionary<string, object>? Capabilities { get; set; } + } } \ No newline at end of file diff --git a/LibMatrix/Homeservers/RemoteHomeServer.cs b/LibMatrix/Homeservers/RemoteHomeServer.cs index ecf3e3a..95dac92 100644 --- a/LibMatrix/Homeservers/RemoteHomeServer.cs +++ b/LibMatrix/Homeservers/RemoteHomeServer.cs @@ -55,6 +55,8 @@ public class RemoteHomeserver { return data; } + + // TODO: Do we need to support retrieving individual profile properties? Is there any use for that besides just getting the full profile? public async Task<ClientVersionsResponse> GetClientVersionsAsync() { var resp = await ClientHttpClient.GetAsync($"/_matrix/client/versions"); diff --git a/LibMatrix/Responses/UserProfileResponse.cs b/LibMatrix/Responses/UserProfileResponse.cs index 6c9380f..30e4c32 100644 --- a/LibMatrix/Responses/UserProfileResponse.cs +++ b/LibMatrix/Responses/UserProfileResponse.cs @@ -1,3 +1,4 @@ +using System.Text.Json; using System.Text.Json.Serialization; namespace LibMatrix.Responses; @@ -8,4 +9,18 @@ public class UserProfileResponse { [JsonPropertyName("displayname")] public string? DisplayName { get; set; } + + // MSC 4133 - Extending User Profile API with Key:Value pairs + [JsonExtensionData] + public Dictionary<string, JsonElement>? CustomKeys { get; set; } + + public JsonElement? this[string key] { + get => CustomKeys?[key]; + set { + if (value is null) + CustomKeys?.Remove(key); + else + (CustomKeys ??= [])[key] = value.Value; + } + } } \ No newline at end of file |