Skip to content

Commit ccf1058

Browse files
committed
compose: Change content input hint text if topic is vacuous and mandatory
Previously, "Message #stream > (no topic)" would appear as the hint text when the topic input is empty but mandatory. The control flow of `getDestinationString` can be simplified. However, it is structured this way to prepare for a later change to support showing "general chat" in the hint text, that adds some more advanced checks. Signed-off-by: Zixuan James Li <[email protected]>
1 parent de46396 commit ccf1058

File tree

2 files changed

+71
-11
lines changed

2 files changed

+71
-11
lines changed

lib/widgets/compose_box.dart

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,30 @@ class ComposeTopicController extends ComposeController<TopicValidationError> {
167167
/// that certain strings are not empty but also indicate the absence of a topic.
168168
bool get isTopicVacuous => textNormalized == kNoTopicTopic;
169169

170+
/// The send destination as a string.
171+
///
172+
/// This returns a string formatted like "#stream name" when topics are
173+
/// mandatory but [textNormalized] is vacuous (see [isTopicVacuous]).
174+
///
175+
/// Otherwise, returns a string formatted like "#stream name > topic name".
176+
// No i18n of the use of "#" and ">" strings; those are part of how
177+
// Zulip expresses channels and topics, not any normal English punctuation,
178+
// so don't make sense to translate. See:
179+
// https://github.com/zulip/zulip-flutter/pull/1148#discussion_r1941990585
180+
String getDestinationString({required String streamName}) {
181+
if (!isTopicVacuous) {
182+
return '#$streamName > $textNormalized';
183+
}
184+
185+
// Sending to a vacuous topic (see [isTopicVacuous]) is not possible if
186+
// topics are [mandatory].
187+
if (mandatory) {
188+
return '#$streamName';
189+
}
190+
191+
return '#$streamName > $kNoTopicTopic';
192+
}
193+
170194
@override
171195
List<TopicValidationError> _computeValidationErrors() {
172196
return [
@@ -585,17 +609,13 @@ class _StreamContentInputState extends State<_StreamContentInput> {
585609
final zulipLocalizations = ZulipLocalizations.of(context);
586610
final streamName = store.streams[widget.narrow.streamId]?.name
587611
?? zulipLocalizations.unknownChannelName;
588-
final topic = TopicName(widget.controller.topic.textNormalized);
589612
return _ContentInput(
590613
narrow: widget.narrow,
591-
destination: TopicNarrow(widget.narrow.streamId, topic),
614+
destination: TopicNarrow(widget.narrow.streamId,
615+
TopicName(widget.controller.topic.textNormalized)),
592616
controller: widget.controller,
593617
hintText: zulipLocalizations.composeBoxChannelContentHint(
594-
// No i18n of this use of "#" and ">" string; those are part of how
595-
// Zulip expresses channels and topics, not any normal English punctuation,
596-
// so don't make sense to translate. See:
597-
// https://github.com/zulip/zulip-flutter/pull/1148#discussion_r1941990585
598-
'#$streamName > ${topic.displayName}'));
618+
widget.controller.topic.getDestinationString(streamName: streamName)));
599619
}
600620
}
601621

test/widgets/compose_box_test.dart

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,13 @@ void main() {
326326

327327
Future<void> prepare(WidgetTester tester, {
328328
required Narrow narrow,
329+
bool? mandatoryTopics,
329330
}) async {
330331
await prepareComposeBox(tester,
331332
narrow: narrow,
332333
otherUsers: [eg.otherUser, eg.thirdUser],
333-
streams: [channel]);
334+
streams: [channel],
335+
mandatoryTopics: mandatoryTopics);
334336
}
335337

336338
/// This checks the input's configured hint text without regard to whether
@@ -351,18 +353,56 @@ void main() {
351353
.decoration.isNotNull().hintText.equals(contentHintText);
352354
}
353355

354-
group('to ChannelNarrow', () {
356+
group('to ChannelNarrow, topics not mandatory', () {
355357
final narrow = ChannelNarrow(channel.streamId);
356358

357359
testWidgets('with empty topic', (tester) async {
358-
await prepare(tester, narrow: narrow);
360+
await prepare(tester, narrow: narrow, mandatoryTopics: false);
361+
checkComposeBoxHintTexts(tester,
362+
topicHintText: 'Topic',
363+
contentHintText: 'Message #${channel.name} > (no topic)');
364+
});
365+
366+
testWidgets('with non-empty but vacuous topic', (tester) async {
367+
await prepare(tester, narrow: narrow, mandatoryTopics: false);
368+
await enterTopic(tester, narrow: narrow, topic: '(no topic)');
369+
await tester.pump();
359370
checkComposeBoxHintTexts(tester,
360371
topicHintText: 'Topic',
361372
contentHintText: 'Message #${channel.name} > (no topic)');
362373
});
363374

364375
testWidgets('with non-empty topic', (tester) async {
365-
await prepare(tester, narrow: narrow);
376+
await prepare(tester, narrow: narrow, mandatoryTopics: false);
377+
await enterTopic(tester, narrow: narrow, topic: 'new topic');
378+
await tester.pump();
379+
checkComposeBoxHintTexts(tester,
380+
topicHintText: 'Topic',
381+
contentHintText: 'Message #${channel.name} > new topic');
382+
});
383+
});
384+
385+
group('to ChannelNarrow, mandatory topics', () {
386+
final narrow = ChannelNarrow(channel.streamId);
387+
388+
testWidgets('with empty topic', (tester) async {
389+
await prepare(tester, narrow: narrow, mandatoryTopics: true);
390+
checkComposeBoxHintTexts(tester,
391+
topicHintText: 'Topic',
392+
contentHintText: 'Message #${channel.name}');
393+
});
394+
395+
testWidgets('with non-empty but vacuous topic', (tester) async {
396+
await prepare(tester, narrow: narrow, mandatoryTopics: true);
397+
await enterTopic(tester, narrow: narrow, topic: '(no topic)');
398+
await tester.pump();
399+
checkComposeBoxHintTexts(tester,
400+
topicHintText: 'Topic',
401+
contentHintText: 'Message #${channel.name}');
402+
});
403+
404+
testWidgets('with non-empty topic', (tester) async {
405+
await prepare(tester, narrow: narrow, mandatoryTopics: true);
366406
await enterTopic(tester, narrow: narrow, topic: 'new topic');
367407
await tester.pump();
368408
checkComposeBoxHintTexts(tester,

0 commit comments

Comments
 (0)