Ensure user invited when updating portal info. Probably fixes #62
This commit is contained in:
@@ -371,10 +371,10 @@ func fnRejoinSpace(ce *WrappedCommandEvent) {
|
|||||||
}
|
}
|
||||||
user := ce.User
|
user := ce.User
|
||||||
if ce.Args[0] == "main" {
|
if ce.Args[0] == "main" {
|
||||||
user.ensureInvited(nil, user.GetSpaceRoom(), false)
|
user.ensureInvited(nil, user.GetSpaceRoom(), false, true)
|
||||||
ce.Reply("Invited you to your main space ([link](%s))", user.GetSpaceRoom().URI(ce.Bridge.AS.HomeserverDomain).MatrixToURL())
|
ce.Reply("Invited you to your main space ([link](%s))", user.GetSpaceRoom().URI(ce.Bridge.AS.HomeserverDomain).MatrixToURL())
|
||||||
} else if ce.Args[0] == "dms" {
|
} else if ce.Args[0] == "dms" {
|
||||||
user.ensureInvited(nil, user.GetDMSpaceRoom(), false)
|
user.ensureInvited(nil, user.GetDMSpaceRoom(), false, true)
|
||||||
ce.Reply("Invited you to your DM space ([link](%s))", user.GetDMSpaceRoom().URI(ce.Bridge.AS.HomeserverDomain).MatrixToURL())
|
ce.Reply("Invited you to your DM space ([link](%s))", user.GetDMSpaceRoom().URI(ce.Bridge.AS.HomeserverDomain).MatrixToURL())
|
||||||
} else if _, err := strconv.Atoi(ce.Args[0]); err == nil {
|
} else if _, err := strconv.Atoi(ce.Args[0]); err == nil {
|
||||||
ce.Reply("Rejoining guild spaces is not yet implemented")
|
ce.Reply("Rejoining guild spaces is not yet implemented")
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ func (guild *Guild) CreateMatrixRoom(user *User, meta *discordgo.Guild) error {
|
|||||||
guild.bridge.guildsLock.Unlock()
|
guild.bridge.guildsLock.Unlock()
|
||||||
guild.log.Infoln("Matrix room created:", guild.MXID)
|
guild.log.Infoln("Matrix room created:", guild.MXID)
|
||||||
|
|
||||||
user.ensureInvited(nil, guild.MXID, false)
|
user.ensureInvited(nil, guild.MXID, false, true)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -236,6 +236,7 @@ func (guild *Guild) UpdateInfo(source *User, meta *discordgo.Guild) *discordgo.G
|
|||||||
guild.UpdateBridgeInfo()
|
guild.UpdateBridgeInfo()
|
||||||
guild.Update()
|
guild.Update()
|
||||||
}
|
}
|
||||||
|
source.ensureInvited(nil, guild.MXID, false, false)
|
||||||
return meta
|
return meta
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
14
portal.go
14
portal.go
@@ -383,6 +383,7 @@ func (portal *Portal) CreateMatrixRoom(user *User, channel *discordgo.Channel) e
|
|||||||
portal.roomCreateLock.Lock()
|
portal.roomCreateLock.Lock()
|
||||||
defer portal.roomCreateLock.Unlock()
|
defer portal.roomCreateLock.Unlock()
|
||||||
if portal.MXID != "" {
|
if portal.MXID != "" {
|
||||||
|
portal.ensureUserInvited(user, false)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
portal.log.Infoln("Creating Matrix room for channel")
|
portal.log.Infoln("Creating Matrix room for channel")
|
||||||
@@ -520,7 +521,7 @@ func (portal *Portal) CreateMatrixRoom(user *User, channel *discordgo.Channel) e
|
|||||||
} else {
|
} else {
|
||||||
portal.updateSpace()
|
portal.updateSpace()
|
||||||
}
|
}
|
||||||
portal.ensureUserInvited(user)
|
portal.ensureUserInvited(user, true)
|
||||||
user.syncChatDoublePuppetDetails(portal, true)
|
user.syncChatDoublePuppetDetails(portal, true)
|
||||||
|
|
||||||
portal.syncParticipants(user, channel.Recipients)
|
portal.syncParticipants(user, channel.Recipients)
|
||||||
@@ -579,8 +580,8 @@ func (portal *Portal) handleDiscordMessages(msg portalDiscordMessage) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) ensureUserInvited(user *User) bool {
|
func (portal *Portal) ensureUserInvited(user *User, ignoreCache bool) bool {
|
||||||
return user.ensureInvited(portal.MainIntent(), portal.MXID, portal.IsPrivateChat())
|
return user.ensureInvited(portal.MainIntent(), portal.MXID, portal.IsPrivateChat(), ignoreCache)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) markMessageHandled(discordID string, editIndex int, authorID string, timestamp time.Time, threadID string, parts []database.MessagePart) {
|
func (portal *Portal) markMessageHandled(discordID string, editIndex int, authorID string, timestamp time.Time, threadID string, parts []database.MessagePart) {
|
||||||
@@ -909,7 +910,7 @@ func (portal *Portal) syncParticipant(source *User, participant *discordgo.User,
|
|||||||
user := portal.bridge.GetUserByID(participant.ID)
|
user := portal.bridge.GetUserByID(participant.ID)
|
||||||
if user != nil {
|
if user != nil {
|
||||||
log.Debug().Msg("Ensuring Matrix user is invited or joined to room")
|
log.Debug().Msg("Ensuring Matrix user is invited or joined to room")
|
||||||
portal.ensureUserInvited(user)
|
portal.ensureUserInvited(user, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if remove {
|
if remove {
|
||||||
@@ -931,7 +932,7 @@ func (portal *Portal) syncParticipants(source *User, participants []*discordgo.U
|
|||||||
|
|
||||||
user := portal.bridge.GetUserByID(participant.ID)
|
user := portal.bridge.GetUserByID(participant.ID)
|
||||||
if user != nil {
|
if user != nil {
|
||||||
portal.ensureUserInvited(user)
|
portal.ensureUserInvited(user, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if user == nil || !puppet.IntentFor(portal).IsCustomPuppet {
|
if user == nil || !puppet.IntentFor(portal).IsCustomPuppet {
|
||||||
@@ -2134,6 +2135,9 @@ func (portal *Portal) UpdateInfo(source *User, meta *discordgo.Channel) *discord
|
|||||||
fallthrough
|
fallthrough
|
||||||
default:
|
default:
|
||||||
changed = portal.UpdateName(meta) || changed
|
changed = portal.UpdateName(meta) || changed
|
||||||
|
if portal.MXID != "" {
|
||||||
|
portal.ensureUserInvited(source, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
changed = portal.UpdateTopic(meta.Topic) || changed
|
changed = portal.UpdateTopic(meta.Topic) || changed
|
||||||
changed = portal.UpdateParent(meta.ParentID) || changed
|
changed = portal.UpdateParent(meta.ParentID) || changed
|
||||||
|
|||||||
10
user.go
10
user.go
@@ -333,7 +333,7 @@ func (user *User) getSpaceRoom(ptr *id.RoomID, name, topic string, parent id.Roo
|
|||||||
} else {
|
} else {
|
||||||
*ptr = resp.RoomID
|
*ptr = resp.RoomID
|
||||||
user.Update()
|
user.Update()
|
||||||
user.ensureInvited(nil, *ptr, false)
|
user.ensureInvited(nil, *ptr, false, true)
|
||||||
|
|
||||||
if parent != "" {
|
if parent != "" {
|
||||||
_, err = user.bridge.Bot.SendStateEvent(parent, event.StateSpaceChild, resp.RoomID.String(), &event.SpaceChildEventContent{
|
_, err = user.bridge.Bot.SendStateEvent(parent, event.StateSpaceChild, resp.RoomID.String(), &event.SpaceChildEventContent{
|
||||||
@@ -1246,10 +1246,16 @@ func (user *User) interactionSuccessHandler(s *discordgo.InteractionSuccess) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) ensureInvited(intent *appservice.IntentAPI, roomID id.RoomID, isDirect bool) bool {
|
func (user *User) ensureInvited(intent *appservice.IntentAPI, roomID id.RoomID, isDirect, ignoreCache bool) bool {
|
||||||
|
if roomID == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if intent == nil {
|
if intent == nil {
|
||||||
intent = user.bridge.Bot
|
intent = user.bridge.Bot
|
||||||
}
|
}
|
||||||
|
if !ignoreCache && intent.StateStore.IsInvited(roomID, user.MXID) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
ret := false
|
ret := false
|
||||||
|
|
||||||
inviteContent := event.Content{
|
inviteContent := event.Content{
|
||||||
|
|||||||
Reference in New Issue
Block a user