mautrix / meta

A Matrix-Facebook Messenger and Instagram DM puppeting bridge.
GNU Affero General Public License v3.0
155 stars 11 forks source link

Better errors for ResponseHandler and cancel ACK and response waits on disconnect #64

Closed javiercr closed 3 months ago

javiercr commented 3 months ago

Context

This PR continues the work on #63 (and should be merged after that one).

Description

Given the following sequence diagram for sending a Message:

If a message is sent by the user, right an instant before a connection refresh start, the message will be delivered by Meta after receiving our PUBLISH (/ls_req) (1) packet.

However the connection refresh could be closing the socket before Meta's PUBACK (2), or the PUBLISH(/ls_resp) (3) are received by us.

In that scenario, the makeLSRequest will be locked until the timeout defined in ResponseHandler.waitForDetails is triggered.

This PR changes that behavior by exposing the Context used by Client, so that whenever that Context is cancelled (by calling stopCurrentConnection), we also notify ResponseHandler.waitForDetails.

This PR also changes the signature for: waitForPubACKDetails, waitForSubACKDetails, and waitForPubResponseDetails so that they return a different sentinel error depending on each scenario.

TO BE DISCUSSED:

We need to discuss how to handle the new ErrContextCancelled in Portal.handleMatrixMessage. With the current implementation in this PR, the sent message will still be flagged as "Not delivered" in Beeper, despite having been delivered properly.