Chat notifications (production-ready) - ChatDeeplinkService: resolves client chat ID from incoming push/WS payloads using the (senderId, chatId) matrix and switches selectedDeviceProvider when the payload references a different watch (multi-device deeplink) - IncomingChatResolver in domain layer with full unit coverage of the 4-case matrix - ChatContext provider (sealed: outsideChat / list / conversation) wired into ChatListScreen and ChatConversationScreen via initState/dispose to enable WhatsApp-style suppression - notifications_init refactor: foreground CHAT_MESSAGE notifications are suppressed on chat list and matching conversation; tap navigation goes through ChatDeeplinkService - ChatSyncService.subscribeToReconnect: reconciles from REST when the WebSocket comes back from a disconnect (recovers messages missed in background) - 5s message-id dedup window in the WS listener (mitigates server-side duplicate chat-message-received events) - Reconcile from remote on conversation mount (covers cached controller from background) - AppBar refresh button + inverted pull-to-refresh in the conversation (overscroll either edge of the reverse list) WS event parser fix - chat-message-received normalises to chat_message_received; parser now accepts both that and chat_message so the conversation reactively refreshes when a watch sends a message Chat application layer - Split the conversation controller into services: chat_send_service, chat_sync_service, chat_participants_service, chat_permission_flow_service, chat_media_cleanup_service - chat_conversation_config centralises page size, polling interval, dedup window - chat_bubble_shell extracted; input bar split into smaller widgets - emoji picker sheet + emoji blocking input formatter + watch_emoji_catalog - Multipart upload header race fixed via synchronized.Lock around the shared Dio instance Videocall (carryover from earlier work in this branch) - Application services: incoming, outgoing, session - Domain entities: VideocallIncomingArgs, VideocallRoom, VideocallUserId, parseDeviceIdFromRoom helper - Views split: idle, incoming, active call, group call - Widgets: picture_in_picture_video, remote_or_fallback_video, video_call_header - videocall_config centralises timeouts, ringing duration, battery threshold - Incoming via push (channel mode) with full-screen notification + ringtone - Hangup-on-remote-left moved to controller; redirect on participant update documented - treezor_token_interceptor: distinguish session expiry from operation-denied 401s Localization & misc - New keys for chat conversation, refresh, errors across en/es/de/fr/it/pt - Location map: dispose ref-after-unmount fix; route history layer cleanup - Legacy device view model: position update event handling - AndroidManifest: notification channel + permissions for incoming-call full-screen intent
210 lines
7.1 KiB
Dart
210 lines
7.1 KiB
Dart
import 'package:auth/auth.dart';
|
|
import 'package:firebase_messaging/firebase_messaging.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:legacy_theme/legacy_theme.dart';
|
|
import 'package:sf_app_platform/core/app_version_check/app_update_gate.dart';
|
|
import 'package:sf_app_platform/core/app_version_check/app_version_check.dart';
|
|
import 'package:sf_app_platform/core/config/app_mode.dart';
|
|
import 'package:sf_app_platform/core/incoming_call_strings_cache.dart';
|
|
import 'package:sf_app_platform/navigation/app_router.dart';
|
|
import 'package:navigation/navigation.dart';
|
|
import 'package:sf_app_platform/providers/app_state_provider.dart';
|
|
import 'package:sf_app_platform/providers/permissions/permissions_provider.dart';
|
|
import 'package:sf_app_platform/providers/legacy_heartbeat_service.dart';
|
|
import 'package:sf_app_platform/providers/wallet_heartbeat_service.dart';
|
|
import 'package:get_it/get_it.dart';
|
|
import 'package:sf_infrastructure/sf_infrastructure.dart';
|
|
import 'package:sf_shared/sf_shared.dart';
|
|
import 'package:sf_tracking/sf_tracking.dart';
|
|
import 'package:sf_localizations/sf_localizations.dart';
|
|
import 'package:utils/utils.dart';
|
|
import 'package:fonts/fonts.dart';
|
|
import 'package:videocall_sdk/videocall_sdk.dart';
|
|
|
|
class SaveFamilyApp extends ConsumerStatefulWidget {
|
|
const SaveFamilyApp({super.key});
|
|
|
|
@override
|
|
SaveFamilyAppState createState() => SaveFamilyAppState();
|
|
}
|
|
|
|
class SaveFamilyAppState extends ConsumerState<SaveFamilyApp>
|
|
with WidgetsBindingObserver {
|
|
WalletHeartbeatService? _walletHeartbeat;
|
|
LegacyHeartbeatService? _legacyHeartbeat;
|
|
SfRouterListener? _trackingRouterListener;
|
|
WebSocketService? _webSocket;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
WidgetsBinding.instance.addObserver(this);
|
|
|
|
_trackingRouterListener = SfRouterListener(
|
|
listenable: appRouter.routerDelegate,
|
|
currentScreenName: () {
|
|
final config = appRouter.routerDelegate.currentConfiguration;
|
|
if (config.matches.isEmpty) return null;
|
|
return config.last.route.name;
|
|
},
|
|
tracking: sfTracking,
|
|
);
|
|
|
|
if (isPaymentMode) {
|
|
_walletHeartbeat = WalletHeartbeatService(
|
|
repository: ref.read(treezorRepositoryProvider),
|
|
sessionLocal: SessionLocalDatasourceImpl(),
|
|
onError: () => appRouter.go(AppRoutes.scaTreezor),
|
|
);
|
|
}
|
|
|
|
if (isLegacyMode) {
|
|
_legacyHeartbeat = LegacyHeartbeatService(
|
|
ref: ref,
|
|
onUnauthorized: () {
|
|
clearSessionData();
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
appRouter.go(AppRoutes.legacyLogin);
|
|
});
|
|
},
|
|
);
|
|
_webSocket = GetIt.I<WebSocketService>();
|
|
appRouter.routerDelegate.addListener(_onRouteChanged);
|
|
}
|
|
|
|
onBeforeSessionCleared = () {
|
|
_walletHeartbeat?.stop();
|
|
_legacyHeartbeat?.stop();
|
|
_webSocket?.disconnect();
|
|
GetIt.I<VideocallClient>().logout();
|
|
FirebaseMessaging.instance.deleteToken().catchError((Object e) {
|
|
debugPrint('[FCM] deleteToken on logout failed: $e');
|
|
});
|
|
};
|
|
}
|
|
|
|
void _onRouteChanged() {
|
|
final heartbeat = _legacyHeartbeat;
|
|
if (heartbeat == null) return;
|
|
|
|
final location = appRouter.routerDelegate.currentConfiguration.uri.path;
|
|
if (location.startsWith(AppRoutes.legacyDashboard)) {
|
|
heartbeat.start();
|
|
_webSocket?.connect();
|
|
} else {
|
|
heartbeat.stop();
|
|
_webSocket?.disconnect();
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
if (isLegacyMode) {
|
|
appRouter.routerDelegate.removeListener(_onRouteChanged);
|
|
}
|
|
_trackingRouterListener?.dispose();
|
|
_walletHeartbeat?.stop();
|
|
_legacyHeartbeat?.stop();
|
|
_webSocket?.disconnect();
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
debugPrint('State: $state');
|
|
ref.read(appLifecycleStateProvider.notifier).setState(state);
|
|
if (state == AppLifecycleState.resumed) {
|
|
_walletHeartbeat?.start();
|
|
if (isLegacyMode) {
|
|
_onRouteChanged();
|
|
}
|
|
ref.read(permissionsProvider.notifier).checkPermissions();
|
|
ref.read(appVersionCheckProvider.notifier).refresh();
|
|
} else if (state == AppLifecycleState.paused) {
|
|
_walletHeartbeat?.stop();
|
|
_legacyHeartbeat?.stop();
|
|
_webSocket?.disconnect();
|
|
}
|
|
super.didChangeAppLifecycleState(state);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
SizeUtils.init(context: context);
|
|
ref.watch(pushTokenRefreshListenerProvider);
|
|
|
|
// Theme wiring:
|
|
// - Legacy mode: new `legacy_theme` package (Material 3 + light/dark/system).
|
|
// - Payment mode: unchanged behaviour (seed-based ColorScheme, light only).
|
|
final ThemeData lightTheme;
|
|
final ThemeData? darkTheme;
|
|
final ThemeMode themeMode;
|
|
if (isLegacyMode) {
|
|
final legacyThemeState = ref.watch(legacyThemeNotifierProvider);
|
|
lightTheme = LegacyAppTheme.light;
|
|
darkTheme = LegacyAppTheme.dark;
|
|
themeMode = legacyThemeState.themeMode;
|
|
} else {
|
|
lightTheme = ThemeData(
|
|
fontFamily: AppFonts.stolzl,
|
|
colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xFF329E95)),
|
|
);
|
|
darkTheme = null;
|
|
themeMode = ThemeMode.light;
|
|
}
|
|
|
|
return AppUpdateGate(
|
|
child: MaterialApp.router(
|
|
title: 'SaveFamily',
|
|
theme: lightTheme,
|
|
darkTheme: darkTheme,
|
|
themeMode: themeMode,
|
|
routerConfig: appRouter,
|
|
debugShowCheckedModeBanner: false,
|
|
localizationsDelegates: [
|
|
SFLocalizations.delegate,
|
|
GlobalMaterialLocalizations.delegate,
|
|
GlobalCupertinoLocalizations.delegate,
|
|
GlobalWidgetsLocalizations.delegate,
|
|
],
|
|
supportedLocales: [for (final lang in supportedLanguages) Locale(lang)],
|
|
localeResolutionCallback: (locale, supportedLocales) {
|
|
if (locale == null) return supportedLocales.first;
|
|
for (var supportedLocale in supportedLocales) {
|
|
if (supportedLocale.languageCode == locale.languageCode) {
|
|
return supportedLocale;
|
|
}
|
|
}
|
|
return supportedLocales.first;
|
|
},
|
|
builder: (context, child) {
|
|
_cacheIncomingCallStrings(context);
|
|
return child ?? const SizedBox.shrink();
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
String? _cachedIncomingCallLocale;
|
|
|
|
void _cacheIncomingCallStrings(BuildContext context) {
|
|
final localeCode = context.locale.languageCode;
|
|
if (_cachedIncomingCallLocale == localeCode) return;
|
|
_cachedIncomingCallLocale = localeCode;
|
|
IncomingCallStringsCache.save(
|
|
IncomingCallStrings(
|
|
title: context.translate(I18n.videocallIncomingVideo),
|
|
body: context.translate(I18n.videocallIncomingPushBody),
|
|
acceptLabel: context.translate(I18n.videocallAccept),
|
|
rejectLabel: context.translate(I18n.videocallReject),
|
|
channelName: context.translate(I18n.videocallNotificationChannelName),
|
|
channelDescription:
|
|
context.translate(I18n.videocallNotificationChannelDescription),
|
|
),
|
|
);
|
|
}
|
|
}
|