From ab758cc2336e88d9cd967238310b433e75d500dc Mon Sep 17 00:00:00 2001 From: Vyr Cossont Date: Fri, 31 Jan 2025 02:40:39 -0800 Subject: [feature] Add system message wrappers for pending replies and placeholder attachments (#3713) Fixes #3712 --- internal/typeutils/util.go | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'internal/typeutils/util.go') diff --git a/internal/typeutils/util.go b/internal/typeutils/util.go index 1747dbdcd..b4f2e41aa 100644 --- a/internal/typeutils/util.go +++ b/internal/typeutils/util.go @@ -128,12 +128,14 @@ func misskeyReportInlineURLs(content string) []*url.URL { // // Example: // -//
-//

ℹ️ Note from your.instance.com: 2 attachment(s) in this status were not downloaded. Treat the following external link(s) with care:

-// +//
+//
+//

ℹ️ Note from your.instance.com: 2 attachment(s) in this status were not downloaded. Treat the following external link(s) with care:

+// +//
func placeholderAttachments(arr []*apimodel.Attachment) (string, []*apimodel.Attachment) { // Extract non-locally stored attachments into a @@ -187,7 +189,7 @@ func placeholderAttachments(arr []*apimodel.Attachment) (string, []*apimodel.Att } note.WriteString(``) - return text.SanitizeToHTML(note.String()), arr + return systemMessage("gts-placeholder-attachments", note.String()), arr } func (c *Converter) pendingReplyNote( @@ -228,7 +230,27 @@ func (c *Converter) pendingReplyNote( note.WriteString(`.`) note.WriteString(`

`) - return text.SanitizeToHTML(note.String()), nil + return systemMessage("gts-pending-reply", note.String()), nil +} + +// systemMessage wraps a note with a div with semantic classes that aren't allowed through the sanitizer, +// but may be emitted to the client as an addition to the status's actual content. +// Clients may want to display these specially or suppress them in favor of their own UI. +// +// messageClass must be valid inside an HTML attribute and should be one or more classes starting with `gts-`. +func systemMessage( + messageClass string, + unsanitizedNoteHTML string, +) string { + var wrappedNote strings.Builder + + wrappedNote.WriteString(`
`) + wrappedNote.WriteString(text.SanitizeToHTML(unsanitizedNoteHTML)) + wrappedNote.WriteString(`
`) + + return wrappedNote.String() } // ContentToContentLanguage tries to -- cgit v1.2.3