Leave all bridged rooms when logging out

This commit is contained in:
zhaoYangguang 2020-11-05 19:22:19 +08:00
parent cd537636e8
commit b21edffadd
3 changed files with 33 additions and 13 deletions

View File

@ -246,12 +246,18 @@ func (handler *CommandHandler) CommandLogin(ce *CommandEvent) {
} }
const cmdLogoutHelp = `logout - Logout from Skype` const cmdLogoutHelp = `logout - Logout from Skype`
func (handler *CommandHandler) CommandLogout(ce *CommandEvent) { func (handler *CommandHandler) CommandLogout(ce *CommandEvent) {
if ce.User.Conn == nil { if ce.User.Conn == nil {
return return
} }
//ce.User.Conn.Conn.LogoutChan <- 1
ce.User.Conn.LoggedIn = false ce.User.Conn.LoggedIn = false
username := ""
password := ""
if ce.User.Conn.LoginInfo != nil {
username = ce.User.Conn.LoginInfo.Username
password = ce.User.Conn.LoginInfo.Password
}
ce.User.Conn.LoginInfo = &skype.Session{ ce.User.Conn.LoginInfo = &skype.Session{
SkypeToken: "", SkypeToken: "",
SkypeExpires: "", SkypeExpires: "",
@ -260,9 +266,24 @@ func (handler *CommandHandler) CommandLogout(ce *CommandEvent) {
RegistrationExpires: "", RegistrationExpires: "",
LocationHost: "", LocationHost: "",
EndpointId: "", EndpointId: "",
Username: username,
Password: password,
}
portals := ce.User.GetPortals()
leave := func(portal *Portal) {
if len(portal.MXID) > 0 {
_, _ = portal.MainIntent().KickUser(portal.MXID, &mautrix.ReqKickUser{
Reason: "Logout",
UserID: ce.User.MXID,
})
}
}
for _, portal := range portals {
leave(portal)
} }
ce.Reply("Logged out successfully.") ce.Reply("Logged out successfully.")
} }
// CommandLogout handles !logout command // CommandLogout handles !logout command
//func (handler *CommandHandler) CommandLogout(ce *CommandEvent) { //func (handler *CommandHandler) CommandLogout(ce *CommandEvent) {
// if ce.User.Session == nil { // if ce.User.Session == nil {

View File

@ -625,17 +625,17 @@ func (portal *Portal) SyncSkype(user *User, chat skype.Conversation) {
portal.log.Warnfln("SyncSkype: SetPowerLevel err: ", err, rep) portal.log.Warnfln("SyncSkype: SetPowerLevel err: ", err, rep)
} }
if portal.IsPrivateChat() { //if portal.IsPrivateChat() {
preUserIds,_ := portal.GetMatrixUsers() // preUserIds,_ := portal.GetMatrixUsers()
for _,userId := range preUserIds { // for _,userId := range preUserIds {
if user.MXID != userId { // if user.MXID != userId {
err := portal.tryKickUser(userId, portal.MainIntent()) // err := portal.tryKickUser(userId, portal.MainIntent())
if err != nil { // if err != nil {
portal.log.Errorln("Failed to try kick user:", err) // portal.log.Errorln("Failed to try kick user:", err)
} // }
} // }
} // }
} //}
} }
if portal.IsPrivateChat() { if portal.IsPrivateChat() {

View File

@ -148,7 +148,6 @@ func (user *User) GetPortals() []*Portal {
for i, key := range keys { for i, key := range keys {
portal, ok := user.bridge.portalsByJID[key] portal, ok := user.bridge.portalsByJID[key]
if !ok { if !ok {
fmt.Println("loadDBPortal4")
portal = user.bridge.loadDBPortal(user.bridge.DB.Portal.GetByJID(key), &key) portal = user.bridge.loadDBPortal(user.bridge.DB.Portal.GetByJID(key), &key)
} }
portals[i] = portal portals[i] = portal