Don't add reply sender to mentions array manually
Discord already adds it to the native mentions array
This commit is contained in:
@@ -217,8 +217,8 @@ func (portal *Portal) convertMessageBatch(log zerolog.Logger, source *User, mess
|
|||||||
puppet := portal.bridge.GetPuppetByID(msg.Author.ID)
|
puppet := portal.bridge.GetPuppetByID(msg.Author.ID)
|
||||||
puppet.UpdateInfo(source, msg.Author, msg.WebhookID)
|
puppet.UpdateInfo(source, msg.Author, msg.WebhookID)
|
||||||
intent := puppet.IntentFor(portal)
|
intent := puppet.IntentFor(portal)
|
||||||
replyTo, replySenderMXID := portal.getReplyTarget(source, "", msg.MessageReference, msg.Embeds, true)
|
replyTo := portal.getReplyTarget(source, "", msg.MessageReference, msg.Embeds, true)
|
||||||
mentions := portal.convertDiscordMentions(msg, replySenderMXID, false)
|
mentions := portal.convertDiscordMentions(msg, false)
|
||||||
|
|
||||||
ts, _ := discordgo.SnowflakeTimestamp(msg.ID)
|
ts, _ := discordgo.SnowflakeTimestamp(msg.ID)
|
||||||
log := log.With().
|
log := log.With().
|
||||||
|
|||||||
20
portal.go
20
portal.go
@@ -636,8 +636,8 @@ func (portal *Portal) handleDiscordMessageCreate(user *User, msg *discordgo.Mess
|
|||||||
lastThreadEvent = lastInThread.MXID
|
lastThreadEvent = lastInThread.MXID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
replyTo, replySenderMXID := portal.getReplyTarget(user, discordThreadID, msg.MessageReference, msg.Embeds, false)
|
replyTo := portal.getReplyTarget(user, discordThreadID, msg.MessageReference, msg.Embeds, false)
|
||||||
mentions := portal.convertDiscordMentions(msg, replySenderMXID, true)
|
mentions := portal.convertDiscordMentions(msg, true)
|
||||||
|
|
||||||
ts, _ := discordgo.SnowflakeTimestamp(msg.ID)
|
ts, _ := discordgo.SnowflakeTimestamp(msg.ID)
|
||||||
parts := portal.convertDiscordMessage(ctx, puppet, intent, msg)
|
parts := portal.convertDiscordMessage(ctx, puppet, intent, msg)
|
||||||
@@ -688,7 +688,7 @@ func isReplyEmbed(embed *discordgo.MessageEmbed) bool {
|
|||||||
return hackyReplyPattern.MatchString(embed.Description)
|
return hackyReplyPattern.MatchString(embed.Description)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) getReplyTarget(source *User, threadID string, ref *discordgo.MessageReference, embeds []*discordgo.MessageEmbed, allowNonExistent bool) (*event.InReplyTo, id.UserID) {
|
func (portal *Portal) getReplyTarget(source *User, threadID string, ref *discordgo.MessageReference, embeds []*discordgo.MessageEmbed, allowNonExistent bool) *event.InReplyTo {
|
||||||
if ref == nil && len(embeds) > 0 {
|
if ref == nil && len(embeds) > 0 {
|
||||||
match := hackyReplyPattern.FindStringSubmatch(embeds[0].Description)
|
match := hackyReplyPattern.FindStringSubmatch(embeds[0].Description)
|
||||||
if match != nil && match[1] == portal.GuildID && (match[2] == portal.Key.ChannelID || match[2] == threadID) {
|
if match != nil && match[1] == portal.GuildID && (match[2] == portal.Key.ChannelID || match[2] == threadID) {
|
||||||
@@ -700,7 +700,7 @@ func (portal *Portal) getReplyTarget(source *User, threadID string, ref *discord
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ref == nil {
|
if ref == nil {
|
||||||
return nil, ""
|
return nil
|
||||||
}
|
}
|
||||||
isHungry := portal.bridge.Config.Homeserver.Software == bridgeconfig.SoftwareHungry
|
isHungry := portal.bridge.Config.Homeserver.Software == bridgeconfig.SoftwareHungry
|
||||||
if !isHungry {
|
if !isHungry {
|
||||||
@@ -713,25 +713,25 @@ func (portal *Portal) getReplyTarget(source *User, threadID string, ref *discord
|
|||||||
if ref.ChannelID != portal.Key.ChannelID && ref.ChannelID != threadID && crossRoomReplies {
|
if ref.ChannelID != portal.Key.ChannelID && ref.ChannelID != threadID && crossRoomReplies {
|
||||||
targetPortal = portal.bridge.GetExistingPortalByID(database.PortalKey{ChannelID: ref.ChannelID, Receiver: source.DiscordID})
|
targetPortal = portal.bridge.GetExistingPortalByID(database.PortalKey{ChannelID: ref.ChannelID, Receiver: source.DiscordID})
|
||||||
if targetPortal == nil {
|
if targetPortal == nil {
|
||||||
return nil, ""
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
replyToMsg := portal.bridge.DB.Message.GetByDiscordID(targetPortal.Key, ref.MessageID)
|
replyToMsg := portal.bridge.DB.Message.GetByDiscordID(targetPortal.Key, ref.MessageID)
|
||||||
if len(replyToMsg) > 0 {
|
if len(replyToMsg) > 0 {
|
||||||
if !crossRoomReplies {
|
if !crossRoomReplies {
|
||||||
return &event.InReplyTo{EventID: replyToMsg[0].MXID}, replyToMsg[0].SenderMXID
|
return &event.InReplyTo{EventID: replyToMsg[0].MXID}
|
||||||
}
|
}
|
||||||
return &event.InReplyTo{
|
return &event.InReplyTo{
|
||||||
EventID: replyToMsg[0].MXID,
|
EventID: replyToMsg[0].MXID,
|
||||||
UnstableRoomID: targetPortal.MXID,
|
UnstableRoomID: targetPortal.MXID,
|
||||||
}, replyToMsg[0].SenderMXID
|
}
|
||||||
} else if allowNonExistent {
|
} else if allowNonExistent {
|
||||||
return &event.InReplyTo{
|
return &event.InReplyTo{
|
||||||
EventID: targetPortal.deterministicEventID(ref.MessageID, ""),
|
EventID: targetPortal.deterministicEventID(ref.MessageID, ""),
|
||||||
UnstableRoomID: targetPortal.MXID,
|
UnstableRoomID: targetPortal.MXID,
|
||||||
}, ""
|
}
|
||||||
}
|
}
|
||||||
return nil, ""
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const JoinThreadReaction = "join thread"
|
const JoinThreadReaction = "join thread"
|
||||||
@@ -902,7 +902,7 @@ func (portal *Portal) handleDiscordMessageUpdate(user *User, msg *discordgo.Mess
|
|||||||
}
|
}
|
||||||
puppet.addWebhookMeta(converted, msg)
|
puppet.addWebhookMeta(converted, msg)
|
||||||
puppet.addMemberMeta(converted, msg)
|
puppet.addMemberMeta(converted, msg)
|
||||||
converted.Content.Mentions = portal.convertDiscordMentions(msg, "", false)
|
converted.Content.Mentions = portal.convertDiscordMentions(msg, false)
|
||||||
converted.Content.SetEdit(existing[0].MXID)
|
converted.Content.SetEdit(existing[0].MXID)
|
||||||
// Never actually mention new users of edits, only include mentions inside m.new_content
|
// Never actually mention new users of edits, only include mentions inside m.new_content
|
||||||
converted.Content.Mentions = &event.Mentions{}
|
converted.Content.Mentions = &event.Mentions{}
|
||||||
|
|||||||
@@ -621,7 +621,7 @@ func isPlainGifMessage(msg *discordgo.Message) bool {
|
|||||||
(msg.Embeds[0].Type == discordgo.EmbedTypeImage && msg.Embeds[0].Image == nil && msg.Embeds[0].Thumbnail != nil))
|
(msg.Embeds[0].Type == discordgo.EmbedTypeImage && msg.Embeds[0].Image == nil && msg.Embeds[0].Thumbnail != nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) convertDiscordMentions(msg *discordgo.Message, replySender id.UserID, syncGhosts bool) *event.Mentions {
|
func (portal *Portal) convertDiscordMentions(msg *discordgo.Message, syncGhosts bool) *event.Mentions {
|
||||||
var matrixMentions event.Mentions
|
var matrixMentions event.Mentions
|
||||||
for _, mention := range msg.Mentions {
|
for _, mention := range msg.Mentions {
|
||||||
puppet := portal.bridge.GetPuppetByID(mention.ID)
|
puppet := portal.bridge.GetPuppetByID(mention.ID)
|
||||||
@@ -635,9 +635,6 @@ func (portal *Portal) convertDiscordMentions(msg *discordgo.Message, replySender
|
|||||||
matrixMentions.UserIDs = append(matrixMentions.UserIDs, puppet.MXID)
|
matrixMentions.UserIDs = append(matrixMentions.UserIDs, puppet.MXID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if replySender != "" {
|
|
||||||
matrixMentions.UserIDs = append(matrixMentions.UserIDs, replySender)
|
|
||||||
}
|
|
||||||
slices.Sort(matrixMentions.UserIDs)
|
slices.Sort(matrixMentions.UserIDs)
|
||||||
matrixMentions.UserIDs = slices.Compact(matrixMentions.UserIDs)
|
matrixMentions.UserIDs = slices.Compact(matrixMentions.UserIDs)
|
||||||
if msg.MentionEveryone {
|
if msg.MentionEveryone {
|
||||||
|
|||||||
Reference in New Issue
Block a user