Browse Source

portal: send checkpoint for matrix messages

Sumner Evans 3 years ago
parent
commit
52f09001a7
2 changed files with 12 additions and 0 deletions
  1. 1 0
      config/config.go
  2. 11 0
      portal.go

+ 1 - 0
config/config.go

@@ -121,6 +121,7 @@ func (config *Config) MakeAppService() (*appservice.AppService, error) {
 	as.HomeserverURL = config.Homeserver.Address
 	as.HomeserverURL = config.Homeserver.Address
 	as.Host.Hostname = config.AppService.Hostname
 	as.Host.Hostname = config.AppService.Hostname
 	as.Host.Port = config.AppService.Port
 	as.Host.Port = config.AppService.Port
+	as.MessageSendCheckpointEndpoint = config.Homeserver.MessageSendCheckpointEndpoint
 	as.DefaultHTTPRetries = 4
 	as.DefaultHTTPRetries = 4
 	var err error
 	var err error
 	as.Registration, err = config.GetRegistration()
 	as.Registration, err = config.GetRegistration()

+ 11 - 0
portal.go

@@ -43,6 +43,7 @@ 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"
@@ -2144,8 +2145,14 @@ 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)
+		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)
+		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)
 	}
 	}
@@ -2179,8 +2186,12 @@ 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)
+		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)
+		go checkpoint.Send(portal.bridge.Config.Homeserver.MessageSendCheckpointEndpoint, portal.bridge.AS.Registration.AppToken)
 		portal.sendDeliveryReceipt(evt.ID)
 		portal.sendDeliveryReceipt(evt.ID)
 	}
 	}
 }
 }