Skip to content

Commit 1ea0fcd

Browse files
committed
compose: Use alternative placeholder if topics are mandatory and missing
Previously, the placeholder reads "#channel name > (no topic)" even if topics are mandatory for the realm. Later, we will expand this logic for "general chat" so that the placeholder is chosen depending on whether topics are mandatory. Signed-off-by: Zixuan James Li <[email protected]>
1 parent 152812c commit 1ea0fcd

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

lib/widgets/compose_box.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,12 +588,21 @@ class _StreamContentInputState extends State<_StreamContentInput> {
588588
final streamName = store.streams[widget.narrow.streamId]?.name
589589
?? zulipLocalizations.unknownChannelName;
590590
final topic = TopicName(_topicTextNormalized);
591+
final String? topicDisplayName;
592+
if (store.realmMandatoryTopics && widget.controller.topic.isTopicVacuous) {
593+
topicDisplayName = null;
594+
} else {
595+
topicDisplayName = topic.displayName;
596+
}
597+
591598
return _ContentInput(
592599
narrow: widget.narrow,
593600
destination: TopicNarrow(widget.narrow.streamId, topic),
594601
controller: widget.controller,
595-
hintText: zulipLocalizations.composeBoxChannelContentHint(
596-
'#$streamName > ${topic.displayName}'));
602+
hintText: topicDisplayName == null
603+
? zulipLocalizations.composeBoxChannelContentHint('#$streamName')
604+
: zulipLocalizations.composeBoxChannelContentHint(
605+
'#$streamName > $topicDisplayName'));
597606
}
598607
}
599608

test/widgets/compose_box_test.dart

Lines changed: 29 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,17 +353,40 @@ void main() {
351353
.decoration.isNotNull().hintText.equals(contentHintText);
352354
}
353355

354-
group('to ChannelNarrow', () {
356+
group('to ChannelNarrow, topics not mandatory', () {
355357
testWidgets('with empty topic', (tester) async {
356-
await prepare(tester, narrow: ChannelNarrow(channel.streamId));
358+
await prepare(tester, narrow: ChannelNarrow(channel.streamId),
359+
mandatoryTopics: false);
357360
checkComposeBoxHintTexts(tester,
358361
topicHintText: 'Topic',
359362
contentHintText: 'Message #${channel.name} > (no topic)');
360363
});
361364

362365
testWidgets('with non-empty topic', (tester) async {
363366
final narrow = ChannelNarrow(channel.streamId);
364-
await prepare(tester, narrow: narrow);
367+
await prepare(tester, narrow: narrow,
368+
mandatoryTopics: false);
369+
await enterTopic(tester, narrow: narrow, topic: 'new topic');
370+
await tester.pump();
371+
checkComposeBoxHintTexts(tester,
372+
topicHintText: 'Topic',
373+
contentHintText: 'Message #${channel.name} > new topic');
374+
});
375+
});
376+
377+
group('to ChannelNarrow, mandatory topics', () {
378+
testWidgets('with empty topic', (tester) async {
379+
await prepare(tester, narrow: ChannelNarrow(channel.streamId),
380+
mandatoryTopics: true);
381+
checkComposeBoxHintTexts(tester,
382+
topicHintText: 'Topic',
383+
contentHintText: 'Message #${channel.name}');
384+
});
385+
386+
testWidgets('with non-empty topic', (tester) async {
387+
final narrow = ChannelNarrow(channel.streamId);
388+
await prepare(tester, narrow: narrow,
389+
mandatoryTopics: true);
365390
await enterTopic(tester, narrow: narrow, topic: 'new topic');
366391
await tester.pump();
367392
checkComposeBoxHintTexts(tester,

0 commit comments

Comments
 (0)