Skip to content

Commit ae5945c

Browse files
committed
ComposeBox: Require topics if topics are set as mandatory.
(For stream messages, that is, not PMs.) Fixes: #4378
1 parent 673e84f commit ae5945c

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/compose/ComposeBox.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { connect } from '../react-redux';
3030
import { withGetText } from '../boot/TranslationProvider';
3131
import { draftUpdate, sendTypingStart, sendTypingStop } from '../actions';
3232
import { FloatingActionButton, Input } from '../common';
33-
import { showToast } from '../utils/info';
33+
import { showToast, showErrorAlert } from '../utils/info';
3434
import { IconDone, IconSend } from '../common/Icons';
3535
import {
3636
isConversationNarrow,
@@ -46,7 +46,13 @@ import getComposeInputPlaceholder from './getComposeInputPlaceholder';
4646
import NotSubscribed from '../message/NotSubscribed';
4747
import AnnouncementOnly from '../message/AnnouncementOnly';
4848
import MentionWarnings from './MentionWarnings';
49-
import { getAuth, getIsAdmin, getStreamInNarrow, getVideoChatProvider } from '../selectors';
49+
import {
50+
getAuth,
51+
getIsAdmin,
52+
getStreamInNarrow,
53+
getVideoChatProvider,
54+
getRealm,
55+
} from '../selectors';
5056
import {
5157
getIsActiveStreamSubscribed,
5258
getIsActiveStreamAnnouncementOnly,
@@ -64,6 +70,7 @@ type SelectorProps = {|
6470
isAnnouncementOnly: boolean,
6571
isSubscribed: boolean,
6672
videoChatProvider: VideoChatProvider | null,
73+
mandatoryTopics: boolean,
6774
stream: Subscription | {| ...Stream, in_home_view: boolean |},
6875
|};
6976

@@ -401,10 +408,21 @@ class ComposeBoxInner extends PureComponent<Props, State> {
401408
};
402409

403410
handleSend = () => {
404-
const { dispatch } = this.props;
411+
const { dispatch, mandatoryTopics, _ } = this.props;
405412
const { message } = this.state;
406413
const destinationNarrow = this.getDestinationNarrow();
407414

415+
if (
416+
isTopicNarrow(destinationNarrow)
417+
&& topicOfNarrow(destinationNarrow) === apiConstants.NO_TOPIC_TOPIC
418+
&& mandatoryTopics
419+
) {
420+
// TODO how should this behave in the isEditing case? See
421+
// https://github.com/zulip/zulip-mobile/pull/4798#discussion_r731341400.
422+
showErrorAlert(_('Message not sent'), _('Please specify a topic.'));
423+
return;
424+
}
425+
408426
this.props.onSend(message, destinationNarrow);
409427

410428
this.setMessageInputValue('');
@@ -588,6 +606,7 @@ const ComposeBox: ComponentType<OuterProps> = compose(
588606
isSubscribed: getIsActiveStreamSubscribed(state, props.narrow),
589607
stream: getStreamInNarrow(state, props.narrow),
590608
videoChatProvider: getVideoChatProvider(state),
609+
mandatoryTopics: getRealm(state).mandatoryTopics,
591610
})),
592611
withSafeAreaInsets,
593612
)(withGetText(ComposeBoxInner));

static/translations/messages_en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2+
"Message not sent": "Message not sent",
3+
"Please specify a topic.": "Please specify a topic.",
24
"Failed to connect to server: {realm}": "Failed to connect to server: {realm}",
35
"{_}": "{_}",
46
"Home": "Home",

0 commit comments

Comments
 (0)