Skip to content

Commit e5af07a

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

14 files changed

+269
-26
lines changed

Diff for: assets/l10n/app_en.arb

+4
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."

Diff for: lib/generated/l10n/zulip_localizations.dart

+6
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:

Diff for: lib/generated/l10n/zulip_localizations_ar.dart

+3
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

Diff for: lib/generated/l10n/zulip_localizations_en.dart

+3
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

Diff for: lib/generated/l10n/zulip_localizations_ja.dart

+3
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

Diff for: lib/generated/l10n/zulip_localizations_nb.dart

+3
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

Diff for: lib/generated/l10n/zulip_localizations_pl.dart

+3
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

Diff for: lib/generated/l10n/zulip_localizations_ru.dart

+3
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

Diff for: lib/generated/l10n/zulip_localizations_sk.dart

+3
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

Diff for: lib/widgets/action_sheet.dart

+53
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,59 @@ class ActionSheetCancelButton extends StatelessWidget {
163163
}
164164
}
165165

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

Diff for: lib/widgets/inbox.dart

+15-1
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 {

Diff for: lib/widgets/message_list.dart

+36-25
Original file line numberDiff line numberDiff line change
@@ -395,36 +395,46 @@ 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);
399-
398+
return GestureDetector(
399+
behavior: HitTestBehavior.translucent,
400+
onLongPress: () {
401+
showChannelActionSheet(context, channelId: streamId);
402+
},
403+
child: _buildStreamRow(context, stream: stream),
404+
);
400405
case TopicNarrow(:var streamId, :var topic):
401406
final store = PerAccountStoreWidget.of(context);
402407
final stream = store.streams[streamId];
403408
return SizedBox(
404409
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-
])));
410+
child: Column(
411+
crossAxisAlignment: willCenterTitle ? CrossAxisAlignment.center
412+
: CrossAxisAlignment.start,
413+
children: [
414+
GestureDetector(
415+
behavior: HitTestBehavior.translucent,
416+
onLongPress: () {
417+
showChannelActionSheet(context, channelId: streamId);
418+
},
419+
child: _buildStreamRow(context, stream: stream),
420+
),
421+
GestureDetector(
422+
behavior: HitTestBehavior.translucent,
423+
onLongPress: () {
424+
final someMessage = MessageListPage.ancestorOf(context)
425+
.model?.messages.firstOrNull;
426+
// If someMessage is null, the topic action sheet won't have a
427+
// resolve/unresolve button. That seems OK; in that case we're
428+
// either still fetching messages (and the user can reopen the
429+
// sheet after that finishes) or there aren't any messages to
430+
// act on anyway.
431+
assert(someMessage == null || narrow.containsMessage(someMessage));
432+
showTopicActionSheet(context,
433+
channelId: streamId,
434+
topic: topic,
435+
someMessageIdInTopic: someMessage?.id);
436+
},
437+
child: _buildTopicRow(context, stream: stream, topic: topic))]));
428438

429439
case DmNarrow(:var otherRecipientIds):
430440
final store = PerAccountStoreWidget.of(context);
@@ -1083,6 +1093,7 @@ class StreamMessageRecipientHeader extends StatelessWidget {
10831093
onTap: () => Navigator.push(context,
10841094
MessageListPage.buildRoute(context: context,
10851095
narrow: ChannelNarrow(message.streamId))),
1096+
onLongPress: () => showChannelActionSheet(context, channelId: message.streamId),
10861097
child: Row(
10871098
crossAxisAlignment: CrossAxisAlignment.center,
10881099
children: [

Diff for: lib/widgets/subscription_list.dart

+2
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)