Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/msgconv/from-matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/msgconv/from-whatsapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 1 addition & 0 deletions pkg/msgconv/matrixpoll.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down