From e08f23ba657a83a7c705497aba8f20b666ffa27c Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 15 Apr 2022 23:44:59 +0300 Subject: [PATCH] Only linkify text if inline URLs are enabled --- ui/messages/filemessage.go | 10 +++++++--- ui/messages/html/parser.go | 7 +++++-- ui/messages/parser.go | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ui/messages/filemessage.go b/ui/messages/filemessage.go index 5ad8d49..cbcc5be 100644 --- a/ui/messages/filemessage.go +++ b/ui/messages/filemessage.go @@ -147,11 +147,15 @@ func (msg *FileMessage) CalculateBuffer(prefs config.UserPreferences, width int, if prefs.BareMessageView || prefs.DisableImages || len(msg.imageData) == 0 { url := msg.matrix.GetDownloadURL(msg.URL) + var urlTString tstring.TString + if prefs.InlineURLs { + urlTString = tstring.NewStyleTString(url, tcell.StyleDefault.Hyperlink(url, msg.eventID.String())) + } else { + urlTString = tstring.NewTString(url) + } text := tstring.NewTString(msg.Body). Append(": "). - AppendTString(tstring.NewStyleTString( - url, - tcell.StyleDefault.Hyperlink(url, msg.eventID.String()))) + AppendTString(urlTString) msg.buffer = calculateBufferWithText(prefs, text, width, uiMsg) return } diff --git a/ui/messages/html/parser.go b/ui/messages/html/parser.go index 554f4fa..a9d6d3f 100644 --- a/ui/messages/html/parser.go +++ b/ui/messages/html/parser.go @@ -383,10 +383,13 @@ func (parser *htmlParser) tagNodeToEntity(node *html.Node) Entity { var spaces = regexp.MustCompile("\\s+") var links = regexp.MustCompile(`https?://\S+`) -func TextToEntity(text string, eventID id.EventID) Entity { +func TextToEntity(text string, eventID id.EventID, linkify bool) Entity { if len(text) == 0 { return nil } + if !linkify { + return NewTextEntity(text) + } indices := links.FindAllStringIndex(text, -1) if len(indices) == 0 { return NewTextEntity(text) @@ -418,7 +421,7 @@ func (parser *htmlParser) singleNodeToEntity(node *html.Node) Entity { node.Data = strings.ReplaceAll(node.Data, "\n", "") node.Data = spaces.ReplaceAllLiteralString(node.Data, " ") } - return TextToEntity(node.Data, parser.evt.ID) + return TextToEntity(node.Data, parser.evt.ID, parser.prefs.InlineURLs) case html.ElementNode: parsed := parser.tagNodeToEntity(node) if parsed != nil && !parsed.IsBlock() && parsed.IsEmpty() { diff --git a/ui/messages/parser.go b/ui/messages/parser.go index c609032..07197db 100644 --- a/ui/messages/parser.go +++ b/ui/messages/parser.go @@ -208,7 +208,7 @@ func ParseMessage(matrix ifc.MatrixContainer, room *rooms.Room, evt *muksevt.Eve return NewHTMLMessage(evt, displayname, html.Parse(matrix.Preferences(), room, content, evt, displayname)) } content.Body = strings.Replace(content.Body, "\t", " ", -1) - return NewHTMLMessage(evt, displayname, html.TextToEntity(content.Body, evt.ID)) + return NewHTMLMessage(evt, displayname, html.TextToEntity(content.Body, evt.ID, matrix.Preferences().InlineURLs)) case event.MsgImage, event.MsgVideo, event.MsgAudio, event.MsgFile: msg := NewFileMessage(matrix, evt, displayname) if !matrix.Preferences().DisableDownloads {