diff --git a/commands.go b/commands.go index ad980dc..d4ad9c0 100644 --- a/commands.go +++ b/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{ diff --git a/database/user.go b/database/user.go index 14ed243..45ac771 100644 --- a/database/user.go +++ b/database/user.go @@ -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 diff --git a/portal.go b/portal.go index d7489e0..4c453d8 100644 --- a/portal.go +++ b/portal.go @@ -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) diff --git a/user.go b/user.go index 018679c..f3ca29e 100644 --- a/user.go +++ b/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