better for leave room with command 'logout'
This commit is contained in:
parent
403e28baa1
commit
c2a347096b
30
commands.go
30
commands.go
|
@ -251,7 +251,7 @@ func (handler *CommandHandler) CommandLogout(ce *CommandEvent) {
|
|||
if ce.User.Conn == nil {
|
||||
return
|
||||
}
|
||||
_ = ce.User.Conn.GetConversations("", ce.User.bridge.Config.Bridge.InitialChatSync)
|
||||
//_ = ce.User.Conn.GetConversations("", ce.User.bridge.Config.Bridge.InitialChatSync)
|
||||
ce.User.Conn.LoggedIn = false
|
||||
username := ""
|
||||
password := ""
|
||||
|
@ -272,19 +272,19 @@ func (handler *CommandHandler) CommandLogout(ce *CommandEvent) {
|
|||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
//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) {
|
||||
if len(portal.MXID) > 0 {
|
||||
|
@ -294,7 +294,7 @@ func (handler *CommandHandler) CommandLogout(ce *CommandEvent) {
|
|||
})
|
||||
}
|
||||
}
|
||||
for _, portal := range allPortals {
|
||||
for _, portal := range portals {
|
||||
leave(portal)
|
||||
}
|
||||
ce.User.Conn.Store = &skype.Store{
|
||||
|
|
|
@ -183,6 +183,17 @@ func (user *User) SetPortalKeys(newKeys []PortalKeyWithMeta) error {
|
|||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (user *User) CreateUserPortal(newKey PortalKeyWithMeta) {
|
||||
user.log.Debugfln("Creating new portal %s for %s", newKey.PortalKey.JID, newKey.PortalKey.Receiver)
|
||||
_, err := user.db.Exec(`INSERT INTO user_portal (user_jid, portal_jid, portal_receiver, in_community) VALUES ($1, $2, $3, $4)`,
|
||||
user.jidPtr(),
|
||||
newKey.PortalKey.JID, newKey.PortalKey.Receiver,
|
||||
newKey.InCommunity)
|
||||
if err != nil {
|
||||
user.log.Warnfln("Failed to insert %s: %v", user.MXID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (user *User) IsInPortal(key PortalKey) bool {
|
||||
row := user.db.QueryRow(`SELECT EXISTS(SELECT 1 FROM user_portal WHERE user_jid=$1 AND portal_jid=$2 AND portal_receiver=$3)`, user.jidPtr(), &key.JID, &key.Receiver)
|
||||
var exists bool
|
||||
|
|
|
@ -1237,7 +1237,7 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
|||
_ = customPuppet.CustomIntent().EnsureJoined(portal.MXID)
|
||||
}
|
||||
}
|
||||
user.addPortalToCommunity(portal)
|
||||
inCommunity := user.addPortalToCommunity(portal)
|
||||
if portal.IsPrivateChat() {
|
||||
puppet := user.bridge.GetPuppetByJID(portal.Key.JID)
|
||||
user.addPuppetToCommunity(puppet)
|
||||
|
@ -1249,6 +1249,7 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
|||
}
|
||||
}
|
||||
}
|
||||
user.CreateUserPortal(database.PortalKeyWithMeta{PortalKey: portal.Key, InCommunity: inCommunity})
|
||||
err = portal.FillInitialHistory(user)
|
||||
if err != nil {
|
||||
portal.log.Errorln("Failed to fill history:", err)
|
||||
|
|
17
user.go
17
user.go
|
@ -463,23 +463,6 @@ func (user *User) intPostLogin() {
|
|||
}
|
||||
}
|
||||
|
||||
func (user *User) HandleChatList(chats []skype.Conversation) {
|
||||
user.log.Infoln("Chat list received")
|
||||
chatMap := make(map[string]skype.Conversation)
|
||||
//for _, chat := range user.Conn.Store.Chats {
|
||||
// chatMap[chat.Jid] = chat
|
||||
//}
|
||||
for _, chat := range chats {
|
||||
cid, _ := chat.Id.(string)
|
||||
chatMap[cid] = chat
|
||||
}
|
||||
select {
|
||||
case user.chatListReceived <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
go user.syncPortals(chatMap, false)
|
||||
}
|
||||
|
||||
func (user *User) syncPortals(chatMap map[string]skype.Conversation, createAll bool) {
|
||||
if chatMap == nil {
|
||||
chatMap = user.Conn.Store.Chats
|
||||
|
|
Loading…
Reference in New Issue