- Upgrade Fastify 4→5 with all plugins (@fastify/websocket 11, cors 11, sensible 6) - Migrate all SSE endpoints to WebSocket + FCM push (mitra chat requests, customer pairing status) - Add flutter_local_notifications for foreground push notifications with sound - Add splash screen to both apps (hide auth loading flash) - Introduce constants/enums across entire codebase (no raw string literals) - Move price tiers from hardcoded array to app_config DB (data-driven, includes 1-min test tier) - Add session ownership validation on all shared chat routes - Add ownership checks on endSession, respondToExtension, requestExtension - Fix session timer: auto-complete expired/stale sessions on server restart - Add 5-min grace period for abandoned closing sessions - Fix extension flow: proper session_resumed handling, clearExtensionRequest, closure grace timer cleanup - Fix chat screens: ConnectChat in initState, session status check on connect - Fix customer expired view: 5-min countdown, closure state priority over expired state - Fix mitra extension UI: loading spinner, disable buttons, handle EXTENSION_RESOLVED error - Fix GoRouter navigation consistency (no more Navigator.pushNamed) - Fix goodbye view keyboard overflow (SingleChildScrollView) - Add active session card on customer home screen with refresh on navigate back - Fix PricingBottomSheet extension mode (RequestExtension instead of new pairing) - Send session_resumed to both parties on extension accept Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
68 lines
2.5 KiB
Dart
68 lines
2.5 KiB
Dart
import 'dart:async';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'core/auth/auth_bloc.dart';
|
|
import 'features/splash/splash_screen.dart';
|
|
import 'features/auth/screens/login_screen.dart';
|
|
import 'features/auth/screens/otp_screen.dart';
|
|
import 'features/home/home_screen.dart';
|
|
import 'features/chat/screens/active_sessions_screen.dart';
|
|
import 'features/chat/screens/mitra_chat_screen.dart';
|
|
import 'features/chat/screens/chat_history_screen.dart';
|
|
import 'features/chat/screens/chat_transcript_screen.dart';
|
|
|
|
class _BlocRefreshNotifier extends ChangeNotifier {
|
|
late final StreamSubscription _subscription;
|
|
|
|
_BlocRefreshNotifier(AuthBloc bloc) {
|
|
_subscription = bloc.stream.listen((_) => notifyListeners());
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_subscription.cancel();
|
|
super.dispose();
|
|
}
|
|
}
|
|
|
|
GoRouter buildRouter(AuthBloc authBloc) {
|
|
return GoRouter(
|
|
initialLocation: '/splash',
|
|
refreshListenable: _BlocRefreshNotifier(authBloc),
|
|
redirect: (context, state) {
|
|
final authState = authBloc.state;
|
|
final isSplash = state.matchedLocation == '/splash';
|
|
final isAuthRoute = state.matchedLocation.startsWith('/login') ||
|
|
state.matchedLocation.startsWith('/otp');
|
|
|
|
// Show splash while loading
|
|
if (authState is AuthLoading) return isSplash ? null : '/splash';
|
|
|
|
if (authState is AuthAuthenticated) {
|
|
return (isSplash || isAuthRoute) ? '/home' : null;
|
|
}
|
|
if (!isAuthRoute && !isSplash) return '/login';
|
|
if (isSplash) return '/login';
|
|
return null;
|
|
},
|
|
routes: [
|
|
GoRoute(path: '/splash', builder: (_, __) => const SplashScreen()),
|
|
GoRoute(path: '/login', builder: (_, __) => const LoginScreen()),
|
|
GoRoute(path: '/otp', builder: (context, state) => OtpScreen(phone: state.extra as String)),
|
|
GoRoute(path: '/home', builder: (_, __) => const HomeScreen()),
|
|
GoRoute(path: '/sessions', builder: (_, __) => const ActiveSessionsScreen()),
|
|
GoRoute(path: '/chat/session/:sessionId', builder: (context, state) {
|
|
final extra = state.extra as Map<String, dynamic>?;
|
|
return MitraChatScreen(
|
|
sessionId: state.pathParameters['sessionId']!,
|
|
customerName: extra?['customerName'] as String? ?? 'Customer',
|
|
);
|
|
}),
|
|
GoRoute(path: '/chat/history', builder: (_, __) => const MitraChatHistoryScreen()),
|
|
GoRoute(path: '/chat/history/:sessionId', builder: (context, state) {
|
|
return MitraChatTranscriptScreen(sessionId: state.pathParameters['sessionId']!);
|
|
}),
|
|
],
|
|
);
|
|
}
|