diff --git a/pkg/msgconv/from-matrix.go b/pkg/msgconv/from-matrix.go index 49f60486..ac26a543 100644 --- a/pkg/msgconv/from-matrix.go +++ b/pkg/msgconv/from-matrix.go @@ -181,6 +181,7 @@ func (mc *MessageConverter) constructMediaMessage( var caption string if content.FileName != "" && content.Body != content.FileName { caption, contextInfo.MentionedJID = mc.parseText(ctx, content) + caption = replaceRoomMention(caption, content.Mentions) } switch content.MsgType { case event.MessageType(event.EventSticker.Type): @@ -305,6 +306,13 @@ func (mc *MessageConverter) constructMediaMessage( } } +func replaceRoomMention(text string, mentions *event.Mentions) string { + if mentions != nil && mentions.Room { + text = strings.Replace(text, "@room", "@all", 1) + } + return text +} + func (mc *MessageConverter) parseText(ctx context.Context, content *event.MessageEventContent) (text string, mentions []string) { mentions = make([]string, 0) @@ -330,6 +338,7 @@ func (mc *MessageConverter) constructTextMessage( return mc.constructGroupInviteMessage(ctx, content, groupInvite, contextInfo) } text, mentions := mc.parseText(ctx, content) + text = replaceRoomMention(text, content.Mentions) if len(mentions) > 0 { contextInfo.MentionedJID = mentions } @@ -358,6 +367,7 @@ func (mc *MessageConverter) constructGroupInviteMessage( return nil, fmt.Errorf("failed to parse invite meta: %w", err) } text, mentions := mc.parseText(ctx, content) + text = replaceRoomMention(text, content.Mentions) if len(mentions) > 0 { contextInfo.MentionedJID = mentions } diff --git a/pkg/msgconv/from-whatsapp.go b/pkg/msgconv/from-whatsapp.go index 11569e29..ac8a64be 100644 --- a/pkg/msgconv/from-whatsapp.go +++ b/pkg/msgconv/from-whatsapp.go @@ -239,6 +239,10 @@ func (mc *MessageConverter) ToMatrix( mc.addMentions(ctx, contextInfo.GetMentionedJID(), part.Content) if contextInfo.GetNonJIDMentions() == 1 { part.Content.Mentions.Room = true + part.Content.Body = strings.Replace(part.Content.Body, "@all", "@room", 1) + if part.Content.FormattedBody != "" { + part.Content.FormattedBody = strings.Replace(part.Content.FormattedBody, "@all", "@room", 1) + } } cm := &bridgev2.ConvertedMessage{ diff --git a/pkg/msgconv/matrixpoll.go b/pkg/msgconv/matrixpoll.go index 0dc32132..eb0737ee 100644 --- a/pkg/msgconv/matrixpoll.go +++ b/pkg/msgconv/matrixpoll.go @@ -74,6 +74,7 @@ func (mc *MessageConverter) PollStartToWhatsApp( contextInfo := mc.generateContextInfo(ctx, replyTo, portal, nil, content.Mentions != nil && content.Mentions.Room) var question string question, contextInfo.MentionedJID = mc.msc1767ToWhatsApp(ctx, content.PollStart.Question, content.Mentions) + question = replaceRoomMention(question, content.Mentions) if len(question) == 0 { return nil, nil, errPollMissingQuestion }