Skip to content

Fix data sync for demo mode #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 25, 2025
Merged

Fix data sync for demo mode #55

merged 13 commits into from
Jun 25, 2025

Conversation

fulleni
Copy link
Member

@fulleni fulleni commented Jun 25, 2025

Description

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

fulleni added 13 commits June 24, 2025 18:15
- Migrates user data on demo login
- Handles UserAppSettings migration
- Handles UserContentPreferences migration
- Idempotent and resilient
- Instantiate only in demo env
- Pass to App widget
- Added migration service
- Injected into AppBloc
- Migrate data on auth change
- Handle guest to user transition
- Inject demo data migration service
- Try update, create, then update
- Handles concurrent creation
- Migrate data in demo mode
- Refresh settings after migration
- Pass environment to AccountBloc
- Add delay in demo mode
- Improved code readability
- Updated constructor formatting
- Adjusted conditional logic
…ous user authentication in demo mode has been resolved. The lib/account/bloc/account_bloc.dart file has been updated to ensure that UserContentPreferences are correctly loaded or created for the authenticated user, even after data migration.
@fulleni fulleni merged commit 1482e19 into main Jun 25, 2025
0 of 2 checks passed
@fulleni fulleni deleted the fix_data_sync_for_demo_mode branch June 25, 2025 06:56
@fulleni
Copy link
Member Author

fulleni commented Jul 4, 2025

/gemini summary

Copy link

Summary of Changes

This pull request primarily addresses a critical data synchronization bug in the application's demo mode. It introduces a dedicated client-side service to manage the migration of user settings and content preferences when an anonymous user transitions to an authenticated one. This ensures data persistence and a smoother user experience in the demo environment, while also improving the robustness of data handling with enhanced error management and general code cleanup.

Highlights

  • Core Bug Fix for Demo Mode Data Sync: Implemented a client-side data migration service (DemoDataMigrationService) to correctly transfer UserAppSettings and UserContentPreferences from anonymous (guestUser) to authenticated (standardUser) profiles specifically in the demo environment. This service is conditionally instantiated and integrated into the AppBloc lifecycle.
  • Race Condition Mitigation: Introduced a 1-second delay and retry mechanism in AccountBloc when UserContentPreferences are not found in demo mode. This helps mitigate race conditions during data migration, ensuring preferences are correctly loaded or created after an anonymous user authenticates. Additionally, ConflictException is now explicitly handled during preference creation, triggering a re-read to resolve concurrent writes.
  • Codebase Cleanup and Consistency: Performed extensive minor refactoring across numerous files, including removing redundant comments, simplifying variable usage, streamlining emit calls in BLoCs, and updating imports. This contributes to overall code hygiene and readability.
  • Linter Rule Adjustments: Added comment_references, deprecated_member_use, and prefer_asserts_with_message to the ignored rules in analysis_options.yaml to manage specific linter warnings.
