From 0e43e947ca8be0e529f2505a66143cb8b1fcbb8e Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Wed, 12 Jul 2023 00:18:56 +0200 Subject: Changes --- .../Responses/CreateRoomRequest.cs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'MatrixRoomUtils.Core/Responses') diff --git a/MatrixRoomUtils.Core/Responses/CreateRoomRequest.cs b/MatrixRoomUtils.Core/Responses/CreateRoomRequest.cs index 334c05c..be78a97 100644 --- a/MatrixRoomUtils.Core/Responses/CreateRoomRequest.cs +++ b/MatrixRoomUtils.Core/Responses/CreateRoomRequest.cs @@ -1,6 +1,8 @@ +using System.Reflection; using System.Text.Json.Nodes; using System.Text.Json.Serialization; using System.Text.RegularExpressions; +using MatrixRoomUtils.Core.Extensions; using MatrixRoomUtils.Core.Interfaces; using MatrixRoomUtils.Core.StateEventTypes; using MatrixRoomUtils.Core.StateEventTypes.Spec; @@ -21,7 +23,7 @@ public class CreateRoomRequest { //we dont want to use this, we want more control // [JsonPropertyName("preset")] // public string Preset { get; set; } = null!; - + [JsonPropertyName("initial_state")] public List InitialState { get; set; } = null!; @@ -39,7 +41,21 @@ public class CreateRoomRequest { /// public StateEvent this[string event_type, string event_key = ""] { - get => InitialState.First(x => x.Type == event_type && x.StateKey == event_key); + get { + var stateEvent = InitialState.FirstOrDefault(x => x.Type == event_type && x.StateKey == event_key); + if (stateEvent == null) { + InitialState.Add(stateEvent = new StateEvent { + Type = event_type, + StateKey = event_key, + TypedContent = Activator.CreateInstance( + StateEvent.KnownStateEventTypes.FirstOrDefault(x => + x.GetCustomAttributes()? + .Any(y => y.EventName == event_type) ?? false) ?? typeof(object) + ) + }); + } + return stateEvent; + } set { var stateEvent = InitialState.FirstOrDefault(x => x.Type == event_type && x.StateKey == event_key); if (stateEvent == null) @@ -57,4 +73,4 @@ public class CreateRoomRequest { return errors; } -} \ No newline at end of file +} -- cgit 1.5.1