Skip to content

Commit 872e205

Browse files
committed
action_sheet: Add channel action sheet with mark as read option
Fixes: zulip#1226
1 parent 9e7a237 commit 872e205

14 files changed

+345
-27
lines changed

assets/l10n/app_en.arb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@
7676
"@permissionsDeniedReadExternalStorage": {
7777
"description": "Message for dialog asking the user to grant permissions for external storage read access."
7878
},
79+
"actionSheetOptionMarkChannelAsRead": "Mark channel as read",
80+
"@actionSheetOptionMarkChannelAsRead": {
81+
"description": "Label for marking a channel as read."
82+
},
7983
"actionSheetOptionMuteTopic": "Mute topic",
8084
"@actionSheetOptionMuteTopic": {
8185
"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
@@ -219,6 +219,12 @@ abstract class ZulipLocalizations {
219219
/// **'To upload files, please grant Zulip additional permissions in Settings.'**
220220
String get permissionsDeniedReadExternalStorage;
221221

222+
/// Label for marking a channel as read.
223+
///
224+
/// In en, this message translates to:
225+
/// **'Mark channel as read'**
226+
String get actionSheetOptionMarkChannelAsRead;
227+
222228
/// Label for muting a topic on action sheet.
223229
///
224230
/// 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
@@ -67,6 +67,9 @@ class ZulipLocalizationsAr extends ZulipLocalizations {
6767
@override
6868
String get permissionsDeniedReadExternalStorage => 'To upload files, please grant Zulip additional permissions in Settings.';
6969

70+
@override
71+
String get actionSheetOptionMarkChannelAsRead => 'Mark channel as read';
72+
7073
@override
7174
String get actionSheetOptionMuteTopic => 'Mute topic';
7275

lib/generated/l10n/zulip_localizations_en.dart

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

70+
@override
71+
String get actionSheetOptionMarkChannelAsRead => 'Mark channel as read';
72+
7073
@override
7174
String get actionSheetOptionMuteTopic => 'Mute topic';
7275

lib/generated/l10n/zulip_localizations_ja.dart

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

70+
@override
71+
String get actionSheetOptionMarkChannelAsRead => 'Mark channel as read';
72+
7073
@override
7174
String get actionSheetOptionMuteTopic => 'Mute topic';
7275

lib/generated/l10n/zulip_localizations_nb.dart

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

70+
@override
71+
String get actionSheetOptionMarkChannelAsRead => 'Mark channel as read';
72+
7073
@override
7174
String get actionSheetOptionMuteTopic => 'Mute topic';
7275

lib/generated/l10n/zulip_localizations_pl.dart

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

70+
@override
71+
String get actionSheetOptionMarkChannelAsRead => 'Mark channel as read';
72+
7073
@override
7174
String get actionSheetOptionMuteTopic => 'Wycisz wątek';
7275

lib/generated/l10n/zulip_localizations_ru.dart

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

70+
@override
71+
String get actionSheetOptionMarkChannelAsRead => 'Mark channel as read';
72+
7073
@override
7174
String get actionSheetOptionMuteTopic => 'Отключить тему';
7275

lib/generated/l10n/zulip_localizations_sk.dart

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

70+
@override
71+
String get actionSheetOptionMarkChannelAsRead => 'Mark channel as read';
72+
7073
@override
7174
String get actionSheetOptionMuteTopic => 'Stlmiť tému';
7275

lib/widgets/action_sheet.dart

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,57 @@ class ActionSheetCancelButton extends StatelessWidget {
163163
}
164164
}
165165

166+
/// Show a sheet of actions you can take on a channel.
167+
///
168+
/// Needs a [PageRoot] ancestor.
169+
void showChannelActionSheet(BuildContext context, {
170+
required int channelId,
171+
}) {
172+
final pageContext = PageRoot.contextOf(context);
173+
final store = PerAccountStoreWidget.of(pageContext);
174+
175+
final optionButtons = <ActionSheetMenuItemButton>[];
176+
final unreadCount = store.unreads.countInChannelNarrow(channelId);
177+
if (unreadCount > 0) {
178+
optionButtons.add(
179+
MarkChannelAsReadButton(pageContext: pageContext, channelId: channelId));
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(pageContext, optionButtons: optionButtons);
191+
}
192+
193+
class MarkChannelAsReadButton extends ActionSheetMenuItemButton {
194+
const MarkChannelAsReadButton({
195+
super.key,
196+
required this.channelId,
197+
required super.pageContext,
198+
});
199+
200+
final int channelId;
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+
final narrow = ChannelNarrow(channelId);
213+
await ZulipAction.markNarrowAsRead(pageContext, narrow);
214+
}
215+
}
216+
166217
/// Show a sheet of actions you can take on a topic.
167218
///
168219
/// Needs a [PageRoot] ancestor.

lib/widgets/inbox.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ abstract class _HeaderItem extends StatelessWidget {
272272
// But that's in tension with the Figma, which gives these header rows
273273
// 40px min height.
274274
onTap: onCollapseButtonTap,
275+
onLongPress: this is _LongPressable
276+
? (this as _LongPressable).onLongPress
277+
: null,
275278
child: Row(crossAxisAlignment: CrossAxisAlignment.center, children: [
276279
Padding(padding: const EdgeInsets.all(10),
277280
child: Icon(size: 20, color: designVariables.sectionCollapseIcon,
@@ -431,7 +434,13 @@ class _DmItem extends StatelessWidget {
431434
}
432435
}
433436

434-
class _StreamHeaderItem extends _HeaderItem {
437+
mixin _LongPressable on _HeaderItem {
438+
// TODO(#1272) move to _HeaderItem base class
439+
// when DM headers become long-pressable; remove mixin
440+
Future<void> onLongPress();
441+
}
442+
443+
class _StreamHeaderItem extends _HeaderItem with _LongPressable {
435444
final Subscription subscription;
436445

437446
const _StreamHeaderItem({
@@ -464,6 +473,11 @@ class _StreamHeaderItem extends _HeaderItem {
464473
}
465474
}
466475
@override Future<void> onRowTap() => onCollapseButtonTap(); // TODO open channel narrow
476+
477+
@override
478+
Future<void> onLongPress() async {
479+
showChannelActionSheet(sectionContext, channelId: subscription.streamId);
480+
}
467481
}
468482

469483
class _StreamSection extends StatelessWidget {

lib/widgets/message_list.dart

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -395,36 +395,56 @@ class MessageListAppBarTitle extends StatelessWidget {
395395
case ChannelNarrow(:var streamId):
396396
final store = PerAccountStoreWidget.of(context);
397397
final stream = store.streams[streamId];
398-
return _buildStreamRow(context, stream: stream);
398+
final alignment = willCenterTitle
399+
? Alignment.center
400+
: AlignmentDirectional.centerStart;
401+
return Column(
402+
crossAxisAlignment: CrossAxisAlignment.stretch,
403+
children: [
404+
GestureDetector(
405+
behavior: HitTestBehavior.translucent,
406+
onLongPress: () {
407+
showChannelActionSheet(context, channelId: streamId);
408+
},
409+
child: Align(alignment: alignment,
410+
child: _buildStreamRow(context, stream: stream))),
411+
]);
399412

400413
case TopicNarrow(:var streamId, :var topic):
401414
final store = PerAccountStoreWidget.of(context);
402415
final stream = store.streams[streamId];
403-
return SizedBox(
404-
width: double.infinity,
405-
child: GestureDetector(
406-
behavior: HitTestBehavior.translucent,
407-
onLongPress: () {
408-
final someMessage = MessageListPage.ancestorOf(context)
409-
.model?.messages.firstOrNull;
410-
// If someMessage is null, the topic action sheet won't have a
411-
// resolve/unresolve button. That seems OK; in that case we're
412-
// either still fetching messages (and the user can reopen the
413-
// sheet after that finishes) or there aren't any messages to
414-
// act on anyway.
415-
assert(someMessage == null || narrow.containsMessage(someMessage));
416-
showTopicActionSheet(context,
417-
channelId: streamId,
418-
topic: topic,
419-
someMessageIdInTopic: someMessage?.id);
420-
},
421-
child: Column(
422-
crossAxisAlignment: willCenterTitle ? CrossAxisAlignment.center
423-
: CrossAxisAlignment.start,
424-
children: [
425-
_buildStreamRow(context, stream: stream),
426-
_buildTopicRow(context, stream: stream, topic: topic),
427-
])));
416+
final alignment = willCenterTitle
417+
? Alignment.center
418+
: AlignmentDirectional.centerStart;
419+
return Column(
420+
crossAxisAlignment: CrossAxisAlignment.stretch,
421+
children: [
422+
GestureDetector(
423+
behavior: HitTestBehavior.translucent,
424+
onLongPress: () {
425+
showChannelActionSheet(context, channelId: streamId);
426+
},
427+
child: Align(alignment: alignment,
428+
child: _buildStreamRow(context, stream: stream))),
429+
GestureDetector(
430+
behavior: HitTestBehavior.translucent,
431+
onLongPress: () {
432+
final someMessage = MessageListPage.ancestorOf(context)
433+
.model?.messages.firstOrNull;
434+
// If someMessage is null, the topic action sheet won't have a
435+
// resolve/unresolve button. That seems OK; in that case we're
436+
// either still fetching messages (and the user can reopen the
437+
// sheet after that finishes) or there aren't any messages to
438+
// act on anyway.
439+
assert(someMessage == null || narrow.containsMessage(someMessage));
440+
showTopicActionSheet(context,
441+
channelId: streamId,
442+
topic: topic,
443+
someMessageIdInTopic: someMessage?.id);
444+
},
445+
child: Align(alignment: alignment,
446+
child: _buildTopicRow(context, stream: stream, topic: topic))),
447+
]);
428448

429449
case DmNarrow(:var otherRecipientIds):
430450
final store = PerAccountStoreWidget.of(context);
@@ -1083,6 +1103,7 @@ class StreamMessageRecipientHeader extends StatelessWidget {
10831103
onTap: () => Navigator.push(context,
10841104
MessageListPage.buildRoute(context: context,
10851105
narrow: ChannelNarrow(message.streamId))),
1106+
onLongPress: () => showChannelActionSheet(context, channelId: message.streamId),
10861107
child: Row(
10871108
crossAxisAlignment: CrossAxisAlignment.center,
10881109
children: [

lib/widgets/subscription_list.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import '../api/model/model.dart';
44
import '../generated/l10n/zulip_localizations.dart';
55
import '../model/narrow.dart';
66
import '../model/unreads.dart';
7+
import 'action_sheet.dart';
78
import 'icons.dart';
89
import 'message_list.dart';
910
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, channelId: subscription.streamId),
233235
child: Row(crossAxisAlignment: CrossAxisAlignment.center, children: [
234236
const SizedBox(width: 16),
235237
Padding(

0 commit comments

Comments
 (0)