mirror of
https://github.com/mautrix/whatsapp.git
synced 2026-07-11 08:26:08 -04:00
Compare commits
4 commits
nick/test-
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5250ddfa7d | ||
|
|
a1a4cf87b3 | ||
|
|
942d1b4c0a | ||
|
|
8d34f6f6bd |
11 changed files with 49 additions and 24 deletions
2
go.mod
2
go.mod
|
|
@ -12,7 +12,7 @@ require (
|
|||
github.com/tidwall/gjson v1.19.0
|
||||
go.mau.fi/util v0.9.10
|
||||
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/net v0.56.0
|
||||
golang.org/x/sync v0.21.0
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -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/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/whatsmeow v0.0.0-20260708165445-a2136cc8d5db h1:giO0YkqIJlbKURx7kj4i7zicLKj2ZODMM5X1tZAadH0=
|
||||
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 h1:VZkwFBEQ9TbB9IWsldw8BJDhHbEBElm9VD2VQXbSc9s=
|
||||
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/go.mod h1:J0Vn0prHNOm493oZoQ84kq83ZaNCYZnq+noI1b1eN8w=
|
||||
golang.org/x/crypto v0.53.0 h1:QZ4Muo8THX6CizN2vPPd5fBGHyogrdK9fG4wLPFUsto=
|
||||
|
|
|
|||
|
|
@ -750,7 +750,7 @@ func (wa *WhatsAppClient) convertHistorySyncMessage(
|
|||
// TODO use proper intent
|
||||
intent := wa.Main.Bridge.Bot
|
||||
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),
|
||||
ID: waid.MakeMessageID(info.Chat, info.Sender, info.ID),
|
||||
TxnID: networkid.TransactionID(waid.MakeMessageID(info.Chat, info.Sender, info.ID)),
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ func (wa *WhatsAppClient) getPortalKeyByMessageSource(ms types.MessageSource) ne
|
|||
}
|
||||
|
||||
type MessageInfoWrapper struct {
|
||||
OrigSource types.MessageSource
|
||||
Info types.MessageInfo
|
||||
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())
|
||||
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) {
|
||||
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) {
|
||||
evt.wa.EnqueuePortalResync(portal, false)
|
||||
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) {
|
||||
evt.postHandle = func() {
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ func (wa *WhatsAppClient) HandleMatrixReaction(ctx context.Context, msg *bridgev
|
|||
defer wa.mcTrack(msg, time.Now(), &retErr)
|
||||
var req whatsmeow.SendRequestExtra
|
||||
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 {
|
||||
return nil, fmt.Errorf("failed to encrypt reaction: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -358,6 +358,7 @@ func (wa *WhatsAppClient) handleWAMessage(ctx context.Context, evt *events.Messa
|
|||
evt.UnwrapRaw()
|
||||
parsedMessageType = getMessageType(evt.Message)
|
||||
}
|
||||
origSource := evt.Info.MessageSource
|
||||
wa.rerouteWAMessage(ctx, "message", &evt.Info.MessageSource, evt.Info.ID)
|
||||
wa.UserLogin.Log.Trace().
|
||||
Any("info", evt.Info).
|
||||
|
|
@ -409,6 +410,7 @@ func (wa *WhatsAppClient) handleWAMessage(ctx context.Context, evt *events.Messa
|
|||
|
||||
res := wa.UserLogin.QueueRemoteEvent(&WAMessageEvent{
|
||||
MessageInfoWrapper: &MessageInfoWrapper{
|
||||
OrigSource: origSource,
|
||||
Info: evt.Info,
|
||||
wa: wa,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -67,10 +67,11 @@ func getMessageType(waMsg *waE2E.Message) string {
|
|||
return "encrypted comment"
|
||||
case waMsg.CommentMessage != nil:
|
||||
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"
|
||||
case waMsg.PollCreationMessageV4 != nil || waMsg.PollCreationMessageV5 != nil:
|
||||
return "poll create (vNext)"
|
||||
case waMsg.PollCreationMessageV4 != nil:
|
||||
return "poll create (v4)"
|
||||
case waMsg.PollUpdateMessage != nil:
|
||||
return "poll update"
|
||||
case waMsg.ProtocolMessage != nil:
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ func (mc *MessageConverter) ToWhatsApp(
|
|||
if err != nil {
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to encrypt comment: %w", err)
|
||||
|
|
|
|||
|
|
@ -136,6 +136,7 @@ func (mc *MessageConverter) ToMatrix(
|
|||
waMsg *waE2E.Message,
|
||||
rawWaMsg *waE2E.Message,
|
||||
info *types.MessageInfo,
|
||||
origSource *types.MessageSource,
|
||||
isViewOnce bool,
|
||||
isBackfill bool,
|
||||
previouslyConvertedPart *bridgev2.ConvertedMessagePart,
|
||||
|
|
@ -175,8 +176,14 @@ func (mc *MessageConverter) ToMatrix(
|
|||
part, contextInfo = mc.convertPollCreationMessage(ctx, waMsg.PollCreationMessageV2)
|
||||
case waMsg.PollCreationMessageV3 != nil:
|
||||
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:
|
||||
part, contextInfo = mc.convertPollUpdateMessage(ctx, info, waMsg.PollUpdateMessage)
|
||||
part, contextInfo = mc.convertPollUpdateMessage(ctx, info, origSource, waMsg.PollUpdateMessage)
|
||||
case waMsg.EventMessage != nil:
|
||||
part, contextInfo = mc.convertEventMessage(ctx, waMsg.EventMessage)
|
||||
case waMsg.PinInChatMessage != nil:
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ func (mc *MessageConverter) PollVoteToWhatsApp(
|
|||
zerolog.Ctx(ctx).Err(err).Msg("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"
|
||||
optionHashes := make([][]byte, 0, len(content.Response.Answers))
|
||||
if pollMsg.Metadata.(*waid.MessageMetadata).IsMatrixPoll {
|
||||
|
|
@ -146,13 +146,23 @@ func (mc *MessageConverter) PollVoteToWhatsApp(
|
|||
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{
|
||||
MessageSource: types.MessageSource{
|
||||
Chat: parsedMsgID.Chat,
|
||||
Sender: parsedMsgID.Sender,
|
||||
IsFromMe: parsedMsgID.Sender.User == client.Store.GetLID().User || parsedMsgID.Sender.User == client.Store.GetJID().User,
|
||||
IsGroup: parsedMsgID.Chat.Server == types.GroupServer,
|
||||
Chat: chat,
|
||||
Sender: sender,
|
||||
IsFromMe: sender.User == client.Store.GetLID().User || sender.User == client.Store.GetJID().User,
|
||||
IsGroup: chat.Server == types.GroupServer,
|
||||
},
|
||||
ID: parsedMsgID.ID,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ var failedPollUpdatePart = &bridgev2.ConvertedMessagePart{
|
|||
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)
|
||||
pollMessageID := KeyToMessageID(ctx, getClient(ctx), info.Chat, info.Sender, msg.PollCreationMessageKey)
|
||||
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")
|
||||
return failedPollUpdatePart, nil
|
||||
}
|
||||
infoForDecrypt := *info
|
||||
if origSource != nil {
|
||||
infoForDecrypt.MessageSource = *origSource
|
||||
}
|
||||
vote, err := getClient(ctx).DecryptPollVote(ctx, &events.Message{
|
||||
Info: *info,
|
||||
Info: infoForDecrypt,
|
||||
Message: &waE2E.Message{PollUpdateMessage: msg},
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue