Skip to content

Commit

Permalink
Add support for Matrix -> WhatsApp captions with MSC2530
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jul 11, 2022
1 parent 73f4449 commit 794975e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2779,9 +2779,16 @@ func (portal *Portal) convertWebPtoPNG(webpImage []byte) ([]byte, error) {
}

func (portal *Portal) preprocessMatrixMedia(ctx context.Context, sender *User, relaybotFormatted bool, content *event.MessageEventContent, eventID id.EventID, mediaType whatsmeow.MediaType) (*MediaUpload, error) {
fileName := content.Body
var caption string
var mentionedJIDs []string
if relaybotFormatted {
var hasHTMLCaption bool
if content.FileName != "" && content.Body != content.FileName {
fileName = content.FileName
caption = content.Body
hasHTMLCaption = content.Format == event.FormatHTML
}
if relaybotFormatted || hasHTMLCaption {
caption, mentionedJIDs = portal.bridge.Formatter.ParseMatrix(content.FormattedBody)
}

Expand Down Expand Up @@ -2839,6 +2846,7 @@ func (portal *Portal) preprocessMatrixMedia(ctx context.Context, sender *User, r

return &MediaUpload{
UploadResponse: uploadResp,
FileName: fileName,
Caption: caption,
MentionedJIDs: mentionedJIDs,
Thumbnail: thumbnail,
Expand All @@ -2849,6 +2857,7 @@ func (portal *Portal) preprocessMatrixMedia(ctx context.Context, sender *User, r
type MediaUpload struct {
whatsmeow.UploadResponse
Caption string
FileName string
MentionedJIDs []string
Thumbnail []byte
FileLength int
Expand Down Expand Up @@ -3054,10 +3063,11 @@ func (portal *Portal) convertMatrixMessage(ctx context.Context, sender *User, ev
}
msg.DocumentMessage = &waProto.DocumentMessage{
ContextInfo: &ctxInfo,
Caption: &media.Caption,
JpegThumbnail: media.Thumbnail,
Url: &media.URL,
Title: &content.Body,
FileName: &content.Body,
Title: &media.FileName,
FileName: &media.FileName,
MediaKey: media.MediaKey,
Mimetype: &content.GetInfo().MimeType,
FileEncSha256: media.FileEncSHA256,
Expand Down

0 comments on commit 794975e

Please sign in to comment.