mirror of
https://github.com/nostrlabs-io/zap-stream-flutter.git
synced 2025-06-15 03:46:33 +00:00
fix: dont make notepush requests unless notifications is authorized
This commit is contained in:
@ -136,6 +136,8 @@ Notepush? getNotificationService() {
|
||||
: null;
|
||||
}
|
||||
|
||||
NotificationSettings? notifications;
|
||||
|
||||
Future<void> setupNotifications() async {
|
||||
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
||||
|
||||
@ -175,7 +177,7 @@ Future<void> setupNotifications() async {
|
||||
}
|
||||
});
|
||||
|
||||
await fbase.requestPermission(provisional: true);
|
||||
notifications = await fbase.requestPermission(provisional: true);
|
||||
await fbase.setAutoInitEnabled(true);
|
||||
await fbase.setForegroundNotificationPresentationOptions(
|
||||
alert: true,
|
||||
@ -192,7 +194,7 @@ Future<void> setupNotifications() async {
|
||||
await localNotifications.initialize(
|
||||
InitializationSettings(
|
||||
android: AndroidInitializationSettings("@mipmap/ic_launcher"),
|
||||
iOS: DarwinInitializationSettings()
|
||||
iOS: DarwinInitializationSettings(),
|
||||
),
|
||||
);
|
||||
fbase.onTokenRefresh.listen((token) async {
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:zap_stream_flutter/notifications.dart';
|
||||
import 'package:zap_stream_flutter/theme.dart';
|
||||
@ -17,8 +18,13 @@ class _NotificationsButtonWidget extends State<NotificationsButtonWidget> {
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder(
|
||||
future: () async {
|
||||
final n = getNotificationService();
|
||||
return await n?.getWatchedKeys();
|
||||
if (notifications?.authorizationStatus ==
|
||||
AuthorizationStatus.authorized) {
|
||||
final n = getNotificationService();
|
||||
return await n?.getWatchedKeys();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}(),
|
||||
builder: (context, state) {
|
||||
if (state.data == null) {
|
||||
|
Reference in New Issue
Block a user