Skip to content

Commit 8c65058

Browse files
authored
fix: properly delete drafts with quoted messages (#1573)
## CLA - [ ] I have signed the [Stream CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) (required). - [ ] Code changes are tested ## Description of the changes, What, Why and How? This PR fixes an issue where `draft`s containing a `quotedMessage` were never cleared from the `messageComposer` state unless manually deleted. The easiest way to reproduce this is to: - Create a `draft` that contains a quoted message - Make sure the draft is there on the server (reload or whatever suits best) - Send the draft message from whichever SDK is being used - Reload the app again - The draft will still be there and no matter how many times we send it it is never going to be removed The reason this happens is [this check](https://github.com/GetStream/stream-chat-js/blob/7dcf10dd4f5234fbc228409222d003e90f6a020d/src/messageComposer/messageComposer.ts#L298), which is used to determine whether a draft should be deleted on pretty much all `state` listeners in the `messageComposer`, [like so](https://github.com/GetStream/stream-chat-js/blob/7dcf10dd4f5234fbc228409222d003e90f6a020d/src/messageComposer/messageComposer.ts#L512). However, since we're doing `messageComposer.clear()` every time we send a message the composite invocation never clears the quoted message state whenever that happens (as seen [here](https://github.com/GetStream/stream-chat-js/blob/7dcf10dd4f5234fbc228409222d003e90f6a020d/src/messageComposer/messageComposer.ts#L624) and then [here](https://github.com/GetStream/stream-chat-js/blob/7dcf10dd4f5234fbc228409222d003e90f6a020d/src/messageComposer/messageComposer.ts#L328)). This in turn causes `channel.deleteDraft` to never be invoked hence the bug. ## Changelog -
1 parent 7dcf10d commit 8c65058

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

src/messageComposer/messageComposer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ export class MessageComposer extends WithSubscriptions {
621621
};
622622

623623
clear = () => {
624+
this.setQuotedMessage(null);
624625
this.initState();
625626
};
626627

test/unit/MessageComposer/messageComposer.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ describe('MessageComposer', () => {
701701
expect(spyPollComposer).toHaveBeenCalled();
702702
expect(spyCustomDataManager).toHaveBeenCalled();
703703
expect(spyInitState).toHaveBeenCalled();
704+
expect(messageComposer.quotedMessage).to.be.null;
704705
});
705706

706707
it('should restore state from edited message if available', () => {

0 commit comments

Comments
 (0)