mirror of
https://github.com/mautrix/whatsapp.git
synced 2026-11-12 00:59:17 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
015ad733a3 |
||
|
|
a15089b18d |
5 changed files with 40 additions and 47 deletions
|
|
@ -293,7 +293,10 @@ func (wa *WhatsAppClient) handleWAHistorySync(
|
|||
for i, rawMsg := range rawMessages {
|
||||
// Don't store messages that will just be skipped.
|
||||
msgEvt, err := wa.Client.ParseWebMessage(jid, rawMsg.GetMessage())
|
||||
if err != nil {
|
||||
if err != nil && getMessageType(rawMsg.GetMessage().GetMessage()) == "ignore" {
|
||||
ignoredTypes++
|
||||
continue
|
||||
} else if err != nil {
|
||||
log.Warn().Err(err).
|
||||
Int("msg_index", i).
|
||||
Str("msg_id", rawMsg.GetMessage().GetKey().GetID()).
|
||||
|
|
|
|||
|
|
@ -273,12 +273,9 @@ func (wa *WhatsAppClient) HandleMatrixEdit(ctx context.Context, edit *bridgev2.M
|
|||
return fmt.Errorf("failed to parse portal ID: %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))
|
||||
}
|
||||
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)
|
||||
|
||||
|
|
|
|||
|
|
@ -204,46 +204,6 @@ 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,
|
||||
|
|
|
|||
|
|
@ -322,6 +322,7 @@ func (mc *MessageConverter) ToMatrix(
|
|||
cm.ThreadRoot = ptr.Ptr(waid.MakeMessageID(chat, pcp, commentTarget.GetID()))
|
||||
}
|
||||
mc.cutOffLongMessage(part.Content)
|
||||
logOversizedPart(ctx, part)
|
||||
|
||||
return cm
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package msgconv
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html"
|
||||
"regexp"
|
||||
|
|
@ -25,6 +26,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"go.mau.fi/whatsmeow/proto/waE2E"
|
||||
"maunium.net/go/mautrix/bridgev2"
|
||||
"maunium.net/go/mautrix/event"
|
||||
|
|
@ -72,6 +74,36 @@ func (mc *MessageConverter) cutOffLongMessage(content *event.MessageEventContent
|
|||
}
|
||||
}
|
||||
|
||||
func logOversizedPart(ctx context.Context, part *bridgev2.ConvertedMessagePart) {
|
||||
if part == nil || part.Content == nil {
|
||||
return
|
||||
}
|
||||
contentJSON, _ := json.Marshal(part.Content)
|
||||
extraJSON, _ := json.Marshal(part.Extra)
|
||||
if len(contentJSON)+len(extraJSON) <= 40000 {
|
||||
return
|
||||
}
|
||||
extraKeys := make([]string, 0, len(part.Extra))
|
||||
for key := range part.Extra {
|
||||
extraKeys = append(extraKeys, key)
|
||||
}
|
||||
var mentionCount int
|
||||
if part.Content.Mentions != nil {
|
||||
mentionCount = len(part.Content.Mentions.UserIDs)
|
||||
}
|
||||
linkPreviewJSON, _ := json.Marshal(part.Content.BeeperLinkPreviews)
|
||||
zerolog.Ctx(ctx).Warn().
|
||||
Str("msg_type", string(part.Content.MsgType)).
|
||||
Int("content_json_size", len(contentJSON)).
|
||||
Int("extra_json_size", len(extraJSON)).
|
||||
Int("body_size", len(part.Content.Body)).
|
||||
Int("formatted_body_size", len(part.Content.FormattedBody)).
|
||||
Int("mention_count", mentionCount).
|
||||
Int("link_preview_json_size", len(linkPreviewJSON)).
|
||||
Strs("extra_keys", extraKeys).
|
||||
Msg("Converted message part is larger than the cut-off limit")
|
||||
}
|
||||
|
||||
func (mc *MessageConverter) parseFormatting(content *event.MessageEventContent, allowInlineURL, forceHTML bool) {
|
||||
parsedHTML := parseWAFormattingToHTML(content.Body, allowInlineURL)
|
||||
if forceHTML || parsedHTML != event.TextToHTML(content.Body) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue