Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent sending messages with attachments multiple times by adding current state check #3100

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ts/components/conversation/composition/CompositionBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ class CompositionBoxInner extends React.Component<Props, State> {
private linkPreviewAbortController?: AbortController;
private container: HTMLDivElement | null;
private lastBumpTypingMessageLength: number = 0;
private isSendingMessage: boolean;

constructor(props: Props) {
super(props);
Expand All @@ -290,6 +291,8 @@ class CompositionBoxInner extends React.Component<Props, State> {
this.emojiPanelButton = React.createRef();
autoBind(this);
this.toggleEmojiPanel = debounce(this.toggleEmojiPanel.bind(this), 100);

this.isSendingMessage = false;
}

public componentDidMount() {
Expand Down Expand Up @@ -907,6 +910,10 @@ class CompositionBoxInner extends React.Component<Props, State> {
if (!this.props.selectedConversationKey) {
throw new Error('selectedConversationKey is needed');
}
if (this.isSendingMessage) {
return;
}

this.linkPreviewAbortController?.abort();

const messagePlaintext = cleanMentions(this.state.draft);
Expand Down Expand Up @@ -956,6 +963,8 @@ class CompositionBoxInner extends React.Component<Props, State> {
? _.pick(stagedLinkPreview, 'url', 'image', 'title')
: undefined;

this.isSendingMessage = true;

try {
// this does not call call removeAllStagedAttachmentsInConvers
const { attachments, previews } = await this.getFiles(linkPreview);
Expand Down Expand Up @@ -986,6 +995,8 @@ class CompositionBoxInner extends React.Component<Props, State> {
} catch (e) {
// Message sending failed
window?.log?.error(e);
} finally {
this.isSendingMessage = false;
}
}

Expand Down