Skip to content

Commit 2d620f3

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

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
@@ -673,6 +673,7 @@ void main() {
673673
Future<void> setupAndTapSend(WidgetTester tester, {
674674
required String topicInputText,
675675
required bool mandatoryTopics,
676+
int? zulipFeatureLevel,
676677
}) async {
677678
TypingNotifier.debugEnable = false;
678679
addTearDown(TypingNotifier.debugReset);
@@ -681,7 +682,8 @@ void main() {
681682
final narrow = ChannelNarrow(channel.streamId);
682683
await prepareComposeBox(tester,
683684
narrow: narrow, streams: [channel],
684-
mandatoryTopics: mandatoryTopics);
685+
mandatoryTopics: mandatoryTopics,
686+
zulipFeatureLevel: zulipFeatureLevel);
685687

686688
await enterTopic(tester, narrow: narrow, topic: topicInputText);
687689
await tester.enterText(contentInputFinder, 'test content');
@@ -696,10 +698,21 @@ void main() {
696698
expectedMessage: 'Topics are required in this organization.');
697699
}
698700

699-
testWidgets('empty topic -> "(no topic)"', (tester) async {
701+
testWidgets('empty topic -> empty topic', (tester) async {
700702
await setupAndTapSend(tester,
701703
topicInputText: '',
702704
mandatoryTopics: false);
705+
check(connection.lastRequest).isA<http.Request>()
706+
..method.equals('POST')
707+
..url.path.equals('/api/v1/messages')
708+
..bodyFields['topic'].equals('');
709+
}, skip: true); // null topic names soon to be enabled
710+
711+
testWidgets('legacy: empty topic -> "(no topic)"', (tester) async {
712+
await setupAndTapSend(tester,
713+
topicInputText: '',
714+
mandatoryTopics: false,
715+
zulipFeatureLevel: 333);
703716
check(connection.lastRequest).isA<http.Request>()
704717
..method.equals('POST')
705718
..url.path.equals('/api/v1/messages')
@@ -713,12 +726,27 @@ void main() {
713726
checkMessageNotSent(tester);
714727
});
715728

729+
testWidgets('if topics are mandatory, reject `realmEmptyTopicDisplayName`', (tester) async {
730+
await setupAndTapSend(tester,
731+
topicInputText: eg.defaultRealmEmptyTopicDisplayName,
732+
mandatoryTopics: true);
733+
checkMessageNotSent(tester);
734+
}, skip: true); // null topic names soon to be enabled
735+
716736
testWidgets('if topics are mandatory, reject "(no topic)"', (tester) async {
717737
await setupAndTapSend(tester,
718738
topicInputText: '(no topic)',
719739
mandatoryTopics: true);
720740
checkMessageNotSent(tester);
721741
});
742+
743+
testWidgets('legacy: if topics are mandatory, reject "(no topic)"', (tester) async {
744+
await setupAndTapSend(tester,
745+
topicInputText: '(no topic)',
746+
mandatoryTopics: true,
747+
zulipFeatureLevel: 333);
748+
checkMessageNotSent(tester);
749+
});
722750
});
723751

724752
group('uploads', () {

0 commit comments

Comments
 (0)