about summary refs log tree commit diff
path: root/LibMatrix/Responses
diff options
context:
space:
mode:
Diffstat (limited to 'LibMatrix/Responses')
-rw-r--r--LibMatrix/Responses/Admin/AdminRoomDeleteRequest.cs18
-rw-r--r--LibMatrix/Responses/Admin/AdminRoomListingResult.cs64
-rw-r--r--LibMatrix/Responses/CreateRoomRequest.cs74
-rw-r--r--LibMatrix/Responses/CreationContentBaseType.cs18
-rw-r--r--LibMatrix/Responses/LoginResponse.cs17
-rw-r--r--LibMatrix/Responses/StateEventResponse.cs47
6 files changed, 238 insertions, 0 deletions
diff --git a/LibMatrix/Responses/Admin/AdminRoomDeleteRequest.cs b/LibMatrix/Responses/Admin/AdminRoomDeleteRequest.cs
new file mode 100644
index 0000000..f22c8d2
--- /dev/null
+++ b/LibMatrix/Responses/Admin/AdminRoomDeleteRequest.cs
@@ -0,0 +1,18 @@
+using System.Text.Json.Serialization;
+
+namespace LibMatrix.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; }
+}
diff --git a/LibMatrix/Responses/Admin/AdminRoomListingResult.cs b/LibMatrix/Responses/Admin/AdminRoomListingResult.cs
new file mode 100644
index 0000000..f035184
--- /dev/null
+++ b/LibMatrix/Responses/Admin/AdminRoomListingResult.cs
@@ -0,0 +1,64 @@
+using System.Text.Json.Serialization;
+
+namespace LibMatrix.Responses.Admin;
+
+public class AdminRoomListingResult {
+    [JsonPropertyName("offset")]
+    public int Offset { get; set; }
+
+    [JsonPropertyName("total_rooms")]
+    public int TotalRooms { get; set; }
+
+    [JsonPropertyName("next_batch")]
+    public int? NextBatch { get; set; }
+
+    [JsonPropertyName("prev_batch")]
+    public int? PrevBatch { get; set; }
+
+    [JsonPropertyName("rooms")]
+    public List<AdminRoomListingResultRoom> Rooms { get; set; } = new();
+
+    public class AdminRoomListingResultRoom {
+        [JsonPropertyName("room_id")]
+        public string RoomId { get; set; }
+
+        [JsonPropertyName("name")]
+        public string? Name { get; set; }
+
+        [JsonPropertyName("canonical_alias")]
+        public string? CanonicalAlias { get; set; }
+
+        [JsonPropertyName("joined_members")]
+        public int JoinedMembers { get; set; }
+
+        [JsonPropertyName("joined_local_members")]
+        public int JoinedLocalMembers { get; set; }
+
+        [JsonPropertyName("version")]
+        public string Version { get; set; }
+
+        [JsonPropertyName("creator")]
+        public string Creator { get; set; }
+
+        [JsonPropertyName("encryption")]
+        public string? Encryption { get; set; }
+
+        [JsonPropertyName("federatable")]
+        public bool Federatable { get; set; }
+
+        [JsonPropertyName("public")]
+        public bool Public { get; set; }
+
+        [JsonPropertyName("join_rules")]
+        public string? JoinRules { get; set; }
+
+        [JsonPropertyName("guest_access")]
+        public string? GuestAccess { get; set; }
+
+        [JsonPropertyName("history_visibility")]
+        public string? HistoryVisibility { get; set; }
+
+        [JsonPropertyName("state_events")]
+        public int StateEvents { get; set; }
+    }
+}
diff --git a/LibMatrix/Responses/CreateRoomRequest.cs b/LibMatrix/Responses/CreateRoomRequest.cs
new file mode 100644
index 0000000..d59e6fd
--- /dev/null
+++ b/LibMatrix/Responses/CreateRoomRequest.cs
@@ -0,0 +1,74 @@
+using System.Reflection;
+using System.Text.Json.Nodes;
+using System.Text.Json.Serialization;
+using System.Text.RegularExpressions;
+using LibMatrix.Extensions;
+using LibMatrix.StateEventTypes.Spec;
+
+namespace LibMatrix.Responses;
+
+public class CreateRoomRequest {
+    [JsonIgnore] public CreationContentBaseType _creationContentBaseType;
+
+    public CreateRoomRequest() => _creationContentBaseType = new CreationContentBaseType(this);
+
+    [JsonPropertyName("name")]
+    public string Name { get; set; } = null!;
+
+    [JsonPropertyName("room_alias_name")]
+    public string RoomAliasName { get; set; } = null!;
+
+    //we dont want to use this, we want more control
+    // [JsonPropertyName("preset")]
+    // public string Preset { get; set; } = null!;
+
+    [JsonPropertyName("initial_state")]
+    public List<StateEvent> InitialState { get; set; } = null!;
+
+    [JsonPropertyName("visibility")]
+    public string Visibility { get; set; } = null!;
+
+    [JsonPropertyName("power_level_content_override")]
+    public RoomPowerLevelEventData PowerLevelContentOverride { get; set; } = null!;
+
+    [JsonPropertyName("creation_content")]
+    public JsonObject CreationContent { get; set; } = new();
+
+    /// <summary>
+    ///     For use only when you can't use the CreationContent property
+    /// </summary>
+
+    public StateEvent this[string event_type, string 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<MatrixEventAttribute>()?
+                                .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)
+                InitialState.Add(value);
+            else
+                InitialState[InitialState.IndexOf(stateEvent)] = value;
+        }
+    }
+
+    public Dictionary<string, string> Validate() {
+        Dictionary<string, string> errors = new();
+        if (!Regex.IsMatch(RoomAliasName, @"[a-zA-Z0-9_\-]+$"))
+            errors.Add("room_alias_name",
+                "Room alias name must only contain letters, numbers, underscores, and hyphens.");
+
+        return errors;
+    }
+}
diff --git a/LibMatrix/Responses/CreationContentBaseType.cs b/LibMatrix/Responses/CreationContentBaseType.cs
new file mode 100644
index 0000000..ba3ce5e
--- /dev/null
+++ b/LibMatrix/Responses/CreationContentBaseType.cs
@@ -0,0 +1,18 @@
+using System.Text.Json.Serialization;
+
+namespace LibMatrix.Responses;
+
+public class CreationContentBaseType {
+    private readonly CreateRoomRequest createRoomRequest;
+
+    public CreationContentBaseType(CreateRoomRequest createRoomRequest) => this.createRoomRequest = createRoomRequest;
+
+    [JsonPropertyName("type")]
+    public string Type {
+        get => (string)createRoomRequest.CreationContent["type"];
+        set {
+            if (value is "null" or "") createRoomRequest.CreationContent.Remove("type");
+            else createRoomRequest.CreationContent["type"] = value;
+        }
+    }
+}
diff --git a/LibMatrix/Responses/LoginResponse.cs b/LibMatrix/Responses/LoginResponse.cs
new file mode 100644
index 0000000..2800a9c
--- /dev/null
+++ b/LibMatrix/Responses/LoginResponse.cs
@@ -0,0 +1,17 @@
+using System.Text.Json.Serialization;
+
+namespace LibMatrix.Responses;
+
+public class LoginResponse {
+    [JsonPropertyName("access_token")]
+    public string AccessToken { get; set; }
+
+    [JsonPropertyName("device_id")]
+    public string DeviceId { get; set; }
+
+    [JsonPropertyName("home_server")]
+    public string Homeserver { get; set; }
+
+    [JsonPropertyName("user_id")]
+    public string UserId { get; set; }
+}
diff --git a/LibMatrix/Responses/StateEventResponse.cs b/LibMatrix/Responses/StateEventResponse.cs
new file mode 100644
index 0000000..b3d5b96
--- /dev/null
+++ b/LibMatrix/Responses/StateEventResponse.cs
@@ -0,0 +1,47 @@
+using System.Text.Json.Nodes;
+using System.Text.Json.Serialization;
+
+namespace LibMatrix.Responses;
+
+public class StateEventResponse : StateEvent {
+    [JsonPropertyName("origin_server_ts")]
+    public ulong OriginServerTs { get; set; }
+
+    [JsonPropertyName("room_id")]
+    public string RoomId { get; set; }
+
+    [JsonPropertyName("sender")]
+    public string Sender { get; set; }
+
+    [JsonPropertyName("unsigned")]
+    public UnsignedData? Unsigned { get; set; }
+
+    [JsonPropertyName("event_id")]
+    public string EventId { get; set; }
+
+    [JsonPropertyName("user_id")]
+    public string UserId { get; set; }
+
+    [JsonPropertyName("replaces_state")]
+    public string ReplacesState { get; set; }
+
+    public class UnsignedData {
+        [JsonPropertyName("age")]
+        public ulong? Age { get; set; }
+
+        [JsonPropertyName("redacted_because")]
+        public object? RedactedBecause { get; set; }
+
+        [JsonPropertyName("transaction_id")]
+        public string? TransactionId { get; set; }
+
+        [JsonPropertyName("replaces_state")]
+        public string? ReplacesState { get; set; }
+
+        [JsonPropertyName("prev_sender")]
+        public string? PrevSender { get; set; }
+
+        [JsonPropertyName("prev_content")]
+        public JsonObject? PrevContent { get; set; }
+    }
+}