feat: launch url for push notifications

closes #32
This commit is contained in:
2025-05-23 12:38:36 +01:00
parent acbf311972
commit 8f41ed6d0e

View File

@ -9,8 +9,10 @@ import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:ndk/ndk.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:zap_stream_flutter/const.dart';
import 'package:http/http.dart' as http;
import 'package:zap_stream_flutter/utils.dart';
class Notepush {
final String base;
@ -158,9 +160,17 @@ Future<void> setupNotifications() async {
}
});
FirebaseMessaging.onMessageOpenedApp.listen((msg) {
try {
final notification = msg.notification;
if (notification != null) {
// TODO: redirect to stream
final String? json = msg.data["nostr_event"];
if (notification != null && json != null) {
// Just launch the URL because we support deep links
final event = Nip01Event.fromJson(JsonCodec().decode(json));
final stream = StreamEvent(event);
launchUrl(Uri.parse("https://zap.stream/${stream.link}"));
}
} catch (e) {
developer.log("Failed to process push notification\n ${e.toString()}");
}
});
await fbase.setAutoInitEnabled(true);