Remove duplicate calls to send m.space.child for DM rooms
This commit is contained in:
25
portal.go
25
portal.go
@@ -424,7 +424,11 @@ func (portal *Portal) CreateMatrixRoom(user *User, channel *discordgo.Channel) e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
portal.updateSpace(user)
|
if portal.GuildID == "" {
|
||||||
|
user.addPrivateChannelToSpace(portal)
|
||||||
|
} else {
|
||||||
|
portal.updateSpace()
|
||||||
|
}
|
||||||
portal.ensureUserInvited(user)
|
portal.ensureUserInvited(user)
|
||||||
user.syncChatDoublePuppetDetails(portal, true)
|
user.syncChatDoublePuppetDetails(portal, true)
|
||||||
|
|
||||||
@@ -1704,21 +1708,11 @@ func (portal *Portal) ExpectedSpaceID() id.RoomID {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) IsInSpace(user *User) bool {
|
func (portal *Portal) updateSpace() bool {
|
||||||
if portal.GuildID == "" {
|
|
||||||
return user.IsInSpace(portal.Key.ChannelID)
|
|
||||||
} else {
|
|
||||||
return portal.ExpectedSpaceID() == portal.InSpace
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (portal *Portal) updateSpace(user *User) bool {
|
|
||||||
if portal.MXID == "" {
|
if portal.MXID == "" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if portal.GuildID == "" {
|
if portal.Parent != nil {
|
||||||
user.addPrivateChannelToSpace(portal)
|
|
||||||
} else if portal.Parent != nil {
|
|
||||||
return portal.addToSpace(portal.Parent.MXID)
|
return portal.addToSpace(portal.Parent.MXID)
|
||||||
} else if portal.Guild != nil {
|
} else if portal.Guild != nil {
|
||||||
return portal.addToSpace(portal.Guild.MXID)
|
return portal.addToSpace(portal.Guild.MXID)
|
||||||
@@ -1781,8 +1775,9 @@ func (portal *Portal) UpdateInfo(source *User, meta *discordgo.Channel) *discord
|
|||||||
}
|
}
|
||||||
changed = portal.UpdateTopic(meta.Topic) || changed
|
changed = portal.UpdateTopic(meta.Topic) || changed
|
||||||
changed = portal.UpdateParent(meta.ParentID) || changed
|
changed = portal.UpdateParent(meta.ParentID) || changed
|
||||||
if portal.MXID != "" && !portal.IsInSpace(source) {
|
// Private channels are added to the space in User.handlePrivateChannel
|
||||||
changed = portal.updateSpace(source) || changed
|
if portal.GuildID != "" && portal.MXID != "" && portal.ExpectedSpaceID() != portal.InSpace {
|
||||||
|
changed = portal.updateSpace() || changed
|
||||||
}
|
}
|
||||||
if changed {
|
if changed {
|
||||||
portal.UpdateBridgeInfo()
|
portal.UpdateBridgeInfo()
|
||||||
|
|||||||
4
user.go
4
user.go
@@ -541,11 +541,11 @@ func (user *User) readyHandler(_ *discordgo.Session, r *discordgo.Ready) {
|
|||||||
for _, guild := range r.Guilds {
|
for _, guild := range r.Guilds {
|
||||||
user.handleGuild(guild, updateTS, portalsInSpace[guild.ID])
|
user.handleGuild(guild, updateTS, portalsInSpace[guild.ID])
|
||||||
}
|
}
|
||||||
user.PrunePortalList(updateTS)
|
|
||||||
for i, ch := range r.PrivateChannels {
|
for i, ch := range r.PrivateChannels {
|
||||||
portal := user.GetPortalByMeta(ch)
|
portal := user.GetPortalByMeta(ch)
|
||||||
user.handlePrivateChannel(portal, ch, updateTS, i < user.bridge.Config.Bridge.PrivateChannelCreateLimit, portalsInSpace[portal.Key.ChannelID])
|
user.handlePrivateChannel(portal, ch, updateTS, i < user.bridge.Config.Bridge.PrivateChannelCreateLimit, portalsInSpace[portal.Key.ChannelID])
|
||||||
}
|
}
|
||||||
|
user.PrunePortalList(updateTS)
|
||||||
|
|
||||||
if r.ReadState.Version > user.ReadStateVersion {
|
if r.ReadState.Version > user.ReadStateVersion {
|
||||||
// TODO can we figure out which read states are actually new?
|
// TODO can we figure out which read states are actually new?
|
||||||
@@ -595,7 +595,7 @@ func (user *User) handlePrivateChannel(portal *Portal, meta *discordgo.Channel,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) addGuildToSpace(guild *Guild, isInSpace bool, timestamp time.Time) bool {
|
func (user *User) addGuildToSpace(guild *Guild, isInSpace bool, timestamp time.Time) bool {
|
||||||
if len(guild.MXID) > 0 {
|
if len(guild.MXID) > 0 && !isInSpace {
|
||||||
_, err := user.bridge.Bot.SendStateEvent(user.GetSpaceRoom(), event.StateSpaceChild, guild.MXID.String(), &event.SpaceChildEventContent{
|
_, err := user.bridge.Bot.SendStateEvent(user.GetSpaceRoom(), event.StateSpaceChild, guild.MXID.String(), &event.SpaceChildEventContent{
|
||||||
Via: []string{user.bridge.AS.HomeserverDomain},
|
Via: []string{user.bridge.AS.HomeserverDomain},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user