@@ -438,30 +438,41 @@ class ScrollToBottomButton extends StatelessWidget {
438438 }
439439}
440440
441- class MarkAsReadWidget extends StatelessWidget {
441+ class MarkAsReadWidget extends StatefulWidget {
442442 const MarkAsReadWidget ({super .key, required this .narrow});
443443
444444 final Narrow narrow;
445445
446+ @override
447+ State <MarkAsReadWidget > createState () => MarkAsReadWidgetState ();
448+ }
449+
450+ class MarkAsReadWidgetState extends State <MarkAsReadWidget > {
451+ @visibleForTesting
452+ bool loading = false ;
453+
446454 void _handlePress (BuildContext context) async {
447455 if (! context.mounted) return ;
448456
449457 final store = PerAccountStoreWidget .of (context);
450458 final connection = store.connection;
451459 final useLegacy = connection.zulipFeatureLevel! < 155 ;
460+ setState (() => loading = true );
452461
453462 try {
454- await markNarrowAsRead (context, narrow, useLegacy);
463+ await markNarrowAsRead (context, widget. narrow, useLegacy);
455464 } catch (e) {
456465 if (! context.mounted) return ;
457466 final zulipLocalizations = ZulipLocalizations .of (context);
458- await showErrorDialog (context: context,
467+ showErrorDialog (context: context,
459468 title: zulipLocalizations.errorMarkAsReadFailedTitle,
460469 message: e.toString ()); // TODO(#741): extract user-facing message better
461470 return ;
471+ } finally {
472+ setState (() => loading = false );
462473 }
463474 if (! context.mounted) return ;
464- if (narrow is CombinedFeedNarrow && ! useLegacy) {
475+ if (widget. narrow is CombinedFeedNarrow && ! useLegacy) {
465476 PerAccountStoreWidget .of (context).unreads.handleAllMessagesReadSuccess ();
466477 }
467478 }
@@ -470,7 +481,7 @@ class MarkAsReadWidget extends StatelessWidget {
470481 Widget build (BuildContext context) {
471482 final zulipLocalizations = ZulipLocalizations .of (context);
472483 final store = PerAccountStoreWidget .of (context);
473- final unreadCount = store.unreads.countInNarrow (narrow);
484+ final unreadCount = store.unreads.countInNarrow (widget. narrow);
474485 final areMessagesRead = unreadCount == 0 ;
475486
476487 return IgnorePointer (
@@ -503,7 +514,7 @@ class MarkAsReadWidget extends StatelessWidget {
503514 .merge (weightVariableTextStyle (context, wght: 400 ))),
504515 shape: RoundedRectangleBorder (borderRadius: BorderRadius .circular (7 )),
505516 ),
506- onPressed: () => _handlePress (context),
517+ onPressed: () => loading ? null : _handlePress (context),
507518 icon: const Icon (Icons .playlist_add_check),
508519 label: Text (zulipLocalizations.markAllAsReadLabel))))));
509520 }
0 commit comments