mirror of
https://github.com/mautrix/whatsapp.git
synced 2026-11-12 09:09:17 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7cf259940d | ||
|
|
d9525654ae | ||
|
|
f269a5b4ec |
7 changed files with 50 additions and 46 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()).
|
||||||
|
|
|
||||||
|
|
@ -273,10 +273,13 @@ func (wa *WhatsAppClient) HandleMatrixEdit(ctx context.Context, edit *bridgev2.M
|
||||||
return fmt.Errorf("failed to parse portal ID: %w", err)
|
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)
|
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 {
|
if err != nil {
|
||||||
return wrapConversionError(fmt.Errorf("failed to convert message: %w", err))
|
return wrapConversionError(fmt.Errorf("failed to convert message: %w", err))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
defer wa.mcTrack(edit, time.Now(), &retErr)
|
defer wa.mcTrack(edit, time.Now(), &retErr)
|
||||||
|
|
||||||
convertedEdit := wa.Client.BuildEdit(messageID.Chat, messageID.ID, waMsg)
|
convertedEdit := wa.Client.BuildEdit(messageID.Chat, messageID.ID, waMsg)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
-- v0 -> v12 (compatible with v3+): Latest revision
|
-- v0 -> v11 (compatible with v3+): Latest revision
|
||||||
|
|
||||||
CREATE TABLE whatsapp_poll_option_id (
|
CREATE TABLE whatsapp_poll_option_id (
|
||||||
bridge_id TEXT NOT NULL,
|
bridge_id TEXT NOT NULL,
|
||||||
|
|
@ -50,8 +50,6 @@ CREATE TABLE whatsapp_history_sync_message (
|
||||||
REFERENCES whatsapp_history_sync_conversation (bridge_id, user_login_id, chat_jid) ON UPDATE CASCADE ON DELETE CASCADE
|
REFERENCES whatsapp_history_sync_conversation (bridge_id, user_login_id, chat_jid) ON UPDATE CASCADE ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX whatsapp_history_sync_message_chat_ts_idx ON whatsapp_history_sync_message (bridge_id, user_login_id, chat_jid, timestamp);
|
|
||||||
|
|
||||||
CREATE TABLE whatsapp_media_backfill_request (
|
CREATE TABLE whatsapp_media_backfill_request (
|
||||||
bridge_id TEXT NOT NULL,
|
bridge_id TEXT NOT NULL,
|
||||||
user_login_id TEXT NOT NULL,
|
user_login_id TEXT NOT NULL,
|
||||||
|
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
-- v12 (compatible with v3+): Add index for history sync message timestamp lookups
|
|
||||||
CREATE INDEX whatsapp_history_sync_message_chat_ts_idx ON whatsapp_history_sync_message (bridge_id, user_login_id, chat_jid, timestamp);
|
|
||||||
|
|
@ -204,6 +204,46 @@ func (mc *MessageConverter) ToWhatsApp(
|
||||||
return message, extra, nil
|
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(
|
func (mc *MessageConverter) constructMediaMessage(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
content *event.MessageEventContent,
|
content *event.MessageEventContent,
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,8 @@ func (mc *MessageConverter) getBasicUserInfo(ctx context.Context, user types.JID
|
||||||
var pnJID types.JID
|
var pnJID types.JID
|
||||||
if user.Server == types.DefaultUserServer {
|
if user.Server == types.DefaultUserServer {
|
||||||
pnJID = user
|
pnJID = user
|
||||||
} else if cli := getClient(ctx); user.Server == types.HiddenUserServer && cli != nil {
|
} else if user.Server == types.HiddenUserServer {
|
||||||
|
cli := getClient(ctx)
|
||||||
if user.User == cli.Store.GetLID().User {
|
if user.User == cli.Store.GetLID().User {
|
||||||
pnJID = cli.Store.GetJID()
|
pnJID = cli.Store.GetJID()
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -321,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