summaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
authorDellle <39235395+Dellle@users.noreply.github.com>2020-08-20 22:41:53 +0200
committerGitHub <noreply@github.com>2020-08-20 22:41:53 +0200
commit63a1847cdc895a3e968c567c20d20359f0785ce2 (patch)
tree9d41a50401082217a900551699d3e2a26bb3b4f6 /bridge
parent4e50fd864921c556988c919269448efdb90fa961 (diff)
downloadmatterbridge-msglm-63a1847cdc895a3e968c567c20d20359f0785ce2.tar.gz
matterbridge-msglm-63a1847cdc895a3e968c567c20d20359f0785ce2.tar.bz2
matterbridge-msglm-63a1847cdc895a3e968c567c20d20359f0785ce2.zip
Remove HTML formatting for push messages (#1188) (#1189)
When there is a valid HTML formatting then remove this in the cleartext field of the matrix client. This leads to nicer push messages on smartphone apps. Fix #1188
Diffstat (limited to 'bridge')
-rw-r--r--bridge/matrix/matrix.go15
1 files changed, 12 insertions, 3 deletions
diff --git a/bridge/matrix/matrix.go b/bridge/matrix/matrix.go
index 6521fe86..615dcfb7 100644
--- a/bridge/matrix/matrix.go
+++ b/bridge/matrix/matrix.go
@@ -20,13 +20,15 @@ type Bmatrix struct {
UserID string
RoomMap map[string]string
sync.RWMutex
- htmlTag *regexp.Regexp
+ htmlTag *regexp.Regexp
+ htmlReplacementTag *regexp.Regexp
*bridge.Config
}
func New(cfg *bridge.Config) bridge.Bridger {
b := &Bmatrix{Config: cfg}
b.htmlTag = regexp.MustCompile("</.*?>")
+ b.htmlReplacementTag = regexp.MustCompile("<[^>]*>")
b.RoomMap = make(map[string]string)
return b
}
@@ -132,13 +134,20 @@ func (b *Bmatrix) Send(msg config.Message) (string, error) {
return resp.EventID, err
}
- username := html.EscapeString(msg.Username)
+ var username string
+ var plainUsername string
// check if we have a </tag>. if we have, we don't escape HTML. #696
if b.htmlTag.MatchString(msg.Username) {
username = msg.Username
+ // remove the HTML formatting for beautiful push messages #1188
+ plainUsername = b.htmlReplacementTag.ReplaceAllString(msg.Username, "")
+ } else {
+ username = html.EscapeString(msg.Username)
+ plainUsername = msg.Username
}
+
// Post normal message with HTML support (eg riot.im)
- resp, err := b.mc.SendHTML(channel, msg.Username+msg.Text, username+helper.ParseMarkdown(msg.Text))
+ resp, err := b.mc.SendHTML(channel, plainUsername+msg.Text, username+helper.ParseMarkdown(msg.Text))
if err != nil {
return "", err
}