folder restructuring
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../widget/debug/debug_tile.dart';
|
||||
import '../widget/debug/json_viewer.dart';
|
||||
import 'notification_tasks.dart';
|
||||
|
||||
class NotificationController {
|
||||
@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 {
|
||||
NotificationTasks.updateProviders(context);
|
||||
NotificationTasks.updateBadgeCount(message);
|
||||
}
|
||||
|
||||
static Future<void> onAppOpenedByNotification(RemoteMessage message, BuildContext context) async {
|
||||
NotificationTasks.navigateToTalk(context, chatToken: _extractChatToken(message));
|
||||
NotificationTasks.updateProviders(context);
|
||||
|
||||
DebugTile(context).run(() {
|
||||
showDialog(context: context, builder: (context) => AlertDialog(
|
||||
title: const Text('Notification report'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text('Dieser Bericht wird angezeigt, da du den Entwicklermodus aktiviert hast und die App über eine Benachrichtigung geöffnet wurde.'),
|
||||
Text(JsonViewer.format(message.data)),
|
||||
],
|
||||
),
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
static String? _extractChatToken(RemoteMessage message) {
|
||||
for (final key in const ['chatToken', 'token', 'roomToken']) {
|
||||
final value = message.data[key];
|
||||
if (value is String && value.isNotEmpty) return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user