24 lines
864 B
Dart
24 lines
864 B
Dart
import 'package:go_router/go_router.dart';
|
|
|
|
/// Parses FCM / notification payloads so the app opens the correct chat.
|
|
/// Expected keys: `contextId`, `roomId` (and optional `type`).
|
|
class PushRouting {
|
|
const PushRouting();
|
|
|
|
/// Build location for go_router, e.g. `/chat?roomId=...&contextId=...`
|
|
String? locationFromPayload(Map<String, dynamic> data) {
|
|
final roomId = data['roomId'] as String? ?? data['room_id'] as String?;
|
|
final contextId = data['contextId'] as String? ?? data['context_id'] as String?;
|
|
if (roomId == null || contextId == null) return null;
|
|
return Uri(
|
|
path: '/chat',
|
|
queryParameters: {'roomId': roomId, 'contextId': contextId},
|
|
).toString();
|
|
}
|
|
|
|
void navigateFromPayload(GoRouter router, Map<String, dynamic> data) {
|
|
final loc = locationFromPayload(data);
|
|
if (loc != null) router.go(loc);
|
|
}
|
|
}
|