diff options
Diffstat (limited to 'LibMatrix.EventTypes')
-rw-r--r-- | LibMatrix.EventTypes/Events/RoomMembershipEventContent.cs | 12 | ||||
-rw-r--r-- | LibMatrix.EventTypes/Events/RoomMessageEventContent.cs | 57 | ||||
-rw-r--r-- | LibMatrix.EventTypes/LibMatrix.EventTypes.csproj | 14 | ||||
-rw-r--r-- | LibMatrix.EventTypes/MatrixEvent.cs | 9 | ||||
-rw-r--r-- | LibMatrix.EventTypes/MatrixEventCollection.cs | 71 | ||||
-rw-r--r-- | LibMatrix.EventTypes/MatrixEventContent.cs | 60 | ||||
-rw-r--r-- | LibMatrix.EventTypes/temp/Program.cs | 30 |
7 files changed, 0 insertions, 253 deletions
diff --git a/LibMatrix.EventTypes/Events/RoomMembershipEventContent.cs b/LibMatrix.EventTypes/Events/RoomMembershipEventContent.cs deleted file mode 100644 index fe50a2e..0000000 --- a/LibMatrix.EventTypes/Events/RoomMembershipEventContent.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.EventTypes.Events; - -[MatrixEvent("m.room.member")] -[JsonConverter(typeof(MatrixEventContentConverter<RoomMembershipEventContent>))] -public class RoomMembershipEventContent : MatrixEventContent { - public string Membership { - get => InternalJson["membership"]!.GetValue<string>(); - set => InternalJson["membership"] = value; - } -} \ No newline at end of file diff --git a/LibMatrix.EventTypes/Events/RoomMessageEventContent.cs b/LibMatrix.EventTypes/Events/RoomMessageEventContent.cs deleted file mode 100644 index 55c2b6c..0000000 --- a/LibMatrix.EventTypes/Events/RoomMessageEventContent.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System.Text.Json.Serialization; -using LibMatrix.EventTypes; - -namespace LibMatrix.LegacyEvents.EventTypes.Spec; - -[MatrixEvent(EventId)] -public class RoomMessageEventContent : MatrixEventContent { - public const string EventId = "m.room.message"; - - public RoomMessageEventContent(string messageType = "m.notice", string? body = null) { - MessageType = messageType; - Body = body ?? ""; - } - - [JsonPropertyName("body")] - public string Body { get; set; } - - [JsonPropertyName("msgtype")] - public string MessageType { get; set; } = "m.notice"; - - [JsonPropertyName("formatted_body")] - public string? FormattedBody { get; set; } - - [JsonPropertyName("format")] - public string? Format { get; set; } - - /// <summary> - /// Media URI for this message, if any - /// </summary> - [JsonPropertyName("url")] - public string? Url { get; set; } - - public string? FileName { get; set; } - - [JsonPropertyName("info")] - public FileInfoStruct? FileInfo { get; set; } - - [JsonIgnore] - public string BodyWithoutReplyFallback => Body.Split('\n').SkipWhile(x => x.StartsWith(">")).SkipWhile(x=>x.Trim().Length == 0).Aggregate((x, y) => $"{x}\n{y}"); - - public class FileInfoStruct { - [JsonPropertyName("mimetype")] - public string? MimeType { get; set; } - - [JsonPropertyName("size")] - public long Size { get; set; } - - [JsonPropertyName("thumbnail_url")] - public string? ThumbnailUrl { get; set; } - - [JsonPropertyName("w")] - public int? Width { get; set; } - - [JsonPropertyName("h")] - public int? Height { get; set; } - } -} \ No newline at end of file diff --git a/LibMatrix.EventTypes/LibMatrix.EventTypes.csproj b/LibMatrix.EventTypes/LibMatrix.EventTypes.csproj deleted file mode 100644 index bd33993..0000000 --- a/LibMatrix.EventTypes/LibMatrix.EventTypes.csproj +++ /dev/null @@ -1,14 +0,0 @@ -<Project Sdk="Microsoft.NET.Sdk"> - - <PropertyGroup> - <TargetFramework>net8.0</TargetFramework> - <ImplicitUsings>enable</ImplicitUsings> - <Nullable>enable</Nullable> - <OutputType>Exe</OutputType> - </PropertyGroup> - - <ItemGroup> - <ProjectReference Include="..\ArcaneLibs\ArcaneLibs\ArcaneLibs.csproj" /> - </ItemGroup> - -</Project> diff --git a/LibMatrix.EventTypes/MatrixEvent.cs b/LibMatrix.EventTypes/MatrixEvent.cs deleted file mode 100644 index 63f1e75..0000000 --- a/LibMatrix.EventTypes/MatrixEvent.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Text.Json.Serialization; - -namespace LibMatrix.EventTypes; - -public interface IMatrixEvent<out T> where T : MatrixEventContent; -public class MatrixEvent<T> : IMatrixEvent<T> where T : MatrixEventContent { - [JsonPropertyName("content")] - public T? Content { get; set; } -} \ No newline at end of file diff --git a/LibMatrix.EventTypes/MatrixEventCollection.cs b/LibMatrix.EventTypes/MatrixEventCollection.cs deleted file mode 100644 index 78886d9..0000000 --- a/LibMatrix.EventTypes/MatrixEventCollection.cs +++ /dev/null @@ -1,71 +0,0 @@ -// using System.Collections; -// -// namespace LibMatrix.EventTypes; -// -// public interface IMatrixEventCollection<out T> : IEnumerable<IMatrixEvent<T>> where T : MatrixEventContent { -// -// } -// public class MatrixEventCollection : IMatrixEventCollection<MatrixEventContent>, IList<MatrixEvent<MatrixEventContent> { -// private IList<MatrixEvent<MatrixEventContent>> _listImplementation; -// public IEnumerator<MatrixEvent<MatrixEventContent>> GetEnumerator() => _listImplementation.GetEnumerator(); -// -// IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)_listImplementation).GetEnumerator(); -// -// public void Add(MatrixEvent<MatrixEventContent> item) => _listImplementation.Add(item); -// -// public void Clear() => _listImplementation.Clear(); -// -// public bool Contains(MatrixEvent<MatrixEventContent> item) => _listImplementation.Contains(item); -// -// public void CopyTo(MatrixEvent<MatrixEventContent>[] array, int arrayIndex) => _listImplementation.CopyTo(array, arrayIndex); -// -// public bool Remove(MatrixEvent<MatrixEventContent> item) => _listImplementation.Remove(item); -// -// public int Count => _listImplementation.Count; -// -// public bool IsReadOnly => _listImplementation.IsReadOnly; -// -// public int IndexOf(MatrixEvent<MatrixEventContent> item) => _listImplementation.IndexOf(item); -// -// public void Insert(int index, MatrixEvent<MatrixEventContent> item) => _listImplementation.Insert(index, item); -// -// public void RemoveAt(int index) => _listImplementation.RemoveAt(index); -// -// public MatrixEvent<MatrixEventContent> this[int index] { -// get => _listImplementation[index]; -// set => _listImplementation[index] = value; -// } -// } -// public class MatrixEventCollection<T> : IMatrixEventCollection<T>, IList<MatrixEvent<T>> where T : MatrixEventContent { -// //TODO: implement -// -// private IList<MatrixEvent<T>> _listImplementation = new List<MatrixEvent<T>>(); -// public IEnumerator<MatrixEvent<T>> GetEnumerator() => _listImplementation.GetEnumerator(); -// -// IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)_listImplementation).GetEnumerator(); -// -// public void Add(MatrixEvent<T> item) => _listImplementation.Add(item); -// -// public void Clear() => _listImplementation.Clear(); -// -// public bool Contains(MatrixEvent<T> item) => _listImplementation.Contains(item); -// -// public void CopyTo(MatrixEvent<T>[] array, int arrayIndex) => _listImplementation.CopyTo(array, arrayIndex); -// -// public bool Remove(MatrixEvent<T> item) => _listImplementation.Remove(item); -// -// public int Count => _listImplementation.Count; -// -// public bool IsReadOnly => _listImplementation.IsReadOnly; -// -// public int IndexOf(MatrixEvent<T> item) => _listImplementation.IndexOf(item); -// -// public void Insert(int index, MatrixEvent<T> item) => _listImplementation.Insert(index, item); -// -// public void RemoveAt(int index) => _listImplementation.RemoveAt(index); -// -// public MatrixEvent<T> this[int index] { -// get => _listImplementation[index]; -// set => _listImplementation[index] = value; -// } -// }a \ No newline at end of file diff --git a/LibMatrix.EventTypes/MatrixEventContent.cs b/LibMatrix.EventTypes/MatrixEventContent.cs deleted file mode 100644 index 81b8c52..0000000 --- a/LibMatrix.EventTypes/MatrixEventContent.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System.Reflection; -using System.Text.Json; -using System.Text.Json.Nodes; -using System.Text.Json.Serialization; -using ArcaneLibs.Extensions; - -namespace LibMatrix.EventTypes; - -// <T> : MatrixEventContent where T : MatrixEventContent<T>, new() { -/// <summary> -/// Extensible Event Content, aims to provide an API similar to JsonNode/JsonObject -/// <seealso cref="System.Text.Json.Nodes.JsonNode"/> -/// <seealso cref="System.Text.Json.Nodes.JsonObject"/> -/// </summary> -[JsonConverter(typeof(MatrixEventContentConverter<MatrixEventContent>))] -public class MatrixEventContent { - - [JsonExtensionData, JsonInclude] - public JsonObject InternalJson { get; set; } = new(); - - - - public MatrixEventContent() { } - - public MatrixEventContent(JsonNode json) { - InternalJson = json.AsObject(); - } - - public static implicit operator MatrixEventContent(JsonNode json) => new(json); - - // public static implicit operator JsonNode(MatrixEventContent content) => content.InternalJson; - - [JsonIgnore] - public IEnumerable<string> EventTypes => this.GetType().GetCustomAttributes<MatrixEventAttribute>().Select(x => x.EventType); - - [JsonIgnore] - public string EventType => EventTypes.First(); - - public JsonNode? this[string key] => InternalJson[key]; - - public string ToJson() => InternalJson.ToJson(); - - - public class MatrixEventContentConverter<T> : JsonConverter<T> where T : MatrixEventContent, new() { - public override T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - // read entire object into a JsonObject - var json = JsonNode.Parse(ref reader); - return new T { InternalJson = json.AsObject() }; - } - - public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) { - value.InternalJson.WriteTo(writer); - } - } -} - -public class MatrixEventAttribute(string eventType, bool deprecated = false) : Attribute { - public string EventType { get; } = eventType; - public bool Deprecated { get; } = deprecated; -} \ No newline at end of file diff --git a/LibMatrix.EventTypes/temp/Program.cs b/LibMatrix.EventTypes/temp/Program.cs deleted file mode 100644 index 22a65d4..0000000 --- a/LibMatrix.EventTypes/temp/Program.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Text.Json; -using System.Text.Json.Serialization; -using ArcaneLibs.Extensions; -using LibMatrix.EventTypes.Events; - -namespace LibMatrix.EventTypes.temp; - -public class Program { - // public MatrixEventCollection<MatrixEventContent> Members = [ - // new MatrixEvent<RoomMembershipEventContent>() { - // Content = new() { - // Membership = "join" - // } - // } - // ]; - - public static void Main(string[] args) { - var evt = new RoomMembershipEventContent() { - Membership = "join" - }; - Console.WriteLine(evt.ToJson()); - - var eventJson = File.ReadAllText("test-event.json"); - var evt2 = JsonSerializer.Deserialize<MatrixEvent<RoomMembershipEventContent>>(eventJson); - evt2.Content.Membership = "meow"; - Console.WriteLine(evt2.Content.ToJson()); - Console.WriteLine(ObjectExtensions.ToJson(evt2)); - - } -} \ No newline at end of file |