From 0665c74cce518b96c8f7e5d81f467bf15feeb920 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 2 May 2022 15:35:47 +0300 Subject: [PATCH] Merge incoming receipt and message channels Otherwise receipts after downtime might be handled before the messages those receipts point at. --- portal.go | 12 +++--------- user.go | 2 +- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/portal.go b/portal.go index 1c3deef..1ee4fe1 100644 --- a/portal.go +++ b/portal.go @@ -144,7 +144,6 @@ func (bridge *Bridge) newBlankPortal(key database.PortalKey) *Portal { log: bridge.Log.Sub(fmt.Sprintf("Portal/%s", key)), messages: make(chan PortalMessage, bridge.Config.Bridge.PortalMessageBuffer), - receipts: make(chan PortalReceipt, bridge.Config.Bridge.PortalMessageBuffer), matrixMessages: make(chan PortalMatrixMessage, bridge.Config.Bridge.PortalMessageBuffer), mediaRetries: make(chan PortalMediaRetry, bridge.Config.Bridge.PortalMessageBuffer), @@ -180,15 +179,11 @@ type fakeMessage struct { type PortalMessage struct { evt *events.Message undecryptable *events.UndecryptableMessage + receipt *events.Receipt fake *fakeMessage source *User } -type PortalReceipt struct { - evt *events.Receipt - source *User -} - type PortalMatrixMessage struct { evt *event.Event user *User @@ -225,7 +220,6 @@ type Portal struct { currentlyTypingLock sync.Mutex messages chan PortalMessage - receipts chan PortalReceipt matrixMessages chan PortalMatrixMessage mediaRetries chan PortalMediaRetry @@ -249,6 +243,8 @@ func (portal *Portal) handleMessageLoopItem(msg PortalMessage) { } if msg.evt != nil { portal.handleMessage(msg.source, msg.evt) + } else if msg.receipt != nil { + portal.handleReceipt(msg.receipt, msg.source) } else if msg.undecryptable != nil { portal.handleUndecryptableMessage(msg.source, msg.undecryptable) } else if msg.fake != nil { @@ -313,8 +309,6 @@ func (portal *Portal) handleMessageLoop() { select { case msg := <-portal.messages: portal.handleMessageLoopItem(msg) - case receipt := <-portal.receipts: - portal.handleReceipt(receipt.evt, receipt.source) case msg := <-portal.matrixMessages: portal.handleMatrixMessageLoopItem(msg) case retry := <-portal.mediaRetries: diff --git a/user.go b/user.go index 6350320..3dc13f6 100644 --- a/user.go +++ b/user.go @@ -1019,7 +1019,7 @@ func (user *User) handleReceipt(receipt *events.Receipt) { if portal == nil || len(portal.MXID) == 0 { return } - portal.receipts <- PortalReceipt{evt: receipt, source: user} + portal.messages <- PortalMessage{receipt: receipt, source: user} } func makeReadMarkerContent(eventID id.EventID, doublePuppet bool) CustomReadMarkers {