Merge branch 'develop'
This commit is contained in:
commit
7ea55b8e70
18
commands.go
18
commands.go
|
@ -251,6 +251,7 @@ func (handler *CommandHandler) CommandLogout(ce *CommandEvent) {
|
|||
if ce.User.Conn == nil {
|
||||
return
|
||||
}
|
||||
_ = ce.User.Conn.GetConversations("", ce.User.bridge.Config.Bridge.InitialChatSync)
|
||||
ce.User.Conn.LoggedIn = false
|
||||
username := ""
|
||||
password := ""
|
||||
|
@ -269,7 +270,22 @@ func (handler *CommandHandler) CommandLogout(ce *CommandEvent) {
|
|||
Username: username,
|
||||
Password: password,
|
||||
}
|
||||
|
||||
portals := ce.User.GetPortals()
|
||||
newPortals := ce.User.GetPortalsNew()
|
||||
allPortals := newPortals[0:]
|
||||
for _, portal := range portals {
|
||||
var newPortalsHas bool
|
||||
for _, newPortal := range newPortals {
|
||||
if portal.Key == newPortal.Key {
|
||||
newPortalsHas = true
|
||||
}
|
||||
}
|
||||
if !newPortalsHas {
|
||||
allPortals = append(allPortals, portal)
|
||||
}
|
||||
}
|
||||
|
||||
leave := func(portal *Portal) {
|
||||
if len(portal.MXID) > 0 {
|
||||
_, _ = portal.MainIntent().KickUser(portal.MXID, &mautrix.ReqKickUser{
|
||||
|
@ -278,7 +294,7 @@ func (handler *CommandHandler) CommandLogout(ce *CommandEvent) {
|
|||
})
|
||||
}
|
||||
}
|
||||
for _, portal := range portals {
|
||||
for _, portal := range allPortals {
|
||||
leave(portal)
|
||||
}
|
||||
ce.Reply("Logged out successfully.")
|
||||
|
|
|
@ -186,6 +186,16 @@ func (formatter *Formatter) ParseSkype(content *event.MessageEventContent, RoomM
|
|||
content.Body = content.Body + backStr
|
||||
content.FormattedBody = content.FormattedBody + backStr
|
||||
}
|
||||
|
||||
//filter edit tag
|
||||
e := regexp.MustCompile(`(<e_m a=".*></e_m>)`)
|
||||
editMatches := e.FindAllStringSubmatch(content.Body, -1)
|
||||
if len(editMatches) > 0 {
|
||||
for _, match := range editMatches {
|
||||
content.Body = strings.ReplaceAll(content.Body, match[0], "")
|
||||
content.FormattedBody = strings.ReplaceAll(content.FormattedBody, match[0], "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (formatter *Formatter) ParseMatrix(html string) string {
|
||||
|
|
3
go.mod
3
go.mod
|
@ -5,11 +5,10 @@ go 1.14
|
|||
require (
|
||||
github.com/chai2010/webp v1.1.0
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
github.com/kelaresg/go-skypeapi v0.1.2-0.20201211120317-8651f9f08575
|
||||
github.com/kelaresg/go-skypeapi v0.1.2-0.20210120095455-33c3f50415c4
|
||||
github.com/lib/pq v1.7.0
|
||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||
golang.org/x/image v0.0.0-20200618115811-c13761719519
|
||||
gopkg.in/yaml.v2 v2.3.0
|
||||
|
|
6
go.sum
6
go.sum
|
@ -156,6 +156,10 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV
|
|||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||
github.com/kelaresg/go-skypeapi v0.1.2-0.20201126103218-226d1ec92858 h1:dHavsrpbaOA/fqwB39zndM1uHIy84EDKhldWajIcfJg=
|
||||
github.com/kelaresg/go-skypeapi v0.1.2-0.20201126103218-226d1ec92858/go.mod h1:2Mxwa2Flo+PKlVYEM4QBNgs408C/mUSBXRzAb6+B+Zg=
|
||||
github.com/kelaresg/go-skypeapi v0.1.2-0.20201211120317-8651f9f08575 h1:4M0mtPS+W+In2sjh/g+/gfagn7mMG6igvMOLl2zgiKc=
|
||||
github.com/kelaresg/go-skypeapi v0.1.2-0.20201211120317-8651f9f08575/go.mod h1:2Mxwa2Flo+PKlVYEM4QBNgs408C/mUSBXRzAb6+B+Zg=
|
||||
github.com/kelaresg/go-skypeapi v0.1.2-0.20210120095455-33c3f50415c4 h1:8tif5ndoTRHAOj4j2Ump9uyDaKoQ/W17dJ2K36G418U=
|
||||
github.com/kelaresg/go-skypeapi v0.1.2-0.20210120095455-33c3f50415c4/go.mod h1:2Mxwa2Flo+PKlVYEM4QBNgs408C/mUSBXRzAb6+B+Zg=
|
||||
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
|
||||
|
@ -214,6 +218,8 @@ github.com/pidongqianqian/mautrix-go v0.7.3-0.20201126040927-dbde233d88f6 h1:A2W
|
|||
github.com/pidongqianqian/mautrix-go v0.7.3-0.20201126040927-dbde233d88f6/go.mod h1:TtVePxoEaw6+RZDKVajw66Yaj1lqLjH8l4FF3krsqWY=
|
||||
github.com/pidongqianqian/mautrix-go v0.8.0-rc.4.0.20201126070406-7b13ac473bcc h1:wXc6kSKzzYrLgqJwaCgJvKZc4Qfq85/3TivSItUFuNk=
|
||||
github.com/pidongqianqian/mautrix-go v0.8.0-rc.4.0.20201126070406-7b13ac473bcc/go.mod h1:TtVePxoEaw6+RZDKVajw66Yaj1lqLjH8l4FF3krsqWY=
|
||||
github.com/pidongqianqian/mautrix-go v0.8.0-rc.4.0.20201208081810-787323a21113 h1:tetxcECwIGgb7Gl4AyY/9+MXmuUfp33FweuGU/Bb7AM=
|
||||
github.com/pidongqianqian/mautrix-go v0.8.0-rc.4.0.20201208081810-787323a21113/go.mod h1:TtVePxoEaw6+RZDKVajw66Yaj1lqLjH8l4FF3krsqWY=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
|
|
89
portal.go
89
portal.go
|
@ -216,9 +216,6 @@ func (portal *Portal) handleMessage(msg PortalMessage) {
|
|||
default:
|
||||
portal.log.Warnln("Unknown message type:", reflect.TypeOf(msg.data))
|
||||
}
|
||||
if data.MessageType == "RichText" || data.MessageType == "Text" {
|
||||
portal.HandleTextMessage(msg.source, data)
|
||||
}
|
||||
} else {
|
||||
portal.log.Warnln("Unknown message type:", reflect.TypeOf(msg.data))
|
||||
}
|
||||
|
@ -1341,7 +1338,8 @@ func (portal *Portal) HandleMessageRevokeSkype(user *User, message skype.Resourc
|
|||
if message.GetFromMe(user.Conn.Conn) {
|
||||
if portal.IsPrivateChat() {
|
||||
intent = portal.bridge.GetPuppetByJID(user.JID).CustomIntent()
|
||||
} else {
|
||||
}
|
||||
if intent == nil {
|
||||
intent = portal.bridge.GetPuppetByJID(user.JID).IntentFor(portal)
|
||||
}
|
||||
}
|
||||
|
@ -1461,6 +1459,25 @@ func (portal *Portal) HandleTextMessage(source *User, message skype.Resource) {
|
|||
}
|
||||
|
||||
portal.bridge.Formatter.ParseSkype(content, portal.MXID)
|
||||
|
||||
// reedit message
|
||||
if len(message.SkypeEditedId) > 0 {
|
||||
message.ClientMessageId = message.SkypeEditedId + message.Id
|
||||
msg := source.bridge.DB.Message.GetByJID(portal.Key, message.SkypeEditedId)
|
||||
if msg != nil && len(msg.MXID) > 0 {
|
||||
inRelateTo := &event.RelatesTo{
|
||||
Type: event.RelReplace,
|
||||
EventID: msg.MXID,
|
||||
}
|
||||
content.SetRelatesTo(inRelateTo)
|
||||
content.NewContent = &event.MessageEventContent{
|
||||
MsgType: content.MsgType,
|
||||
Body: content.Body,
|
||||
FormattedBody: content.FormattedBody,
|
||||
Format: content.Format,
|
||||
}
|
||||
}
|
||||
}
|
||||
// portal.SetReplySkype(content, message)
|
||||
|
||||
fmt.Println()
|
||||
|
@ -1898,8 +1915,52 @@ func (portal *Portal) convertMatrixMessageSkype(sender *User, evt *event.Event)
|
|||
Jid: portal.Key.JID,//receiver id(conversation id)
|
||||
Timestamp: time.Now().Unix(),
|
||||
}
|
||||
//ctxInfo := &waProto.ContextInfo{}
|
||||
|
||||
replyToID := content.GetReplyTo()
|
||||
|
||||
// reedit message
|
||||
if content.NewContent != nil {
|
||||
a := strings.Replace(sender.JID, skypeExt.NewUserSuffix, "", 1)
|
||||
a = strings.Replace(a, "8:", "", 1)
|
||||
tsMs := strconv.FormatInt(time.Now().UnixNano()/1e6, 10)
|
||||
r := []rune(tsMs)
|
||||
ts := string(r[:len(r) - 3])
|
||||
msg := portal.bridge.DB.Message.GetByMXID(content.RelatesTo.EventID)
|
||||
if msg != nil && len(msg.JID) > 0 {
|
||||
info.SkypeEditedId = msg.JID
|
||||
//info.ClientMessageId = info.ClientMessageId + info.SkypeEditedId
|
||||
content.Body = content.Body + fmt.Sprintf("<e_m a=\"%s\" ts_ms=\"%s\" ts=\"%s\" t=\"61\"></e_m>", a, tsMs, ts)
|
||||
content.Body = strings.TrimPrefix(content.Body, " * ")
|
||||
if len(content.FormattedBody) > 0 {
|
||||
content.FormattedBody = content.FormattedBody + fmt.Sprintf("<e_m a=\"%s\" ts_ms=\"%s\" ts=\"%s\" t=\"61\"></e_m>", a, tsMs, ts)
|
||||
content.FormattedBody = strings.TrimPrefix(content.FormattedBody, " * ")
|
||||
}
|
||||
}
|
||||
|
||||
// in reedit message we can't obtain the "relayId" from RelatesTo.EventID cause the matrix message doesn't put it in "RelatesTo".
|
||||
// so i get relayId with use regexp, but it's not a good way,
|
||||
// now there is no way to get relayId if reedit message with add a mention user
|
||||
// TODO maybe we can record the relayId to DB
|
||||
rQuote := regexp.MustCompile(`<mx-reply><blockquote><a href=".*#/room/` + string(portal.MXID) + `/(.*)\?via=.*">In reply to.*</blockquote></mx-reply>(.*)`)
|
||||
quoteMatches := rQuote.FindAllStringSubmatch(content.FormattedBody, -1)
|
||||
if len(replyToID) < 1 {
|
||||
if len(quoteMatches) > 0 {
|
||||
if len(quoteMatches[0]) > 0 {
|
||||
replyToID = id.EventID(quoteMatches[0][1])
|
||||
}
|
||||
|
||||
//Filter out the " * " in the matrix editing message (i don't why the matrix need a * in the edit message body)
|
||||
if len(quoteMatches[0]) > 1 {
|
||||
needReplace := quoteMatches[0][2]
|
||||
afterReplace := strings.TrimPrefix(needReplace, " * ")
|
||||
content.Body = strings.Replace(content.Body, needReplace, afterReplace, 1)
|
||||
content.FormattedBody = strings.Replace(content.FormattedBody, needReplace, afterReplace, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// reply message
|
||||
var newContent string
|
||||
backStr := ""
|
||||
if len(replyToID) > 0 {
|
||||
|
@ -1959,8 +2020,10 @@ func (portal *Portal) convertMatrixMessageSkype(sender *User, evt *event.Event)
|
|||
if evt.Type == event.EventSticker {
|
||||
content.MsgType = event.MsgImage
|
||||
}
|
||||
|
||||
fmt.Println("convertMatrixMessage content.MsgType: ", content.MsgType)
|
||||
fmt.Println("convertMatrixMessage content.Body: ", content.Body)
|
||||
fmt.Println("convertMatrixMessage content.NewBody: ", content.NewContent)
|
||||
fmt.Println("convertMatrixMessage content.FormattedBody: ", content.FormattedBody)
|
||||
info.Type = string(content.MsgType)
|
||||
switch content.MsgType {
|
||||
|
@ -1977,6 +2040,8 @@ func (portal *Portal) convertMatrixMessageSkype(sender *User, evt *event.Event)
|
|||
if len(backStr) > 0 {
|
||||
matchStr = backStr
|
||||
}
|
||||
|
||||
// mention user message
|
||||
r := regexp.MustCompile(`(?m)<a[^>]+\bhref="(.*?)://` + portal.bridge.Config.Homeserver.Domain + `/#/@([^"]+):(.*?)">(.*?)</a>`)
|
||||
matches := r.FindAllStringSubmatch(matchStr, -1)
|
||||
fmt.Println("matches: ", matches)
|
||||
|
@ -2001,7 +2066,9 @@ func (portal *Portal) convertMatrixMessageSkype(sender *User, evt *event.Event)
|
|||
content.FormattedBody = content.FormattedBody + backStr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(content.FormattedBody) > 0 {
|
||||
info.SendTextMessage = &skype.SendTextMessage{
|
||||
Content : content.FormattedBody,
|
||||
}
|
||||
|
@ -2010,18 +2077,6 @@ func (portal *Portal) convertMatrixMessageSkype(sender *User, evt *event.Event)
|
|||
Content : content.Body,
|
||||
}
|
||||
}
|
||||
//ctxInfo.MentionedJid = mentionRegex.FindAllString(text, -1)
|
||||
//for index, mention := range ctxInfo.MentionedJid {
|
||||
// ctxInfo.MentionedJid[index] = mention[1:] + whatsappExt.NewUserSuffix
|
||||
//}
|
||||
//if ctxInfo.StanzaId != nil || ctxInfo.MentionedJid != nil {
|
||||
// info.Message.ExtendedTextMessage = &waProto.ExtendedTextMessage{
|
||||
// Text: &text,
|
||||
// ContextInfo: ctxInfo,
|
||||
// }
|
||||
//} else {
|
||||
// info.Message.Conversation = &text
|
||||
//}
|
||||
case event.MsgImage:
|
||||
caption, fileSize , data := portal.preprocessMatrixMediaSkype(relaybotFormatted, content, evt.ID)
|
||||
//if media == nil {
|
||||
|
|
24
user.go
24
user.go
|
@ -156,6 +156,28 @@ func (user *User) GetPortals() []*Portal {
|
|||
return portals
|
||||
}
|
||||
|
||||
func (user *User) GetPortalsNew() []*Portal {
|
||||
keys := make([]database.PortalKey, len(user.Conn.Store.Chats))
|
||||
i := 0
|
||||
for jid, _ := range user.Conn.Store.Chats {
|
||||
keys[i] = database.NewPortalKey(jid, user.JID)
|
||||
i++
|
||||
}
|
||||
|
||||
portals := make([]*Portal, len(keys))
|
||||
|
||||
user.bridge.portalsLock.Lock()
|
||||
for i, key := range keys {
|
||||
portal, ok := user.bridge.portalsByJID[key]
|
||||
if !ok {
|
||||
portal = user.bridge.loadDBPortal(user.bridge.DB.Portal.GetByJID(key), &key)
|
||||
}
|
||||
portals[i] = portal
|
||||
}
|
||||
user.bridge.portalsLock.Unlock()
|
||||
return portals
|
||||
}
|
||||
|
||||
func (bridge *Bridge) NewUser(dbUser *database.User) *User {
|
||||
user := &User{
|
||||
User: dbUser,
|
||||
|
@ -394,9 +416,9 @@ func (user *User) Login(ce *CommandEvent, name string, password string) (err err
|
|||
go user.Conn.Poll()
|
||||
|
||||
user.ConnectionErrors = 0
|
||||
user.SetSession(user.Conn.LoginInfo)
|
||||
user.JID = "8:" + user.Conn.UserProfile.Username + skypeExt.NewUserSuffix
|
||||
user.addToJIDMap()
|
||||
user.SetSession(user.Conn.LoginInfo)
|
||||
_ = ce.User.Conn.GetConversations("", user.bridge.Config.Bridge.InitialChatSync)
|
||||
user.PostLogin()
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue