Skip to content

Commit 2facd04

Browse files
committed
compose: Change content input hint text if topic is empty 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 e584b97 commit 2facd04

File tree

2 files changed

+70
-10
lines changed

2 files changed

+70
-10
lines changed

lib/widgets/compose_box.dart

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,32 @@ 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 the trimmed input is empty.
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+
final textTrimmed = text.trim();
182+
if (textTrimmed.isNotEmpty) {
183+
return '#$streamName > $textTrimmed';
184+
}
185+
186+
assert(isTopicVacuous);
187+
// Sending to a vacuous topic (see [isTopicVacuous]) is not possible if
188+
// topics are [mandatory].
189+
if (mandatory) {
190+
return '#$streamName';
191+
}
192+
193+
return '#$streamName > $kNoTopicTopic';
194+
}
195+
170196
@override
171197
List<TopicValidationError> _computeValidationErrors() {
172198
return [
@@ -585,17 +611,13 @@ class _StreamContentInputState extends State<_StreamContentInput> {
585611
final zulipLocalizations = ZulipLocalizations.of(context);
586612
final streamName = store.streams[widget.narrow.streamId]?.name
587613
?? zulipLocalizations.unknownChannelName;
588-
final topic = TopicName(widget.controller.topic.textNormalized);
589614
return _ContentInput(
590615
narrow: widget.narrow,
591-
destination: TopicNarrow(widget.narrow.streamId, topic),
616+
destination: TopicNarrow(widget.narrow.streamId,
617+
TopicName(widget.controller.topic.textNormalized)),
592618
controller: widget.controller,
593619
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}'));
620+
widget.controller.topic.getDestinationString(streamName: streamName)));
599621
}
600622
}
601623

test/widgets/compose_box_test.dart

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,18 +353,56 @@ void main() {
353353
.decoration.isNotNull().hintText.equals(contentHintText);
354354
}
355355

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

359359
testWidgets('with empty topic', (tester) async {
360-
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();
370+
checkComposeBoxHintTexts(tester,
371+
topicHintText: 'Topic',
372+
contentHintText: 'Message #${channel.name} > (no topic)');
373+
});
374+
375+
testWidgets('with non-empty topic', (tester) async {
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();
361399
checkComposeBoxHintTexts(tester,
362400
topicHintText: 'Topic',
363401
contentHintText: 'Message #${channel.name} > (no topic)');
364402
});
365403

366404
testWidgets('with non-empty topic', (tester) async {
367-
await prepare(tester, narrow: narrow);
405+
await prepare(tester, narrow: narrow, mandatoryTopics: true);
368406
await enterTopic(tester, narrow: narrow, topic: 'new topic');
369407
await tester.pump();
370408
checkComposeBoxHintTexts(tester,

0 commit comments

Comments
 (0)