Merge branch 'develop' into kelare-develop

This commit is contained in:
zhaoYangguang 2021-11-16 18:03:18 +08:00
commit 5c1efc6c6d
2 changed files with 61 additions and 75 deletions

View File

@ -2,14 +2,13 @@ package main
import ( import (
"bytes" "bytes"
"github.com/gabriel-vasile/mimetype" "github.com/gabriel-vasile/mimetype"
"maunium.net/go/mautrix/patch" "maunium.net/go/mautrix/patch"
"encoding/hex" "encoding/hex"
"encoding/xml" "encoding/xml"
"fmt" "fmt"
skype "github.com/kelaresg/go-skypeapi"
skypeExt "github.com/kelaresg/matrix-skype/skype-ext"
"html" "html"
"image" "image"
"image/gif" "image/gif"
@ -24,6 +23,9 @@ import (
"sync" "sync"
"time" "time"
skype "github.com/kelaresg/go-skypeapi"
skypeExt "github.com/kelaresg/matrix-skype/skype-ext"
"github.com/pkg/errors" "github.com/pkg/errors"
log "maunium.net/go/maulogger/v2" log "maunium.net/go/maulogger/v2"
"maunium.net/go/mautrix" "maunium.net/go/mautrix"
@ -1723,13 +1725,7 @@ func (portal *Portal) HandleMediaMessageSkype(source *User, download func(conn *
} else { } else {
content.URL = uploaded.ContentURI.CUString() content.URL = uploaded.ContentURI.CUString()
} }
// portal.SetReplySkype(content, info)
fmt.Println()
fmt.Println("mediaMessage.UrlThumbnail", mediaMessage.UrlThumbnail)
fmt.Println()
fmt.Printf("%+v", mediaMessage)
fmt.Println()
thumbnail, err = skype.Download(mediaMessage.UrlThumbnail, source.Conn.Conn, 0) thumbnail, err = skype.Download(mediaMessage.UrlThumbnail, source.Conn.Conn, 0)
if err != nil { if err != nil {
portal.log.Errorfln("Failed to download thumbnail for %s: %v", err) portal.log.Errorfln("Failed to download thumbnail for %s: %v", err)
@ -1756,14 +1752,6 @@ func (portal *Portal) HandleMediaMessageSkype(source *User, download func(conn *
Height: thumbnailCfg.Height, Height: thumbnailCfg.Height,
MimeType: thumbnailMime, MimeType: thumbnailMime,
} }
fmt.Println("content.Info")
fmt.Printf("%+v", content)
fmt.Println()
fmt.Printf("%+v", *content.Info.ThumbnailInfo)
fmt.Println()
fmt.Println()
fmt.Printf("%+v", content.Info.ThumbnailInfo)
fmt.Println()
} }
} }
@ -2056,11 +2044,10 @@ func (portal *Portal) convertMatrixMessageSkype(sender *User, evt *event.Event)
if evt.Type == event.EventSticker { if evt.Type == event.EventSticker {
content.MsgType = event.MsgImage content.MsgType = event.MsgImage
} }
portal.log.Debugln("convertMatrixMessage content.MsgType: ", content.MsgType)
fmt.Println("convertMatrixMessage content.MsgType: ", content.MsgType) portal.log.Debugln("convertMatrixMessage content.Body: ", content.Body)
fmt.Println("convertMatrixMessage content.Body: ", content.Body) portal.log.Debugln("convertMatrixMessage content.NewBody: ", content.NewContent)
fmt.Println("convertMatrixMessage content.NewBody: ", content.NewContent) portal.log.Debugln("convertMatrixMessage content.FormattedBody: ", content.FormattedBody)
fmt.Println("convertMatrixMessage content.FormattedBody: ", content.FormattedBody)
info.Type = string(content.MsgType) info.Type = string(content.MsgType)
switch content.MsgType { switch content.MsgType {
case event.MsgText, event.MsgEmote, event.MsgNotice: case event.MsgText, event.MsgEmote, event.MsgNotice:
@ -2080,12 +2067,12 @@ func (portal *Portal) convertMatrixMessageSkype(sender *User, evt *event.Event)
// mention user message // mention user message
r := regexp.MustCompile(`(?m)<a[^>]+\bhref="(.*?)://` + portal.bridge.Config.Homeserver.ServerName + `/#/@([^"]+):(.*?)">(.*?)</a>`) r := regexp.MustCompile(`(?m)<a[^>]+\bhref="(.*?)://` + portal.bridge.Config.Homeserver.ServerName + `/#/@([^"]+):(.*?)">(.*?)</a>`)
matches := r.FindAllStringSubmatch(matchStr, -1) matches := r.FindAllStringSubmatch(matchStr, -1)
fmt.Println("matches: ", matches) portal.log.Debugln("matches: ", matches)
if len(matches) > 0 { if len(matches) > 0 {
for _, match := range matches { for _, match := range matches {
if len(match) > 2 { if len(match) > 2 {
skyId := patch.ParseLocalPart(html.UnescapeString(match[2]), false) skyId := patch.ParseLocalPart(html.UnescapeString(match[2]), false)
skyId = strings.ReplaceAll(skyId, "skype&", "") skyId = strings.ReplaceAll(skyId, patch.AsUserPrefix, "")
skyId = strings.ReplaceAll(skyId, "-", ":") skyId = strings.ReplaceAll(skyId, "-", ":")
// Adapt to the message format sent by the matrix front end // Adapt to the message format sent by the matrix front end
matchStr = strings.ReplaceAll(matchStr, match[0]+":", fmt.Sprintf(`<at id="%s">%s</at>`, skyId, match[4])) matchStr = strings.ReplaceAll(matchStr, match[0]+":", fmt.Sprintf(`<at id="%s">%s</at>`, skyId, match[4]))
@ -2197,11 +2184,10 @@ func (portal *Portal) sendDeliveryReceipt(eventID id.EventID) {
var timeout = errors.New("message sending timed out") var timeout = errors.New("message sending timed out")
func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event) { func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event) {
fmt.Println("portal HandleMatrixMessage sender.JID: ", sender.JID) portal.log.Debugln("HandleMatrixMessage sender.JID: ", sender.JID)
fmt.Println("portal HandleMatrixMessage portal.Key.Receiver: ", portal.Key.Receiver) portal.log.Debugln("HandleMatrixMessage portal.Key.Receiver: ", portal.Key.Receiver)
fmt.Println("portal HandleMatrixMessage portal.Key.JID: ", portal.Key.JID) portal.log.Debugln("HandleMatrixMessage portal.Key.JID: ", portal.Key.JID)
if !portal.HasRelaybot() && ( if !portal.HasRelaybot() && ((portal.IsPrivateChat() && sender.JID != portal.Key.Receiver) ||
(portal.IsPrivateChat() && sender.JID != portal.Key.Receiver) ||
portal.sendMatrixConnectionError(sender, evt.ID)) { portal.sendMatrixConnectionError(sender, evt.ID)) {
return return
} }