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

Compare commits

...
Author SHA1 Message Date
indent[bot]
015ad733a3
msgconv: log size breakdown of converted parts over the cut-off limit (#1047)
Co-authored-by: Indent <noreply@indent.com>
2026-11-11 00:53:07 +00:00
indent[bot]
a15089b18d
backfill: skip unparseable history messages without content (#1046)
Co-authored-by: Indent <noreply@indent.com>
2026-11-10 06:19:41 -07:00
indent[bot]
945474343f
backfill: log stub and message type of unparseable history messages (#1034)
Co-authored-by: Indent <noreply@indent.com>
2026-11-09 18:09:56 +00:00
indent[bot]
5c8c1fc835
handlewhatsapp: ignore HD replacement messages without replacement content (#1037)
Co-authored-by: Indent <noreply@indent.com>
2026-11-09 18:09:28 +00:00
4 changed files with 48 additions and 1 deletions

View file

@ -293,11 +293,17 @@ func (wa *WhatsAppClient) handleWAHistorySync(
for i, rawMsg := range rawMessages { for i, rawMsg := range rawMessages {
// Don't store messages that will just be skipped. // Don't store messages that will just be skipped.
msgEvt, err := wa.Client.ParseWebMessage(jid, rawMsg.GetMessage()) 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). log.Warn().Err(err).
Int("msg_index", i). Int("msg_index", i).
Str("msg_id", rawMsg.GetMessage().GetKey().GetID()). Str("msg_id", rawMsg.GetMessage().GetKey().GetID()).
Uint64("msg_time_seconds", rawMsg.GetMessage().GetMessageTimestamp()). Uint64("msg_time_seconds", rawMsg.GetMessage().GetMessageTimestamp()).
Stringer("stub_type", rawMsg.GetMessage().GetMessageStubType()).
Str("message_type", getMessageType(rawMsg.GetMessage().GetMessage())).
Bool("from_me", rawMsg.GetMessage().GetKey().GetFromMe()).
Msg("Dropping historical message due to parse error") Msg("Dropping historical message due to parse error")
log.Trace(). log.Trace().
Any("web_message_info", rawMsg.GetMessage()). Any("web_message_info", rawMsg.GetMessage()).

View file

@ -374,6 +374,14 @@ func (wa *WhatsAppClient) handleWAMessage(ctx context.Context, evt *events.Messa
if assocType := messageAssoc.GetAssociationType(); assocType == waE2E.MessageAssociation_HD_IMAGE_DUAL_UPLOAD || assocType == waE2E.MessageAssociation_HD_VIDEO_DUAL_UPLOAD { if assocType := messageAssoc.GetAssociationType(); assocType == waE2E.MessageAssociation_HD_IMAGE_DUAL_UPLOAD || assocType == waE2E.MessageAssociation_HD_VIDEO_DUAL_UPLOAD {
parentKey := messageAssoc.GetParentMessageKey() parentKey := messageAssoc.GetParentMessageKey()
protocolMsg, shouldHideEdit := makeHDMediaReplacementEdit(evt.Message, parentKey) protocolMsg, shouldHideEdit := makeHDMediaReplacementEdit(evt.Message, parentKey)
if protocolMsg.GetEditedMessage() == nil {
wa.UserLogin.Log.Debug().
Str("message_id", evt.Info.ID).
Str("parent_id", parentKey.GetID()).
Stringer("assoc_type", assocType).
Msg("Ignoring HD replacement message without replacement content")
return
}
dontRenderEdited = shouldHideEdit dontRenderEdited = shouldHideEdit
wa.UserLogin.Log.Debug(). wa.UserLogin.Log.Debug().
Str("message_id", evt.Info.ID). Str("message_id", evt.Info.ID).

View file

@ -322,6 +322,7 @@ func (mc *MessageConverter) ToMatrix(
cm.ThreadRoot = ptr.Ptr(waid.MakeMessageID(chat, pcp, commentTarget.GetID())) cm.ThreadRoot = ptr.Ptr(waid.MakeMessageID(chat, pcp, commentTarget.GetID()))
} }
mc.cutOffLongMessage(part.Content) mc.cutOffLongMessage(part.Content)
logOversizedPart(ctx, part)
return cm return cm
} }

View file

@ -18,6 +18,7 @@ package msgconv
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"html" "html"
"regexp" "regexp"
@ -25,6 +26,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/rs/zerolog"
"go.mau.fi/whatsmeow/proto/waE2E" "go.mau.fi/whatsmeow/proto/waE2E"
"maunium.net/go/mautrix/bridgev2" "maunium.net/go/mautrix/bridgev2"
"maunium.net/go/mautrix/event" "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) { func (mc *MessageConverter) parseFormatting(content *event.MessageEventContent, allowInlineURL, forceHTML bool) {
parsedHTML := parseWAFormattingToHTML(content.Body, allowInlineURL) parsedHTML := parseWAFormattingToHTML(content.Body, allowInlineURL)
if forceHTML || parsedHTML != event.TextToHTML(content.Body) { if forceHTML || parsedHTML != event.TextToHTML(content.Body) {