diff --git a/database/portalquery.go b/database/portalquery.go index d9dd1ba..c055ad6 100644 --- a/database/portalquery.go +++ b/database/portalquery.go @@ -36,11 +36,11 @@ func (pq *PortalQuery) GetByMXID(mxid id.RoomID) *Portal { return pq.get(portalSelect+" WHERE mxid=$1", mxid) } -func (pq *PortalQuery) GetAllByID(id string) []*Portal { - return pq.getAll(portalSelect+" WHERE receiver=$1", id) +func (pq *PortalQuery) FindPrivateChatsWith(id string) []*Portal { + return pq.getAll(portalSelect+" WHERE dmuser=$1 AND type=$2", id, discordgo.ChannelTypeDM) } -func (pq *PortalQuery) FindPrivateChats(receiver string) []*Portal { +func (pq *PortalQuery) FindPrivateChatsOf(receiver string) []*Portal { query := portalSelect + " portal WHERE receiver=$1 AND type=$2;" return pq.getAll(query, receiver, discordgo.ChannelTypeDM) diff --git a/portal.go b/portal.go index b9589ff..9c6d7e1 100644 --- a/portal.go +++ b/portal.go @@ -118,8 +118,8 @@ func (br *DiscordBridge) GetAllPortals() []*Portal { return br.dbPortalsToPortals(br.DB.Portal.GetAll()) } -func (br *DiscordBridge) GetAllPortalsByID(id string) []*Portal { - return br.dbPortalsToPortals(br.DB.Portal.GetAllByID(id)) +func (br *DiscordBridge) GetDMPortalsWith(otherUserID string) []*Portal { + return br.dbPortalsToPortals(br.DB.Portal.FindPrivateChatsWith(otherUserID)) } func (br *DiscordBridge) dbPortalsToPortals(dbPortals []*database.Portal) []*Portal { diff --git a/puppet.go b/puppet.go index 1b31d50..a803b7c 100644 --- a/puppet.go +++ b/puppet.go @@ -171,7 +171,7 @@ func (puppet *Puppet) CustomIntent() *appservice.IntentAPI { } func (puppet *Puppet) updatePortalMeta(meta func(portal *Portal)) { - for _, portal := range puppet.bridge.GetAllPortalsByID(puppet.ID) { + for _, portal := range puppet.bridge.GetDMPortalsWith(puppet.ID) { // Get room create lock to prevent races between receiving contact info and room creation. portal.roomCreateLock.Lock() meta(portal) diff --git a/user.go b/user.go index f8b2b5a..b5bf75e 100644 --- a/user.go +++ b/user.go @@ -682,7 +682,7 @@ func (user *User) ensureInvited(intent *appservice.IntentAPI, roomID id.RoomID, func (user *User) getDirectChats() map[id.UserID][]id.RoomID { chats := map[id.UserID][]id.RoomID{} - privateChats := user.bridge.DB.Portal.FindPrivateChats(user.ID) + privateChats := user.bridge.DB.Portal.FindPrivateChatsOf(user.ID) for _, portal := range privateChats { if portal.MXID != "" { puppetMXID := user.bridge.FormatPuppetMXID(portal.Key.Receiver)