Skip to content

Commit a2e4aa4

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

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-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: 35 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
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,8 +698,24 @@ void main() {
696698
expectedMessage: 'Topics are required in this organization.');
697699
}
698700

699-
testWidgets('empty topic -> (no topic)', (tester) async {
701+
testWidgets('empty topic -> general chat', (tester) async {
700702
await setupAndTapSend(tester, topicInputText: '');
703+
check(connection.lastRequest).isA<http.Request>()
704+
..method.equals('POST')
705+
..url.path.equals('/api/v1/messages')
706+
..bodyFields.deepEquals({
707+
'type': 'stream',
708+
'to': channel.streamId.toString(),
709+
'topic': '',
710+
'content': 'test content',
711+
'read_by_sender': 'true',
712+
});
713+
}, skip: true); // null topic names soon to be enabled
714+
715+
testWidgets('legacy: empty topic -> (no topic)', (tester) async {
716+
await setupAndTapSend(tester,
717+
topicInputText: '',
718+
zulipFeatureLevel: 333);
701719
check(connection.lastRequest).isA<http.Request>()
702720
..method.equals('POST')
703721
..url.path.equals('/api/v1/messages')
@@ -717,12 +735,27 @@ void main() {
717735
checkMessageNotSent(tester);
718736
});
719737

738+
testWidgets('if topics are mandatory, reject `realmEmptyTopicDisplayName`', (tester) async {
739+
await setupAndTapSend(tester,
740+
topicInputText: eg.defaultRealmEmptyTopicDisplayName,
741+
mandatoryTopics: true);
742+
checkMessageNotSent(tester);
743+
}, skip: true); // null topic names soon to be enabled
744+
720745
testWidgets('if topics are mandatory, reject (no topic)', (tester) async {
721746
await setupAndTapSend(tester,
722747
topicInputText: '(no topic)',
723748
mandatoryTopics: true);
724749
checkMessageNotSent(tester);
725750
});
751+
752+
testWidgets('legacy: if topics are mandatory, reject (no topic)', (tester) async {
753+
await setupAndTapSend(tester,
754+
topicInputText: '(no topic)',
755+
mandatoryTopics: true,
756+
zulipFeatureLevel: 333);
757+
checkMessageNotSent(tester);
758+
});
726759
});
727760

728761
group('uploads', () {

0 commit comments

Comments
 (0)