From 4bfdf0e667d43b3e97a27c6c62e80576f8335141 Mon Sep 17 00:00:00 2001 From: Fabian Siegel Date: Sun, 31 Jan 2021 23:57:50 +0100 Subject: [PATCH] Fix codeblocks in chat (#676) * allowed codeblocks in chat (owncast#675) * dont send empty chat messages back to frontend (owncast#675) --- core/chat/server.go | 10 ++++++---- models/chatMessage.go | 8 ++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/core/chat/server.go b/core/chat/server.go index d3daec0b7..33dbe1bfb 100644 --- a/core/chat/server.go +++ b/core/chat/server.go @@ -117,11 +117,13 @@ func (s *server) Listen() { // and standardize this message into something safe we can send everyone else. msg.RenderAndSanitizeMessageBody() - s.listener.MessageSent(msg) - s.sendAll(msg) + if !msg.Empty() { + s.listener.MessageSent(msg) + s.sendAll(msg) - // Store in the message history - addMessage(msg) + // Store in the message history + addMessage(msg) + } case ping := <-s.pingCh: fmt.Println("PING?", ping) diff --git a/models/chatMessage.go b/models/chatMessage.go index 99656c60b..5db416e46 100644 --- a/models/chatMessage.go +++ b/models/chatMessage.go @@ -38,6 +38,10 @@ func (m *ChatEvent) RenderAndSanitizeMessageBody() { m.Body = RenderAndSanitize(raw) } +func (m *ChatEvent) Empty() bool { + return m.Body == "" +} + // RenderAndSanitize will turn markdown into HTML, sanitize raw user-supplied HTML and standardize // the message into something safe and renderable for clients. func RenderAndSanitize(raw string) string { @@ -111,5 +115,9 @@ func sanitize(raw string) string { // Allow emphasis p.AllowElements("em") + // Allow code blocks + p.AllowElements("code") + p.AllowElements("pre") + return p.Sanitize(raw) }