mirror of
https://github.com/mautrix/whatsapp.git
synced 2026-07-11 08:26:08 -04:00
Compare commits
1 commit
main
...
nick/bios-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91ea5c60c8 |
12 changed files with 27 additions and 49 deletions
2
go.mod
2
go.mod
|
|
@ -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-20260709092057-73fe7355f59f
|
go.mau.fi/whatsmeow v0.0.0-20260630180629-b572e5bcb92b
|
||||||
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
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/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-20260709092057-73fe7355f59f h1:VZkwFBEQ9TbB9IWsldw8BJDhHbEBElm9VD2VQXbSc9s=
|
go.mau.fi/whatsmeow v0.0.0-20260630180629-b572e5bcb92b h1:ZUk1ErarDNpnbosXR/MeOz2gkqA4S1bh8zjaSRj7N+Y=
|
||||||
go.mau.fi/whatsmeow v0.0.0-20260709092057-73fe7355f59f/go.mod h1:9dmNTYZ/1pHjPw/bz+azBsGjAkcrZbqzMrKcvG5bJ8U=
|
go.mau.fi/whatsmeow v0.0.0-20260630180629-b572e5bcb92b/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=
|
||||||
|
|
|
||||||
|
|
@ -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, nil, isViewOnce, true, nil),
|
ConvertedMessage: wa.Main.MsgConv.ToMatrix(ctx, portal, wa.Client, intent, msg, rawMsg, info, 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)),
|
||||||
|
|
|
||||||
|
|
@ -338,6 +338,9 @@ func (wa *WhatsAppClient) receiveDirectMediaRetry(ctx context.Context, msg *data
|
||||||
retryData, err := whatsmeow.DecryptMediaRetryNotification(retry, keys.Key)
|
retryData, err := whatsmeow.DecryptMediaRetryNotification(retry, keys.Key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn().Err(err).Msg("Failed to decrypt media retry notification")
|
log.Warn().Err(err).Msg("Failed to decrypt media retry notification")
|
||||||
|
if state != nil {
|
||||||
|
state.resultType = waMmsRetry.MediaRetryNotification_DECRYPTION_ERROR
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if state != nil {
|
if state != nil {
|
||||||
|
|
|
||||||
|
|
@ -52,9 +52,8 @@ 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (evt *MessageInfoWrapper) ShouldCreatePortal() bool {
|
func (evt *MessageInfoWrapper) ShouldCreatePortal() bool {
|
||||||
|
|
@ -201,7 +200,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.OrigSource, evt.isViewOnce(), false, previouslyConvertedPart,
|
ctx, portal, evt.wa.Client, intent, editedMsg, evt.MsgEvent.RawMessage, &evt.Info, evt.isViewOnce(), false, previouslyConvertedPart,
|
||||||
)
|
)
|
||||||
if evt.isUndecryptableUpsertSubEvent && isFailedMedia(cm) {
|
if evt.isUndecryptableUpsertSubEvent && isFailedMedia(cm) {
|
||||||
evt.postHandle = func() {
|
evt.postHandle = func() {
|
||||||
|
|
@ -286,7 +285,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.OrigSource, evt.isViewOnce(), false, nil,
|
ctx, portal, evt.wa.Client, intent, evt.Message, evt.MsgEvent.RawMessage, &evt.Info, evt.isViewOnce(), false, nil,
|
||||||
)
|
)
|
||||||
if isFailedMedia(converted) {
|
if isFailedMedia(converted) {
|
||||||
evt.postHandle = func() {
|
evt.postHandle = func() {
|
||||||
|
|
|
||||||
|
|
@ -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(ctx, wa.Client, messageID), reactionMsg.ReactionMessage)
|
reactionMsg.EncReactionMessage, err = wa.Client.EncryptReaction(ctx, msgconv.MessageIDToInfo(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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -358,7 +358,6 @@ 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).
|
||||||
|
|
@ -410,9 +409,8 @@ 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,
|
|
||||||
},
|
},
|
||||||
Message: evt.Message,
|
Message: evt.Message,
|
||||||
MsgEvent: evt,
|
MsgEvent: evt,
|
||||||
|
|
|
||||||
|
|
@ -67,11 +67,10 @@ 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:
|
case waMsg.PollCreationMessageV4 != nil || waMsg.PollCreationMessageV5 != nil:
|
||||||
return "poll create (v4)"
|
return "poll create (vNext)"
|
||||||
case waMsg.PollUpdateMessage != nil:
|
case waMsg.PollUpdateMessage != nil:
|
||||||
return "poll update"
|
return "poll update"
|
||||||
case waMsg.ProtocolMessage != nil:
|
case waMsg.ProtocolMessage != nil:
|
||||||
|
|
|
||||||
|
|
@ -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(ctx, client, parsedID)
|
rootMsgInfo := MessageIDToInfo(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)
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,6 @@ 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,
|
||||||
|
|
@ -176,14 +175,8 @@ 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, origSource, waMsg.PollUpdateMessage)
|
part, contextInfo = mc.convertPollUpdateMessage(ctx, info, 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:
|
||||||
|
|
|
||||||
|
|
@ -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(ctx, client, parsedMsgID)
|
pollMsgInfo := MessageIDToInfo(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,23 +146,13 @@ func (mc *MessageConverter) PollVoteToWhatsApp(
|
||||||
return &waE2E.Message{PollUpdateMessage: pollUpdate}, err
|
return &waE2E.Message{PollUpdateMessage: pollUpdate}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func MessageIDToInfo(ctx context.Context, client *whatsmeow.Client, parsedMsgID *waid.ParsedMessageID) *types.MessageInfo {
|
func MessageIDToInfo(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: chat,
|
Chat: parsedMsgID.Chat,
|
||||||
Sender: sender,
|
Sender: parsedMsgID.Sender,
|
||||||
IsFromMe: sender.User == client.Store.GetLID().User || sender.User == client.Store.GetJID().User,
|
IsFromMe: parsedMsgID.Sender.User == client.Store.GetLID().User || parsedMsgID.Sender.User == client.Store.GetJID().User,
|
||||||
IsGroup: chat.Server == types.GroupServer,
|
IsGroup: parsedMsgID.Chat.Server == types.GroupServer,
|
||||||
},
|
},
|
||||||
ID: parsedMsgID.ID,
|
ID: parsedMsgID.ID,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,7 @@ var failedPollUpdatePart = &bridgev2.ConvertedMessagePart{
|
||||||
DontBridge: true,
|
DontBridge: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mc *MessageConverter) convertPollUpdateMessage(ctx context.Context, info *types.MessageInfo, origSource *types.MessageSource, msg *waE2E.PollUpdateMessage) (*bridgev2.ConvertedMessagePart, *waE2E.ContextInfo) {
|
func (mc *MessageConverter) convertPollUpdateMessage(ctx context.Context, info *types.MessageInfo, 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,12 +181,8 @@ 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: infoForDecrypt,
|
Info: *info,
|
||||||
Message: &waE2E.Message{PollUpdateMessage: msg},
|
Message: &waE2E.Message{PollUpdateMessage: msg},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue