portal: send checkpoint for matrix messages

This commit is contained in:
Sumner Evans 2021-11-16 13:08:21 -07:00
parent 712dc5a7b6
commit 52f09001a7
No known key found for this signature in database
GPG key ID: 8904527AB50022FD
2 changed files with 12 additions and 0 deletions

View file

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

View file

@ -43,6 +43,7 @@ import (
"golang.org/x/image/webp"
"google.golang.org/protobuf/proto"
"maunium.net/go/mautrix/bridge"
"maunium.net/go/mautrix/format"
"go.mau.fi/whatsmeow"
@ -2144,8 +2145,14 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event) {
if err != nil {
portal.log.Errorln("Error sending message: %v", err)
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 {
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)
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)
if err != nil {
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 {
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)
}
}