Chat: Handle the new "duplicate" message error type, by not displaying it #7879
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@keybase/react-hackers CC @chrisnojima @mmaxim
If we get a message with error type "duplicate". it means it was rejected by Gregor as a duplicate attempted send. Normally we display errors for failed messages and offer to retry them, but that's not appropriate here -- we don't want to display anything at all.
This PR seems to work, but I don't much like the way it turned out. We can learn of "duplicate" error messages in three different ways:
They can be relayed to us from the outbox as part of a GetThread call, in which case we need to not render them at all.
Race outcome 1: we can send a message, display it in pending state in the GUI, and then get an IncomingMessage notification telling us about the duplicate failure, in which case we need to delete it from the GUI after it's already been rendered.
Race outcome 2: we can send a message, but due to a race between sagas and RPCs that RPCs win, we learn of the message's duplicate failure before we finish thinking we've sent a message. In this case we need to store away the fact that we've been told of a failure, and the fact that it's this special kind of failure, and then when we would normally render the message as pending in the GUI we decide not to.
To achieve this, I went with:
When we unbox a message with this duplicate error, we store it as a messageKind of 'errorInvisible' instead of 'outboxText'. We have to store some kind of message, because it's an invariant in all of our code that an _unboxedToMessage() call produces a Message object for the store in every case.
When we're rendering a thread, we now render these 'errorInvisible' messages an an empty
<Box />
.When we get an IncomingMessage telling us about a failure (Race outcome 1), we update the Message object in the store to have the messageKind updated to
errorInvisible
at that point, and it's rendered away as it would be in the first case.When we get an IncomingMessage telling us about a failure we haven't rendered yet (Race outcome 2), we just don't add anything at all in the store.
This is complicated enough that I'm not confident the code's going to be correct, and in general debugging these errors and races in transitioning messages from pending -> sent -> deleted is causing us a lot of hassle, so I don't feel good about merging this PR yet. We might be better just asking for CORE help to take care of this case. Or, we could try to refactor our code to eliminate this RPC<->sagas race, which I think would make us feel happier about adding new edge cases to this code.
What do you think?