Skip to content

Commit

Permalink
Merge pull request #11530 from nanaya/chat-announce-input
Browse files Browse the repository at this point in the history
Add warning before sending message to announcement channel
  • Loading branch information
notbakaneko authored Oct 3, 2024
2 parents 8c2664b + 771901b commit 29af0c1
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions resources/js/chat/input-box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class InputBox extends React.Component<Props> {
private readonly inputBoxRef = React.createRef<HTMLTextAreaElement>();

get allowMultiLine() {
return this.currentChannel?.type === 'ANNOUNCE';
return this.isAnnouncement;
}

@computed
Expand All @@ -37,6 +37,10 @@ export default class InputBox extends React.Component<Props> {
return !this.currentChannel?.canMessage;
}

get isAnnouncement() {
return this.currentChannel != null && this.currentChannel.type === 'ANNOUNCE';
}

@computed
get sendDisabled() {
return this.inputDisabled || !core.dataStore.chatState.isReady;
Expand Down Expand Up @@ -67,8 +71,7 @@ export default class InputBox extends React.Component<Props> {
}

buttonClicked = () => {
this.sendMessage(this.currentChannel?.inputText);
this.currentChannel?.setInputText('');
this.startSendMessage();
};

checkIfEnterPressed = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
Expand All @@ -77,8 +80,7 @@ export default class InputBox extends React.Component<Props> {

e.preventDefault();
if (!this.sendDisabled) {
this.sendMessage(this.currentChannel?.inputText);
this.currentChannel?.setInputText('');
this.startSendMessage();
}
}
};
Expand Down Expand Up @@ -181,4 +183,13 @@ export default class InputBox extends React.Component<Props> {

dispatch(new ChatMessageSendAction(message));
}

@action
private readonly startSendMessage = () => {
if (this.isAnnouncement && !confirm(trans('common.confirmation'))) {
return;
}
this.sendMessage(this.currentChannel?.inputText);
this.currentChannel?.setInputText('');
};
}

0 comments on commit 29af0c1

Please sign in to comment.