From 8dadf547033d71480fd7756809992c0f32549f59 Mon Sep 17 00:00:00 2001 From: "Emma [it/its]@Rory&" Date: Thu, 11 Jan 2024 07:31:09 +0100 Subject: Cleanup, more message formatters, messagebuilder start --- LibMatrix/Helpers/MessageFormatter.cs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'LibMatrix/Helpers/MessageFormatter.cs') diff --git a/LibMatrix/Helpers/MessageFormatter.cs b/LibMatrix/Helpers/MessageFormatter.cs index b2dda61..b7c6975 100644 --- a/LibMatrix/Helpers/MessageFormatter.cs +++ b/LibMatrix/Helpers/MessageFormatter.cs @@ -13,7 +13,7 @@ public static class MessageFormatter { public static RoomMessageEventContent FormatException(string error, Exception e) { return new RoomMessageEventContent(body: $"{error}: {e.Message}", messageType: "m.text") { - FormattedBody = $"{error}:
{e.Message}
", + FormattedBody = $"{error}:
{e.Message}
", Format = "org.matrix.custom.html" }; } @@ -27,7 +27,7 @@ public static class MessageFormatter { public static RoomMessageEventContent FormatSuccessJson(string text, object data) { return new RoomMessageEventContent(body: text, messageType: "m.text") { - FormattedBody = $"{text}:
{data.ToJson(ignoreNull: true)}
", + FormattedBody = $"{text}:
{data.ToJson(ignoreNull: true)}
", Format = "org.matrix.custom.html" }; } @@ -53,4 +53,24 @@ public static class MessageFormatter { Format = "org.matrix.custom.html" }; } + + public static RoomMessageEventContent FormatWarningJson(string warning, object data) { + return new RoomMessageEventContent(body: warning, messageType: "m.text") { + FormattedBody = $"{warning}:
{data.ToJson(ignoreNull: true)}
", + Format = "org.matrix.custom.html" + }; + } + + public static RoomMessageEventContent Concat(this RoomMessageEventContent a, RoomMessageEventContent b) { + return new RoomMessageEventContent(body: $"{a.Body}{b.Body}", messageType: a.MessageType) { + FormattedBody = $"{a.FormattedBody}{b.FormattedBody}", + Format = a.Format + }; + } + public static RoomMessageEventContent ConcatLine(this RoomMessageEventContent a, RoomMessageEventContent b) { + return new RoomMessageEventContent(body: $"{a.Body}\n{b.Body}", messageType: "m.text") { + FormattedBody = $"{a.FormattedBody}
{b.FormattedBody}", + Format = "org.matrix.custom.html" + }; + } } -- cgit 1.4.1