From 4ef9ae4b396b0eb37036d4008e8cb40e468dbe73 Mon Sep 17 00:00:00 2001 From: "Emma [it/its]@Rory&" Date: Fri, 9 Feb 2024 16:32:46 +0100 Subject: Apply syntax style to LibMatrix --- LibMatrix/Helpers/MessageFormatter.cs | 55 +++++++++++++++-------------------- 1 file changed, 23 insertions(+), 32 deletions(-) (limited to 'LibMatrix/Helpers/MessageFormatter.cs') diff --git a/LibMatrix/Helpers/MessageFormatter.cs b/LibMatrix/Helpers/MessageFormatter.cs index b7c6975..1b9b4f3 100644 --- a/LibMatrix/Helpers/MessageFormatter.cs +++ b/LibMatrix/Helpers/MessageFormatter.cs @@ -4,73 +4,64 @@ using LibMatrix.EventTypes.Spec; namespace LibMatrix.Helpers; public static class MessageFormatter { - public static RoomMessageEventContent FormatError(string error) { - return new RoomMessageEventContent(body: error, messageType: "m.text") { + public static RoomMessageEventContent FormatError(string error) => + new(body: error, messageType: "m.text") { FormattedBody = $"{error}", Format = "org.matrix.custom.html" }; - } - public static RoomMessageEventContent FormatException(string error, Exception e) { - return new RoomMessageEventContent(body: $"{error}: {e.Message}", messageType: "m.text") { + public static RoomMessageEventContent FormatException(string error, Exception e) => + new(body: $"{error}: {e.Message}", messageType: "m.text") { FormattedBody = $"{error}:
{e.Message}
", Format = "org.matrix.custom.html" }; - } - public static RoomMessageEventContent FormatSuccess(string text) { - return new RoomMessageEventContent(body: text, messageType: "m.text") { + public static RoomMessageEventContent FormatSuccess(string text) => + new(body: text, messageType: "m.text") { FormattedBody = $"{text}", Format = "org.matrix.custom.html" }; - } - public static RoomMessageEventContent FormatSuccessJson(string text, object data) { - return new RoomMessageEventContent(body: text, messageType: "m.text") { + public static RoomMessageEventContent FormatSuccessJson(string text, object data) => + new(body: text, messageType: "m.text") { FormattedBody = $"{text}:
{data.ToJson(ignoreNull: true)}
", Format = "org.matrix.custom.html" }; - } - public static string HtmlFormatMention(string id, string? displayName = null) { - return $"{displayName ?? id}"; - } + public static string HtmlFormatMention(string id, string? displayName = null) => $"{displayName ?? id}"; public static string HtmlFormatMessageLink(string roomId, string eventId, string[]? servers = null, string? displayName = null) { if (servers is not { Length: > 0 }) servers = new[] { roomId.Split(':', 2)[1] }; return $"{displayName ?? eventId}"; } - #region Extension functions +#region Extension functions public static RoomMessageEventContent ToMatrixMessage(this Exception e, string error) => FormatException(error, e); - #endregion +#endregion - public static RoomMessageEventContent FormatWarning(string warning) { - return new RoomMessageEventContent(body: warning, messageType: "m.text") { + public static RoomMessageEventContent FormatWarning(string warning) => + new(body: warning, messageType: "m.text") { FormattedBody = $"{warning}", Format = "org.matrix.custom.html" }; - } - - public static RoomMessageEventContent FormatWarningJson(string warning, object data) { - return new RoomMessageEventContent(body: warning, messageType: "m.text") { + + public static RoomMessageEventContent FormatWarningJson(string warning, object data) => + new(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) { + + public static RoomMessageEventContent Concat(this RoomMessageEventContent a, RoomMessageEventContent b) => + new(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") { + + public static RoomMessageEventContent ConcatLine(this RoomMessageEventContent a, RoomMessageEventContent b) => + new(body: $"{a.Body}\n{b.Body}", messageType: "m.text") { FormattedBody = $"{a.FormattedBody}
{b.FormattedBody}", Format = "org.matrix.custom.html" }; - } -} +} \ No newline at end of file -- cgit 1.4.1