Skip to content

Commit 89b66a6

Browse files
committed
compose: Send to general chat if empty topic
Signed-off-by: Zixuan James Li <[email protected]>
1 parent 43049ee commit 89b66a6

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

lib/widgets/compose_box.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,20 @@ class ComposeTopicController extends ComposeController<TopicValidationError> {
104104
@override
105105
String _computeTextNormalized() {
106106
String trimmed = text.trim();
107-
return trimmed.isEmpty ? kNoTopicTopic : trimmed;
107+
// TODO(server-10): simplify
108+
if (store.connection.zulipFeatureLevel! < 334) {
109+
return trimmed.isEmpty ? kNoTopicTopic : trimmed;
110+
}
111+
112+
return trimmed;
108113
}
109114

110115
@override
111116
List<TopicValidationError> _computeValidationErrors() {
112117
return [
113-
if (mandatory && textNormalized == kNoTopicTopic)
118+
if (mandatory && (textNormalized.isEmpty
119+
|| textNormalized == kNoTopicTopic
120+
|| textNormalized == store.realmEmptyTopicDisplayName))
114121
TopicValidationError.mandatoryButEmpty,
115122

116123
if (

test/widgets/compose_box_test.dart

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ void main() {
681681
Future<void> setupAndTapSend(WidgetTester tester, {
682682
required String topicInputText,
683683
required bool mandatoryTopics,
684+
int? zulipFeatureLevel,
684685
}) async {
685686
TypingNotifier.debugEnable = false;
686687
addTearDown(TypingNotifier.debugReset);
@@ -689,7 +690,8 @@ void main() {
689690
final narrow = ChannelNarrow(channel.streamId);
690691
await prepareComposeBox(tester,
691692
narrow: narrow, streams: [channel],
692-
mandatoryTopics: mandatoryTopics);
693+
mandatoryTopics: mandatoryTopics,
694+
zulipFeatureLevel: zulipFeatureLevel);
693695

694696
await enterTopic(tester, narrow: narrow, topic: topicInputText);
695697
await tester.enterText(contentInputFinder, 'test content');
@@ -704,10 +706,21 @@ void main() {
704706
expectedMessage: 'Topics are required in this organization.');
705707
}
706708

707-
testWidgets('empty topic -> "(no topic)"', (tester) async {
709+
testWidgets('empty topic -> empty topic', (tester) async {
708710
await setupAndTapSend(tester,
709711
topicInputText: '',
710712
mandatoryTopics: false);
713+
check(connection.lastRequest).isA<http.Request>()
714+
..method.equals('POST')
715+
..url.path.equals('/api/v1/messages')
716+
..bodyFields['topic'].equals('');
717+
}, skip: true); // null topic names soon to be enabled
718+
719+
testWidgets('legacy: empty topic -> "(no topic)"', (tester) async {
720+
await setupAndTapSend(tester,
721+
topicInputText: '',
722+
mandatoryTopics: false,
723+
zulipFeatureLevel: 333);
711724
check(connection.lastRequest).isA<http.Request>()
712725
..method.equals('POST')
713726
..url.path.equals('/api/v1/messages')
@@ -721,12 +734,27 @@ void main() {
721734
checkMessageNotSent(tester);
722735
});
723736

737+
testWidgets('if topics are mandatory, reject `realmEmptyTopicDisplayName`', (tester) async {
738+
await setupAndTapSend(tester,
739+
topicInputText: eg.defaultRealmEmptyTopicDisplayName,
740+
mandatoryTopics: true);
741+
checkMessageNotSent(tester);
742+
}, skip: true); // null topic names soon to be enabled
743+
724744
testWidgets('if topics are mandatory, reject "(no topic)"', (tester) async {
725745
await setupAndTapSend(tester,
726746
topicInputText: '(no topic)',
727747
mandatoryTopics: true);
728748
checkMessageNotSent(tester);
729749
});
750+
751+
testWidgets('legacy: if topics are mandatory, reject "(no topic)"', (tester) async {
752+
await setupAndTapSend(tester,
753+
topicInputText: '(no topic)',
754+
mandatoryTopics: true,
755+
zulipFeatureLevel: 333);
756+
checkMessageNotSent(tester);
757+
});
730758
});
731759

732760
group('uploads', () {

0 commit comments

Comments
 (0)