forward message(still need to optimize if have a good idea)
This commit is contained in:
parent
e91fa5506c
commit
6d18d6bb32
|
@ -122,7 +122,7 @@ func (formatter *Formatter) ParseSkype(content *event.MessageEventContent, RoomM
|
||||||
|
|
||||||
// parse quote message(set reply)
|
// parse quote message(set reply)
|
||||||
content.Body = strings.ReplaceAll(content.Body, "\n", "")
|
content.Body = strings.ReplaceAll(content.Body, "\n", "")
|
||||||
quoteReg := regexp.MustCompile(`<quote[^>]+\bauthor="([^"]+)" authorname="([^"]+)" timestamp="([^"]+)" conversation.* messageid="([^"]+)".*>.*?</legacyquote>(.*?)<legacyquote>.*?</legacyquote></quote>(.*)`)
|
quoteReg := regexp.MustCompile(`<quote[^>]+\bauthor="([^"]+)" authorname="([^"]+)" timestamp="([^"]+)" conversation="([^"]+)" messageid="([^"]+)".*>.*?</legacyquote>(.*?)<legacyquote>.*?</legacyquote></quote>(.*)`)
|
||||||
quoteMatches := quoteReg.FindAllStringSubmatch(content.Body, -1)
|
quoteMatches := quoteReg.FindAllStringSubmatch(content.Body, -1)
|
||||||
|
|
||||||
if len(quoteMatches) > 0 {
|
if len(quoteMatches) > 0 {
|
||||||
|
@ -132,8 +132,14 @@ func (formatter *Formatter) ParseSkype(content *event.MessageEventContent, RoomM
|
||||||
fmt.Println("ParseSkype quoteMatches a:", a)
|
fmt.Println("ParseSkype quoteMatches a:", a)
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
|
portal := formatter.bridge.GetPortalByMXID(RoomMXID)
|
||||||
|
if portal.Key.JID != match[4] {
|
||||||
|
content.FormattedBody = match[6]
|
||||||
|
content.Body = fmt.Sprintf("%s\n\n", match[6])
|
||||||
|
continue
|
||||||
|
}
|
||||||
msgMXID := ""
|
msgMXID := ""
|
||||||
msg := formatter.bridge.DB.Message.GetByID(match[4])
|
msg := formatter.bridge.DB.Message.GetByID(match[5])
|
||||||
if msg != nil {
|
if msg != nil {
|
||||||
msgMXID = string(msg.MXID)
|
msgMXID = string(msg.MXID)
|
||||||
}
|
}
|
||||||
|
@ -144,21 +150,21 @@ func (formatter *Formatter) ParseSkype(content *event.MessageEventContent, RoomM
|
||||||
href1,
|
href1,
|
||||||
href2,
|
href2,
|
||||||
mxid,
|
mxid,
|
||||||
match[5])
|
match[6])
|
||||||
content.FormattedBody = newContent
|
content.FormattedBody = newContent
|
||||||
content.Body = fmt.Sprintf("> <%s> %s\n\n", mxid, match[5])
|
content.Body = fmt.Sprintf("> <%s> %s\n\n", mxid, match[6])
|
||||||
inRelateTo := &event.RelatesTo{
|
inRelateTo := &event.RelatesTo{
|
||||||
Type: event.RelReply,
|
Type: event.RelReply,
|
||||||
EventID: id.EventID(msgMXID),
|
EventID: id.EventID(msgMXID),
|
||||||
}
|
}
|
||||||
content.SetRelatesTo(inRelateTo)
|
content.SetRelatesTo(inRelateTo)
|
||||||
backStr = match[6]
|
backStr = match[7]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse mention user message
|
// parse mention user message
|
||||||
r := regexp.MustCompile(`(?m)<at[^>]+\bid="([^"]+)"(.*?)</at>`)
|
r := regexp.MustCompile(`(?m)<at[^>]+\bid="([^"]+)">(.*?)</at>`)
|
||||||
var originStr string
|
var originStr string
|
||||||
var originBodyStr string
|
var originBodyStr string
|
||||||
if len(backStr) == 0 {
|
if len(backStr) == 0 {
|
||||||
|
@ -170,8 +176,14 @@ func (formatter *Formatter) ParseSkype(content *event.MessageEventContent, RoomM
|
||||||
if len(matches) > 0 {
|
if len(matches) > 0 {
|
||||||
for _, match := range matches {
|
for _, match := range matches {
|
||||||
mxid, displayname := formatter.getMatrixInfoByJID(match[1] + skypeExt.NewUserSuffix)
|
mxid, displayname := formatter.getMatrixInfoByJID(match[1] + skypeExt.NewUserSuffix)
|
||||||
|
replaceStr := ""
|
||||||
|
if len(displayname) < 1 {
|
||||||
|
// TODO need to optimize
|
||||||
|
replaceStr = match[2] + ":"
|
||||||
|
} else {
|
||||||
|
replaceStr = fmt.Sprintf(`<a href="https://%s/#/%s">%s</a>:`, formatter.bridge.Config.Homeserver.ServerName, mxid, displayname)
|
||||||
|
}
|
||||||
// number := "@" + strings.Replace(match[1], skypeExt.NewUserSuffix, "", 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)
|
originStr = strings.ReplaceAll(originStr, match[0], replaceStr)
|
||||||
originBodyStr = strings.ReplaceAll(originStr, replaceStr, displayname + ":")
|
originBodyStr = strings.ReplaceAll(originStr, replaceStr, displayname + ":")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue