Send checkpoints using new API and send DECRYPTED step checkpoints

This commit is contained in:
Sumner Evans 2021-11-17 14:52:16 -07:00
parent 52f09001a7
commit 139a0bd679
No known key found for this signature in database
GPG key ID: 8904527AB50022FD
2 changed files with 18 additions and 14 deletions

View file

@ -342,16 +342,20 @@ func (mx *MatrixHandler) HandleEncrypted(evt *event.Event) {
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)
} else { } else {
mx.as.SendErrorMessageSendCheckpoint(evt, appservice.StepDecrypted, err, false)
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.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.bridge.EventProcessor.Dispatch(decrypted) mx.bridge.EventProcessor.Dispatch(decrypted)
} }
@ -375,14 +379,18 @@ 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.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", err) mx.log.Warnfln("Failed to decrypt %s: %v", evt.ID, err)
mx.as.SendErrorMessageSendCheckpoint(evt, appservice.StepDecrypted, err, true)
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) errMsg := fmt.Sprintf("Didn't get %s, giving up on %s", content.SessionID, evt.ID)
mx.log.Debugfln(errMsg)
mx.as.SendErrorMessageSendCheckpoint(evt, appservice.StepDecrypted, fmt.Errorf(errMsg), true)
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 keeps happening, try restarting your client." "If this keeps happening, try restarting your client."
} }
@ -395,7 +403,10 @@ func (mx *MatrixHandler) waitLongerForSession(evt *event.Event) {
EventID: resp.EventID, EventID: resp.EventID,
} }
} }
_, _ = mx.bridge.Bot.SendMessageEvent(evt.RoomID, event.EventMessage, &update) _, err = mx.bridge.Bot.SendMessageEvent(evt.RoomID, event.EventMessage, &update)
if err != nil {
mx.log.Debugfln("Failed to update decryption error notice %s: %v", resp.EventID, err)
}
} }
func (mx *MatrixHandler) HandleMessage(evt *event.Event) { func (mx *MatrixHandler) HandleMessage(evt *event.Event) {

View file

@ -43,7 +43,6 @@ import (
"golang.org/x/image/webp" "golang.org/x/image/webp"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"maunium.net/go/mautrix/bridge"
"maunium.net/go/mautrix/format" "maunium.net/go/mautrix/format"
"go.mau.fi/whatsmeow" "go.mau.fi/whatsmeow"
@ -2145,14 +2144,10 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event) {
if err != nil { if err != nil {
portal.log.Errorln("Error sending message: %v", err) portal.log.Errorln("Error sending message: %v", err)
portal.sendErrorMessage(err.Error(), true) portal.sendErrorMessage(err.Error(), true)
checkpoint := bridge.NewErrorMessageSendCheckpoint(evt.ID, evt.RoomID, bridge.StepRemote, evt.Type, err) portal.bridge.AS.SendErrorMessageSendCheckpoint(evt, appservice.StepRemote, err, true)
checkpoint.MessageType = evt.Content.AsMessage().MsgType
go checkpoint.Send(portal.bridge.Config.Homeserver.MessageSendCheckpointEndpoint, portal.bridge.AS.Registration.AppToken)
} else { } else {
portal.log.Debugfln("Handled Matrix event %s", evt.ID) portal.log.Debugfln("Handled Matrix event %s", evt.ID)
checkpoint := bridge.NewMessageSendCheckpoint(evt.ID, evt.RoomID, bridge.StepRemote, bridge.StatusSuccesss, evt.Type) portal.bridge.AS.SendMessageSendCheckpoint(evt, appservice.StepRemote)
checkpoint.MessageType = evt.Content.AsMessage().MsgType
go checkpoint.Send(portal.bridge.Config.Homeserver.MessageSendCheckpointEndpoint, portal.bridge.AS.Registration.AppToken)
portal.sendDeliveryReceipt(evt.ID) portal.sendDeliveryReceipt(evt.ID)
dbMsg.MarkSent(ts) dbMsg.MarkSent(ts)
} }
@ -2186,12 +2181,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)
checkpoint := bridge.NewErrorMessageSendCheckpoint(evt.ID, evt.RoomID, bridge.StepRemote, evt.Type, err) portal.bridge.AS.SendErrorMessageSendCheckpoint(evt, appservice.StepRemote, err, true)
go checkpoint.Send(portal.bridge.Config.Homeserver.MessageSendCheckpointEndpoint, portal.bridge.AS.Registration.AppToken)
} 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)
checkpoint := bridge.NewMessageSendCheckpoint(evt.ID, evt.RoomID, bridge.StepRemote, bridge.StatusSuccesss, evt.Type) portal.bridge.AS.SendMessageSendCheckpoint(evt, appservice.StepRemote)
go checkpoint.Send(portal.bridge.Config.Homeserver.MessageSendCheckpointEndpoint, portal.bridge.AS.Registration.AppToken)
portal.sendDeliveryReceipt(evt.ID) portal.sendDeliveryReceipt(evt.ID)
} }
} }