diff options
Diffstat (limited to 'LibMatrix')
-rw-r--r-- | LibMatrix/Helpers/MessageBuilder.cs | 37 | ||||
-rw-r--r-- | LibMatrix/Helpers/SyncHelper.cs | 2 | ||||
-rw-r--r-- | LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs | 2 | ||||
-rw-r--r-- | LibMatrix/Homeservers/FederationClient.cs | 5 | ||||
-rw-r--r-- | LibMatrix/Homeservers/RemoteHomeServer.cs | 1 | ||||
-rw-r--r-- | LibMatrix/Responses/CreateRoomRequest.cs | 1 | ||||
-rw-r--r-- | LibMatrix/RoomTypes/SpaceRoom.cs | 1 | ||||
-rw-r--r-- | LibMatrix/StateEvent.cs | 2 |
8 files changed, 32 insertions, 19 deletions
diff --git a/LibMatrix/Helpers/MessageBuilder.cs b/LibMatrix/Helpers/MessageBuilder.cs index 0753aca..d897078 100644 --- a/LibMatrix/Helpers/MessageBuilder.cs +++ b/LibMatrix/Helpers/MessageBuilder.cs @@ -1,4 +1,3 @@ -using ArcaneLibs; using LibMatrix.EventTypes.Spec; namespace LibMatrix.Helpers; @@ -50,7 +49,7 @@ public class MessageBuilder(string msgType = "m.text", string format = "org.matr Content.FormattedBody += "</font>"; return this; } - + public MessageBuilder WithCustomEmoji(string mxcUri, string name) { Content.Body += $"{{{name}}}"; Content.FormattedBody += $"<img data-mx-emoticon height=\"32\" src=\"{mxcUri}\" alt=\"{name}\" title=\"{name}\" />"; @@ -72,23 +71,51 @@ public class MessageBuilder(string msgType = "m.text", string format = "org.matr // } return this; } - + public MessageBuilder WithCodeBlock(string code, string language = "plaintext") { Content.Body += code; Content.FormattedBody += $"<pre><code class=\"language-{language}\">{code}</code></pre>"; return this; } - + public MessageBuilder WithCollapsibleSection(string title, string body) { Content.Body += body; Content.FormattedBody += $"<details><summary>{title}</summary>{body}</details>"; return this; } - + public MessageBuilder WithCollapsibleSection(string title, Action<MessageBuilder> bodyBuilder) { Content.FormattedBody += $"<details><summary>{title}</summary>"; bodyBuilder(this); Content.FormattedBody += "</details>"; return this; } + + public MessageBuilder WithTable(Action<TableBuilder> tableBuilder) { + var tb = new TableBuilder(this); + this.WithHtmlTag("table", msb => tableBuilder(tb)); + return this; + } + + public class TableBuilder(MessageBuilder msb) { + public TableBuilder WithTitle(string title, int colspan) { + msb.Content.Body += title + "\n"; + msb.Content.FormattedBody += $"<thead><tr><th colspan=\"{colspan}\">{title}</th></tr></thead>"; + return this; + } + + public TableBuilder WithRow(Action<RowBuilder> rowBuilder) { + var rb = new RowBuilder(msb); + msb.WithHtmlTag("tr", msb => rowBuilder(rb)).WithBody("\n"); + return this; + } + + public class RowBuilder(MessageBuilder msb) { + public RowBuilder WithCell(string content, Dictionary<string, string>? attributes = null) { + msb.Content.Body += content + "\n"; + msb.Content.FormattedBody += $"<td>{content}</td>\t"; + return this; + } + } + } } \ No newline at end of file diff --git a/LibMatrix/Helpers/SyncHelper.cs b/LibMatrix/Helpers/SyncHelper.cs index e696b70..1833bd0 100644 --- a/LibMatrix/Helpers/SyncHelper.cs +++ b/LibMatrix/Helpers/SyncHelper.cs @@ -1,7 +1,5 @@ using System.Diagnostics; using System.Net.Http.Json; -using System.Text.Json; -using System.Text.Json.Serialization; using ArcaneLibs.Extensions; using LibMatrix.Filters; using LibMatrix.Homeservers; diff --git a/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs b/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs index 4f3bb41..727c0ea 100644 --- a/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs +++ b/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs @@ -1,7 +1,5 @@ -using System.Diagnostics.CodeAnalysis; using System.Net.Http.Headers; using System.Net.Http.Json; -using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Nodes; using System.Text.Json.Serialization; diff --git a/LibMatrix/Homeservers/FederationClient.cs b/LibMatrix/Homeservers/FederationClient.cs index 288b6b5..3926b29 100644 --- a/LibMatrix/Homeservers/FederationClient.cs +++ b/LibMatrix/Homeservers/FederationClient.cs @@ -1,10 +1,5 @@ -using System.Net.Http.Json; -using System.Text.Json; using System.Text.Json.Serialization; -using System.Web; -using ArcaneLibs.Extensions; using LibMatrix.Extensions; -using LibMatrix.Responses; using LibMatrix.Services; namespace LibMatrix.Homeservers; diff --git a/LibMatrix/Homeservers/RemoteHomeServer.cs b/LibMatrix/Homeservers/RemoteHomeServer.cs index 422a8a9..8cd7ad7 100644 --- a/LibMatrix/Homeservers/RemoteHomeServer.cs +++ b/LibMatrix/Homeservers/RemoteHomeServer.cs @@ -1,5 +1,4 @@ using System.Net.Http.Json; -using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.Json.Serialization; using System.Web; diff --git a/LibMatrix/Responses/CreateRoomRequest.cs b/LibMatrix/Responses/CreateRoomRequest.cs index ee4317e..6f47183 100644 --- a/LibMatrix/Responses/CreateRoomRequest.cs +++ b/LibMatrix/Responses/CreateRoomRequest.cs @@ -5,7 +5,6 @@ using System.Text.RegularExpressions; using LibMatrix.EventTypes; using LibMatrix.EventTypes.Spec.State; using LibMatrix.Homeservers; -using LibMatrix.Interfaces; namespace LibMatrix.Responses; diff --git a/LibMatrix/RoomTypes/SpaceRoom.cs b/LibMatrix/RoomTypes/SpaceRoom.cs index 49e751d..b40ccc6 100644 --- a/LibMatrix/RoomTypes/SpaceRoom.cs +++ b/LibMatrix/RoomTypes/SpaceRoom.cs @@ -1,6 +1,5 @@ using ArcaneLibs.Extensions; using LibMatrix.Homeservers; -using Microsoft.Extensions.Logging; namespace LibMatrix.RoomTypes; diff --git a/LibMatrix/StateEvent.cs b/LibMatrix/StateEvent.cs index 541fb78..d9d0f4e 100644 --- a/LibMatrix/StateEvent.cs +++ b/LibMatrix/StateEvent.cs @@ -1,6 +1,4 @@ using System.Collections.Frozen; -using System.Collections.Immutable; -using System.ComponentModel.DataAnnotations; using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Text.Json; |