mirror of
https://github.com/mautrix/whatsapp.git
synced 2026-11-12 00:59:17 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08f33e20cf | ||
|
|
6cb748bc9c | ||
|
|
5edff0e7bf |
4 changed files with 6 additions and 37 deletions
|
|
@ -293,10 +293,7 @@ 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 && getMessageType(rawMsg.GetMessage().GetMessage()) == "ignore" {
|
if err != nil {
|
||||||
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()).
|
||||||
|
|
|
||||||
|
|
@ -168,6 +168,11 @@ func (mc *MessageConverter) ToWhatsApp(
|
||||||
Comment: &content.Body,
|
Comment: &content.Body,
|
||||||
ContextInfo: contextInfo,
|
ContextInfo: contextInfo,
|
||||||
}
|
}
|
||||||
|
if msc3488, ok := evt.Content.Raw["org.matrix.msc3488.location"].(map[string]any); ok {
|
||||||
|
if description, ok := msc3488["description"].(string); ok && description != "" {
|
||||||
|
message.LocationMessage.Name = &description
|
||||||
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return nil, nil, fmt.Errorf("%w %s", bridgev2.ErrUnsupportedMessageType, content.MsgType)
|
return nil, nil, fmt.Errorf("%w %s", bridgev2.ErrUnsupportedMessageType, content.MsgType)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -322,7 +322,6 @@ 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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package msgconv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"html"
|
"html"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
@ -26,7 +25,6 @@ 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"
|
||||||
|
|
@ -74,36 +72,6 @@ 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) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue