From 9a39b69dce54237b186a03e02b0bfaa51ed3cff8 Mon Sep 17 00:00:00 2001 From: zhaoYangguang <1163765691@qq.com> Date: Wed, 26 May 2021 20:39:02 +0800 Subject: [PATCH] in progress --- commands.go | 10 +++++++++- user.go | 27 ++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/commands.go b/commands.go index a6864e4..4e4ae8f 100644 --- a/commands.go +++ b/commands.go @@ -271,7 +271,6 @@ func (handler *CommandHandler) CommandLogout(ce *CommandEvent) { Username: username, Password: password, } - portals := ce.User.GetPortals() //newPortals := ce.User.GetPortalsNew() //allPortals := newPortals[0:] @@ -303,6 +302,15 @@ func (handler *CommandHandler) CommandLogout(ce *CommandEvent) { Chats: make(map[string]skype.Conversation), } ce.Reply("Logged out successfully.") + + //defer func() { + // if r := recover(); r != nil { + // fmt.Printf("close ReRefresh:%s\n", r) + // } + //}() + if ce.User.Conn.Refresh != nil { + ce.User.Conn.Refresh <- -1 + } } // CommandLogout handles !logout command diff --git a/user.go b/user.go index 891ef88..ce91661 100644 --- a/user.go +++ b/user.go @@ -285,6 +285,7 @@ func (user *User) Connect(evenIfNoSession bool) bool { //_ = user.Conn.SetClientName("matrix-skype bridge", "mx-wa", SkypeVersion) user.log.Debugln("skype connection successful") user.Conn.AddHandler(user) + return user.RestoreSession() } @@ -371,9 +372,10 @@ func (user *User) Login(ce *CommandEvent, name string, password string) (err err userIds = append(userIds, userId) } ce.User.Conn.SubscribeUsers(userIds) - go loopPresence(ce, user) + go loopPresence(user) } go user.Conn.Poll() + go user.monitorSession(ce) user.ConnectionErrors = 0 user.JID = "8:" + user.Conn.UserProfile.Username + skypeExt.NewUserSuffix @@ -384,12 +386,27 @@ func (user *User) Login(ce *CommandEvent, name string, password string) (err err return } -func loopPresence(ce *CommandEvent, user *User) { - for { - if user.Conn.LoggedIn == false { +func (user *User) monitorSession(ce *CommandEvent) { + user.Conn.Refresh = make(chan int) + for x := range user.Conn.Refresh { + fmt.Println("monitorSession: ", x) + if x > 0 { + user.SetSession(user.Conn.LoginInfo) + } else { ce.Reply("Session expired") - break + close(user.Conn.Refresh) } + } + + item, ok := <- user.Conn.Refresh + if !ok { + user.Conn.Refresh = nil + } + fmt.Println("monitorSession1", item, ok) +} + +func loopPresence(user *User) { + for { for cid, contact := range user.contactsPresence { puppet := user.bridge.GetPuppetByJID(cid) _ = puppet.DefaultIntent().SetPresence(event.Presence(strings.ToLower(contact.Availability)))