Skip to content

Commit bc0fb29

Browse files
committed
feat: Track user account action shown
- Added event for user action - Updates user last shown timestamp - Backend update pending
1 parent 75fcf7a commit bc0fb29

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

lib/app/bloc/app_bloc.dart

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class AppBloc extends Bloc<AppEvent, AppState> {
3131
) {
3232
on<AppUserChanged>(_onAppUserChanged);
3333
on<AppSettingsRefreshed>(_onAppSettingsRefreshed);
34-
on<_AppConfigFetchRequested>(_onAppConfigFetchRequested); // Added
34+
on<_AppConfigFetchRequested>(_onAppConfigFetchRequested);
35+
on<AppUserAccountActionShown>(_onAppUserAccountActionShown); // Added
3536
on<AppLogoutRequested>(_onLogoutRequested);
3637
on<AppThemeModeChanged>(_onThemeModeChanged);
3738
on<AppFlexSchemeChanged>(_onFlexSchemeChanged);
@@ -324,4 +325,36 @@ class AppBloc extends Bloc<AppEvent, AppState> {
324325
emit(state.copyWith(appConfig: null, clearAppConfig: true));
325326
}
326327
}
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+
}
327360
}

0 commit comments

Comments
 (0)