claude refactorings, flutter best practices, platform dependent changes, general cleanup
This commit is contained in:
@@ -6,36 +6,10 @@ import '../widget/debug/json_viewer.dart';
|
||||
import 'notification_tasks.dart';
|
||||
|
||||
class NotificationController {
|
||||
// Notification display is handled by the Firebase SDK using server-generated payloads.
|
||||
@pragma('vm:entry-point')
|
||||
static Future<void> onBackgroundMessageHandler(RemoteMessage message) async {
|
||||
NotificationTasks.updateBadgeCount(message);
|
||||
return; // Displaying the notification is curently done via the Firebase SDK itself. The Message is server-generated.
|
||||
|
||||
//
|
||||
// await Firebase.initializeApp();
|
||||
// AccountData().waitForPopulation().then((value) {
|
||||
// log("User account status: $value");
|
||||
// if(value) {
|
||||
// GetRoom(
|
||||
// GetRoomParams(
|
||||
// includeStatus: false,
|
||||
// ),
|
||||
// ).run().then((value) {
|
||||
// var messageCount = value.data.map((e) => e.unreadMessages).reduce((a, b) => a + b);
|
||||
// var chatCount = value.data.where((e) => e.unreadMessages > 0).length;
|
||||
// var people = value.data.where((e) => e.unreadMessages > 0).map((e) => e.displayName.split(" ")[0]);
|
||||
//
|
||||
// final NotificationService service = NotificationService();
|
||||
// service.initializeNotifications().then((value) {
|
||||
// service.showNotification(
|
||||
// title: "Du hast $messageCount ungelesene Nachrichten!",
|
||||
// body: "In $chatCount Chats, von ${people.join(", ")}",
|
||||
// badgeCount: messageCount,
|
||||
// );
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
static Future<void> onForegroundMessageHandler(RemoteMessage message, BuildContext context) async {
|
||||
|
||||
@@ -5,11 +5,11 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../routing/app_routes.dart';
|
||||
import '../state/app/modules/chat/bloc/chat_bloc.dart';
|
||||
import '../state/app/modules/chatList/bloc/chat_list_bloc.dart';
|
||||
import '../state/app/modules/chat_list/bloc/chat_list_bloc.dart';
|
||||
|
||||
class NotificationTasks {
|
||||
static void updateBadgeCount(RemoteMessage notification) {
|
||||
FlutterAppBadge.count(int.parse(notification.data['unreadCount'] ?? '0'));
|
||||
FlutterAppBadge.count(int.parse((notification.data['unreadCount'] as String?) ?? '0'));
|
||||
}
|
||||
|
||||
static void updateProviders(BuildContext context) {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../api/mhsl/notify/register/notifyRegister.dart';
|
||||
import '../api/mhsl/notify/register/notifyRegisterParams.dart';
|
||||
import '../api/mhsl/notify/register/notify_register.dart';
|
||||
import '../api/mhsl/notify/register/notify_register_params.dart';
|
||||
import '../model/account_data.dart';
|
||||
import '../state/app/modules/settings/bloc/settings_cubit.dart';
|
||||
import '../widget/confirm_dialog.dart';
|
||||
@@ -17,9 +19,9 @@ class NotifyUpdater {
|
||||
'Für mehr Informationen drücke lange auf die Einstellungsoption!',
|
||||
confirmButton: 'Aktivieren',
|
||||
onConfirm: () {
|
||||
FirebaseMessaging.instance.requestPermission(provisional: false);
|
||||
unawaited(FirebaseMessaging.instance.requestPermission(provisional: false));
|
||||
settings.val(write: true).notificationSettings.enabled = true;
|
||||
NotifyUpdater.registerToServer();
|
||||
unawaited(NotifyUpdater.registerToServer());
|
||||
},
|
||||
);
|
||||
|
||||
@@ -29,12 +31,12 @@ class NotifyUpdater {
|
||||
throw Exception('Failed to register push notification because there is no FBC token!');
|
||||
}
|
||||
|
||||
NotifyRegister(
|
||||
unawaited(NotifyRegister(
|
||||
NotifyRegisterParams(
|
||||
username: AccountData().getUsername(),
|
||||
password: AccountData().getPassword(),
|
||||
fcmToken: fcmToken,
|
||||
),
|
||||
).run();
|
||||
).run());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user