Skip to content

Commit 59fb9c2

Browse files
committed
action_sheet: Add "Mark Topic As Read" button
Adds button to mark all messages in a topic as read. The button: - Appears only when the topic has unread messages - Uses mark_topic_as_read API for server feature level < 155 - Uses messages/flags/narrow API for server feature level >= 155 - Shows error dialog if the request fails fixes: #1225
1 parent 51d71a9 commit 59fb9c2

11 files changed

+171
-0
lines changed

assets/l10n/app_en.arb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,5 +716,13 @@
716716
"emojiPickerSearchEmoji": "Search emoji",
717717
"@emojiPickerSearchEmoji": {
718718
"description": "Hint text for the emoji picker search text field."
719+
},
720+
"actionSheetOptionMarkTopicAsRead": "Mark Topic As Read",
721+
"@actionSheetOptionMarkTopicAsRead": {
722+
"description": "Option to mark a specific topic as read in the action sheet."
723+
},
724+
"errorMarkTopicAsReadFailed": "Failed to mark the topic as read. Please try again.",
725+
"@errorMarkTopicAsReadFailed": {
726+
"description": "Error message displayed when marking a topic as read fails."
719727
}
720728
}

lib/generated/l10n/zulip_localizations.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,18 @@ abstract class ZulipLocalizations {
10701070
/// In en, this message translates to:
10711071
/// **'Search emoji'**
10721072
String get emojiPickerSearchEmoji;
1073+
1074+
/// Option to mark a specific topic as read in the action sheet.
1075+
///
1076+
/// In en, this message translates to:
1077+
/// **'Mark Topic As Read'**
1078+
String get actionSheetOptionMarkTopicAsRead;
1079+
1080+
/// Error message displayed when marking a topic as read fails.
1081+
///
1082+
/// In en, this message translates to:
1083+
/// **'Failed to mark the topic as read. Please try again.'**
1084+
String get errorMarkTopicAsReadFailed;
10731085
}
10741086

10751087
class _ZulipLocalizationsDelegate extends LocalizationsDelegate<ZulipLocalizations> {

lib/generated/l10n/zulip_localizations_ar.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,4 +564,10 @@ class ZulipLocalizationsAr extends ZulipLocalizations {
564564

565565
@override
566566
String get emojiPickerSearchEmoji => 'Search emoji';
567+
568+
@override
569+
String get actionSheetOptionMarkTopicAsRead => 'Mark Topic As Read';
570+
571+
@override
572+
String get errorMarkTopicAsReadFailed => 'Failed to mark the topic as read. Please try again.';
567573
}

lib/generated/l10n/zulip_localizations_en.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,4 +564,10 @@ class ZulipLocalizationsEn extends ZulipLocalizations {
564564

565565
@override
566566
String get emojiPickerSearchEmoji => 'Search emoji';
567+
568+
@override
569+
String get actionSheetOptionMarkTopicAsRead => 'Mark Topic As Read';
570+
571+
@override
572+
String get errorMarkTopicAsReadFailed => 'Failed to mark the topic as read. Please try again.';
567573
}

lib/generated/l10n/zulip_localizations_ja.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,4 +564,10 @@ class ZulipLocalizationsJa extends ZulipLocalizations {
564564

565565
@override
566566
String get emojiPickerSearchEmoji => 'Search emoji';
567+
568+
@override
569+
String get actionSheetOptionMarkTopicAsRead => 'Mark Topic As Read';
570+
571+
@override
572+
String get errorMarkTopicAsReadFailed => 'Failed to mark the topic as read. Please try again.';
567573
}

lib/generated/l10n/zulip_localizations_nb.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,4 +564,10 @@ class ZulipLocalizationsNb extends ZulipLocalizations {
564564

565565
@override
566566
String get emojiPickerSearchEmoji => 'Search emoji';
567+
568+
@override
569+
String get actionSheetOptionMarkTopicAsRead => 'Mark Topic As Read';
570+
571+
@override
572+
String get errorMarkTopicAsReadFailed => 'Failed to mark the topic as read. Please try again.';
567573
}

lib/generated/l10n/zulip_localizations_pl.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,4 +564,10 @@ class ZulipLocalizationsPl extends ZulipLocalizations {
564564

565565
@override
566566
String get emojiPickerSearchEmoji => 'Szukaj emoji';
567+
568+
@override
569+
String get actionSheetOptionMarkTopicAsRead => 'Mark Topic As Read';
570+
571+
@override
572+
String get errorMarkTopicAsReadFailed => 'Failed to mark the topic as read. Please try again.';
567573
}

lib/generated/l10n/zulip_localizations_ru.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,4 +564,10 @@ class ZulipLocalizationsRu extends ZulipLocalizations {
564564

565565
@override
566566
String get emojiPickerSearchEmoji => 'Поиск эмодзи';
567+
568+
@override
569+
String get actionSheetOptionMarkTopicAsRead => 'Mark Topic As Read';
570+
571+
@override
572+
String get errorMarkTopicAsReadFailed => 'Failed to mark the topic as read. Please try again.';
567573
}

lib/generated/l10n/zulip_localizations_sk.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,4 +564,10 @@ class ZulipLocalizationsSk extends ZulipLocalizations {
564564

565565
@override
566566
String get emojiPickerSearchEmoji => 'Hľadať emotikon';
567+
568+
@override
569+
String get actionSheetOptionMarkTopicAsRead => 'Mark Topic As Read';
570+
571+
@override
572+
String get errorMarkTopicAsReadFailed => 'Failed to mark the topic as read. Please try again.';
567573
}

lib/widgets/action_sheet.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,14 @@ void showTopicActionSheet(BuildContext context, {
240240
pageContext: context);
241241
}));
242242

243+
final unreadCount = store.unreads.countInTopicNarrow(channelId, topic);
244+
if (unreadCount > 0) {
245+
optionButtons.add(MarkTopicAsReadButton(
246+
channelId: channelId,
247+
topic: topic,
248+
pageContext: context));
249+
}
250+
243251
if (optionButtons.isEmpty) {
244252
// TODO(a11y): This case makes a no-op gesture handler; as a consequence,
245253
// we're presenting some UI (to people who use screen-reader software) as
@@ -372,6 +380,31 @@ class UserTopicUpdateButton extends ActionSheetMenuItemButton {
372380
}
373381
}
374382

383+
class MarkTopicAsReadButton extends ActionSheetMenuItemButton {
384+
const MarkTopicAsReadButton({
385+
super.key,
386+
required this.channelId,
387+
required this.topic,
388+
required super.pageContext,
389+
});
390+
391+
final int channelId;
392+
final TopicName topic;
393+
394+
@override IconData get icon => ZulipIcons.message_checked;
395+
396+
@override
397+
String label(ZulipLocalizations zulipLocalizations) {
398+
return zulipLocalizations.actionSheetOptionMarkTopicAsRead;
399+
}
400+
401+
@override void onPressed() async {
402+
if (!pageContext.mounted) return;
403+
final narrow = TopicNarrow(channelId, topic);
404+
await markNarrowAsRead(pageContext, narrow);
405+
}
406+
}
407+
375408
/// Show a sheet of actions you can take on a message in the message list.
376409
///
377410
/// Must have a [MessageListPage] ancestor.

0 commit comments

Comments
 (0)