From b21edffadda78596f39961dc4547caf9a4592f84 Mon Sep 17 00:00:00 2001 From: zhaoYangguang <1163765691@qq.com> Date: Thu, 5 Nov 2020 19:22:19 +0800 Subject: [PATCH] Leave all bridged rooms when logging out --- commands.go | 23 ++++++++++++++++++++++- portal.go | 22 +++++++++++----------- user.go | 1 - 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/commands.go b/commands.go index 7a90cc8..88f0589 100644 --- a/commands.go +++ b/commands.go @@ -246,12 +246,18 @@ func (handler *CommandHandler) CommandLogin(ce *CommandEvent) { } const cmdLogoutHelp = `logout - Logout from Skype` + func (handler *CommandHandler) CommandLogout(ce *CommandEvent) { if ce.User.Conn == nil { return } - //ce.User.Conn.Conn.LogoutChan <- 1 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{ SkypeToken: "", SkypeExpires: "", @@ -260,9 +266,24 @@ func (handler *CommandHandler) CommandLogout(ce *CommandEvent) { RegistrationExpires: "", LocationHost: "", 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.") } + // CommandLogout handles !logout command //func (handler *CommandHandler) CommandLogout(ce *CommandEvent) { // if ce.User.Session == nil { diff --git a/portal.go b/portal.go index f406046..d3ad95b 100644 --- a/portal.go +++ b/portal.go @@ -625,17 +625,17 @@ func (portal *Portal) SyncSkype(user *User, chat skype.Conversation) { portal.log.Warnfln("SyncSkype: SetPowerLevel err: ", err, rep) } - if portal.IsPrivateChat() { - 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() { + // 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() { diff --git a/user.go b/user.go index cd8bc10..54aa7a5 100644 --- a/user.go +++ b/user.go @@ -148,7 +148,6 @@ func (user *User) GetPortals() []*Portal { for i, key := range keys { portal, ok := user.bridge.portalsByJID[key] if !ok { - fmt.Println("loadDBPortal4") portal = user.bridge.loadDBPortal(user.bridge.DB.Portal.GetByJID(key), &key) } portals[i] = portal