mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-12-14 09:23:51 +01:00
checkpoints: send retry_num
This commit is contained in:
parent
6cb5301996
commit
ed2bb3ac5f
2 changed files with 15 additions and 13 deletions
14
matrix.go
14
matrix.go
|
@ -335,27 +335,29 @@ func (mx *MatrixHandler) HandleEncrypted(evt *event.Event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
decrypted, err := mx.bridge.Crypto.Decrypt(evt)
|
decrypted, err := mx.bridge.Crypto.Decrypt(evt)
|
||||||
|
decryptionRetryCount := 0
|
||||||
if errors.Is(err, NoSessionFound) {
|
if errors.Is(err, NoSessionFound) {
|
||||||
content := evt.Content.AsEncrypted()
|
content := evt.Content.AsEncrypted()
|
||||||
mx.log.Debugfln("Couldn't find session %s trying to decrypt %s, waiting %d seconds...", content.SessionID, evt.ID, int(sessionWaitTimeout.Seconds()))
|
mx.log.Debugfln("Couldn't find session %s trying to decrypt %s, waiting %d seconds...", content.SessionID, evt.ID, int(sessionWaitTimeout.Seconds()))
|
||||||
if mx.bridge.Crypto.WaitForSession(evt.RoomID, content.SenderKey, content.SessionID, sessionWaitTimeout) {
|
if mx.bridge.Crypto.WaitForSession(evt.RoomID, content.SenderKey, content.SessionID, sessionWaitTimeout) {
|
||||||
mx.log.Debugfln("Got session %s after waiting, trying to decrypt %s again", content.SessionID, evt.ID)
|
mx.log.Debugfln("Got session %s after waiting, trying to decrypt %s again", content.SessionID, evt.ID)
|
||||||
decrypted, err = mx.bridge.Crypto.Decrypt(evt)
|
decrypted, err = mx.bridge.Crypto.Decrypt(evt)
|
||||||
|
decryptionRetryCount++
|
||||||
} else {
|
} else {
|
||||||
mx.as.SendErrorMessageSendCheckpoint(evt, appservice.StepDecrypted, fmt.Errorf("didn't receive encryption keys"), false)
|
mx.as.SendErrorMessageSendCheckpoint(evt, appservice.StepDecrypted, fmt.Errorf("didn't receive encryption keys"), false, decryptionRetryCount)
|
||||||
go mx.waitLongerForSession(evt)
|
go mx.waitLongerForSession(evt)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mx.as.SendErrorMessageSendCheckpoint(evt, appservice.StepDecrypted, err, true)
|
mx.as.SendErrorMessageSendCheckpoint(evt, appservice.StepDecrypted, err, true, decryptionRetryCount)
|
||||||
|
|
||||||
mx.log.Warnfln("Failed to decrypt %s: %v", evt.ID, err)
|
mx.log.Warnfln("Failed to decrypt %s: %v", evt.ID, err)
|
||||||
_, _ = mx.bridge.Bot.SendNotice(evt.RoomID, fmt.Sprintf(
|
_, _ = mx.bridge.Bot.SendNotice(evt.RoomID, fmt.Sprintf(
|
||||||
"\u26a0 Your message was not bridged: %v", err))
|
"\u26a0 Your message was not bridged: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
mx.as.SendMessageSendCheckpoint(decrypted, appservice.StepDecrypted)
|
mx.as.SendMessageSendCheckpoint(decrypted, appservice.StepDecrypted, decryptionRetryCount)
|
||||||
mx.bridge.EventProcessor.Dispatch(decrypted)
|
mx.bridge.EventProcessor.Dispatch(decrypted)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,17 +383,17 @@ func (mx *MatrixHandler) waitLongerForSession(evt *event.Event) {
|
||||||
mx.log.Debugfln("Got session %s after waiting more, trying to decrypt %s again", content.SessionID, evt.ID)
|
mx.log.Debugfln("Got session %s after waiting more, trying to decrypt %s again", content.SessionID, evt.ID)
|
||||||
decrypted, err := mx.bridge.Crypto.Decrypt(evt)
|
decrypted, err := mx.bridge.Crypto.Decrypt(evt)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
mx.as.SendMessageSendCheckpoint(decrypted, appservice.StepDecrypted)
|
mx.as.SendMessageSendCheckpoint(decrypted, appservice.StepDecrypted, 1)
|
||||||
mx.bridge.EventProcessor.Dispatch(decrypted)
|
mx.bridge.EventProcessor.Dispatch(decrypted)
|
||||||
_, _ = mx.bridge.Bot.RedactEvent(evt.RoomID, resp.EventID)
|
_, _ = mx.bridge.Bot.RedactEvent(evt.RoomID, resp.EventID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
mx.log.Warnfln("Failed to decrypt %s: %v", evt.ID, err)
|
mx.log.Warnfln("Failed to decrypt %s: %v", evt.ID, err)
|
||||||
mx.as.SendErrorMessageSendCheckpoint(evt, appservice.StepDecrypted, err, true)
|
mx.as.SendErrorMessageSendCheckpoint(evt, appservice.StepDecrypted, err, true, 1)
|
||||||
update.Body = fmt.Sprintf("\u26a0 Your message was not bridged: %v", err)
|
update.Body = fmt.Sprintf("\u26a0 Your message was not bridged: %v", err)
|
||||||
} else {
|
} else {
|
||||||
mx.log.Debugfln("Didn't get %s, giving up on %s", content.SessionID, evt.ID)
|
mx.log.Debugfln("Didn't get %s, giving up on %s", content.SessionID, evt.ID)
|
||||||
mx.as.SendErrorMessageSendCheckpoint(evt, appservice.StepDecrypted, fmt.Errorf("didn't receive encryption keys"), true)
|
mx.as.SendErrorMessageSendCheckpoint(evt, appservice.StepDecrypted, fmt.Errorf("didn't receive encryption keys"), true, 1)
|
||||||
update.Body = "\u26a0 Your message was not bridged: the bridge hasn't received the decryption keys. " +
|
update.Body = "\u26a0 Your message was not bridged: the bridge hasn't received the decryption keys. " +
|
||||||
"If this error keeps happening, try restarting your client."
|
"If this error keeps happening, try restarting your client."
|
||||||
}
|
}
|
||||||
|
|
14
portal.go
14
portal.go
|
@ -2144,10 +2144,10 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
portal.log.Errorfln("Error sending message: %v", err)
|
portal.log.Errorfln("Error sending message: %v", err)
|
||||||
portal.sendErrorMessage(err.Error(), true)
|
portal.sendErrorMessage(err.Error(), true)
|
||||||
portal.bridge.AS.SendErrorMessageSendCheckpoint(evt, appservice.StepRemote, err, true)
|
portal.bridge.AS.SendErrorMessageSendCheckpoint(evt, appservice.StepRemote, err, true, 0)
|
||||||
} else {
|
} else {
|
||||||
portal.log.Debugfln("Handled Matrix event %s", evt.ID)
|
portal.log.Debugfln("Handled Matrix event %s", evt.ID)
|
||||||
portal.bridge.AS.SendMessageSendCheckpoint(evt, appservice.StepRemote)
|
portal.bridge.AS.SendMessageSendCheckpoint(evt, appservice.StepRemote, 0)
|
||||||
portal.sendDeliveryReceipt(evt.ID)
|
portal.sendDeliveryReceipt(evt.ID)
|
||||||
dbMsg.MarkSent(ts)
|
dbMsg.MarkSent(ts)
|
||||||
}
|
}
|
||||||
|
@ -2168,15 +2168,15 @@ func (portal *Portal) HandleMatrixRedaction(sender *User, evt *event.Event) {
|
||||||
msg := portal.bridge.DB.Message.GetByMXID(evt.Redacts)
|
msg := portal.bridge.DB.Message.GetByMXID(evt.Redacts)
|
||||||
if msg == nil {
|
if msg == nil {
|
||||||
portal.log.Debugfln("Ignoring redaction %s of unknown event by %s", msg, senderLogIdentifier)
|
portal.log.Debugfln("Ignoring redaction %s of unknown event by %s", msg, senderLogIdentifier)
|
||||||
portal.bridge.AS.SendErrorMessageSendCheckpoint(evt, appservice.StepRemote, errors.New("target not found"), true)
|
portal.bridge.AS.SendErrorMessageSendCheckpoint(evt, appservice.StepRemote, errors.New("target not found"), true, 0)
|
||||||
return
|
return
|
||||||
} else if msg.IsFakeJID() {
|
} else if msg.IsFakeJID() {
|
||||||
portal.log.Debugfln("Ignoring redaction %s of fake event by %s", msg, senderLogIdentifier)
|
portal.log.Debugfln("Ignoring redaction %s of fake event by %s", msg, senderLogIdentifier)
|
||||||
portal.bridge.AS.SendErrorMessageSendCheckpoint(evt, appservice.StepRemote, errors.New("target is a fake event"), true)
|
portal.bridge.AS.SendErrorMessageSendCheckpoint(evt, appservice.StepRemote, errors.New("target is a fake event"), true, 0)
|
||||||
return
|
return
|
||||||
} else if msg.Sender.User != sender.JID.User {
|
} 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, senderLogIdentifier, msg.Sender, sender.JID)
|
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, senderLogIdentifier, msg.Sender, sender.JID)
|
||||||
portal.bridge.AS.SendErrorMessageSendCheckpoint(evt, appservice.StepRemote, errors.New("message was sent by someone else"), true)
|
portal.bridge.AS.SendErrorMessageSendCheckpoint(evt, appservice.StepRemote, errors.New("message was sent by someone else"), true, 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2184,10 +2184,10 @@ func (portal *Portal) HandleMatrixRedaction(sender *User, evt *event.Event) {
|
||||||
_, err := sender.Client.RevokeMessage(portal.Key.JID, msg.JID)
|
_, err := sender.Client.RevokeMessage(portal.Key.JID, msg.JID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
portal.log.Errorfln("Error handling Matrix redaction %s: %v", evt.ID, err)
|
portal.log.Errorfln("Error handling Matrix redaction %s: %v", evt.ID, err)
|
||||||
portal.bridge.AS.SendErrorMessageSendCheckpoint(evt, appservice.StepRemote, err, true)
|
portal.bridge.AS.SendErrorMessageSendCheckpoint(evt, appservice.StepRemote, err, true, 0)
|
||||||
} else {
|
} else {
|
||||||
portal.log.Debugfln("Handled Matrix redaction %s of %s", evt.ID, evt.Redacts)
|
portal.log.Debugfln("Handled Matrix redaction %s of %s", evt.ID, evt.Redacts)
|
||||||
portal.bridge.AS.SendMessageSendCheckpoint(evt, appservice.StepRemote)
|
portal.bridge.AS.SendMessageSendCheckpoint(evt, appservice.StepRemote, 0)
|
||||||
portal.sendDeliveryReceipt(evt.ID)
|
portal.sendDeliveryReceipt(evt.ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue