about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs4
-rw-r--r--LibMatrix/RoomTypes/GenericRoom.cs2
2 files changed, 5 insertions, 1 deletions
diff --git a/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs b/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs
index 89e2fdb..5bfd77b 100644
--- a/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs
+++ b/LibMatrix.EventTypes/Spec/State/Policy/PolicyRuleStateEventContent.cs
@@ -1,5 +1,7 @@
+using System.Security.Cryptography;
 using System.Text.Json.Serialization;
 using ArcaneLibs.Attributes;
+using ArcaneLibs.Extensions;
 
 namespace LibMatrix.EventTypes.Spec.State.Policy;
 
@@ -87,6 +89,8 @@ public abstract class PolicyRuleEventContent : EventContent {
                 Expiry = ((DateTimeOffset)value).ToUnixTimeMilliseconds();
         }
     }
+
+    public string GetDraupnir2StateKey() => Convert.ToBase64String(SHA256.HashData($"{Entity}{Recommendation}".AsBytes().ToArray()));
 }
 
 public static class PolicyRecommendationTypes {
diff --git a/LibMatrix/RoomTypes/GenericRoom.cs b/LibMatrix/RoomTypes/GenericRoom.cs
index a1ef617..b9d98bd 100644
--- a/LibMatrix/RoomTypes/GenericRoom.cs
+++ b/LibMatrix/RoomTypes/GenericRoom.cs
@@ -393,7 +393,7 @@ public class GenericRoom {
             .Content.ReadFromJsonAsync<EventIdResponse>();
 
     public async Task<EventIdResponse?> SendStateEventAsync(string eventType, string stateKey, object content) =>
-        await (await Homeserver.ClientHttpClient.PutAsJsonAsync($"/_matrix/client/v3/rooms/{RoomId}/state/{eventType}/{stateKey}", content))
+        await (await Homeserver.ClientHttpClient.PutAsJsonAsync($"/_matrix/client/v3/rooms/{RoomId}/state/{eventType.UrlEncode()}/{stateKey.UrlEncode()}", content))
             .Content.ReadFromJsonAsync<EventIdResponse>();
 
     public async Task<EventIdResponse> SendTimelineEventAsync(string eventType, TimelineEventContent content) {