Skip to content

Commit 83c9a5a

Browse files
committed
fix(notification): update last fetch time globally
The updat of last fetch time shall be globally, not only in the notification page.
1 parent 300547f commit 83c9a5a

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

lib/features/notification/view/notification_page.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ class _NotificationPageState extends State<NotificationPage> with SingleTickerPr
8181
Widget build(BuildContext context) {
8282
final tr = context.t.noticePage;
8383
return BlocListener<NotificationBloc, NotificationState>(
84-
listenWhen: (prev, curr) => prev.status != curr.status,
8584
listener: (context, state) {
8685
if (state.status == NotificationStatus.failure) {
8786
showFailedToLoadSnackBar(context);
@@ -94,11 +93,6 @@ class _NotificationPageState extends State<NotificationPage> with SingleTickerPr
9493
personalMessageCount: pm,
9594
broadcastMessageCount: bm,
9695
);
97-
98-
// Update last fetch notification time.
99-
if (state.latestTime != null) {
100-
context.read<NotificationBloc>().add(NotificationRecordFetchTimeRequested(state.latestTime!));
101-
}
10296
}
10397
},
10498
child: BlocBuilder<NotificationBloc, NotificationState>(

lib/features/root/view/root_page.dart

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,20 @@ class _RootPageState extends State<RootPage> with LoggerMixin {
7171
},
7272
),
7373
BlocListener<NotificationBloc, NotificationState>(
74-
listenWhen: (_, curr) => curr.status == NotificationStatus.loading,
75-
listener: (context, _) {
76-
final autoSyncState = context.read<AutoNotificationCubit>();
77-
if (autoSyncState.state is AutoNoticeStateTicking) {
78-
// Restart the auto notification sync process.
79-
context.read<AutoNotificationCubit>().restart();
74+
listener: (context, state) {
75+
if (state.status == NotificationStatus.loading) {
76+
final autoSyncState = context.read<AutoNotificationCubit>();
77+
if (autoSyncState.state is AutoNoticeStateTicking) {
78+
// Restart the auto notification sync process.
79+
context.read<AutoNotificationCubit>().restart();
80+
}
81+
} else if (state.status == NotificationStatus.success) {
82+
// Update last fetch notification time.
83+
// We do it here because it's a global action lives in the entire lifetime of the app, not only when
84+
// the notification page is live. This fixes the critical issue where time not updated.
85+
if (state.latestTime != null) {
86+
context.read<NotificationBloc>().add(NotificationRecordFetchTimeRequested(state.latestTime!));
87+
}
8088
}
8189
},
8290
),

0 commit comments

Comments
 (0)