Convert mentions to names in plaintext body. Fixes #3

This commit is contained in:
Tulir Asokan
2018-08-28 20:09:37 +03:00
parent eca9bc7887
commit 6ad224a58b
3 changed files with 23 additions and 19 deletions

View File

@ -64,7 +64,7 @@ var strikethroughRegex = regexp.MustCompile("([\\s>_*]|^)~(.+?)~([^a-zA-Z\\d]|$)
var codeBlockRegex = regexp.MustCompile("```(?:.|\n)+?```")
var mentionRegex = regexp.MustCompile("@[0-9]+")
func (user *User) newWhatsAppFormatMaps() (map[*regexp.Regexp]string, map[*regexp.Regexp]func(string) string) {
func (user *User) newWhatsAppFormatMaps() (map[*regexp.Regexp]string, map[*regexp.Regexp]func(string) string, map[*regexp.Regexp]func(string) string) {
return map[*regexp.Regexp]string{
italicRegex: "$1<em>$2</em>$3",
boldRegex: "$1<strong>$2</strong>$3",
@ -86,5 +86,10 @@ func (user *User) newWhatsAppFormatMaps() (map[*regexp.Regexp]string, map[*regex
}
return fmt.Sprintf(`<a href="https://matrix.to/#/%s">%s</a>`, mxid, puppet.Displayname)
},
}, map[*regexp.Regexp]func(string)string {
mentionRegex: func(str string) string {
puppet := user.GetPuppetByJID(str[1:] + whatsappExt.NewUserSuffix)
return puppet.Displayname
},
}
}