diff --git a/lib/cinema/ui/pages/detail_page/detail_page.dart b/lib/cinema/ui/pages/detail_page/detail_page.dart index 106503ebf..42c56a509 100644 --- a/lib/cinema/ui/pages/detail_page/detail_page.dart +++ b/lib/cinema/ui/pages/detail_page/detail_page.dart @@ -310,12 +310,7 @@ class DetailPage extends HookConsumerWidget { content: 'La séance ' '${session.name}' ' commence dans 10 minutes', - context: session.id, - isVisible: true, title: '🎬 Cinéma', - deliveryDateTime: session.start.subtract( - const Duration(minutes: 10), - ), ), ); displayToast( diff --git a/lib/ph/notification_service.dart b/lib/ph/notification_service.dart index 7235bdea8..ec150a764 100644 --- a/lib/ph/notification_service.dart +++ b/lib/ph/notification_service.dart @@ -5,8 +5,7 @@ import 'package:tuple/tuple.dart'; final Map>> phProviders = { "ph": Tuple2( - // L'actionTable de la notification est "session" - PhRouter.root, // La page principale du module ciné + PhRouter.root, // La page principale du module ph [phListProvider], // Le provider de la liste des sessions ), }; diff --git a/lib/service/class/message.dart b/lib/service/class/message.dart index 99575783b..d59af78f7 100644 --- a/lib/service/class/message.dart +++ b/lib/service/class/message.dart @@ -1,22 +1,14 @@ -import 'package:myecl/tools/functions.dart'; - class Message { late final String? title; late final String? content; late final String? actionModule; late final String? actionTable; - late final bool isVisible; - late final String context; - late final DateTime? deliveryDateTime; Message({ required this.title, required this.content, required this.actionModule, required this.actionTable, - required this.context, - required this.isVisible, - this.deliveryDateTime, }); Message.fromJson(Map json) { @@ -24,11 +16,6 @@ class Message { content = json['content']; actionModule = json['action_module']; actionTable = json['action_table']; - context = json['context']; - isVisible = json['is_visible']; - deliveryDateTime = json['delivery_datetime'] != null - ? processDateFromAPI(json['delivery_datetime']) - : null; } Map toJson() { @@ -37,15 +24,11 @@ class Message { data['content'] = content; data['action_module'] = actionModule; data['action_table'] = actionTable; - data['context'] = context; - data['is_visible'] = isVisible; - data['delivery_datetime'] = - (deliveryDateTime != null) ? processDateToAPI(deliveryDateTime!) : null; return data; } @override String toString() { - return 'Message{title: $title, content: $content, actionModule: $actionModule, actionTable: $actionTable, context: $context, isVisible: $isVisible}'; + return 'Message{title: $title, content: $content, actionModule: $actionModule, actionTable: $actionTable}'; } } diff --git a/lib/service/local_notification_service.dart b/lib/service/local_notification_service.dart index 64337d0d1..cfcb2aeee 100644 --- a/lib/service/local_notification_service.dart +++ b/lib/service/local_notification_service.dart @@ -9,6 +9,7 @@ import 'package:qlevar_router/qlevar_router.dart'; import 'package:rxdart/subjects.dart'; import 'package:timezone/timezone.dart' as tz; import 'package:timezone/data/latest.dart' as tz; +import 'package:uuid/uuid.dart'; class LocalNotificationService { LocalNotificationService() { @@ -65,42 +66,14 @@ class LocalNotificationService { Future showNotification(message_class.Message message) async { final notificationDetails = getNotificationDetails(); - if (message.deliveryDateTime == null) { - _localNotificationService.show( - generateIntFromString(message.context), - message.title, - message.content, - notificationDetails, - payload: json.encode(message.toJson()), - ); - return; - } - final dateToDisplay = tz.TZDateTime.from( - message.deliveryDateTime!, - tz.local, + _localNotificationService.show( + generateIntFromString(const Uuid().toString()), + message.title, + message.content, + notificationDetails, + payload: json.encode(message.toJson()), ); - final now = tz.TZDateTime.now(tz.local); - if (dateToDisplay.isAfter(now)) { - _localNotificationService.zonedSchedule( - generateIntFromString(message.context), - message.title, - message.content, - dateToDisplay, - notificationDetails, - androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, - uiLocalNotificationDateInterpretation: - UILocalNotificationDateInterpretation.absoluteTime, - payload: json.encode(message.toJson()), - ); - } else { - _localNotificationService.show( - generateIntFromString(message.context), - message.title, - message.content, - notificationDetails, - payload: json.encode(message.toJson()), - ); - } + return; } Future showPeriodicNotification( @@ -283,7 +256,7 @@ void onDidReceiveBackgroundNotificationResponse( final message = message_class.Message.fromJson( jsonDecode(utf8.decode(response.payload!.runes.toList())), ); - if (message.actionModule != null && message.actionTable != null) { + if (message.actionModule != null) { final provider = providers[message.actionModule]; if (provider == null) { return; diff --git a/lib/service/tools/setup.dart b/lib/service/tools/setup.dart index adacc9bc3..b84175fd7 100644 --- a/lib/service/tools/setup.dart +++ b/lib/service/tools/setup.dart @@ -1,16 +1,15 @@ import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; +import 'package:myecl/service/class/message.dart' as message_class; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:myecl/service/local_notification_service.dart'; import 'package:myecl/service/providers/firebase_token_expiration_provider.dart'; import 'package:myecl/service/providers/firebase_token_provider.dart'; import 'package:myecl/service/providers/messages_provider.dart'; import 'package:myecl/service/providers/topic_provider.dart'; -import 'package:myecl/service/repositories/notification_repository.dart'; import 'package:myecl/tools/logs/log.dart'; import 'package:myecl/tools/repository/repository.dart'; -import 'package:myecl/tools/token_expire_wrapper.dart'; import 'package:myecl/user/providers/user_provider.dart'; void setUpNotification(WidgetRef ref) { @@ -50,40 +49,19 @@ void setUpNotification(WidgetRef ref) { } }); - void handleMessages() async { - tokenExpireWrapper(ref, () async { - final messages = await messageNotifier.getMessages(); - messages.maybeWhen( - data: (messageList) async { - for (final message in messageList) { - Repository.logger.logNotification(message); - final actionModule = message.actionModule; - final actionTable = message.actionTable; - if (!message.isVisible && - actionModule != null && - actionTable != null) { - localNotificationService.handleAction(actionModule, actionTable); - } else { - localNotificationService.showNotification(message); - } - } - }, - orElse: () {}, - ); - }); - } - FirebaseMessaging.onMessage.listen((RemoteMessage message) { + message_class.Message messages = + message_class.Message.fromJson(message.data); Repository.logger .writeLog(Log(message: "GOT trigger onMessage", level: LogLevel.error)); - handleMessages(); - }); - FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) { - Repository.logger.writeLog( - Log(message: "GOT trigger onMessageOpenedApp", level: LogLevel.error), + message_class.Message me = message_class.Message( + title: message.notification?.title ?? "No title", + content: message.notification?.body ?? "No body", + actionModule: messages.actionModule, + actionTable: messages.actionTable, ); - handleMessages(); + localNotificationService.showNotification(me); }); } @@ -96,14 +74,4 @@ Future firebaseMessagingBackgroundHandler(RemoteMessage message) async { final LocalNotificationService localNotificationService = LocalNotificationService(); localNotificationService.init(); - final firebaseToken = await FirebaseMessaging.instance - .getToken(vapidKey: "") - .then((value) => value.toString()); - NotificationRepository notificationRepository = NotificationRepository(); - final messages = await notificationRepository.getMessages(firebaseToken); - for (final message in messages) { - if (message.isVisible) { - localNotificationService.showNotification(message); - } - } } diff --git a/pubspec.yaml b/pubspec.yaml index 0cf5c4015..d39df46ea 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -65,6 +65,7 @@ dependencies: url_launcher: ^6.2.5 pdfx: ^2.6.0 file_saver: ^0.2.12 + uuid: ^4.4.2 dev_dependencies: flutter_launcher_icons: ^0.14.2