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`
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 {

View File

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

View File

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