nix-packages/matrix/mautrix-discord/no-category-spaces.patch
2022-11-24 14:39:18 +01:00

101 lines
4 KiB
Diff

diff --git a/database/portal.go b/database/portal.go
index d8ce90d..7c2d431 100644
--- a/database/portal.go
+++ b/database/portal.go
@@ -150,13 +150,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)
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)
`
_, 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())
@@ -169,13 +169,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
- WHERE dcid=$17 AND receiver=$18
+ SET type=$1, other_user_id=$2, dc_guild_id=$3, mxid=$4,
+ plain_name=$5, name=$6, name_set=$7, topic=$8, topic_set=$9, avatar=$10, avatar_url=$11, avatar_set=$12,
+ encrypted=$13, in_space=$14, first_event_id=$15
+ WHERE dcid=$16 AND receiver=$17
`
_, 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(),
p.Key.ChannelID, p.Key.Receiver)
diff --git a/portal.go b/portal.go
index 25e0dc2..e305942 100644
--- a/portal.go
+++ b/portal.go
@@ -108,15 +108,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
}
@@ -351,7 +342,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
@@ -1777,18 +1768,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 ""
@@ -1798,9 +1783,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