Skip to content

Commit 8d23d3b

Browse files
author
chimnayajith
committed
action_sheet: Add channel action sheet with mark as read option
Fixes: #1226
1 parent 1bb22c4 commit 8d23d3b

13 files changed

+221
-0
lines changed

assets/l10n/app_en.arb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@
7272
"@permissionsDeniedReadExternalStorage": {
7373
"description": "Message for dialog asking the user to grant permissions for external storage read access."
7474
},
75+
"actionSheetOptionMarkChannelAsRead": "Mark channel as read",
76+
"@actionSheetOptionMarkChannelAsRead": {
77+
"description": "Label for marking a channel as read."
78+
},
7579
"actionSheetOptionMuteTopic": "Mute topic",
7680
"@actionSheetOptionMuteTopic": {
7781
"description": "Label for muting a topic on action sheet."

lib/generated/l10n/zulip_localizations.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ abstract class ZulipLocalizations {
213213
/// **'To upload files, please grant Zulip additional permissions in Settings.'**
214214
String get permissionsDeniedReadExternalStorage;
215215

216+
/// Label for marking a channel as read.
217+
///
218+
/// In en, this message translates to:
219+
/// **'Mark channel as read'**
220+
String get actionSheetOptionMarkChannelAsRead;
221+
216222
/// Label for muting a topic on action sheet.
217223
///
218224
/// In en, this message translates to:

lib/generated/l10n/zulip_localizations_ar.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class ZulipLocalizationsAr extends ZulipLocalizations {
6464
@override
6565
String get permissionsDeniedReadExternalStorage => 'To upload files, please grant Zulip additional permissions in Settings.';
6666

67+
@override
68+
String get actionSheetOptionMarkChannelAsRead => 'Mark channel as read';
69+
6770
@override
6871
String get actionSheetOptionMuteTopic => 'Mute topic';
6972

lib/generated/l10n/zulip_localizations_en.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class ZulipLocalizationsEn extends ZulipLocalizations {
6464
@override
6565
String get permissionsDeniedReadExternalStorage => 'To upload files, please grant Zulip additional permissions in Settings.';
6666

67+
@override
68+
String get actionSheetOptionMarkChannelAsRead => 'Mark channel as read';
69+
6770
@override
6871
String get actionSheetOptionMuteTopic => 'Mute topic';
6972

lib/generated/l10n/zulip_localizations_ja.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class ZulipLocalizationsJa extends ZulipLocalizations {
6464
@override
6565
String get permissionsDeniedReadExternalStorage => 'To upload files, please grant Zulip additional permissions in Settings.';
6666

67+
@override
68+
String get actionSheetOptionMarkChannelAsRead => 'Mark channel as read';
69+
6770
@override
6871
String get actionSheetOptionMuteTopic => 'Mute topic';
6972

lib/generated/l10n/zulip_localizations_nb.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class ZulipLocalizationsNb extends ZulipLocalizations {
6464
@override
6565
String get permissionsDeniedReadExternalStorage => 'To upload files, please grant Zulip additional permissions in Settings.';
6666

67+
@override
68+
String get actionSheetOptionMarkChannelAsRead => 'Mark channel as read';
69+
6770
@override
6871
String get actionSheetOptionMuteTopic => 'Mute topic';
6972

lib/generated/l10n/zulip_localizations_pl.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class ZulipLocalizationsPl extends ZulipLocalizations {
6464
@override
6565
String get permissionsDeniedReadExternalStorage => 'Aby odebrać pliki Zulip musi uzyskać dodatkowe uprawnienia w Ustawieniach.';
6666

67+
@override
68+
String get actionSheetOptionMarkChannelAsRead => 'Mark channel as read';
69+
6770
@override
6871
String get actionSheetOptionMuteTopic => 'Wycisz wątek';
6972

lib/generated/l10n/zulip_localizations_ru.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class ZulipLocalizationsRu extends ZulipLocalizations {
6464
@override
6565
String get permissionsDeniedReadExternalStorage => 'Для загрузки файлов, пожалуйста, предоставьте Zulip дополнительные разрешения в настройках.';
6666

67+
@override
68+
String get actionSheetOptionMarkChannelAsRead => 'Mark channel as read';
69+
6770
@override
6871
String get actionSheetOptionMuteTopic => 'Отключить тему';
6972

lib/generated/l10n/zulip_localizations_sk.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class ZulipLocalizationsSk extends ZulipLocalizations {
6464
@override
6565
String get permissionsDeniedReadExternalStorage => 'To upload files, please grant Zulip additional permissions in Settings.';
6666

67+
@override
68+
String get actionSheetOptionMarkChannelAsRead => 'Mark channel as read';
69+
6770
@override
6871
String get actionSheetOptionMuteTopic => 'Stlmiť tému';
6972

lib/widgets/action_sheet.dart

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,67 @@ class ActionSheetCancelButton extends StatelessWidget {
162162
}
163163
}
164164

165+
/// Show a sheet of actions you can take on a channel.
166+
void showChannelActionSheet(BuildContext context, {
167+
required int streamId,
168+
}) {
169+
final store = PerAccountStoreWidget.of(context);
170+
171+
final optionButtons = <ActionSheetMenuItemButton>[];
172+
final unreadCount = store.unreads.countInChannelNarrow(streamId);
173+
if(unreadCount > 0){
174+
optionButtons.add(
175+
MarkChannelAsReadButton(
176+
streamId: streamId,
177+
pageContext: context,
178+
)
179+
);
180+
}
181+
if (optionButtons.isEmpty) {
182+
// TODO(a11y): This case makes a no-op gesture handler; as a consequence,
183+
// we're presenting some UI (to people who use screen-reader software) as
184+
// though it offers a gesture interaction that it doesn't meaningfully
185+
// offer, which is confusing. The solution here is probably to remove this
186+
// is-empty case by having at least one button that's always present,
187+
// such as "copy link to topic".
188+
return;
189+
}
190+
_showActionSheet(context, optionButtons: optionButtons);
191+
}
192+
193+
class MarkChannelAsReadButton extends ActionSheetMenuItemButton {
194+
const MarkChannelAsReadButton({
195+
super.key,
196+
required this.streamId,
197+
required super.pageContext
198+
});
199+
final int streamId;
200+
201+
@override
202+
IconData get icon => ZulipIcons.message_checked;
203+
204+
@override
205+
String label(ZulipLocalizations zulipLocalizations) {
206+
return zulipLocalizations.actionSheetOptionMarkChannelAsRead;
207+
}
208+
209+
@override
210+
void onPressed() async {
211+
try {
212+
final narrow = ChannelNarrow(streamId);
213+
await markNarrowAsRead(pageContext, narrow);
214+
} catch (e) {
215+
if (!pageContext.mounted) return;
216+
217+
showErrorDialog(
218+
context: pageContext,
219+
title: "Failed to mark channel as read",
220+
message: e.toString(),
221+
);
222+
}
223+
}
224+
}
225+
165226
/// Show a sheet of actions you can take on a topic.
166227
void showTopicActionSheet(BuildContext context, {
167228
required int channelId,

0 commit comments

Comments
 (0)