Watch
1
0
Fork
You've already forked mautrix-whatsapp
0
mirror of https://github.com/mautrix/whatsapp.git synced 2026-11-12 00:59:17 -05:00

Compare commits

...
Author SHA1 Message Date
Gerardo Rodriguez
7cf259940d msgconv/from-matrix: build caption edits through constructMediaMessage 2026-11-10 19:06:21 +00:00
Gerardo Rodriguez
d9525654ae handlematrix: match GIF edits to how GIFs were sent 2026-11-10 06:14:14 +00:00
Gerardo Rodriguez
f269a5b4ec handlematrix: send only the caption in media edits 2026-11-10 06:10:00 +00:00
2 changed files with 46 additions and 3 deletions

View file

@ -273,9 +273,12 @@ func (wa *WhatsAppClient) HandleMatrixEdit(ctx context.Context, edit *bridgev2.M
return fmt.Errorf("failed to parse portal ID: %w", err)
}
waMsg, _, err := wa.Main.MsgConv.ToWhatsApp(ctx, wa.Client, edit.Event, edit.Content, nil, nil, edit.Portal)
if err != nil {
return wrapConversionError(fmt.Errorf("failed to convert message: %w", err))
waMsg := wa.Main.MsgConv.CaptionEditToWhatsApp(ctx, wa.Client, edit.Event, edit.Content, edit.Portal)
if waMsg == nil {
waMsg, _, err = wa.Main.MsgConv.ToWhatsApp(ctx, wa.Client, edit.Event, edit.Content, nil, nil, edit.Portal)
if err != nil {
return wrapConversionError(fmt.Errorf("failed to convert message: %w", err))
}
}
defer wa.mcTrack(edit, time.Now(), &retErr)

View file

@ -204,6 +204,46 @@ func (mc *MessageConverter) ToWhatsApp(
return message, extra, nil
}
func (mc *MessageConverter) CaptionEditToWhatsApp(
ctx context.Context,
client *whatsmeow.Client,
evt *event.Event,
content *event.MessageEventContent,
portal *bridgev2.Portal,
) *waE2E.Message {
mime := content.GetInfo().MimeType
if mime == "" {
return nil
} else if mime == "image/gif" {
content.MsgType = event.MsgVideo
}
ctx = context.WithValue(ctx, contextKeyClient, client)
ctx = context.WithValue(ctx, contextKeyPortal, portal)
contextInfo := mc.generateContextInfo(ctx, nil, content.RelatesTo, portal, content.BeeperDisappearingTimer, content.Mentions != nil && content.Mentions.Room)
msg := mc.constructMediaMessage(ctx, content, evt, &whatsmeow.UploadResponse{}, nil, contextInfo, mime)
switch {
case msg.GetImageMessage() != nil:
return &waE2E.Message{ImageMessage: &waE2E.ImageMessage{
Caption: msg.ImageMessage.Caption,
ContextInfo: contextInfo,
}}
case msg.GetVideoMessage() != nil:
return &waE2E.Message{VideoMessage: &waE2E.VideoMessage{
Caption: msg.VideoMessage.Caption,
ContextInfo: contextInfo,
}}
case msg.GetDocumentMessage() != nil, msg.GetDocumentWithCaptionMessage() != nil:
return &waE2E.Message{DocumentWithCaptionMessage: &waE2E.FutureProofMessage{
Message: &waE2E.Message{DocumentMessage: &waE2E.DocumentMessage{
Caption: proto.String(msg.GetDocumentWithCaptionMessage().GetMessage().GetDocumentMessage().GetCaption()),
ContextInfo: contextInfo,
}},
}}
default:
return nil
}
}
func (mc *MessageConverter) constructMediaMessage(
ctx context.Context,
content *event.MessageEventContent,