Only send checkpoint after message reaches phone
This commit is contained in:
parent
af212c9339
commit
40f78b8fd6
2 changed files with 33 additions and 1 deletions
|
@ -25,11 +25,13 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"go.mau.fi/util/jsontime"
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/bridge/status"
|
||||
"maunium.net/go/mautrix/event"
|
||||
"maunium.net/go/mautrix/id"
|
||||
|
||||
"go.mau.fi/mautrix-gmessages/database"
|
||||
"go.mau.fi/mautrix-gmessages/libgm/gmproto"
|
||||
)
|
||||
|
||||
|
@ -126,6 +128,26 @@ func (portal *Portal) sendErrorMessage(evt *event.Event, err error, msgType stri
|
|||
return resp.EventID
|
||||
}
|
||||
|
||||
func (portal *Portal) sendCheckpoint(dbMsg *database.Message, err error, delivered bool) {
|
||||
checkpoint := status.MessageCheckpoint{
|
||||
EventID: dbMsg.MXID,
|
||||
RoomID: dbMsg.RoomID,
|
||||
Step: status.MsgStepRemote,
|
||||
Timestamp: jsontime.UnixMilliNow(),
|
||||
Status: "",
|
||||
ReportedBy: status.MsgReportedByBridge,
|
||||
}
|
||||
if err != nil {
|
||||
checkpoint.Status = status.MsgStatusPermFailure
|
||||
checkpoint.Info = err.Error()
|
||||
} else if delivered {
|
||||
checkpoint.Status = status.MsgStatusDelivered
|
||||
} else {
|
||||
checkpoint.Status = status.MsgStatusSuccess
|
||||
}
|
||||
go portal.bridge.SendRawMessageCheckpoint(&checkpoint)
|
||||
}
|
||||
|
||||
func (portal *Portal) sendStatusEvent(evtID, lastRetry id.EventID, err error, deliveredTo *[]id.UserID) {
|
||||
if !portal.bridge.Config.Bridge.MessageStatusEvents {
|
||||
return
|
||||
|
@ -209,8 +231,8 @@ func (portal *Portal) sendMessageMetrics(evt *event.Event, err error, part strin
|
|||
Str("event_type", evt.Type.Type).
|
||||
Msg("Handled Matrix event")
|
||||
portal.sendDeliveryReceipt(evt.ID)
|
||||
portal.bridge.SendMessageSuccessCheckpoint(evt, status.MsgStepRemote, ms.getRetryNum())
|
||||
if msgType != "message" {
|
||||
portal.bridge.SendMessageSuccessCheckpoint(evt, status.MsgStepRemote, ms.getRetryNum())
|
||||
portal.sendStatusEvent(origEvtID, evt.ID, nil, nil)
|
||||
}
|
||||
if prevNotice := ms.popNoticeID(); prevNotice != "" {
|
||||
|
|
10
portal.go
10
portal.go
|
@ -495,16 +495,24 @@ func (portal *Portal) handleExistingMessageUpdate(ctx context.Context, source *U
|
|||
}
|
||||
case !dbMsg.Status.ReadReceiptSent && portal.IsPrivateChat() && newStatus == gmproto.MessageStatusType_OUTGOING_DISPLAYED:
|
||||
dbMsg.Status.ReadReceiptSent = true
|
||||
if !dbMsg.Status.MSSSent {
|
||||
portal.sendCheckpoint(dbMsg, nil, false)
|
||||
}
|
||||
if !dbMsg.Status.MSSDeliverySent {
|
||||
dbMsg.Status.MSSDeliverySent = true
|
||||
dbMsg.Status.MSSSent = true
|
||||
go portal.sendStatusEvent(dbMsg.MXID, "", nil, &[]id.UserID{portal.MainIntent().UserID})
|
||||
portal.sendCheckpoint(dbMsg, nil, true)
|
||||
}
|
||||
err := portal.MainIntent().MarkRead(portal.MXID, dbMsg.MXID)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("Failed to mark message as read")
|
||||
}
|
||||
case !dbMsg.Status.MSSDeliverySent && portal.IsPrivateChat() && newStatus == gmproto.MessageStatusType_OUTGOING_DELIVERED:
|
||||
if !dbMsg.Status.MSSSent {
|
||||
portal.sendCheckpoint(dbMsg, nil, false)
|
||||
}
|
||||
portal.sendCheckpoint(dbMsg, nil, true)
|
||||
dbMsg.Status.MSSDeliverySent = true
|
||||
dbMsg.Status.MSSSent = true
|
||||
go portal.sendStatusEvent(dbMsg.MXID, "", nil, &[]id.UserID{portal.MainIntent().UserID})
|
||||
|
@ -516,8 +524,10 @@ func (portal *Portal) handleExistingMessageUpdate(ctx context.Context, source *U
|
|||
deliveredTo = &[]id.UserID{}
|
||||
}
|
||||
go portal.sendStatusEvent(dbMsg.MXID, "", nil, deliveredTo)
|
||||
portal.sendCheckpoint(dbMsg, nil, false)
|
||||
case !dbMsg.Status.MSSFailSent && !dbMsg.Status.MSSSent && isFailSendStatus(newStatus):
|
||||
go portal.sendStatusEvent(dbMsg.MXID, "", OutgoingStatusError(newStatus), nil)
|
||||
portal.sendCheckpoint(dbMsg, OutgoingStatusError(newStatus), false)
|
||||
// TODO error notice
|
||||
default:
|
||||
log.Debug().Msg("Ignored message update")
|
||||
|
|
Loading…
Reference in a new issue