optimize the process that logout with double puppeting enabled
This commit is contained in:
parent
2e904aa753
commit
949fbc7ba8
18
commands.go
18
commands.go
|
@ -251,6 +251,7 @@ func (handler *CommandHandler) CommandLogout(ce *CommandEvent) {
|
||||||
if ce.User.Conn == nil {
|
if ce.User.Conn == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
_ = ce.User.Conn.GetConversations("", ce.User.bridge.Config.Bridge.InitialChatSync)
|
||||||
ce.User.Conn.LoggedIn = false
|
ce.User.Conn.LoggedIn = false
|
||||||
username := ""
|
username := ""
|
||||||
password := ""
|
password := ""
|
||||||
|
@ -269,7 +270,22 @@ func (handler *CommandHandler) CommandLogout(ce *CommandEvent) {
|
||||||
Username: username,
|
Username: username,
|
||||||
Password: password,
|
Password: password,
|
||||||
}
|
}
|
||||||
|
|
||||||
portals := ce.User.GetPortals()
|
portals := ce.User.GetPortals()
|
||||||
|
newPortals := ce.User.GetPortalsNew()
|
||||||
|
allPortals := newPortals[0:]
|
||||||
|
for _, portal := range portals {
|
||||||
|
var newPortalsHas bool
|
||||||
|
for _, newPortal := range newPortals {
|
||||||
|
if portal.Key == newPortal.Key {
|
||||||
|
newPortalsHas = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !newPortalsHas {
|
||||||
|
allPortals = append(allPortals, portal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
leave := func(portal *Portal) {
|
leave := func(portal *Portal) {
|
||||||
if len(portal.MXID) > 0 {
|
if len(portal.MXID) > 0 {
|
||||||
_, _ = portal.MainIntent().KickUser(portal.MXID, &mautrix.ReqKickUser{
|
_, _ = portal.MainIntent().KickUser(portal.MXID, &mautrix.ReqKickUser{
|
||||||
|
@ -278,7 +294,7 @@ func (handler *CommandHandler) CommandLogout(ce *CommandEvent) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, portal := range portals {
|
for _, portal := range allPortals {
|
||||||
leave(portal)
|
leave(portal)
|
||||||
}
|
}
|
||||||
ce.Reply("Logged out successfully.")
|
ce.Reply("Logged out successfully.")
|
||||||
|
|
24
user.go
24
user.go
|
@ -156,6 +156,28 @@ func (user *User) GetPortals() []*Portal {
|
||||||
return portals
|
return portals
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (user *User) GetPortalsNew() []*Portal {
|
||||||
|
keys := make([]database.PortalKey, len(user.Conn.Store.Chats))
|
||||||
|
i := 0
|
||||||
|
for jid, _ := range user.Conn.Store.Chats {
|
||||||
|
keys[i] = database.NewPortalKey(jid, user.JID)
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
|
||||||
|
portals := make([]*Portal, len(keys))
|
||||||
|
|
||||||
|
user.bridge.portalsLock.Lock()
|
||||||
|
for i, key := range keys {
|
||||||
|
portal, ok := user.bridge.portalsByJID[key]
|
||||||
|
if !ok {
|
||||||
|
portal = user.bridge.loadDBPortal(user.bridge.DB.Portal.GetByJID(key), &key)
|
||||||
|
}
|
||||||
|
portals[i] = portal
|
||||||
|
}
|
||||||
|
user.bridge.portalsLock.Unlock()
|
||||||
|
return portals
|
||||||
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) NewUser(dbUser *database.User) *User {
|
func (bridge *Bridge) NewUser(dbUser *database.User) *User {
|
||||||
user := &User{
|
user := &User{
|
||||||
User: dbUser,
|
User: dbUser,
|
||||||
|
@ -394,9 +416,9 @@ func (user *User) Login(ce *CommandEvent, name string, password string) (err err
|
||||||
go user.Conn.Poll()
|
go user.Conn.Poll()
|
||||||
|
|
||||||
user.ConnectionErrors = 0
|
user.ConnectionErrors = 0
|
||||||
user.SetSession(user.Conn.LoginInfo)
|
|
||||||
user.JID = "8:" + user.Conn.UserProfile.Username + skypeExt.NewUserSuffix
|
user.JID = "8:" + user.Conn.UserProfile.Username + skypeExt.NewUserSuffix
|
||||||
user.addToJIDMap()
|
user.addToJIDMap()
|
||||||
|
user.SetSession(user.Conn.LoginInfo)
|
||||||
_ = ce.User.Conn.GetConversations("", user.bridge.Config.Bridge.InitialChatSync)
|
_ = ce.User.Conn.GetConversations("", user.bridge.Config.Bridge.InitialChatSync)
|
||||||
user.PostLogin()
|
user.PostLogin()
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue