1
0
Fork 0
mirror of https://github.com/mautrix/whatsapp.git synced 2026-07-11 08:26:08 -04:00

Compare commits

..

4 commits

Author SHA1 Message Date
Tulir Asokan
5250ddfa7d msgconv/from-whatsapp: handle v5 and v6 poll creations 2026-07-10 18:36:17 +03:00
Tulir Asokan
a1a4cf87b3 msgconv/from-matrix: add hack to use LID for message secrets in DMs 2026-07-09 14:44:00 +03:00
Tulir Asokan
942d1b4c0a dependencies: update whatsmeow 2026-07-09 14:27:54 +03:00
Tulir Asokan
8d34f6f6bd msgconv/from-whatsapp: use correct message info for decrypting poll votes 2026-07-09 12:12:18 +03:00
11 changed files with 49 additions and 24 deletions

2
go.mod
View file

@ -12,7 +12,7 @@ require (
github.com/tidwall/gjson v1.19.0 github.com/tidwall/gjson v1.19.0
go.mau.fi/util v0.9.10 go.mau.fi/util v0.9.10
go.mau.fi/webp v0.3.0 go.mau.fi/webp v0.3.0
go.mau.fi/whatsmeow v0.0.0-20260708165445-a2136cc8d5db go.mau.fi/whatsmeow v0.0.0-20260709092057-73fe7355f59f
golang.org/x/image v0.42.0 golang.org/x/image v0.42.0
golang.org/x/net v0.56.0 golang.org/x/net v0.56.0
golang.org/x/sync v0.21.0 golang.org/x/sync v0.21.0

4
go.sum
View file

@ -75,8 +75,8 @@ go.mau.fi/util v0.9.10 h1:wzvz5iDHyqDXB8vgisD4d3SzucLXNM3iNY+1O1RoHtg=
go.mau.fi/util v0.9.10/go.mod h1:YQOxySn+ZE3qSYqNxvyX7Yi3suA8YK17PS6QqBREW7A= go.mau.fi/util v0.9.10/go.mod h1:YQOxySn+ZE3qSYqNxvyX7Yi3suA8YK17PS6QqBREW7A=
go.mau.fi/webp v0.3.0 h1:gVHQZtz21Ziwj+CDuklbX9mqpsnDIFKxs/BJyV7iZzA= go.mau.fi/webp v0.3.0 h1:gVHQZtz21Ziwj+CDuklbX9mqpsnDIFKxs/BJyV7iZzA=
go.mau.fi/webp v0.3.0/go.mod h1:rlZFTev+dYxhvk+XNBP/5GcTt4gXmzAB4DU0aGUYIQo= go.mau.fi/webp v0.3.0/go.mod h1:rlZFTev+dYxhvk+XNBP/5GcTt4gXmzAB4DU0aGUYIQo=
go.mau.fi/whatsmeow v0.0.0-20260708165445-a2136cc8d5db h1:giO0YkqIJlbKURx7kj4i7zicLKj2ZODMM5X1tZAadH0= go.mau.fi/whatsmeow v0.0.0-20260709092057-73fe7355f59f h1:VZkwFBEQ9TbB9IWsldw8BJDhHbEBElm9VD2VQXbSc9s=
go.mau.fi/whatsmeow v0.0.0-20260708165445-a2136cc8d5db/go.mod h1:9dmNTYZ/1pHjPw/bz+azBsGjAkcrZbqzMrKcvG5bJ8U= go.mau.fi/whatsmeow v0.0.0-20260709092057-73fe7355f59f/go.mod h1:9dmNTYZ/1pHjPw/bz+azBsGjAkcrZbqzMrKcvG5bJ8U=
go.mau.fi/zeroconfig v0.2.0 h1:e/OGEERqVRRKlgaro7E6bh8xXiKFSXB3eNNIud7FUjU= go.mau.fi/zeroconfig v0.2.0 h1:e/OGEERqVRRKlgaro7E6bh8xXiKFSXB3eNNIud7FUjU=
go.mau.fi/zeroconfig v0.2.0/go.mod h1:J0Vn0prHNOm493oZoQ84kq83ZaNCYZnq+noI1b1eN8w= go.mau.fi/zeroconfig v0.2.0/go.mod h1:J0Vn0prHNOm493oZoQ84kq83ZaNCYZnq+noI1b1eN8w=
golang.org/x/crypto v0.53.0 h1:QZ4Muo8THX6CizN2vPPd5fBGHyogrdK9fG4wLPFUsto= golang.org/x/crypto v0.53.0 h1:QZ4Muo8THX6CizN2vPPd5fBGHyogrdK9fG4wLPFUsto=

View file

@ -750,7 +750,7 @@ func (wa *WhatsAppClient) convertHistorySyncMessage(
// TODO use proper intent // TODO use proper intent
intent := wa.Main.Bridge.Bot intent := wa.Main.Bridge.Bot
wrapped := &bridgev2.BackfillMessage{ wrapped := &bridgev2.BackfillMessage{
ConvertedMessage: wa.Main.MsgConv.ToMatrix(ctx, portal, wa.Client, intent, msg, rawMsg, info, isViewOnce, true, nil), ConvertedMessage: wa.Main.MsgConv.ToMatrix(ctx, portal, wa.Client, intent, msg, rawMsg, info, nil, isViewOnce, true, nil),
Sender: wa.makeEventSender(ctx, info.Sender), Sender: wa.makeEventSender(ctx, info.Sender),
ID: waid.MakeMessageID(info.Chat, info.Sender, info.ID), ID: waid.MakeMessageID(info.Chat, info.Sender, info.ID),
TxnID: networkid.TransactionID(waid.MakeMessageID(info.Chat, info.Sender, info.ID)), TxnID: networkid.TransactionID(waid.MakeMessageID(info.Chat, info.Sender, info.ID)),

View file

@ -52,6 +52,7 @@ func (wa *WhatsAppClient) getPortalKeyByMessageSource(ms types.MessageSource) ne
} }
type MessageInfoWrapper struct { type MessageInfoWrapper struct {
OrigSource types.MessageSource
Info types.MessageInfo Info types.MessageInfo
wa *WhatsAppClient wa *WhatsAppClient
} }
@ -200,7 +201,7 @@ func (evt *WAMessageEvent) ConvertEdit(ctx context.Context, portal *bridgev2.Por
ctx = context.WithValue(ctx, msgconv.ContextKeyEditTargetID, evt.Message.GetProtocolMessage().GetKey().GetID()) ctx = context.WithValue(ctx, msgconv.ContextKeyEditTargetID, evt.Message.GetProtocolMessage().GetKey().GetID())
cm := evt.wa.Main.MsgConv.ToMatrix( cm := evt.wa.Main.MsgConv.ToMatrix(
ctx, portal, evt.wa.Client, intent, editedMsg, evt.MsgEvent.RawMessage, &evt.Info, evt.isViewOnce(), false, previouslyConvertedPart, ctx, portal, evt.wa.Client, intent, editedMsg, evt.MsgEvent.RawMessage, &evt.Info, &evt.OrigSource, evt.isViewOnce(), false, previouslyConvertedPart,
) )
if evt.isUndecryptableUpsertSubEvent && isFailedMedia(cm) { if evt.isUndecryptableUpsertSubEvent && isFailedMedia(cm) {
evt.postHandle = func() { evt.postHandle = func() {
@ -285,7 +286,7 @@ func (evt *WAMessageEvent) HandleExisting(ctx context.Context, portal *bridgev2.
func (evt *WAMessageEvent) ConvertMessage(ctx context.Context, portal *bridgev2.Portal, intent bridgev2.MatrixAPI) (*bridgev2.ConvertedMessage, error) { func (evt *WAMessageEvent) ConvertMessage(ctx context.Context, portal *bridgev2.Portal, intent bridgev2.MatrixAPI) (*bridgev2.ConvertedMessage, error) {
evt.wa.EnqueuePortalResync(portal, false) evt.wa.EnqueuePortalResync(portal, false)
converted := evt.wa.Main.MsgConv.ToMatrix( converted := evt.wa.Main.MsgConv.ToMatrix(
ctx, portal, evt.wa.Client, intent, evt.Message, evt.MsgEvent.RawMessage, &evt.Info, evt.isViewOnce(), false, nil, ctx, portal, evt.wa.Client, intent, evt.Message, evt.MsgEvent.RawMessage, &evt.Info, &evt.OrigSource, evt.isViewOnce(), false, nil,
) )
if isFailedMedia(converted) { if isFailedMedia(converted) {
evt.postHandle = func() { evt.postHandle = func() {

View file

@ -177,7 +177,7 @@ func (wa *WhatsAppClient) HandleMatrixReaction(ctx context.Context, msg *bridgev
defer wa.mcTrack(msg, time.Now(), &retErr) defer wa.mcTrack(msg, time.Now(), &retErr)
var req whatsmeow.SendRequestExtra var req whatsmeow.SendRequestExtra
if msg.Portal.Metadata.(*waid.PortalMetadata).CommunityAnnouncementGroup { if msg.Portal.Metadata.(*waid.PortalMetadata).CommunityAnnouncementGroup {
reactionMsg.EncReactionMessage, err = wa.Client.EncryptReaction(ctx, msgconv.MessageIDToInfo(wa.Client, messageID), reactionMsg.ReactionMessage) reactionMsg.EncReactionMessage, err = wa.Client.EncryptReaction(ctx, msgconv.MessageIDToInfo(ctx, wa.Client, messageID), reactionMsg.ReactionMessage)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to encrypt reaction: %w", err) return nil, fmt.Errorf("failed to encrypt reaction: %w", err)
} }

View file

@ -358,6 +358,7 @@ func (wa *WhatsAppClient) handleWAMessage(ctx context.Context, evt *events.Messa
evt.UnwrapRaw() evt.UnwrapRaw()
parsedMessageType = getMessageType(evt.Message) parsedMessageType = getMessageType(evt.Message)
} }
origSource := evt.Info.MessageSource
wa.rerouteWAMessage(ctx, "message", &evt.Info.MessageSource, evt.Info.ID) wa.rerouteWAMessage(ctx, "message", &evt.Info.MessageSource, evt.Info.ID)
wa.UserLogin.Log.Trace(). wa.UserLogin.Log.Trace().
Any("info", evt.Info). Any("info", evt.Info).
@ -409,6 +410,7 @@ func (wa *WhatsAppClient) handleWAMessage(ctx context.Context, evt *events.Messa
res := wa.UserLogin.QueueRemoteEvent(&WAMessageEvent{ res := wa.UserLogin.QueueRemoteEvent(&WAMessageEvent{
MessageInfoWrapper: &MessageInfoWrapper{ MessageInfoWrapper: &MessageInfoWrapper{
OrigSource: origSource,
Info: evt.Info, Info: evt.Info,
wa: wa, wa: wa,
}, },

View file

@ -67,10 +67,11 @@ func getMessageType(waMsg *waE2E.Message) string {
return "encrypted comment" return "encrypted comment"
case waMsg.CommentMessage != nil: case waMsg.CommentMessage != nil:
return "comment" return "comment"
case waMsg.PollCreationMessage != nil || waMsg.PollCreationMessageV2 != nil || waMsg.PollCreationMessageV3 != nil: case waMsg.PollCreationMessage != nil || waMsg.PollCreationMessageV2 != nil || waMsg.PollCreationMessageV3 != nil ||
waMsg.PollCreationMessageV5 != nil || waMsg.PollCreationMessageV6 != nil:
return "poll create" return "poll create"
case waMsg.PollCreationMessageV4 != nil || waMsg.PollCreationMessageV5 != nil: case waMsg.PollCreationMessageV4 != nil:
return "poll create (vNext)" return "poll create (v4)"
case waMsg.PollUpdateMessage != nil: case waMsg.PollUpdateMessage != nil:
return "poll update" return "poll update"
case waMsg.ProtocolMessage != nil: case waMsg.ProtocolMessage != nil:

View file

@ -143,7 +143,7 @@ func (mc *MessageConverter) ToWhatsApp(
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("failed to parse message ID: %w", err) return nil, nil, fmt.Errorf("failed to parse message ID: %w", err)
} }
rootMsgInfo := MessageIDToInfo(client, parsedID) rootMsgInfo := MessageIDToInfo(ctx, client, parsedID)
message, err = client.EncryptComment(ctx, rootMsgInfo, message) message, err = client.EncryptComment(ctx, rootMsgInfo, message)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("failed to encrypt comment: %w", err) return nil, nil, fmt.Errorf("failed to encrypt comment: %w", err)

View file

@ -136,6 +136,7 @@ func (mc *MessageConverter) ToMatrix(
waMsg *waE2E.Message, waMsg *waE2E.Message,
rawWaMsg *waE2E.Message, rawWaMsg *waE2E.Message,
info *types.MessageInfo, info *types.MessageInfo,
origSource *types.MessageSource,
isViewOnce bool, isViewOnce bool,
isBackfill bool, isBackfill bool,
previouslyConvertedPart *bridgev2.ConvertedMessagePart, previouslyConvertedPart *bridgev2.ConvertedMessagePart,
@ -175,8 +176,14 @@ func (mc *MessageConverter) ToMatrix(
part, contextInfo = mc.convertPollCreationMessage(ctx, waMsg.PollCreationMessageV2) part, contextInfo = mc.convertPollCreationMessage(ctx, waMsg.PollCreationMessageV2)
case waMsg.PollCreationMessageV3 != nil: case waMsg.PollCreationMessageV3 != nil:
part, contextInfo = mc.convertPollCreationMessage(ctx, waMsg.PollCreationMessageV3) part, contextInfo = mc.convertPollCreationMessage(ctx, waMsg.PollCreationMessageV3)
//case waMsg.PollCreationMessageV4 != nil:
// part, contextInfo = mc.convertPollCreationMessage(ctx, waMsg.PollCreationMessageV4)
case waMsg.PollCreationMessageV5 != nil:
part, contextInfo = mc.convertPollCreationMessage(ctx, waMsg.PollCreationMessageV5)
case waMsg.PollCreationMessageV6 != nil:
part, contextInfo = mc.convertPollCreationMessage(ctx, waMsg.PollCreationMessageV6)
case waMsg.PollUpdateMessage != nil: case waMsg.PollUpdateMessage != nil:
part, contextInfo = mc.convertPollUpdateMessage(ctx, info, waMsg.PollUpdateMessage) part, contextInfo = mc.convertPollUpdateMessage(ctx, info, origSource, waMsg.PollUpdateMessage)
case waMsg.EventMessage != nil: case waMsg.EventMessage != nil:
part, contextInfo = mc.convertEventMessage(ctx, waMsg.EventMessage) part, contextInfo = mc.convertEventMessage(ctx, waMsg.EventMessage)
case waMsg.PinInChatMessage != nil: case waMsg.PinInChatMessage != nil:

View file

@ -115,7 +115,7 @@ func (mc *MessageConverter) PollVoteToWhatsApp(
zerolog.Ctx(ctx).Err(err).Msg("Failed to parse message ID") zerolog.Ctx(ctx).Err(err).Msg("Failed to parse message ID")
return nil, fmt.Errorf("failed to parse message ID") return nil, fmt.Errorf("failed to parse message ID")
} }
pollMsgInfo := MessageIDToInfo(client, parsedMsgID) pollMsgInfo := MessageIDToInfo(ctx, client, parsedMsgID)
pollMsgInfo.Type = "poll" pollMsgInfo.Type = "poll"
optionHashes := make([][]byte, 0, len(content.Response.Answers)) optionHashes := make([][]byte, 0, len(content.Response.Answers))
if pollMsg.Metadata.(*waid.MessageMetadata).IsMatrixPoll { if pollMsg.Metadata.(*waid.MessageMetadata).IsMatrixPoll {
@ -146,13 +146,23 @@ func (mc *MessageConverter) PollVoteToWhatsApp(
return &waE2E.Message{PollUpdateMessage: pollUpdate}, err return &waE2E.Message{PollUpdateMessage: pollUpdate}, err
} }
func MessageIDToInfo(client *whatsmeow.Client, parsedMsgID *waid.ParsedMessageID) *types.MessageInfo { func MessageIDToInfo(ctx context.Context, client *whatsmeow.Client, parsedMsgID *waid.ParsedMessageID) *types.MessageInfo {
chat := parsedMsgID.Chat
sender := parsedMsgID.Sender
if client.Store.LIDMigrationTimestamp != 0 && chat.Server == types.DefaultUserServer {
chatLID, _ := client.Store.LIDs.GetLIDForPN(ctx, chat)
senderLID, _ := client.Store.LIDs.GetLIDForPN(ctx, sender)
if !chatLID.IsEmpty() && !senderLID.IsEmpty() {
chat = chatLID
sender = senderLID
}
}
return &types.MessageInfo{ return &types.MessageInfo{
MessageSource: types.MessageSource{ MessageSource: types.MessageSource{
Chat: parsedMsgID.Chat, Chat: chat,
Sender: parsedMsgID.Sender, Sender: sender,
IsFromMe: parsedMsgID.Sender.User == client.Store.GetLID().User || parsedMsgID.Sender.User == client.Store.GetJID().User, IsFromMe: sender.User == client.Store.GetLID().User || sender.User == client.Store.GetJID().User,
IsGroup: parsedMsgID.Chat.Server == types.GroupServer, IsGroup: chat.Server == types.GroupServer,
}, },
ID: parsedMsgID.ID, ID: parsedMsgID.ID,
} }

View file

@ -170,7 +170,7 @@ var failedPollUpdatePart = &bridgev2.ConvertedMessagePart{
DontBridge: true, DontBridge: true,
} }
func (mc *MessageConverter) convertPollUpdateMessage(ctx context.Context, info *types.MessageInfo, msg *waE2E.PollUpdateMessage) (*bridgev2.ConvertedMessagePart, *waE2E.ContextInfo) { func (mc *MessageConverter) convertPollUpdateMessage(ctx context.Context, info *types.MessageInfo, origSource *types.MessageSource, msg *waE2E.PollUpdateMessage) (*bridgev2.ConvertedMessagePart, *waE2E.ContextInfo) {
log := zerolog.Ctx(ctx) log := zerolog.Ctx(ctx)
pollMessageID := KeyToMessageID(ctx, getClient(ctx), info.Chat, info.Sender, msg.PollCreationMessageKey) pollMessageID := KeyToMessageID(ctx, getClient(ctx), info.Chat, info.Sender, msg.PollCreationMessageKey)
pollMessage, err := mc.Bridge.DB.Message.GetPartByID(ctx, getPortal(ctx).Receiver, pollMessageID, "") pollMessage, err := mc.Bridge.DB.Message.GetPartByID(ctx, getPortal(ctx).Receiver, pollMessageID, "")
@ -181,8 +181,12 @@ func (mc *MessageConverter) convertPollUpdateMessage(ctx context.Context, info *
log.Warn().Str("target_message_id", string(pollMessageID)).Msg("Poll update target message not found") log.Warn().Str("target_message_id", string(pollMessageID)).Msg("Poll update target message not found")
return failedPollUpdatePart, nil return failedPollUpdatePart, nil
} }
infoForDecrypt := *info
if origSource != nil {
infoForDecrypt.MessageSource = *origSource
}
vote, err := getClient(ctx).DecryptPollVote(ctx, &events.Message{ vote, err := getClient(ctx).DecryptPollVote(ctx, &events.Message{
Info: *info, Info: infoForDecrypt,
Message: &waE2E.Message{PollUpdateMessage: msg}, Message: &waE2E.Message{PollUpdateMessage: msg},
}) })
if err != nil { if err != nil {