Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions lib/widgets/compose_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ abstract class _ComposeBoxBody extends StatelessWidget {

ComposeBoxController get controller;

Widget? buildTopicInput();
Widget? buildTopicInput(BuildContext context);
Widget buildContentInput();
bool getComposeButtonsEnabled(BuildContext context);
Widget? buildSendButton();
Expand Down Expand Up @@ -1471,7 +1471,7 @@ abstract class _ComposeBoxBody extends StatelessWidget {
_AttachFromCameraButton(controller: controller, enabled: composeButtonsEnabled),
];

final topicInput = buildTopicInput();
final topicInput = buildTopicInput(context);
final sendButton = buildSendButton();
return Column(children: [
Padding(
Expand Down Expand Up @@ -1509,10 +1509,21 @@ class _StreamComposeBoxBody extends _ComposeBoxBody {
@override
final StreamComposeBoxController controller;

@override Widget buildTopicInput() => _TopicInput(
streamId: narrow.streamId,
controller: controller,
);
@override
Widget? buildTopicInput(BuildContext context) {
final store = PerAccountStoreWidget.of(context);
final stream = store.streams[narrow.streamId];
final topicsPolicy = stream?.topicsPolicy;

if (topicsPolicy == TopicsPolicy.emptyTopicOnly) {
return null;
}

return _TopicInput(
streamId: narrow.streamId,
controller: controller,
);
}

@override Widget buildContentInput() => _StreamContentInput(
narrow: narrow,
Expand All @@ -1537,7 +1548,7 @@ class _FixedDestinationComposeBoxBody extends _ComposeBoxBody {
@override
final FixedDestinationComposeBoxController controller;

@override Widget? buildTopicInput() => null;
@override Widget? buildTopicInput(BuildContext context) => null;

@override Widget buildContentInput() => _FixedDestinationContentInput(
narrow: narrow,
Expand All @@ -1562,7 +1573,7 @@ class _EditMessageComposeBoxBody extends _ComposeBoxBody {
@override
final EditMessageComposeBoxController controller;

@override Widget? buildTopicInput() => null;
@override Widget? buildTopicInput(BuildContext context) => null;

@override Widget buildContentInput() => _EditMessageContentInput(
narrow: narrow,
Expand Down
24 changes: 24 additions & 0 deletions test/widgets/compose_box_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2360,6 +2360,30 @@ void main() {
// testCancel(narrow: topicNarrow, start: _EditInteractionStart.restoreFailedEdit);
// testCancel(narrow: dmNarrow, start: _EditInteractionStart.restoreFailedEdit);
});

group('compose box inputs visibility by topic policy', () {
void testComposeBoxWidgetVisibility({required TopicsPolicy topicsPolicy, required bool shouldShowTopicInput}) {
final description = shouldShowTopicInput ?
'show topic input when topic policy is $topicsPolicy':
'hide topic input when topic policy is $topicsPolicy';

testWidgets(description, (tester) async {
final channel = eg.stream(topicsPolicy: topicsPolicy);

await prepareComposeBox(tester, narrow: ChannelNarrow(channel.streamId), streams: [channel]);

check(contentInputFinder).findsOne();
shouldShowTopicInput ?
check(topicInputFinder).findsOne():
check(topicInputFinder).findsNothing();
});
}

testComposeBoxWidgetVisibility(topicsPolicy: TopicsPolicy.inherit, shouldShowTopicInput: true);
testComposeBoxWidgetVisibility(topicsPolicy: TopicsPolicy.allowEmptyTopic, shouldShowTopicInput: true);
testComposeBoxWidgetVisibility(topicsPolicy: TopicsPolicy.disableEmptyTopic, shouldShowTopicInput: true);
testComposeBoxWidgetVisibility(topicsPolicy: TopicsPolicy.emptyTopicOnly, shouldShowTopicInput: false);
});
}

/// How the edit interaction is started:
Expand Down
Loading