Changelog
  • analysis_options.yaml
    • Added 'comment_references', 'deprecated_member_use', and 'prefer_asserts_with_message' to ignored linter rules.
  • lib/account/bloc/account_bloc.dart
    • Injected AppEnvironment into AccountBloc constructor.
    • Added demo-specific logic to _onAccountUserChanged to handle NotFoundException for UserContentPreferences, including a 1-second delay and re-attempt to read preferences.
    • Implemented ConflictException handling during UserContentPreferences creation to re-read existing preferences if a conflict occurs.
    • Removed redundant comments and simplified parameter passing for userId.
  • lib/account/bloc/available_sources_bloc.dart
    • Removed commented-out pagination hints.
  • lib/account/bloc/available_sources_state.dart
    • Removed commented-out pagination hints.
  • lib/account/view/account_page.dart
    • Minor code cleanup: removed redundant comments and simplified variable usage for theme and text styles.
  • lib/account/view/manage_followed_items/categories/add_category_to_follow_page.dart
    • Minor code cleanup: removed redundant comments and simplified variable usage for theme and text styles.
  • lib/account/view/manage_followed_items/categories/followed_categories_list_page.dart
    • Minor code cleanup: removed redundant comments and simplified placeholder text.
  • lib/account/view/manage_followed_items/manage_followed_items_page.dart
    • Minor code cleanup: removed redundant comments and simplified variable usage for theme and text styles.
  • lib/account/view/manage_followed_items/sources/followed_sources_list_page.dart
    • Minor code cleanup: removed redundant comments and simplified placeholder text.
  • lib/account/view/saved_headlines_page.dart
    • Minor code cleanup: removed redundant comments and simplified placeholder text.
  • lib/app/bloc/app_bloc.dart
    • Injected DemoDataMigrationService and AppEnvironment into AppBloc constructor.
    • Implemented anonymous to authenticated user data migration logic in _onAppUserChanged for the demo environment, utilizing DemoDataMigrationService.
    • Simplified copyWith calls and removed redundant comments related to AppConfig and UserAppSettings fetching.
  • lib/app/bloc/app_event.dart
    • Removed redundant comments regarding nullable objects in props and User nullability.
  • lib/app/bloc/app_state.dart
    • Removed redundant comments regarding settings and locale properties.
  • lib/app/config/app_config.dart
    • Updated a TODO comment in AppConfig.production.
  • lib/app/view/app.dart
    • Injected DemoDataMigrationService into the App widget and passed it to the AppBloc.
    • Removed redundant comments from imports and constructor parameters.
  • lib/authentication/bloc/authentication_bloc.dart
    • Simplified emit calls by removing redundant parentheses for loading states.
  • lib/authentication/view/authentication_page.dart
    • Minor code cleanup: removed redundant comments and simplified variable usage for UI elements.
  • lib/authentication/view/email_code_verification_page.dart
    • Minor code cleanup: removed redundant comments and simplified variable usage for UI elements.
  • lib/authentication/view/request_code_page.dart
    • Minor code cleanup: removed redundant comments and simplified variable usage for UI elements.
  • lib/bootstrap.dart
    • Conditionally instantiated DemoDataMigrationService based on AppEnvironment and passed it to the App widget.
    • Renamed currentEnvironment to appEnvironment for consistency.
  • lib/entity_details/bloc/entity_details_bloc.dart
    • Added avoid_dynamic_calls ignore.
    • Removed redundant comments and simplified parameter passing.
  • lib/entity_details/bloc/entity_details_event.dart
    • Removed redundant comments for entity type.
  • lib/entity_details/bloc/entity_details_state.dart
    • Removed redundant comments for feedItems and headlines.
  • lib/entity_details/view/entity_details_page.dart
    • Minor code cleanup: removed redundant comments and simplified variable usage for UI elements.
  • lib/headline-details/view/headline_details_page.dart
    • Minor code cleanup: removed redundant comments and simplified variable usage for UI elements.
  • lib/headlines-feed/bloc/categories_filter_bloc.dart
    • Removed redundant comments and simplified emit calls.
  • lib/headlines-feed/bloc/categories_filter_state.dart
    • Removed redundant comments for clearError and clearCursor.
  • lib/headlines-feed/bloc/countries_filter_bloc.dart
    • Removed redundant comments and simplified emit calls.
  • lib/headlines-feed/bloc/countries_filter_state.dart
    • Removed redundant comments for clearError and clearCursor.
  • lib/headlines-feed/bloc/headlines_feed_bloc.dart
    • Removed redundant comments and simplified emit calls.
  • lib/headlines-feed/bloc/headlines_feed_state.dart
    • Removed redundant comments for feedItems and headlines.
  • lib/headlines-feed/bloc/sources_filter_bloc.dart
    • Removed redundant comments and simplified logic for displayableSources.
  • lib/headlines-feed/bloc/sources_filter_state.dart
    • Removed redundant comments for allAvailableSources.
  • lib/headlines-feed/models/headline_filter.dart
    • Removed redundant comments for isFromFollowedItems.
  • lib/headlines-feed/view/category_filter_page.dart
    • Minor code cleanup: removed redundant comments and simplified variable usage for UI elements.
  • lib/headlines-feed/view/country_filter_page.dart
    • Minor code cleanup: removed redundant comments and simplified variable usage for UI elements.
  • lib/headlines-feed/view/headlines_feed_page.dart
    • Minor code cleanup: removed redundant comments and simplified variable usage for UI elements.
  • lib/headlines-feed/view/headlines_filter_page.dart
    • Minor code cleanup: removed redundant comments and simplified variable usage for UI elements.
  • lib/headlines-feed/view/source_filter_page.dart
    • Minor code cleanup: removed redundant comments and simplified variable usage for UI elements.
  • lib/headlines-search/bloc/headlines_search_bloc.dart
    • Removed redundant comments and simplified emit calls.
  • lib/headlines-search/bloc/headlines_search_state.dart
    • Removed redundant comments for items and results.
  • lib/headlines-search/models/search_model_type.dart
    • Updated TODO comment from 'Cline' to 'fulleni'.
    • Removed commented-out 'country' related code.
  • lib/headlines-search/view/headlines_search_page.dart
    • Minor code cleanup: removed redundant comments and simplified variable usage for UI elements.
  • lib/headlines-search/widgets/category_item_widget.dart
    • Removed redundant comments.
  • lib/headlines-search/widgets/source_item_widget.dart
    • Removed redundant comments.
  • lib/main.dart
    • Renamed currentEnvironment to appEnvironment for consistency.
  • lib/router/router.dart
    • Injected AppEnvironment into AccountBloc constructor.
    • Removed redundant comments and simplified route definitions.
  • lib/router/routes.dart
    • Removed redundant comments and simplified route path definitions.
  • lib/settings/bloc/settings_bloc.dart
    • Removed redundant comments.
  • lib/settings/bloc/settings_event.dart
    • Removed redundant comments for enum types.
    • Updated TODO comment from 'cline' to 'fulleni'.
  • lib/settings/bloc/settings_state.dart
    • Removed redundant comments for userAppSettings and clear flags.
  • lib/settings/view/appearance_settings_page.dart
    • Minor code cleanup: removed redundant comments and simplified variable usage for UI elements.
  • lib/settings/view/feed_settings_page.dart
    • Minor code cleanup: removed redundant comments and simplified variable usage for UI elements.
  • lib/settings/view/font_settings_page.dart
    • Minor code cleanup: removed redundant comments and simplified variable usage for UI elements.
  • lib/settings/view/language_settings_page.dart
    • Minor code cleanup: removed redundant comments and simplified variable usage for UI elements.
  • lib/settings/view/notification_settings_page.dart
    • Minor code cleanup: removed redundant comments and updated TODO comment from 'cline' to 'fulleni'.
  • lib/settings/view/settings_page.dart
    • Minor code cleanup: removed redundant comments and simplified variable usage for UI elements.
  • lib/settings/view/theme_settings_page.dart
    • Minor code cleanup: removed redundant comments and simplified variable usage for UI elements.
  • lib/shared/localization/ar_timeago_messages.dart
    • Removed redundant comments for prefix/suffix and 'aDay' translation.
  • lib/shared/localization/en_timeago_messages.dart
    • Removed redundant comments for prefix/suffix.
  • lib/shared/services/demo_data_migration_service.dart
    • New file: Implements DemoDataMigrationService to handle client-side migration of UserAppSettings and UserContentPreferences between anonymous and authenticated user IDs in demo mode, including robust error handling for NotFoundException and ConflictException.
  • lib/shared/services/feed_injector_service.dart
    • Added no_default_cases ignore for switch statement.
    • Removed redundant comments and simplified variable assignments.
  • lib/shared/shared.dart
    • Removed redundant comments for exports.
  • lib/shared/theme/app_theme.dart
    • Removed redundant comments and simplified parameter names.
  • lib/shared/theme/theme.dart
    • Removed redundant comments for exports.
  • lib/shared/widgets/failure_state_widget.dart
    • Removed redundant comments for retryButtonText.
  • lib/shared/widgets/headline_tile_image_start.dart
    • Removed redundant comments and simplified variable usage.
  • lib/shared/widgets/headline_tile_image_top.dart
    • Removed redundant comments and simplified variable usage.
  • lib/shared/widgets/headline_tile_text_only.dart
    • Removed redundant comments and simplified variable usage.
  • web/index.html
    • Removed redundant comments for loading indicator removal.
Activity
  • The pull request author, fulleni, requested a summary of the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant