fix mention user

This commit is contained in:
zhaoYangguang 2021-01-12 20:17:11 +08:00
parent 93d7ad0501
commit 989cb80899
2 changed files with 13 additions and 8 deletions

View File

@ -81,7 +81,8 @@ func NewFormatter(bridge *Bridge) *Formatter {
},
mentionRegex: func(str string) string {
mxid, displayname := formatter.getMatrixInfoByJID(str[1:] + skypeExt.NewUserSuffix)
return fmt.Sprintf(`<a href="https://matrix.to/#/%s">%s</a>`, mxid, displayname)
mxid = id.UserID(html.EscapeString(string(mxid)))
return fmt.Sprintf(`<a href="https://%s/#/%s">%s</a>:`, bridge.Config.Homeserver.Domain, mxid, displayname)
},
}
formatter.waReplFuncText = map[*regexp.Regexp]func(string) string{
@ -96,7 +97,8 @@ func NewFormatter(bridge *Bridge) *Formatter {
}
}
//mxid, displayname := formatter.getMatrixInfoByJID(str[1:] + whatsappExt.NewUserSuffix)
return fmt.Sprintf(`<a href="https://matrix.to/#/%s">%s</a>`, mxid, displayname)
mxid = id.UserID(html.EscapeString(string(mxid)))
return fmt.Sprintf(`<a href="https://%s/#/%s">%s</a>:`, bridge.Config.Homeserver.Domain, mxid, displayname)
// _, displayname = formatter.getMatrixInfoByJID(str[1:] + whatsappExt.NewUserSuffix)
//fmt.Println("ParseWhatsAp4", displayname)
//return displayname
@ -136,7 +138,7 @@ func (formatter *Formatter) ParseSkype(content *event.MessageEventContent) {
if len(matches) > 0 {
for _, match := range matches {
mxid, displayname = formatter.getMatrixInfoByJID(match[1] + skypeExt.NewUserSuffix)
content.FormattedBody = strings.ReplaceAll(content.Body, match[0], fmt.Sprintf(`<a href="https://matrix.to/#/%s">%s</a>`, mxid, displayname))
content.FormattedBody = strings.ReplaceAll(content.Body, match[0], fmt.Sprintf(`<a href="https://%s/#/%s">%s</a>:`, formatter.bridge.Config.Homeserver.Domain, mxid, displayname))
content.Body = content.FormattedBody
}
}
@ -151,7 +153,7 @@ func (formatter *Formatter) ParseSkype(content *event.MessageEventContent) {
//href1 := fmt.Sprintf(`https://matrix.to/#/!kpouCkfhzvXgbIJmkP:oliver.matrix.host/$fHQNRydqqqAVS8usHRmXn0nIBM_FC-lo2wI2Uol7wu8?via=oliver.matrix.host`)
href1 := ""
//mxid `@skype&8-live-xxxxxx:name.matrix.server`
href2 := fmt.Sprintf(`https://matrix.to/#/%s`, mxid)
href2 := fmt.Sprintf(`https://%s/#/%s`, formatter.bridge.Config.Homeserver.Domain, mxid)
newContent := fmt.Sprintf(`<mx-reply><blockquote><a href="%s"></a> <a href="%s">%s</a><br>%s</blockquote></mx-reply>%s`,
href1,
href2,

View File

@ -1895,7 +1895,7 @@ func (portal *Portal) convertMatrixMessageSkype(sender *User, evt *event.Event)
//replyToID := content.GetReplyTo()
var newContent string
//if len(replyToID) > 0 {
rQuote := regexp.MustCompile(`<mx-reply><blockquote><a[^>]+\bhref="(.*?)://matrix\.to/#/@([^"]+):(.*?)">(.*?)<br>([^"]+)</blockquote></mx-reply>(.*)`)
rQuote := regexp.MustCompile(`<mx-reply><blockquote><a[^>]+\bhref="(.*?)://` + portal.bridge.Config.Homeserver.Domain + `/#/@([^"]+):(.*?)">(.*?)<br>([^"]+)</blockquote></mx-reply>(.*)`)
quoteMatches := rQuote.FindAllStringSubmatch(content.FormattedBody, -1)
fmt.Println("matches0: ", content.FormattedBody)
fmt.Println("matches1: ", quoteMatches)
@ -1904,7 +1904,7 @@ func (portal *Portal) convertMatrixMessageSkype(sender *User, evt *event.Event)
if len(match) > 2 {
var skyId string
if strings.Index(match[4], "@skype") > -1 {
skyId = strings.ReplaceAll(match[2], "skype&amp;", "")
skyId = patch.ParseLocalPart(html.UnescapeString(match[2]), false)
skyId = strings.ReplaceAll(skyId, "skype&", "")
skyId = strings.ReplaceAll(skyId, "-", ":")
} else {
@ -1970,13 +1970,16 @@ func (portal *Portal) convertMatrixMessageSkype(sender *User, evt *event.Event)
text = "/me " + text
}
if len(content.FormattedBody) > 0 {
r := regexp.MustCompile(`<a[^>]+\bhref="(.*?)://matrix\.to/#/@skype&amp;([^"]+):(.*?)">(.*?)</a>*`)
//r := regexp.MustCompile(`<a[^>]+\bhref="(.*?)://` + portal.bridge.Config.Homeserver.Domain + `/#/@skype&amp;([^"]+):(.*?)">(.*?)</a>*`)
r := regexp.MustCompile(`<a[^>]+\bhref="(.*?)://` + portal.bridge.Config.Homeserver.Domain + `/#/@([^"]+):(.*?)">(.*?)</a>*`)
matches := r.FindAllStringSubmatch(content.FormattedBody, -1)
fmt.Println("matches: ", matches)
if len(matches) > 0 {
for _, match := range matches {
if len(match) > 2 {
skyId := strings.ReplaceAll(match[2], "-", ":")
skyId := patch.ParseLocalPart(html.UnescapeString(match[2]), false)
skyId = strings.ReplaceAll(skyId, "skype&", "")
skyId = strings.ReplaceAll(skyId, "-", ":")
content.FormattedBody = strings.ReplaceAll(content.FormattedBody, match[0], fmt.Sprintf(`<at id="%s">%s</at>`, skyId, match[4]))
}
}