Skip to content

action_sheet: Put mark-channel-as-read button at top of action sheet #1789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2025
Merged
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
35 changes: 18 additions & 17 deletions lib/widgets/action_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,24 +241,25 @@ void showChannelActionSheet(BuildContext context, {
final pageContext = PageRoot.contextOf(context);
final store = PerAccountStoreWidget.of(pageContext);

final optionButtons = <ActionSheetMenuItemButton>[
TopicListButton(pageContext: pageContext, channelId: channelId),
];
final optionButtons = <ActionSheetMenuItemButton>[];

final unreadCount = store.unreads.countInChannelNarrow(channelId);
if (unreadCount > 0) {
optionButtons.add(
MarkChannelAsReadButton(pageContext: pageContext, channelId: channelId));
}

optionButtons.add(
TopicListButton(pageContext: pageContext, channelId: channelId));

optionButtons.add(
CopyChannelLinkButton(channelId: channelId, pageContext: pageContext));

_showActionSheet(pageContext, optionButtons: optionButtons);
}

class TopicListButton extends ActionSheetMenuItemButton {
const TopicListButton({
class MarkChannelAsReadButton extends ActionSheetMenuItemButton {
const MarkChannelAsReadButton({
super.key,
required this.channelId,
required super.pageContext,
Expand All @@ -267,22 +268,22 @@ class TopicListButton extends ActionSheetMenuItemButton {
final int channelId;

@override
IconData get icon => ZulipIcons.topics;
IconData get icon => ZulipIcons.message_checked;

@override
String label(ZulipLocalizations zulipLocalizations) {
return zulipLocalizations.actionSheetOptionListOfTopics;
return zulipLocalizations.actionSheetOptionMarkChannelAsRead;
}

@override
void onPressed() {
Navigator.push(pageContext,
TopicListPage.buildRoute(context: pageContext, streamId: channelId));
void onPressed() async {
final narrow = ChannelNarrow(channelId);
await ZulipAction.markNarrowAsRead(pageContext, narrow);
}
}

class MarkChannelAsReadButton extends ActionSheetMenuItemButton {
const MarkChannelAsReadButton({
class TopicListButton extends ActionSheetMenuItemButton {
const TopicListButton({
super.key,
required this.channelId,
required super.pageContext,
Expand All @@ -291,17 +292,17 @@ class MarkChannelAsReadButton extends ActionSheetMenuItemButton {
final int channelId;

@override
IconData get icon => ZulipIcons.message_checked;
IconData get icon => ZulipIcons.topics;

@override
String label(ZulipLocalizations zulipLocalizations) {
return zulipLocalizations.actionSheetOptionMarkChannelAsRead;
return zulipLocalizations.actionSheetOptionListOfTopics;
}

@override
void onPressed() async {
final narrow = ChannelNarrow(channelId);
await ZulipAction.markNarrowAsRead(pageContext, narrow);
void onPressed() {
Navigator.push(pageContext,
TopicListPage.buildRoute(context: pageContext, streamId: channelId));
}
}

Expand Down
28 changes: 14 additions & 14 deletions test/widgets/action_sheet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ void main() {
group('showChannelActionSheet', () {
void checkButtons() {
check(actionSheetFinder).findsOne();
checkButton('List of topics');
checkButton('Mark channel as read');
checkButton('List of topics');
checkButton('Copy link to channel');
}

Expand Down Expand Up @@ -291,19 +291,6 @@ void main() {
});
});

testWidgets('TopicListButton', (tester) async {
await prepare();
await showFromAppBar(tester,
narrow: ChannelNarrow(someChannel.streamId));

connection.prepare(json: GetStreamTopicsResult(topics: [
eg.getStreamTopicsEntry(name: 'some topic foo'),
]).toJson());
await tester.tap(findButtonForLabel('List of topics'));
await tester.pumpAndSettle();
check(find.text('some topic foo')).findsOne();
});

group('MarkChannelAsReadButton', () {
void checkRequest(int channelId) {
check(connection.takeRequests()).single.isA<http.Request>()
Expand Down Expand Up @@ -350,6 +337,19 @@ void main() {
});
});

testWidgets('TopicListButton', (tester) async {
await prepare();
await showFromAppBar(tester,
narrow: ChannelNarrow(someChannel.streamId));

connection.prepare(json: GetStreamTopicsResult(topics: [
eg.getStreamTopicsEntry(name: 'some topic foo'),
]).toJson());
await tester.tap(findButtonForLabel('List of topics'));
await tester.pumpAndSettle();
check(find.text('some topic foo')).findsOne();
});

group('CopyChannelLinkButton', () {
setUp(() async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
Expand Down
Loading