Skip to content

Commit 7392ccb

Browse files
Khader-1gnprice
authored andcommitted
msglist: Ensure markNarrowAsRead passes before acting on it
1 parent 8767297 commit 7392ccb

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

lib/widgets/actions.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ import '../model/narrow.dart';
1616
import 'dialog.dart';
1717
import 'store.dart';
1818

19-
Future<void> markNarrowAsRead(
19+
/// Returns true if mark as read process is completed successfully.
20+
Future<bool> markNarrowAsRead(
2021
BuildContext context,
2122
Narrow narrow,
2223
bool useLegacy, // TODO(server-6)
2324
) async {
2425
final store = PerAccountStoreWidget.of(context);
2526
final connection = store.connection;
2627
if (useLegacy) {
27-
return await _legacyMarkNarrowAsRead(context, narrow);
28+
await _legacyMarkNarrowAsRead(context, narrow);
29+
return true;
2830
}
2931

3032
// Compare web's `mark_all_as_read` in web/src/unread_ops.js
@@ -66,7 +68,7 @@ Future<void> markNarrowAsRead(
6668
flag: MessageFlag.read);
6769
if (!context.mounted) {
6870
scaffoldMessenger.clearSnackBars();
69-
return;
71+
return false;
7072
}
7173
responseCount++;
7274
updatedCount += result.updatedCount;
@@ -81,7 +83,7 @@ Future<void> markNarrowAsRead(
8183
..showSnackBar(SnackBar(behavior: SnackBarBehavior.floating,
8284
content: Text(zulipLocalizations.markAsReadComplete(updatedCount))));
8385
}
84-
return;
86+
return true;
8587
}
8688

8789
if (result.lastProcessedId == null) {
@@ -91,7 +93,7 @@ Future<void> markNarrowAsRead(
9193
await showErrorDialog(context: context,
9294
title: zulipLocalizations.errorMarkAsReadFailedTitle,
9395
message: zulipLocalizations.errorInvalidResponse);
94-
return;
96+
return false;
9597
}
9698
anchor = NumericAnchor(result.lastProcessedId!);
9799

lib/widgets/message_list.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,9 @@ class _MarkAsReadWidgetState extends State<MarkAsReadWidget> {
714714
final connection = store.connection;
715715
final useLegacy = connection.zulipFeatureLevel! < 155;
716716
setState(() => _loading = true);
717-
717+
bool didPass = false;
718718
try {
719-
await markNarrowAsRead(context, widget.narrow, useLegacy);
719+
didPass = await markNarrowAsRead(context, widget.narrow, useLegacy);
720720
} catch (e) {
721721
if (!context.mounted) return;
722722
final zulipLocalizations = ZulipLocalizations.of(context);
@@ -727,6 +727,7 @@ class _MarkAsReadWidgetState extends State<MarkAsReadWidget> {
727727
} finally {
728728
setState(() => _loading = false);
729729
}
730+
if (!didPass) return;
730731
if (!context.mounted) return;
731732
if (widget.narrow is CombinedFeedNarrow && !useLegacy) {
732733
PerAccountStoreWidget.of(context).unreads.handleAllMessagesReadSuccess();

0 commit comments

Comments
 (0)