mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-12-04 20:52:54 +01:00
events: fix target message for reactions in DMs
This commit is contained in:
parent
5aee9f2eff
commit
d838491cc5
4 changed files with 12 additions and 28 deletions
2
go.mod
2
go.mod
|
@ -18,7 +18,7 @@ require (
|
|||
golang.org/x/sync v0.9.0
|
||||
google.golang.org/protobuf v1.35.1
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
maunium.net/go/mautrix v0.21.2-0.20241113163141-3f9a63784ec5
|
||||
maunium.net/go/mautrix v0.21.2-0.20241114125808-21aa3291f31f
|
||||
)
|
||||
|
||||
require (
|
||||
|
|
4
go.sum
4
go.sum
|
@ -101,5 +101,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
|
||||
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
|
||||
maunium.net/go/mautrix v0.21.2-0.20241113163141-3f9a63784ec5 h1:dBD+xOAzvhQBcO3RFUK20PwOKhWnY10iXWrehgSTI7c=
|
||||
maunium.net/go/mautrix v0.21.2-0.20241113163141-3f9a63784ec5/go.mod h1:X7VB/wOIUo6c3wACyVwA//v2k8BpMLFB2rvaX2Y0984=
|
||||
maunium.net/go/mautrix v0.21.2-0.20241114125808-21aa3291f31f h1:NyPane3nuWA3Pisj7Z0uG1rmNDOkDFSrXEB8xGN0gzs=
|
||||
maunium.net/go/mautrix v0.21.2-0.20241114125808-21aa3291f31f/go.mod h1:X7VB/wOIUo6c3wACyVwA//v2k8BpMLFB2rvaX2Y0984=
|
||||
|
|
|
@ -117,6 +117,9 @@ func (evt *WAMessageEvent) isViewOnce() bool {
|
|||
}
|
||||
|
||||
func (evt *WAMessageEvent) AddLogContext(c zerolog.Context) zerolog.Context {
|
||||
if targetMsg := evt.GetTargetMessage(); targetMsg != "" {
|
||||
c = c.Str("target_message_id", string(targetMsg))
|
||||
}
|
||||
return evt.MessageInfoWrapper.AddLogContext(c).Str("parsed_message_type", evt.parsedMessageType)
|
||||
}
|
||||
|
||||
|
@ -154,29 +157,9 @@ func (evt *WAMessageEvent) ConvertEdit(ctx context.Context, portal *bridgev2.Por
|
|||
|
||||
func (evt *WAMessageEvent) GetTargetMessage() networkid.MessageID {
|
||||
if reactionMsg := evt.Message.GetReactionMessage(); reactionMsg != nil {
|
||||
key := reactionMsg.GetKey()
|
||||
senderID := key.GetParticipant()
|
||||
if senderID == "" {
|
||||
if key.GetFromMe() {
|
||||
senderID = evt.Info.Sender.ToNonAD().String()
|
||||
} else {
|
||||
senderID = evt.wa.Client.Store.ID.ToNonAD().String() // could be false in groups
|
||||
}
|
||||
}
|
||||
senderJID, _ := types.ParseJID(senderID)
|
||||
return waid.MakeMessageID(evt.Info.Chat, senderJID, *key.ID)
|
||||
return msgconv.KeyToMessageID(evt.wa.Client, evt.Info.Chat, evt.Info.Sender, reactionMsg.GetKey())
|
||||
} else if protocolMsg := evt.Message.GetProtocolMessage(); protocolMsg != nil {
|
||||
key := protocolMsg.GetKey()
|
||||
senderID := key.GetParticipant()
|
||||
if senderID == "" {
|
||||
if key.GetFromMe() {
|
||||
senderID = evt.Info.Sender.ToNonAD().String()
|
||||
} else {
|
||||
senderID = evt.wa.Client.Store.ID.ToNonAD().String() // could be false in groups
|
||||
}
|
||||
}
|
||||
senderJID, _ := types.ParseJID(senderID)
|
||||
return waid.MakeMessageID(evt.Info.Chat, senderJID, *key.ID)
|
||||
return msgconv.KeyToMessageID(evt.wa.Client, evt.Info.Chat, evt.Info.Sender, protocolMsg.GetKey())
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
|
||||
"github.com/rs/zerolog"
|
||||
"go.mau.fi/util/ptr"
|
||||
"go.mau.fi/whatsmeow"
|
||||
"go.mau.fi/whatsmeow/proto/waCommon"
|
||||
"go.mau.fi/whatsmeow/proto/waE2E"
|
||||
"go.mau.fi/whatsmeow/types"
|
||||
|
@ -94,7 +95,7 @@ func (mc *MessageConverter) convertPollCreationMessage(ctx context.Context, msg
|
|||
}, msg.GetContextInfo()
|
||||
}
|
||||
|
||||
func (mc *MessageConverter) keyToMessageID(ctx context.Context, chat, sender types.JID, key *waCommon.MessageKey) networkid.MessageID {
|
||||
func KeyToMessageID(client *whatsmeow.Client, chat, sender types.JID, key *waCommon.MessageKey) networkid.MessageID {
|
||||
sender = sender.ToNonAD()
|
||||
var err error
|
||||
if !key.GetFromMe() {
|
||||
|
@ -108,7 +109,7 @@ func (mc *MessageConverter) keyToMessageID(ctx context.Context, chat, sender typ
|
|||
sender.Server = types.DefaultUserServer
|
||||
}
|
||||
} else if chat.Server == types.DefaultUserServer {
|
||||
ownID := ptr.Val(getClient(ctx).Store.ID).ToNonAD()
|
||||
ownID := ptr.Val(client.Store.ID).ToNonAD()
|
||||
if sender.User == ownID.User {
|
||||
sender = chat
|
||||
} else {
|
||||
|
@ -137,7 +138,7 @@ var failedPollUpdatePart = &bridgev2.ConvertedMessagePart{
|
|||
|
||||
func (mc *MessageConverter) convertPollUpdateMessage(ctx context.Context, info *types.MessageInfo, msg *waE2E.PollUpdateMessage) (*bridgev2.ConvertedMessagePart, *waE2E.ContextInfo) {
|
||||
log := zerolog.Ctx(ctx)
|
||||
pollMessageID := mc.keyToMessageID(ctx, info.Chat, info.Sender, msg.PollCreationMessageKey)
|
||||
pollMessageID := KeyToMessageID(getClient(ctx), info.Chat, info.Sender, msg.PollCreationMessageKey)
|
||||
pollMessage, err := mc.Bridge.DB.Message.GetPartByID(ctx, getPortal(ctx).Receiver, pollMessageID, "")
|
||||
if err != nil {
|
||||
log.Err(err).Msg("Failed to get poll update target message")
|
||||
|
|
Loading…
Reference in a new issue