diff --git a/database/portal.go b/database/portal.go index ba6bccd..2feebba 100644 --- a/database/portal.go +++ b/database/portal.go @@ -159,13 +159,13 @@ func (p *Portal) Scan(row dbutil.Scannable) *Portal { func (p *Portal) Insert() { query := ` - INSERT INTO portal (dcid, receiver, type, other_user_id, dc_guild_id, dc_parent_id, mxid, + INSERT INTO portal (dcid, receiver, type, other_user_id, dc_guild_id, mxid, plain_name, name, name_set, topic, topic_set, avatar, avatar_url, avatar_set, encrypted, in_space, first_event_id, relay_webhook_id, relay_webhook_secret) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19) ` _, err := p.db.Exec(query, p.Key.ChannelID, p.Key.Receiver, p.Type, - strPtr(p.OtherUserID), strPtr(p.GuildID), strPtr(p.ParentID), strPtr(string(p.MXID)), + strPtr(p.OtherUserID), strPtr(p.GuildID), strPtr(string(p.MXID)), p.PlainName, p.Name, p.NameSet, p.Topic, p.TopicSet, p.Avatar, p.AvatarURL.String(), p.AvatarSet, p.Encrypted, p.InSpace, p.FirstEventID.String(), strPtr(p.RelayWebhookID), strPtr(p.RelayWebhookSecret)) @@ -178,13 +178,13 @@ func (p *Portal) Insert() { func (p *Portal) Update() { query := ` UPDATE portal - SET type=$1, other_user_id=$2, dc_guild_id=$3, dc_parent_id=$4, mxid=$5, - plain_name=$6, name=$7, name_set=$8, topic=$9, topic_set=$10, avatar=$11, avatar_url=$12, avatar_set=$13, - encrypted=$14, in_space=$15, first_event_id=$16, relay_webhook_id=$17, relay_webhook_secret=$18 - WHERE dcid=$19 AND receiver=$20 + SET type=$1, other_user_id=$2, dc_guild_id=$3, mxid=$6, + plain_name=$7, name=$8, name_set=$9, topic=$10, topic_set=$11, avatar=$12, avatar_url=$13, avatar_set=$14, + encrypted=$15, in_space=$16, first_event_id=$17, relay_webhook_id=$18, relay_webhook_secret=$19 + WHERE dcid=$20 AND receiver=$21 ` _, err := p.db.Exec(query, - p.Type, strPtr(p.OtherUserID), strPtr(p.GuildID), strPtr(p.ParentID), strPtr(string(p.MXID)), + p.Type, strPtr(p.OtherUserID), strPtr(p.GuildID), strPtr(string(p.MXID)), p.PlainName, p.Name, p.NameSet, p.Topic, p.TopicSet, p.Avatar, p.AvatarURL.String(), p.AvatarSet, p.Encrypted, p.InSpace, p.FirstEventID.String(), strPtr(p.RelayWebhookID), strPtr(p.RelayWebhookSecret), p.Key.ChannelID, p.Key.Receiver) diff --git a/portal.go b/portal.go index bcdbb37..c4b3ecd 100644 --- a/portal.go +++ b/portal.go @@ -119,14 +119,6 @@ func (br *DiscordBridge) loadPortal(dbPortal *database.Portal, key *database.Por if portal.GuildID != "" { portal.Guild = portal.bridge.GetGuildByID(portal.GuildID, true) } - if portal.ParentID != "" { - parentKey := database.NewPortalKey(portal.ParentID, "") - var ok bool - portal.Parent, ok = br.portalsByID[parentKey] - if !ok { - portal.Parent = br.loadPortal(br.DB.Portal.GetByID(parentKey), nil, -1) - } - } return portal } @@ -384,7 +376,7 @@ func (portal *Portal) CreateMatrixRoom(user *User, channel *discordgo.Channel) e creationContent := make(map[string]interface{}) if portal.Type == discordgo.ChannelTypeGuildCategory { - creationContent["type"] = event.RoomTypeSpace + return nil } if !portal.bridge.Config.Bridge.FederateRooms { creationContent["m.federate"] = false @@ -1861,18 +1853,12 @@ func (portal *Portal) UpdateParent(parentID string) bool { } portal.log.Debugfln("Updating parent ID %q -> %q", portal.ParentID, parentID) portal.ParentID = parentID - if portal.ParentID != "" { - portal.Parent = portal.bridge.GetPortalByID(database.NewPortalKey(parentID, ""), discordgo.ChannelTypeGuildCategory) - } else { - portal.Parent = nil - } + portal.Parent = nil return true } func (portal *Portal) ExpectedSpaceID() id.RoomID { - if portal.Parent != nil { - return portal.Parent.MXID - } else if portal.Guild != nil { + if portal.Guild != nil { return portal.Guild.MXID } return "" @@ -1882,9 +1868,7 @@ func (portal *Portal) updateSpace() bool { if portal.MXID == "" { return false } - if portal.Parent != nil { - return portal.addToSpace(portal.Parent.MXID) - } else if portal.Guild != nil { + if portal.Guild != nil { return portal.addToSpace(portal.Guild.MXID) } return false