about summary refs log tree commit diff
path: root/LibMatrix.EventTypes
diff options
context:
space:
mode:
Diffstat (limited to 'LibMatrix.EventTypes')
-rw-r--r--LibMatrix.EventTypes/Events/RoomMembershipEventContent.cs10
-rw-r--r--LibMatrix.EventTypes/MatrixEvent.cs9
-rw-r--r--LibMatrix.EventTypes/MatrixEventCollection.cs71
-rw-r--r--LibMatrix.EventTypes/MatrixEventContent.cs26
-rw-r--r--LibMatrix.EventTypes/temp/Temp.cs17
5 files changed, 133 insertions, 0 deletions
diff --git a/LibMatrix.EventTypes/Events/RoomMembershipEventContent.cs b/LibMatrix.EventTypes/Events/RoomMembershipEventContent.cs
new file mode 100644

index 0000000..dac7094 --- /dev/null +++ b/LibMatrix.EventTypes/Events/RoomMembershipEventContent.cs
@@ -0,0 +1,10 @@ +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes.Events; + +public class RoomMembershipEventContent : MatrixEventContent { + public string Membership { + get => _json["membership"]!.GetValue<string>(); + set => Console.WriteLine(value); + } +} \ No newline at end of file diff --git a/LibMatrix.EventTypes/MatrixEvent.cs b/LibMatrix.EventTypes/MatrixEvent.cs new file mode 100644
index 0000000..63f1e75 --- /dev/null +++ b/LibMatrix.EventTypes/MatrixEvent.cs
@@ -0,0 +1,9 @@ +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 new file mode 100644
index 0000000..35afd2b --- /dev/null +++ b/LibMatrix.EventTypes/MatrixEventCollection.cs
@@ -0,0 +1,71 @@ +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; + } +} \ No newline at end of file diff --git a/LibMatrix.EventTypes/MatrixEventContent.cs b/LibMatrix.EventTypes/MatrixEventContent.cs new file mode 100644
index 0000000..c30ebb0 --- /dev/null +++ b/LibMatrix.EventTypes/MatrixEventContent.cs
@@ -0,0 +1,26 @@ +using System.Text.Json; +using System.Text.Json.Nodes; +using System.Text.Json.Serialization; + +namespace LibMatrix.EventTypes; + +/// <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> +public class MatrixEventContent { + // <T> : MatrixEventContent where T : MatrixEventContent<T>, new() { + internal JsonNode _json = new JsonObject(); + + public static implicit operator MatrixEventContent(JsonNode json) => new(json); + + [JsonConstructor] + public MatrixEventContent(JsonNode json) { + _json = json; + } + + public MatrixEventContent() { } + + public JsonNode? this[string key] => _json[key]; +} \ No newline at end of file diff --git a/LibMatrix.EventTypes/temp/Temp.cs b/LibMatrix.EventTypes/temp/Temp.cs new file mode 100644
index 0000000..3fbb401 --- /dev/null +++ b/LibMatrix.EventTypes/temp/Temp.cs
@@ -0,0 +1,17 @@ +using LibMatrix.EventTypes.Events; + +namespace LibMatrix.EventTypes.temp; + +// public class Temp { +// public MatrixEventCollection<MatrixEventContent> Members = [ +// new MatrixEvent<RoomMembershipEventContent>() { +// Content = new() { +// Membership = "join" +// } +// } +// ]; +// +// public void a() { +// +// } +// } \ No newline at end of file