Skip to content

Commit 5708807

Browse files
authored
fix: reset message composer state partially when poll message is sent (#2703)
When sending a poll message (contains only poll id) the composer id has to be created anew (for the next msg) and the poll composer state has to be reset. The rest of the states should be kept as they can be used for the next message. This should be moved to the LLC in the future, once `MessageComposer.sendMessage()` exists.
1 parent 8bca9f0 commit 5708807

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/components/MessageInput/hooks/useSubmitHandler.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { useCallback } from 'react';
2+
import { MessageComposer } from 'stream-chat';
23
import { useMessageComposer } from './useMessageComposer';
34
import { useChannelActionContext } from '../../../context/ChannelActionContext';
45
import { useTranslationContext } from '../../../context/TranslationContext';
56

67
import type { MessageInputProps } from '../MessageInput';
7-
import type { MessageComposer } from 'stream-chat';
88

99
const takeStateSnapshot = (messageComposer: MessageComposer) => {
1010
const textComposerState = messageComposer.textComposer.state.getLatestValue();
@@ -51,7 +51,17 @@ export const useSubmitHandler = (props: MessageInputProps) => {
5151
} else {
5252
const restoreComposerStateSnapshot = takeStateSnapshot(messageComposer);
5353
try {
54-
messageComposer.clear();
54+
// FIXME: once MessageComposer has sendMessage method, then the following condition should be encapsulated by it
55+
// keep attachments, text, quoted message (treat them as draft) ... if sending a poll
56+
const sentPollMessage = !!message.poll_id;
57+
if (sentPollMessage) {
58+
messageComposer.state.partialNext({
59+
id: MessageComposer.generateId(),
60+
pollId: null,
61+
});
62+
} else {
63+
messageComposer.clear();
64+
}
5565
// todo: get rid of overrideSubmitHandler once MessageComposer supports submission flow
5666
if (overrideSubmitHandler) {
5767
await overrideSubmitHandler({

0 commit comments

Comments
 (0)