From 5211e5a6152abd85eee1fe602ad27fb459f5e700 Mon Sep 17 00:00:00 2001 From: zhaoYangguang <1163765691@qq.com> Date: Mon, 25 Jan 2021 20:19:34 +0800 Subject: [PATCH] add "server_name" to config.yaml --- config/config.go | 1 + example-config.yaml | 2 ++ formatting.go | 11 ++++++----- portal.go | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/config/config.go b/config/config.go index fb19b7d..b999fd7 100644 --- a/config/config.go +++ b/config/config.go @@ -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 { diff --git a/example-config.yaml b/example-config.yaml index d0c4d59..4069c05 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -4,6 +4,8 @@ homeserver: address: https://example.com # The domain of the homeserver (for MXIDs, etc). domain: example.com + # If you don’t 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. diff --git a/formatting.go b/formatting.go index 1ef6bd0..8940f3e 100644 --- a/formatting.go +++ b/formatting.go @@ -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(`
In reply to %s
%s
`, 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(`%s:`, 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(`%s:`, 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 diff --git a/portal.go b/portal.go index ab46068..0bd0ffb 100644 --- a/portal.go +++ b/portal.go @@ -2042,7 +2042,7 @@ func (portal *Portal) convertMatrixMessageSkype(sender *User, evt *event.Event) } // mention user message - r := regexp.MustCompile(`(?m)]+\bhref="(.*?)://` + portal.bridge.Config.Homeserver.Domain + `/#/@([^"]+):(.*?)">(.*?)`) + r := regexp.MustCompile(`(?m)]+\bhref="(.*?)://` + portal.bridge.Config.Homeserver.ServerName + `/#/@([^"]+):(.*?)">(.*?)`) matches := r.FindAllStringSubmatch(matchStr, -1) fmt.Println("matches: ", matches) if len(matches) > 0 {