Skip to content

Commit

Permalink
Only send fallback if event has caption
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Nov 22, 2024
1 parent 6b11e1e commit 7382012
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bridgev2/matrix/intent.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (as *ASIntent) SendMessage(ctx context.Context, roomID id.RoomID, eventType
})
}
if as.Connector.Config.Matrix.CaptionFallbacks && eventType == event.EventMessage {
if msgContent, ok := content.Parsed.(*event.MessageEventContent); ok {
if msgContent, ok := content.Parsed.(*event.MessageEventContent); ok && msgContent.HasCaption() {
defer func() {
go as.sendCaptionFallback(ctx, roomID, msgContent, extra.Timestamp, resp.EventID)
}()
Expand Down
4 changes: 4 additions & 0 deletions event/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ func ReverseTextToHTML(input string) string {
return html.UnescapeString(strings.ReplaceAll(input, "<br/>", "\n"))
}

func (content *MessageEventContent) HasCaption() bool {
return content.MsgType.IsMedia() && content.Body != "" && content.FileName != "" && content.Body != content.FileName
}

func (content *MessageEventContent) EnsureHasHTML() {
if len(content.FormattedBody) == 0 || content.Format != FormatHTML {
content.FormattedBody = TextToHTML(content.Body)
Expand Down

0 comments on commit 7382012

Please sign in to comment.