Solve the problem of switching the matrix client account to synchronize the same Skype account
This commit is contained in:
parent
414db1af6f
commit
ffa87ebcfc
|
@ -239,8 +239,10 @@ func (handler *CommandHandler) CommandLogin(ce *CommandEvent) {
|
||||||
ce.User.log.Debugln("Connect() returned false, assuming error was logged elsewhere and canceling login.")
|
ce.User.log.Debugln("Connect() returned false, assuming error was logged elsewhere and canceling login.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ce.User.Login(ce, ce.Args[0], ce.Args[1])
|
err := ce.User.Login(ce, ce.Args[0], ce.Args[1])
|
||||||
|
if err == nil {
|
||||||
syncAll(ce.User, true)
|
syncAll(ce.User, true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const cmdLogoutHelp = `logout - Logout from WhatsApp`
|
const cmdLogoutHelp = `logout - Logout from WhatsApp`
|
||||||
|
|
|
@ -161,7 +161,7 @@ func (mx *MatrixHandler) handlePrivatePortal(roomID id.RoomID, inviter *User, pu
|
||||||
|
|
||||||
func (mx *MatrixHandler) createPrivatePortalFromInvite(roomID id.RoomID, inviter *User, puppet *Puppet, portal *Portal) {
|
func (mx *MatrixHandler) createPrivatePortalFromInvite(roomID id.RoomID, inviter *User, puppet *Puppet, portal *Portal) {
|
||||||
portal.MXID = roomID
|
portal.MXID = roomID
|
||||||
portal.Topic = "WhatsApp private chat"
|
portal.Topic = "Skype private chat"
|
||||||
_, _ = portal.MainIntent().SetRoomTopic(portal.MXID, portal.Topic)
|
_, _ = portal.MainIntent().SetRoomTopic(portal.MXID, portal.Topic)
|
||||||
if portal.bridge.Config.Bridge.PrivateChatPortalMeta {
|
if portal.bridge.Config.Bridge.PrivateChatPortalMeta {
|
||||||
portal.Name = puppet.Displayname
|
portal.Name = puppet.Displayname
|
||||||
|
|
40
portal.go
40
portal.go
|
@ -620,10 +620,20 @@ func (portal *Portal) SyncSkype(user *User, chat skype.Conversation) {
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("SyncSkype ensureUserInvited", portal.MXID)
|
fmt.Println("SyncSkype ensureUserInvited", portal.MXID)
|
||||||
portal.ensureUserInvited(user)
|
portal.ensureUserInvited(user)
|
||||||
rep, err := portal.MainIntent().SetPowerLevel(portal.MXID, user.MXID, 100)
|
rep, err := portal.MainIntent().SetPowerLevel(portal.MXID, user.MXID, 95)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
portal.log.Warnfln("SyncSkype: SetPowerLevel err: ", err, rep)
|
portal.log.Warnfln("SyncSkype: SetPowerLevel err: ", err, rep)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
preUserIds,_ := portal.GetMatrixUsers()
|
||||||
|
for _,userId := range preUserIds {
|
||||||
|
if user.MXID != userId {
|
||||||
|
err := portal.tryKickUser(userId, portal.MainIntent())
|
||||||
|
if err != nil {
|
||||||
|
portal.log.Errorln("Failed to try kick user:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if portal.IsPrivateChat() {
|
if portal.IsPrivateChat() {
|
||||||
|
@ -683,7 +693,7 @@ func (portal *Portal) SyncSkype(user *User, chat skype.Conversation) {
|
||||||
|
|
||||||
func (portal *Portal) GetBasePowerLevels() *event.PowerLevelsEventContent {
|
func (portal *Portal) GetBasePowerLevels() *event.PowerLevelsEventContent {
|
||||||
anyone := 0
|
anyone := 0
|
||||||
nope := 99
|
nope := 95
|
||||||
invite := 50
|
invite := 50
|
||||||
if portal.bridge.Config.Bridge.AllowUserInvite {
|
if portal.bridge.Config.Bridge.AllowUserInvite {
|
||||||
invite = 0
|
invite = 0
|
||||||
|
@ -1127,7 +1137,7 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
||||||
// content.Users[user.MXID] = 100
|
// content.Users[user.MXID] = 100
|
||||||
//}
|
//}
|
||||||
// When creating a room, make user self the highest level of authority
|
// When creating a room, make user self the highest level of authority
|
||||||
content.Users[user.MXID] = 99
|
content.Users[user.MXID] = 95
|
||||||
initialState := []*event.Event{{
|
initialState := []*event.Event{{
|
||||||
Type: event.StatePowerLevels,
|
Type: event.StatePowerLevels,
|
||||||
Content: event.Content{
|
Content: event.Content{
|
||||||
|
@ -1506,19 +1516,6 @@ func (portal *Portal) sendMediaBridgeFailureSkype(source *User, intent *appservi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) sendMediaBridgeFailure(source *User, intent *appservice.IntentAPI, info whatsapp.MessageInfo, downloadErr error) {
|
|
||||||
portal.log.Errorfln("Failed to download media for %s: %v", info.Id, downloadErr)
|
|
||||||
resp, err := portal.sendMessage(intent, event.EventMessage, &event.MessageEventContent{
|
|
||||||
MsgType: event.MsgNotice,
|
|
||||||
Body: "Failed to bridge media",
|
|
||||||
}, int64(info.Timestamp*1000))
|
|
||||||
if err != nil {
|
|
||||||
portal.log.Errorfln("Failed to send media download error message for %s: %v", info.Id, err)
|
|
||||||
} else {
|
|
||||||
portal.finishHandling(source, info.Source, resp.EventID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (portal *Portal) encryptFile(data []byte, mimeType string) ([]byte, string, *event.EncryptedFileInfo) {
|
func (portal *Portal) encryptFile(data []byte, mimeType string) ([]byte, string, *event.EncryptedFileInfo) {
|
||||||
if !portal.Encrypted {
|
if !portal.Encrypted {
|
||||||
return data, mimeType, nil
|
return data, mimeType, nil
|
||||||
|
@ -1532,6 +1529,17 @@ func (portal *Portal) encryptFile(data []byte, mimeType string) ([]byte, string,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (portal *Portal) tryKickUser(userID id.UserID, intent *appservice.IntentAPI) error {
|
||||||
|
_, err := intent.KickUser(portal.MXID, &mautrix.ReqKickUser{UserID: userID})
|
||||||
|
if err != nil {
|
||||||
|
httpErr, ok := err.(mautrix.HTTPError)
|
||||||
|
if ok && httpErr.RespError != nil && httpErr.RespError.ErrCode == "M_FORBIDDEN" {
|
||||||
|
_, err = portal.MainIntent().KickUser(portal.MXID, &mautrix.ReqKickUser{UserID: userID})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (portal *Portal) HandleMediaMessageSkype(source *User, download func(conn *skype.Conn, mediaType string) (data []byte, mediaMessage *skype.MediaMessageContent, err error), mediaType string, thumbnail []byte, info skype.Resource, sendAsSticker bool) {
|
func (portal *Portal) HandleMediaMessageSkype(source *User, download func(conn *skype.Conn, mediaType string) (data []byte, mediaMessage *skype.MediaMessageContent, err error), mediaType string, thumbnail []byte, info skype.Resource, sendAsSticker bool) {
|
||||||
intent, endHandlePrivateChatFromMe := portal.startHandlingSkype(source, info)
|
intent, endHandlePrivateChatFromMe := portal.startHandlingSkype(source, info)
|
||||||
if endHandlePrivateChatFromMe != nil {
|
if endHandlePrivateChatFromMe != nil {
|
||||||
|
|
21
user.go
21
user.go
|
@ -361,17 +361,16 @@ func (user *User) loginQrChannel(ce *CommandEvent, qrChan <-chan string, eventID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) Login(ce *CommandEvent, name string, password string) {
|
func (user *User) Login(ce *CommandEvent, name string, password string) (err error) {
|
||||||
if user.contactsPresence == nil {
|
if user.contactsPresence == nil {
|
||||||
user.contactsPresence = make(map[string]*skypeExt.Presence)
|
user.contactsPresence = make(map[string]*skypeExt.Presence)
|
||||||
}
|
}
|
||||||
session, err := user.Conn.Login(name, password)
|
err = user.Conn.Login(name, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
user.log.Errorln("Failed to login:", err)
|
user.log.Errorln("Failed to login:", err)
|
||||||
ce.Reply("Please confirm that your account password is entered correctly")
|
ce.Reply(err.Error())
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println("user.MXID", user.MXID)
|
|
||||||
ce.Reply("Successfully logged in")
|
ce.Reply("Successfully logged in")
|
||||||
|
|
||||||
// subscribe basic
|
// subscribe basic
|
||||||
|
@ -381,7 +380,6 @@ func (user *User) Login(ce *CommandEvent, name string, password string) {
|
||||||
if err == nil{
|
if err == nil{
|
||||||
var userIds []string
|
var userIds []string
|
||||||
for _, contact := range user.Conn.Store.Contacts {
|
for _, contact := range user.Conn.Store.Contacts {
|
||||||
//fmt.Println(contact.PersonId)
|
|
||||||
if strings.Index(contact.PersonId, "28:") > -1 {
|
if strings.Index(contact.PersonId, "28:") > -1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -389,24 +387,19 @@ func (user *User) Login(ce *CommandEvent, name string, password string) {
|
||||||
userIds = append(userIds, userId)
|
userIds = append(userIds, userId)
|
||||||
}
|
}
|
||||||
ce.User.Conn.SubscribeUsers(userIds)
|
ce.User.Conn.SubscribeUsers(userIds)
|
||||||
//fmt.Println("Login user0: ", user.JID)
|
|
||||||
go loopPresence(user)
|
go loopPresence(user)
|
||||||
}
|
}
|
||||||
go user.Conn.Poll()
|
go user.Conn.Poll()
|
||||||
|
|
||||||
user.ConnectionErrors = 0
|
user.ConnectionErrors = 0
|
||||||
user.SetSession(&session)
|
user.SetSession(user.Conn.LoginInfo)
|
||||||
user.JID = "8:" + user.Conn.UserProfile.Username + skypeExt.NewUserSuffix
|
user.JID = "8:" + user.Conn.UserProfile.Username + skypeExt.NewUserSuffix
|
||||||
user.addToJIDMap()
|
user.addToJIDMap()
|
||||||
//user.PostLogin()
|
|
||||||
ce.User.Conn.GetConversations("", user.bridge.Config.Bridge.InitialChatSync)
|
ce.User.Conn.GetConversations("", user.bridge.Config.Bridge.InitialChatSync)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
func loopPresence(user *User) {
|
func loopPresence(user *User) {
|
||||||
Loop:
|
for {
|
||||||
for i := 0; i <= 1000; i++ {
|
|
||||||
if i > 1000 {
|
|
||||||
goto Loop
|
|
||||||
}
|
|
||||||
for cid, contact := range user.contactsPresence {
|
for cid, contact := range user.contactsPresence {
|
||||||
puppet := user.bridge.GetPuppetByJID(cid)
|
puppet := user.bridge.GetPuppetByJID(cid)
|
||||||
_ = puppet.DefaultIntent().SetPresence(event.Presence(strings.ToLower(contact.Availability)))
|
_ = puppet.DefaultIntent().SetPresence(event.Presence(strings.ToLower(contact.Availability)))
|
||||||
|
|
Loading…
Reference in New Issue