in progress

This commit is contained in:
zhaoYangguang 2021-05-26 20:39:02 +08:00
parent 459b54955a
commit 9a39b69dce
2 changed files with 31 additions and 6 deletions

View File

@ -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

27
user.go
View File

@ -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)))