Handle edge cases with missing senders in historical messages

This commit is contained in:
Tulir Asokan 2022-05-19 12:08:30 +03:00
parent d33f5aa3d2
commit 962179fb75
4 changed files with 22 additions and 6 deletions

2
go.mod
View file

@ -10,7 +10,7 @@ require (
github.com/prometheus/client_golang v1.12.2-0.20220514081015-5d584e2717ef
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/tidwall/gjson v1.14.1
go.mau.fi/whatsmeow v0.0.0-20220517205516-246a2007ca7f
go.mau.fi/whatsmeow v0.0.0-20220519090423-468ee95de7e7
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9
golang.org/x/net v0.0.0-20220513224357-95641704303c
google.golang.org/protobuf v1.28.0

4
go.sum
View file

@ -62,8 +62,8 @@ github.com/yuin/goldmark v1.4.12 h1:6hffw6vALvEDqJ19dOJvJKOoAOKe4NDaTqvd2sktGN0=
github.com/yuin/goldmark v1.4.12/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.mau.fi/libsignal v0.0.0-20220425070825-c40c839ee6a0 h1:3IQF2bgAyibdo77hTejwuJe4jlypj9QaE4xCQuxrThM=
go.mau.fi/libsignal v0.0.0-20220425070825-c40c839ee6a0/go.mod h1:kBOXTvYyDG/q1Ihgvd4J6WenGPh7wtEGvPKF6vmf5ak=
go.mau.fi/whatsmeow v0.0.0-20220517205516-246a2007ca7f h1:0eo1TMJBx2pv7vNh/sPAl8bXPpn+HwrVJntuOnejMfs=
go.mau.fi/whatsmeow v0.0.0-20220517205516-246a2007ca7f/go.mod h1:iUBgOLNaqShLrR17u0kIiRptIGFH+nbT1tRhaWBEX/c=
go.mau.fi/whatsmeow v0.0.0-20220519090423-468ee95de7e7 h1:08FioJlQ6/50fAp+hRkTWhDuoBeg1UFt3yrNnsWPKuM=
go.mau.fi/whatsmeow v0.0.0-20220519090423-468ee95de7e7/go.mod h1:iUBgOLNaqShLrR17u0kIiRptIGFH+nbT1tRhaWBEX/c=
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220513210258-46612604a0f9 h1:NUzdAbFtCJSXU20AOXgeqaUwg8Ypg4MPYmL+d+rsB5c=
golang.org/x/crypto v0.0.0-20220513210258-46612604a0f9/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=

View file

@ -302,6 +302,7 @@ func (user *User) handleHistorySync(backfillQueue *BackfillQueue, evt *waProto.H
// Don't store messages that will just be skipped.
msgEvt, err := user.Client.ParseWebMessage(portal.Key.JID, rawMsg.GetMessage())
if err != nil {
user.log.Warnln("Dropping historical message due to info parse error:", err)
continue
}
@ -493,6 +494,9 @@ func (portal *Portal) backfill(source *User, messages []*waProto.WebMessageInfo,
}
}
puppet := portal.getMessagePuppet(source, &msgEvt.Info)
if puppet == nil {
continue
}
intent := puppet.IntentFor(portal)
if intent.IsCustomPuppet && !portal.bridge.Config.CanDoublePuppetBackfill(puppet.CustomMXID) {
intent = puppet.DefaultIntent()

View file

@ -560,7 +560,9 @@ func (portal *Portal) handleUndecryptableMessage(source *User, evt *events.Undec
"undecryptableType": metricType,
})
intent := portal.getMessageIntent(source, &evt.Info)
if !intent.IsCustomPuppet && portal.IsPrivateChat() && evt.Info.Sender.User == portal.Key.Receiver.User {
if intent == nil {
return
} else if !intent.IsCustomPuppet && portal.IsPrivateChat() && evt.Info.Sender.User == portal.Key.Receiver.User {
portal.log.Debugfln("Not handling %s (undecryptable): user doesn't have double puppeting enabled", evt.Info.ID)
return
}
@ -634,7 +636,9 @@ func (portal *Portal) handleMessage(source *User, evt *events.Message) {
}
intent := portal.getMessageIntent(source, &evt.Info)
if !intent.IsCustomPuppet && portal.IsPrivateChat() && evt.Info.Sender.User == portal.Key.Receiver.User {
if intent == nil {
return
} else if !intent.IsCustomPuppet && portal.IsPrivateChat() && evt.Info.Sender.User == portal.Key.Receiver.User {
portal.log.Debugfln("Not handling %s (%s): user doesn't have double puppeting enabled", msgID, msgType)
return
}
@ -753,13 +757,21 @@ func (portal *Portal) getMessagePuppet(user *User, info *types.MessageInfo) *Pup
return portal.bridge.GetPuppetByJID(portal.Key.JID)
} else {
puppet := portal.bridge.GetPuppetByJID(info.Sender)
if puppet == nil {
portal.log.Warnfln("Message %+v doesn't seem to have a valid sender (%s): puppet is nil", *info, info.Sender)
return nil
}
puppet.SyncContact(user, true, true, "handling message")
return puppet
}
}
func (portal *Portal) getMessageIntent(user *User, info *types.MessageInfo) *appservice.IntentAPI {
return portal.getMessagePuppet(user, info).IntentFor(portal)
puppet := portal.getMessagePuppet(user, info)
if puppet == nil {
return nil
}
return puppet.IntentFor(portal)
}
func (portal *Portal) finishHandling(existing *database.Message, message *types.MessageInfo, mxid id.EventID, msgType database.MessageType, errType database.MessageErrorType) {