Skip to content

Commit d087994

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

13 files changed

+233
-0
lines changed

assets/l10n/app_en.arb

Lines changed: 8 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."
@@ -230,6 +234,10 @@
230234
"event": {"type": "String", "example": "UpdateMessageEvent(id: 123, messageIds: [2345, 3456], newTopic: 'dinner')"}
231235
}
232236
},
237+
"errorMarkChannelAsReadFailed": "Failed to mark channel as read",
238+
"@errorMarkChannelAsReadFailed": {
239+
"description": "Error message when marking a channel as read."
240+
},
233241
"errorMuteTopicFailed": "Failed to mute topic",
234242
"@errorMuteTopicFailed": {
235243
"description": "Error message when muting a topic failed."

lib/generated/l10n/zulip_localizations.dart

Lines changed: 12 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:
@@ -405,6 +411,12 @@ abstract class ZulipLocalizations {
405411
/// **'Error handling a Zulip event from {serverUrl}; will retry.\n\nError: {error}\n\nEvent: {event}'**
406412
String errorHandlingEventDetails(String serverUrl, String error, String event);
407413

414+
/// Error message when marking a channel as read.
415+
///
416+
/// In en, this message translates to:
417+
/// **'Failed to mark channel as read'**
418+
String get errorMarkChannelAsReadFailed;
419+
408420
/// Error message when muting a topic failed.
409421
///
410422
/// In en, this message translates to:

lib/generated/l10n/zulip_localizations_ar.dart

Lines changed: 6 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

@@ -188,6 +191,9 @@ class ZulipLocalizationsAr extends ZulipLocalizations {
188191
return 'Error handling a Zulip event from $serverUrl; will retry.\n\nError: $error\n\nEvent: $event';
189192
}
190193

194+
@override
195+
String get errorMarkChannelAsReadFailed => 'Failed to mark channel as read';
196+
191197
@override
192198
String get errorMuteTopicFailed => 'Failed to mute topic';
193199

lib/generated/l10n/zulip_localizations_en.dart

Lines changed: 6 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

@@ -188,6 +191,9 @@ class ZulipLocalizationsEn extends ZulipLocalizations {
188191
return 'Error handling a Zulip event from $serverUrl; will retry.\n\nError: $error\n\nEvent: $event';
189192
}
190193

194+
@override
195+
String get errorMarkChannelAsReadFailed => 'Failed to mark channel as read';
196+
191197
@override
192198
String get errorMuteTopicFailed => 'Failed to mute topic';
193199

lib/generated/l10n/zulip_localizations_ja.dart

Lines changed: 6 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

@@ -188,6 +191,9 @@ class ZulipLocalizationsJa extends ZulipLocalizations {
188191
return 'Error handling a Zulip event from $serverUrl; will retry.\n\nError: $error\n\nEvent: $event';
189192
}
190193

194+
@override
195+
String get errorMarkChannelAsReadFailed => 'Failed to mark channel as read';
196+
191197
@override
192198
String get errorMuteTopicFailed => 'Failed to mute topic';
193199

lib/generated/l10n/zulip_localizations_nb.dart

Lines changed: 6 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

@@ -188,6 +191,9 @@ class ZulipLocalizationsNb extends ZulipLocalizations {
188191
return 'Error handling a Zulip event from $serverUrl; will retry.\n\nError: $error\n\nEvent: $event';
189192
}
190193

194+
@override
195+
String get errorMarkChannelAsReadFailed => 'Failed to mark channel as read';
196+
191197
@override
192198
String get errorMuteTopicFailed => 'Failed to mute topic';
193199

lib/generated/l10n/zulip_localizations_pl.dart

Lines changed: 6 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

@@ -188,6 +191,9 @@ class ZulipLocalizationsPl extends ZulipLocalizations {
188191
return 'Błąd zdarzenia Zulip z $serverUrl; ponawiam.\n\nBłąd: $error\n\nZdarzenie: $event';
189192
}
190193

194+
@override
195+
String get errorMarkChannelAsReadFailed => 'Failed to mark channel as read';
196+
191197
@override
192198
String get errorMuteTopicFailed => 'Wyciszenie bez powodzenia';
193199

lib/generated/l10n/zulip_localizations_ru.dart

Lines changed: 6 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

@@ -188,6 +191,9 @@ class ZulipLocalizationsRu extends ZulipLocalizations {
188191
return 'Ошибка обработки события Zulip от $serverUrl; повторим попытку.\n\nОшибка: $error\n\nСобытие: $event';
189192
}
190193

194+
@override
195+
String get errorMarkChannelAsReadFailed => 'Failed to mark channel as read';
196+
191197
@override
192198
String get errorMuteTopicFailed => 'Не удалось отключить тему';
193199

lib/generated/l10n/zulip_localizations_sk.dart

Lines changed: 6 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

@@ -188,6 +191,9 @@ class ZulipLocalizationsSk extends ZulipLocalizations {
188191
return 'Chyba obsluhy Zulip udalosti na serveri $serverUrl; skúsim znovu.\n\nChyba: $error\n\nUdalosť: $event';
189192
}
190193

194+
@override
195+
String get errorMarkChannelAsReadFailed => 'Failed to mark channel as read';
196+
191197
@override
192198
String get errorMuteTopicFailed => 'Nepodarilo sa ztíšiť tému';
193199

lib/widgets/action_sheet.dart

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,68 @@ 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 channel".
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+
200+
final int streamId;
201+
202+
@override
203+
IconData get icon => ZulipIcons.message_checked;
204+
205+
@override
206+
String label(ZulipLocalizations zulipLocalizations) {
207+
return zulipLocalizations.actionSheetOptionMarkChannelAsRead;
208+
}
209+
210+
@override
211+
void onPressed() async {
212+
try {
213+
final narrow = ChannelNarrow(streamId);
214+
await markNarrowAsRead(pageContext, narrow);
215+
} catch (e) {
216+
if (!pageContext.mounted) return;
217+
final zulipLocalizations = ZulipLocalizations.of(pageContext);
218+
219+
showErrorDialog(
220+
context: pageContext,
221+
title: zulipLocalizations.errorMarkChannelAsReadFailed
222+
);
223+
}
224+
}
225+
}
226+
165227
/// Show a sheet of actions you can take on a topic.
166228
void showTopicActionSheet(BuildContext context, {
167229
required int channelId,

lib/widgets/inbox.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ abstract class _HeaderItem extends StatelessWidget {
254254
}
255255

256256
Future<void> onRowTap();
257+
Future<void> onLongPress();
257258

258259
@override
259260
Widget build(BuildContext context) {
@@ -270,6 +271,7 @@ abstract class _HeaderItem extends StatelessWidget {
270271
// But that's in tension with the Figma, which gives these header rows
271272
// 40px min height.
272273
onTap: onCollapseButtonTap,
274+
onLongPress: onLongPress,
273275
child: Row(crossAxisAlignment: CrossAxisAlignment.center, children: [
274276
Padding(padding: const EdgeInsets.all(10),
275277
child: Icon(size: 20, color: designVariables.sectionCollapseIcon,
@@ -327,6 +329,12 @@ class _AllDmsHeaderItem extends _HeaderItem {
327329
pageState.allDmsCollapsed = !collapsed;
328330
}
329331
@override Future<void> onRowTap() => onCollapseButtonTap(); // TODO open all-DMs narrow?
332+
333+
@override
334+
Future<void> onLongPress() async {
335+
// TODO(#1272) action sheet for DM conversation
336+
return;
337+
}
330338
}
331339

332340
class _AllDmsSection extends StatelessWidget {
@@ -456,6 +464,11 @@ class _StreamHeaderItem extends _HeaderItem {
456464
}
457465
}
458466
@override Future<void> onRowTap() => onCollapseButtonTap(); // TODO open channel narrow
467+
468+
@override
469+
Future<void> onLongPress() async {
470+
showChannelActionSheet(sectionContext, streamId: subscription.streamId);
471+
}
459472
}
460473

461474
class _StreamSection extends StatelessWidget {

lib/widgets/subscription_list.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
33
import '../api/model/model.dart';
44
import '../model/narrow.dart';
55
import '../model/unreads.dart';
6+
import 'action_sheet.dart';
67
import 'icons.dart';
78
import 'message_list.dart';
89
import 'store.dart';
@@ -230,6 +231,7 @@ class SubscriptionItem extends StatelessWidget {
230231
MessageListPage.buildRoute(context: context,
231232
narrow: ChannelNarrow(subscription.streamId)));
232233
},
234+
onLongPress: () => showChannelActionSheet(context, streamId: subscription.streamId),
233235
child: Row(crossAxisAlignment: CrossAxisAlignment.center, children: [
234236
const SizedBox(width: 16),
235237
Padding(

0 commit comments

Comments
 (0)