mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-12-14 09:23:51 +01:00
Add support for Matrix -> WhatsApp captions with MSC2530
This commit is contained in:
parent
73f4449761
commit
794975eaa0
1 changed files with 13 additions and 3 deletions
16
portal.go
16
portal.go
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue