Skip to content

Commit

Permalink
handlegmessages: only send initial MSS success for outgoing messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Sep 30, 2024
1 parent ccb3c66 commit 9c9da85
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/connector/dbmeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type MessageMetadata struct {
MediaID string `json:"media_id,omitempty"`
MediaPending bool `json:"media_pending,omitempty"`

IsOutgoing bool `json:"is_outgoing,omitempty"`
MSSSent bool `json:"mss_sent,omitempty"`
MSSFailSent bool `json:"mss_fail_sent,omitempty"`
MSSDeliverySent bool `json:"mss_delivery_sent,omitempty"`
Expand Down
3 changes: 2 additions & 1 deletion pkg/connector/handlegmessages.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ func (m *MessageUpdateEvent) ConvertEdit(ctx context.Context, portal *bridgev2.P

prevMainMeta := existing[0].Metadata.(*MessageMetadata)
newMainMeta := converted.Parts[0].DBMetadata.(*MessageMetadata)
newMainMeta.IsOutgoing = prevMainMeta.IsOutgoing
newMainMeta.MSSSent = prevMainMeta.MSSSent
newMainMeta.MSSFailSent = prevMainMeta.MSSFailSent
newMainMeta.MSSDeliverySent = prevMainMeta.MSSDeliverySent
Expand Down Expand Up @@ -878,7 +879,7 @@ func (m *MessageEvent) HandleExisting(ctx context.Context, portal *bridgev2.Port
(hasPendingMedia && updatedMediaIsComplete) ||
messageWasEdited ||
existingMeta.GlobalPartCount != len(m.MessageInfo)
needsMSSEvent := !existingMeta.MSSSent && isSuccessfullySentStatus(newStatus)
needsMSSEvent := existingMeta.IsOutgoing && !existingMeta.MSSSent && isSuccessfullySentStatus(newStatus)
needsMSSFailureEvent := !existingMeta.MSSFailSent && !existingMeta.MSSSent && getFailMessage(newStatus) != ""
needsMSSDeliveryEvent := !existingMeta.MSSDeliverySent && portal.RoomType == database.RoomTypeDM && (newStatus == gmproto.MessageStatusType_OUTGOING_DELIVERED || newStatus == gmproto.MessageStatusType_OUTGOING_DISPLAYED)
needsReadReceipt := !existingMeta.ReadReceiptSent && portal.RoomType == database.RoomTypeDM && newStatus == gmproto.MessageStatusType_OUTGOING_DISPLAYED
Expand Down
1 change: 1 addition & 0 deletions pkg/connector/handlematrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (gc *GMClient) handleRemoteEcho(rawEvt bridgev2.RemoteMessage, dbMessage *d
evt := rawEvt.(*MessageEvent)
_, textHash := getTextPart(evt.Message)
dbMessage.Metadata = &MessageMetadata{
IsOutgoing: true,
Type: evt.GetMessageStatus().GetStatus(),
TextHash: textHash,
GlobalPartCount: len(evt.MessageInfo),
Expand Down

0 comments on commit 9c9da85

Please sign in to comment.