From 2a1329d9810205afc4df3ba58a3fa13fcf8a782a Mon Sep 17 00:00:00 2001 From: ReK2 Date: Sat, 15 Aug 2020 06:59:02 +0200 Subject: [PATCH] first changes to show urls --- config/config.go | 1 + go.sum | 1 + ui/commands.go | 3 +++ ui/messages/html/parser.go | 25 ++++++++++++++++++++++--- ui/view-main.go | 2 +- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/config/config.go b/config/config.go index 03e186f..ce5ed6f 100644 --- a/config/config.go +++ b/config/config.go @@ -50,6 +50,7 @@ type UserPreferences struct { DisableHTML bool `yaml:"disable_html"` DisableDownloads bool `yaml:"disable_downloads"` DisableNotifications bool `yaml:"disable_notifications"` + DisableShowUrls bool `yaml:"disable_show_urls"` } // Config contains the main config of gomuks. diff --git a/go.sum b/go.sum index f3bd493..1369868 100644 --- a/go.sum +++ b/go.sum @@ -114,6 +114,7 @@ maunium.net/go/mautrix v0.5.5 h1:e0Pql1FdxoNUudx2oXo1gZHMrqIh5MC72cdXEPIrYLA= maunium.net/go/mautrix v0.5.5/go.mod h1:FLbMANzwqlsX2Fgm7SDe+E4I3wSa4UxJRKqS5wGkCwA= maunium.net/go/mautrix v0.7.0-rc.1 h1:DT7bNR9q+HlFs5Oo9IqmtWPkE4WPKZdRfIWRtlqkXtM= maunium.net/go/mautrix v0.7.0-rc.1/go.mod h1:Va/74MijqaS0DQ3aUqxmFO54/PMfr1LVsCOcGRHbYmo= +maunium.net/go/mautrix v0.7.0 h1:9Wxs5S4Wl4S99dbBwfLZYAe/sP7VKaFikw9Ocf88kfk= maunium.net/go/mauview v0.1.1 h1:wfTXyPx3LGAGpTskh+UbBv/QItUWnEpaneHmywoYnfY= maunium.net/go/mauview v0.1.1/go.mod h1:3QBUiuLct9moP1LgDhCGIg0Ovxn38Bd2sGndnUOuj4o= maunium.net/go/tcell v0.2.0 h1:1Q0kN3wCOGAIGu1r3QHADsjSUOPDylKREvCv3EzJpVg= diff --git a/ui/commands.go b/ui/commands.go index 9d38396..6b95ec3 100644 --- a/ui/commands.go +++ b/ui/commands.go @@ -722,6 +722,7 @@ var toggleMsg = map[string]ToggleMessage{ "downloads": SimpleToggleMessage("automatic downloads"), "notifications": SimpleToggleMessage("desktop notifications"), "unverified": SimpleToggleMessage("sending messages to unverified devices"), + "showurls": SimpleToggleMessage("Show text URL"), } func makeUsage() string { @@ -764,6 +765,8 @@ func cmdToggle(cmd *Command) { val = &cmd.Config.Preferences.DisableNotifications case "unverified": val = &cmd.Config.SendToVerifiedOnly + case "showurls": + val = &cmd.Config.Preferences.DisableShowUrls default: cmd.Reply("Unknown toggle %s. Use /toggle without arguments for a list of togglable things.", thing) return diff --git a/ui/messages/html/parser.go b/ui/messages/html/parser.go index 17edc74..3c111fc 100644 --- a/ui/messages/html/parser.go +++ b/ui/messages/html/parser.go @@ -29,6 +29,9 @@ import ( "maunium.net/go/mautrix/event" "maunium.net/go/mautrix/id" + + "maunium.net/go/gomuks/config" + "maunium.net/go/gomuks/debug" "maunium.net/go/tcell" "maunium.net/go/gomuks/matrix/rooms" @@ -40,6 +43,7 @@ var matrixToURL = regexp.MustCompile("^(?:https?://)?(?:www\\.)?matrix\\.to/#/([ type htmlParser struct { room *rooms.Room + Config *config.Config keepLinebreak bool } @@ -160,7 +164,7 @@ func (parser *htmlParser) headerToEntity(node *html.Node) Entity { }, Children: append( []Entity{NewTextEntity(strings.Repeat("#", int(node.Data[1]-'0')) + " ")}, - parser.nodeToEntities(node.FirstChild)... + parser.nodeToEntities(node.FirstChild)..., ), }).AdjustStyle(AdjustStyleBold) } @@ -170,16 +174,31 @@ func (parser *htmlParser) blockquoteToEntity(node *html.Node) Entity { } func (parser *htmlParser) linkToEntity(node *html.Node) Entity { + href := parser.getAttribute(node, "href") + entity := &ContainerEntity{ BaseEntity: &BaseEntity{ Tag: "a", }, Children: parser.nodeToEntities(node.FirstChild), } - href := parser.getAttribute(node, "href") + if len(href) == 0 { return entity } + + debug.Print("here value of parser.config.Preferences.ShowUrls") + + debug.Printf("%v", config.UserPreferences{}.DisableShowUrls) + showurls := config.UserPreferences{}.DisableShowUrls + + if showurls { + entity.Children = append( + []Entity{NewTextEntity("(" + href + ") ")}, + parser.nodeToEntities(node.FirstChild)..., + ) + } + match := matrixToURL.FindStringSubmatch(href) if len(match) == 2 { pillTarget := match[1] @@ -190,7 +209,7 @@ func (parser *htmlParser) linkToEntity(node *html.Node) Entity { text.Style = text.Style.Foreground(widget.GetHashColor(pillTarget)) } entity.Children = []Entity{text} - /*} else if slash := strings.IndexRune(pillTarget, '/'); slash != -1 { + /*} else if slash := strings.IndexRune(pillTarget, '/'); slash != -1 { room := pillTarget[:slash] event := pillTarget[slash+1:]*/ } else if pillTarget[0] == '#' { diff --git a/ui/view-main.go b/ui/view-main.go index fc1b9c9..3bb8a2a 100644 --- a/ui/view-main.go +++ b/ui/view-main.go @@ -33,7 +33,7 @@ import ( "maunium.net/go/gomuks/config" "maunium.net/go/gomuks/debug" - "maunium.net/go/gomuks/interface" + ifc "maunium.net/go/gomuks/interface" "maunium.net/go/gomuks/lib/notification" "maunium.net/go/gomuks/matrix/rooms" "maunium.net/go/gomuks/ui/widget"