From 1ad17048cc4032986c2953d26fd437c41021993a Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 27 Oct 2021 21:34:22 +0300 Subject: [PATCH] Add better logs for Matrix redaction handling --- go.mod | 2 +- go.sum | 4 ++-- portal.go | 23 ++++++++--------------- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 2f2c3a3..5ba5f40 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/mattn/go-sqlite3 v1.14.9 github.com/prometheus/client_golang v1.11.0 github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e - go.mau.fi/whatsmeow v0.0.0-20211027162736-a1c695172891 + go.mau.fi/whatsmeow v0.0.0-20211027183133-07bcb11ceb48 golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d google.golang.org/protobuf v1.27.1 gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum index 44fba80..3a35926 100644 --- a/go.sum +++ b/go.sum @@ -139,8 +139,8 @@ github.com/tidwall/sjson v1.2.3 h1:5+deguEhHSEjmuICXZ21uSSsXotWMA0orU783+Z7Cp8= github.com/tidwall/sjson v1.2.3/go.mod h1:5WdjKx3AQMvCJ4RG6/2UYT7dLrGvJUV1x4jdTAyGvZs= go.mau.fi/libsignal v0.0.0-20211024113310-f9fc6a1855f2 h1:xpQTMgJGGaF+c8jV/LA/FVXAPJxZbSAGeflOc+Ly6uQ= go.mau.fi/libsignal v0.0.0-20211024113310-f9fc6a1855f2/go.mod h1:3XlVlwOfp8f9Wri+C1D4ORqgUsN4ZvunJOoPjQMBhos= -go.mau.fi/whatsmeow v0.0.0-20211027162736-a1c695172891 h1:QemoafkIJVRrCr8mKA9AUb1ACrTiv0wa7R/VtQV3Xwo= -go.mau.fi/whatsmeow v0.0.0-20211027162736-a1c695172891/go.mod h1:ODEmmqeUn9eBDQHFc1S902YA3YFLtmaBujYRRFl53jI= +go.mau.fi/whatsmeow v0.0.0-20211027183133-07bcb11ceb48 h1:e4cAP66APziJd8YFAJbYtPtkMJLi4wullnqs87lWZWo= +go.mau.fi/whatsmeow v0.0.0-20211027183133-07bcb11ceb48/go.mod h1:ODEmmqeUn9eBDQHFc1S902YA3YFLtmaBujYRRFl53jI= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/portal.go b/portal.go index e7a152c..714993b 100644 --- a/portal.go +++ b/portal.go @@ -2435,27 +2435,20 @@ func (portal *Portal) HandleMatrixRedaction(sender *User, evt *event.Event) { } msg := portal.bridge.DB.Message.GetByMXID(evt.Redacts) - if msg == nil || msg.Sender.User != sender.JID.User { + if msg == nil { + portal.log.Debugfln("Ignoring redaction %s of unknown event by %s", msg, sender.MXID) + return + } else if msg.Sender.User != sender.JID.User { + portal.log.Debugfln("Ignoring redaction %s of %s/%s by %s: message was sent by someone else (%s, not %s)", evt.ID, msg.MXID, msg.JID, sender.MXID, msg.Sender, sender.JID) return } - portal.log.Debugfln("Received redaction event %s", evt.ID) - info := portal.generateMessageInfo(sender) - portal.log.Debugln("Sending redaction", evt.ID, "to WhatsApp", info.ID) - err := sender.Client.SendMessage(portal.Key.JID, info.ID, &waProto.Message{ - ProtocolMessage: &waProto.ProtocolMessage{ - Type: waProto.ProtocolMessage_REVOKE.Enum(), - Key: &waProto.MessageKey{ - FromMe: proto.Bool(true), - Id: proto.String(msg.JID), - RemoteJid: proto.String(portal.Key.JID.String()), - }, - }, - }) + portal.log.Debugfln("Sending redaction %s of %s/%s to WhatsApp", evt.ID, msg.MXID, msg.JID) + err := sender.Client.RevokeMessage(portal.Key.JID, msg.JID) if err != nil { portal.log.Errorfln("Error handling Matrix redaction %s: %v", evt.ID, err) } else { - portal.log.Debugln("Handled Matrix redaction %s of %s", evt.ID, evt.Redacts) + portal.log.Debugfln("Handled Matrix redaction %s of %s", evt.ID, evt.Redacts) portal.sendDeliveryReceipt(evt.ID) } }