···
import 'package:flutter/foundation.dart';
import '../models/post.dart';
import '../services/coves_api_service.dart';
···
/// tokens before each authenticated request (critical for atProto OAuth
class FeedProvider with ChangeNotifier {
FeedProvider(this._authProvider, {CovesApiService? apiService}) {
// Use injected service (for testing) or create new one (for production)
// Pass token getter to API service for automatic fresh token retrieval
CovesApiService(tokenGetter: _authProvider.getAccessToken);
// [P0 FIX] Listen to auth state changes and clear feed on sign-out
···
if (!_authProvider.isAuthenticated && _posts.isNotEmpty) {
+
debugPrint('🔒 Auth state changed to unauthenticated - clearing feed');
// Automatically load the public discover feed
final AuthProvider _authProvider;
late final CovesApiService _apiService;
···
+
// Time update mechanism for periodic UI refreshes
+
Timer? _timeUpdateTimer;
+
DateTime? _currentTime;
List<FeedViewPost> get posts => _posts;
···
bool get hasMore => _hasMore;
String get sort => _sort;
String? get timeframe => _timeframe;
+
DateTime? get currentTime => _currentTime;
+
/// Start periodic time updates for "time ago" strings
+
/// Updates currentTime every minute to trigger UI rebuilds for
+
/// post timestamps. This ensures "5m ago" updates to "6m ago" without
+
/// requiring user interaction.
+
void startTimeUpdates() {
+
// Cancel existing timer if any
+
_timeUpdateTimer?.cancel();
+
// Update current time immediately
+
_currentTime = DateTime.now();
+
// Set up periodic updates (every minute)
+
_timeUpdateTimer = Timer.periodic(const Duration(minutes: 1), (_) {
+
_currentTime = DateTime.now();
+
debugPrint('⏰ Started periodic time updates for feed timestamps');
+
/// Stop periodic time updates
+
void stopTimeUpdates() {
+
_timeUpdateTimer?.cancel();
+
_timeUpdateTimer = null;
+
debugPrint('⏰ Stopped periodic time updates');
/// Load feed based on authentication state (business logic
···
await fetchTimeline(refresh: refresh);
await fetchDiscover(refresh: refresh);
+
// Start time updates when feed is loaded
+
if (_posts.isNotEmpty && _timeUpdateTimer == null) {
···
+
// Stop time updates and cancel timer
// Remove auth listener to prevent memory leaks
_authProvider.removeListener(_onAuthChanged);