add "server_name" to config.yaml

This commit is contained in:
zhaoYangguang 2021-01-25 20:19:34 +08:00
parent f73a475132
commit 5211e5a615
4 changed files with 10 additions and 6 deletions

View File

@ -29,6 +29,7 @@ type Config struct {
Homeserver struct {
Address string `yaml:"address"`
Domain string `yaml:"domain"`
ServerName string `yaml:"server_name"`
} `yaml:"homeserver"`
AppService struct {

View File

@ -4,6 +4,8 @@ homeserver:
address: https://example.com
# The domain of the homeserver (for MXIDs, etc).
domain: example.com
# If you dont know what this is, no need to modify(for parse "mention user/reply message, etc")
server_name: matrix.to
# Application service host/registration related details.
# Changing these values requires regeneration of the registration.

View File

@ -138,8 +138,8 @@ func (formatter *Formatter) ParseSkype(content *event.MessageEventContent, RoomM
msgMXID = string(msg.MXID)
}
mxid, _ = formatter.getMatrixInfoByJID("8:" + match[1] + skypeExt.NewUserSuffix)
href1 := fmt.Sprintf(`https://%s/#/room/%s/%s?via=%s`, formatter.bridge.Config.Homeserver.Domain, RoomMXID, msgMXID, formatter.bridge.Config.Homeserver.Domain)
href2 := fmt.Sprintf(`https://%s/#/user/%s`, formatter.bridge.Config.Homeserver.Domain, mxid)
href1 := fmt.Sprintf(`https://%s/#/room/%s/%s?via=%s`, formatter.bridge.Config.Homeserver.ServerName, RoomMXID, msgMXID, formatter.bridge.Config.Homeserver.Domain)
href2 := fmt.Sprintf(`https://%s/#/user/%s`, formatter.bridge.Config.Homeserver.ServerName, mxid)
newContent := fmt.Sprintf(`<mx-reply><blockquote><a href="%s">In reply to</a> <a href="%s">%s</a><br>%s</blockquote></mx-reply>`,
href1,
href2,
@ -170,9 +170,10 @@ func (formatter *Formatter) ParseSkype(content *event.MessageEventContent, RoomM
if len(matches) > 0 {
for _, match := range matches {
mxid, displayname := formatter.getMatrixInfoByJID(match[1] + skypeExt.NewUserSuffix)
number := "@" + strings.Replace(match[1], skypeExt.NewUserSuffix, "", 1)
originStr = strings.ReplaceAll(originStr, match[0], fmt.Sprintf(`<a href="https://%s/#/%s">%s</a>:`, formatter.bridge.Config.Homeserver.Domain, mxid, displayname))
originBodyStr = strings.Replace(originStr, number, displayname, -1)
// number := "@" + strings.Replace(match[1], skypeExt.NewUserSuffix, "", 1)
replaceStr := fmt.Sprintf(`<a href="https://%s/#/%s">%s</a>:`, formatter.bridge.Config.Homeserver.ServerName, mxid, displayname)
originStr = strings.ReplaceAll(originStr, match[0], replaceStr)
originBodyStr = strings.ReplaceAll(originStr, replaceStr, displayname + ":")
}
if len(backStr) == 0 {
content.Format = event.FormatHTML

View File

@ -2042,7 +2042,7 @@ func (portal *Portal) convertMatrixMessageSkype(sender *User, evt *event.Event)
}
// mention user message
r := regexp.MustCompile(`(?m)<a[^>]+\bhref="(.*?)://` + portal.bridge.Config.Homeserver.Domain + `/#/@([^"]+):(.*?)">(.*?)</a>`)
r := regexp.MustCompile(`(?m)<a[^>]+\bhref="(.*?)://` + portal.bridge.Config.Homeserver.ServerName + `/#/@([^"]+):(.*?)">(.*?)</a>`)
matches := r.FindAllStringSubmatch(matchStr, -1)
fmt.Println("matches: ", matches)
if len(matches) > 0 {