Skip to content

Commit a938e0c

Browse files
committed
compose_box: Hide topic input on a general chat only channel
Related: #1604 Fixes: #1843
1 parent 3725eca commit a938e0c

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

lib/widgets/compose_box.dart

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,10 +1509,21 @@ class _StreamComposeBoxBody extends _ComposeBoxBody {
15091509
@override
15101510
final StreamComposeBoxController controller;
15111511

1512-
@override Widget? buildTopicInput(BuildContext context) => _TopicInput(
1513-
streamId: narrow.streamId,
1514-
controller: controller,
1515-
);
1512+
@override
1513+
Widget? buildTopicInput(BuildContext context) {
1514+
final store = PerAccountStoreWidget.of(context);
1515+
final stream = store.streams[narrow.streamId];
1516+
final topicsPolicy = stream?.topicsPolicy;
1517+
1518+
if (topicsPolicy == TopicsPolicy.emptyTopicOnly) {
1519+
return null;
1520+
}
1521+
1522+
return _TopicInput(
1523+
streamId: narrow.streamId,
1524+
controller: controller,
1525+
);
1526+
}
15161527

15171528
@override Widget buildContentInput() => _StreamContentInput(
15181529
narrow: narrow,

test/widgets/compose_box_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,6 +2360,30 @@ void main() {
23602360
// testCancel(narrow: topicNarrow, start: _EditInteractionStart.restoreFailedEdit);
23612361
// testCancel(narrow: dmNarrow, start: _EditInteractionStart.restoreFailedEdit);
23622362
});
2363+
2364+
group('compose box inputs visibility by topic policy', () {
2365+
void testComposeBoxWidgetVisibility({required TopicsPolicy topicsPolicy, required bool shouldShowTopicInput}) {
2366+
final description = shouldShowTopicInput ?
2367+
'show topic input when topic policy is $topicsPolicy':
2368+
'hide topic input when topic policy is $topicsPolicy';
2369+
2370+
testWidgets(description, (tester) async {
2371+
final channel = eg.stream(topicsPolicy: topicsPolicy);
2372+
2373+
await prepareComposeBox(tester, narrow: ChannelNarrow(channel.streamId), streams: [channel]);
2374+
2375+
check(contentInputFinder).findsOne();
2376+
shouldShowTopicInput ?
2377+
check(topicInputFinder).findsOne():
2378+
check(topicInputFinder).findsNothing();
2379+
});
2380+
}
2381+
2382+
testComposeBoxWidgetVisibility(topicsPolicy: TopicsPolicy.inherit, shouldShowTopicInput: true);
2383+
testComposeBoxWidgetVisibility(topicsPolicy: TopicsPolicy.allowEmptyTopic, shouldShowTopicInput: true);
2384+
testComposeBoxWidgetVisibility(topicsPolicy: TopicsPolicy.disableEmptyTopic, shouldShowTopicInput: true);
2385+
testComposeBoxWidgetVisibility(topicsPolicy: TopicsPolicy.emptyTopicOnly, shouldShowTopicInput: false);
2386+
});
23632387
}
23642388

23652389
/// How the edit interaction is started:

0 commit comments

Comments
 (0)