first changes to show urls

This commit is contained in:
ReK2 2020-08-15 06:59:02 +02:00
parent 0d12947b1f
commit 2a1329d981
5 changed files with 28 additions and 4 deletions

View File

@ -50,6 +50,7 @@ type UserPreferences struct {
DisableHTML bool `yaml:"disable_html"` DisableHTML bool `yaml:"disable_html"`
DisableDownloads bool `yaml:"disable_downloads"` DisableDownloads bool `yaml:"disable_downloads"`
DisableNotifications bool `yaml:"disable_notifications"` DisableNotifications bool `yaml:"disable_notifications"`
DisableShowUrls bool `yaml:"disable_show_urls"`
} }
// Config contains the main config of gomuks. // Config contains the main config of gomuks.

1
go.sum
View File

@ -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.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 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-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 h1:wfTXyPx3LGAGpTskh+UbBv/QItUWnEpaneHmywoYnfY=
maunium.net/go/mauview v0.1.1/go.mod h1:3QBUiuLct9moP1LgDhCGIg0Ovxn38Bd2sGndnUOuj4o= maunium.net/go/mauview v0.1.1/go.mod h1:3QBUiuLct9moP1LgDhCGIg0Ovxn38Bd2sGndnUOuj4o=
maunium.net/go/tcell v0.2.0 h1:1Q0kN3wCOGAIGu1r3QHADsjSUOPDylKREvCv3EzJpVg= maunium.net/go/tcell v0.2.0 h1:1Q0kN3wCOGAIGu1r3QHADsjSUOPDylKREvCv3EzJpVg=

View File

@ -722,6 +722,7 @@ var toggleMsg = map[string]ToggleMessage{
"downloads": SimpleToggleMessage("automatic downloads"), "downloads": SimpleToggleMessage("automatic downloads"),
"notifications": SimpleToggleMessage("desktop notifications"), "notifications": SimpleToggleMessage("desktop notifications"),
"unverified": SimpleToggleMessage("sending messages to unverified devices"), "unverified": SimpleToggleMessage("sending messages to unverified devices"),
"showurls": SimpleToggleMessage("Show text URL"),
} }
func makeUsage() string { func makeUsage() string {
@ -764,6 +765,8 @@ func cmdToggle(cmd *Command) {
val = &cmd.Config.Preferences.DisableNotifications val = &cmd.Config.Preferences.DisableNotifications
case "unverified": case "unverified":
val = &cmd.Config.SendToVerifiedOnly val = &cmd.Config.SendToVerifiedOnly
case "showurls":
val = &cmd.Config.Preferences.DisableShowUrls
default: default:
cmd.Reply("Unknown toggle %s. Use /toggle without arguments for a list of togglable things.", thing) cmd.Reply("Unknown toggle %s. Use /toggle without arguments for a list of togglable things.", thing)
return return

View File

@ -29,6 +29,9 @@ import (
"maunium.net/go/mautrix/event" "maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id" "maunium.net/go/mautrix/id"
"maunium.net/go/gomuks/config"
"maunium.net/go/gomuks/debug"
"maunium.net/go/tcell" "maunium.net/go/tcell"
"maunium.net/go/gomuks/matrix/rooms" "maunium.net/go/gomuks/matrix/rooms"
@ -40,6 +43,7 @@ var matrixToURL = regexp.MustCompile("^(?:https?://)?(?:www\\.)?matrix\\.to/#/([
type htmlParser struct { type htmlParser struct {
room *rooms.Room room *rooms.Room
Config *config.Config
keepLinebreak bool keepLinebreak bool
} }
@ -160,7 +164,7 @@ func (parser *htmlParser) headerToEntity(node *html.Node) Entity {
}, },
Children: append( Children: append(
[]Entity{NewTextEntity(strings.Repeat("#", int(node.Data[1]-'0')) + " ")}, []Entity{NewTextEntity(strings.Repeat("#", int(node.Data[1]-'0')) + " ")},
parser.nodeToEntities(node.FirstChild)... parser.nodeToEntities(node.FirstChild)...,
), ),
}).AdjustStyle(AdjustStyleBold) }).AdjustStyle(AdjustStyleBold)
} }
@ -170,16 +174,31 @@ func (parser *htmlParser) blockquoteToEntity(node *html.Node) Entity {
} }
func (parser *htmlParser) linkToEntity(node *html.Node) Entity { func (parser *htmlParser) linkToEntity(node *html.Node) Entity {
href := parser.getAttribute(node, "href")
entity := &ContainerEntity{ entity := &ContainerEntity{
BaseEntity: &BaseEntity{ BaseEntity: &BaseEntity{
Tag: "a", Tag: "a",
}, },
Children: parser.nodeToEntities(node.FirstChild), Children: parser.nodeToEntities(node.FirstChild),
} }
href := parser.getAttribute(node, "href")
if len(href) == 0 { if len(href) == 0 {
return entity 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) match := matrixToURL.FindStringSubmatch(href)
if len(match) == 2 { if len(match) == 2 {
pillTarget := match[1] pillTarget := match[1]

View File

@ -33,7 +33,7 @@ import (
"maunium.net/go/gomuks/config" "maunium.net/go/gomuks/config"
"maunium.net/go/gomuks/debug" "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/lib/notification"
"maunium.net/go/gomuks/matrix/rooms" "maunium.net/go/gomuks/matrix/rooms"
"maunium.net/go/gomuks/ui/widget" "maunium.net/go/gomuks/ui/widget"