# when a user is not logged in to skype and sends a message in a synchronized matrix room, the program will crash
This commit is contained in:
zhaoYangguang 2021-02-02 19:19:02 +08:00
parent c07674ad63
commit 6fd52056fb
2 changed files with 30 additions and 30 deletions

View File

@ -257,7 +257,7 @@ func (mx *MatrixHandler) HandleMembership(evt *event.Event) {
} }
user := mx.bridge.GetUserByMXID(evt.Sender) user := mx.bridge.GetUserByMXID(evt.Sender)
if user == nil || user.Conn == nil || !user.Whitelisted || !user.IsConnected() { if user == nil || user.Conn == nil || user.Conn.LoginInfo == nil || !user.Whitelisted || !user.IsConnected() {
return return
} }
@ -307,7 +307,7 @@ func (mx *MatrixHandler) HandleRoomMetadata(evt *event.Event) {
} }
portal := mx.bridge.GetPortalByMXID(evt.RoomID) portal := mx.bridge.GetPortalByMXID(evt.RoomID)
if user.Conn == nil || portal == nil || portal.IsPrivateChat() { if user.Conn == nil || user.Conn.LoginInfo == nil || portal == nil || portal.IsPrivateChat() {
return return
} }
@ -449,7 +449,7 @@ func (mx *MatrixHandler) HandleRedaction(evt *event.Event) {
} }
portal := mx.bridge.GetPortalByMXID(evt.RoomID) portal := mx.bridge.GetPortalByMXID(evt.RoomID)
if user.Conn != nil && portal != nil { if user.Conn != nil && user.Conn.LoginInfo != nil && portal != nil {
portal.HandleMatrixRedaction(user, evt) portal.HandleMatrixRedaction(user, evt)
} }
} }

View File

@ -1420,8 +1420,8 @@ func (portal *Portal) sendMessage(intent *appservice.IntentAPI, eventType event.
"net.maunium.whatsapp.puppet": intent.IsCustomPuppet, "net.maunium.whatsapp.puppet": intent.IsCustomPuppet,
} }
} }
fmt.Println() fmt.Println("portal sendMessage timestamp:", timestamp)
fmt.Printf("portal sendMessage0: %+v", content) fmt.Printf("portal sendMessage: %+v", content)
if portal.Encrypted && portal.bridge.Crypto != nil { if portal.Encrypted && portal.bridge.Crypto != nil {
encrypted, err := portal.bridge.Crypto.Encrypt(portal.MXID, eventType, wrappedContent) encrypted, err := portal.bridge.Crypto.Encrypt(portal.MXID, eventType, wrappedContent)
if err != nil { if err != nil {
@ -1431,12 +1431,8 @@ func (portal *Portal) sendMessage(intent *appservice.IntentAPI, eventType event.
wrappedContent.Parsed = encrypted wrappedContent.Parsed = encrypted
} }
if timestamp == 0 { if timestamp == 0 {
fmt.Println()
fmt.Printf("portal sendMessage1: %+v", content)
return intent.SendMessageEvent(portal.MXID, eventType, &wrappedContent) return intent.SendMessageEvent(portal.MXID, eventType, &wrappedContent)
} else { } else {
fmt.Println()
fmt.Printf("portal sendMessage2: %+v", content)
return intent.SendMassagedMessageEvent(portal.MXID, eventType, &wrappedContent, timestamp) return intent.SendMassagedMessageEvent(portal.MXID, eventType, &wrappedContent, timestamp)
} }
} }
@ -2226,30 +2222,34 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event) {
func SendMsg(sender *User, chatThreadId string, content *skype.SendMessage, output chan<- error) (err error) { func SendMsg(sender *User, chatThreadId string, content *skype.SendMessage, output chan<- error) (err error) {
fmt.Println("message SendMsg type: ", content.Type) fmt.Println("message SendMsg type: ", content.Type)
switch event.MessageType(content.Type) { if sender.Conn.LoginInfo != nil {
case event.MsgText, event.MsgEmote, event.MsgNotice: switch event.MessageType(content.Type) {
err = sender.Conn.SendText(chatThreadId, content) case event.MsgText, event.MsgEmote, event.MsgNotice:
case event.MsgImage: err = sender.Conn.SendText(chatThreadId, content)
fmt.Println("message SendMsg type m.image: ", content.Type) case event.MsgImage:
err = sender.Conn.SendFile(chatThreadId, content) fmt.Println("message SendMsg type m.image: ", content.Type)
case event.MsgVideo: err = sender.Conn.SendFile(chatThreadId, content)
fmt.Println("message SendMsg type m.video: ", content.Type) case event.MsgVideo:
err = sender.Conn.SendFile(chatThreadId, content) fmt.Println("message SendMsg type m.video: ", content.Type)
case event.MsgAudio: err = sender.Conn.SendFile(chatThreadId, content)
fmt.Println("message SendMsg type m.audio: ", content.Type) case event.MsgAudio:
err = sender.Conn.SendFile(chatThreadId, content) fmt.Println("message SendMsg type m.audio: ", content.Type)
case event.MsgFile: err = sender.Conn.SendFile(chatThreadId, content)
fmt.Println("message SendMsg type m.file: ", content.Type) case event.MsgFile:
err = sender.Conn.SendFile(chatThreadId, content) fmt.Println("message SendMsg type m.file: ", content.Type)
case event.MsgLocation: err = sender.Conn.SendFile(chatThreadId, content)
fmt.Println("message SendMsg type m.location: ", content.Type) case event.MsgLocation:
//err = c.SendFile(chatThreadId, content) fmt.Println("message SendMsg type m.location: ", content.Type)
default: //err = c.SendFile(chatThreadId, content)
err = errors.New("send to skype(unknown message type)") default:
err = errors.New("send to skype(unknown message type)")
}
} else {
err = errors.New("Not logged into Skype or Skype session has expired")
} }
if err != nil { if err != nil {
output <- fmt.Errorf("message sending responded with %d", err) output <- err
} else { } else {
output <- nil output <- nil
} }