@@ -31,7 +31,8 @@ class AppBloc extends Bloc<AppEvent, AppState> {
31
31
) {
32
32
on < AppUserChanged > (_onAppUserChanged);
33
33
on < AppSettingsRefreshed > (_onAppSettingsRefreshed);
34
- on < _AppConfigFetchRequested > (_onAppConfigFetchRequested); // Added
34
+ on < _AppConfigFetchRequested > (_onAppConfigFetchRequested);
35
+ on < AppUserAccountActionShown > (_onAppUserAccountActionShown); // Added
35
36
on < AppLogoutRequested > (_onLogoutRequested);
36
37
on < AppThemeModeChanged > (_onThemeModeChanged);
37
38
on < AppFlexSchemeChanged > (_onFlexSchemeChanged);
@@ -324,4 +325,36 @@ class AppBloc extends Bloc<AppEvent, AppState> {
324
325
emit (state.copyWith (appConfig: null , clearAppConfig: true ));
325
326
}
326
327
}
328
+
329
+ Future <void > _onAppUserAccountActionShown (
330
+ AppUserAccountActionShown event,
331
+ Emitter <AppState > emit,
332
+ ) async {
333
+ if (state.user != null && state.user! .id == event.userId) {
334
+ final now = DateTime .now ();
335
+ // Optimistically update the local user state.
336
+ // Corrected parameter name for copyWith as per User model in models.txt
337
+ final updatedUser = state.user! .copyWith (lastEngagementShownAt: now);
338
+
339
+ // Emit the change so UI can react if needed, and other BLoCs get the update.
340
+ // This also ensures that FeedInjectorService will see the updated timestamp immediately.
341
+ emit (state.copyWith (user: updatedUser));
342
+
343
+ // TODO: Persist this change to the backend.
344
+ // This would typically involve calling a method on a repository, e.g.:
345
+ // try {
346
+ // await _authenticationRepository.updateUserLastActionTimestamp(event.userId, now);
347
+ // // If the repository's authStateChanges stream doesn't automatically emit
348
+ // // the updated user, you might need to re-fetch or handle it here.
349
+ // // For now, we've optimistically updated the local state.
350
+ // } catch (e) {
351
+ // // Handle error, potentially revert optimistic update or show an error.
352
+ // print('Failed to update lastAccountActionShownAt on backend: $e');
353
+ // // Optionally revert: emit(state.copyWith(user: state.user)); // Reverts to original
354
+ // }
355
+ print (
356
+ '[AppBloc] User ${event .userId } AccountAction shown. Last shown timestamp updated locally to $now . Backend update pending.' ,
357
+ );
358
+ }
359
+ }
327
360
}
0 commit comments