TF-1898 Fix there is no notification badge only on IOS

(cherry picked from commit c8c8a03267846df5c5d2032553988fd393fbc02d)
This commit is contained in:
dab246
2023-07-10 13:51:24 +07:00
committed by Dat Vu
parent 356a6b8095
commit b939c59fb0
9 changed files with 52 additions and 3 deletions
+6
View File
@@ -85,6 +85,8 @@ PODS:
- fk_user_agent (2.0.0):
- Flutter
- Flutter (1.0.0)
- flutter_app_badger (1.3.0):
- Flutter
- flutter_appauth (0.0.1):
- AppAuth (= 1.6.0)
- Flutter
@@ -186,6 +188,7 @@ DEPENDENCIES:
- firebase_messaging (from `.symlinks/plugins/firebase_messaging/ios`)
- fk_user_agent (from `.symlinks/plugins/fk_user_agent/ios`)
- Flutter (from `Flutter`)
- flutter_app_badger (from `.symlinks/plugins/flutter_app_badger/ios`)
- flutter_appauth (from `.symlinks/plugins/flutter_appauth/ios`)
- flutter_downloader (from `.symlinks/plugins/flutter_downloader/ios`)
- flutter_image_compress (from `.symlinks/plugins/flutter_image_compress/ios`)
@@ -245,6 +248,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/fk_user_agent/ios"
Flutter:
:path: Flutter
flutter_app_badger:
:path: ".symlinks/plugins/flutter_app_badger/ios"
flutter_appauth:
:path: ".symlinks/plugins/flutter_appauth/ios"
flutter_downloader:
@@ -295,6 +300,7 @@ SPEC CHECKSUMS:
FirebaseMessaging: e345b219fd15d325f0cf2fef28cb8ce00d851b3f
fk_user_agent: 1f47ec39291e8372b1d692b50084b0d54103c545
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
flutter_app_badger: b87fc231847b03b92ce1412aa351842e7e97932f
flutter_appauth: 525652bda90e43ca5eb7ed748ecc106b79d1f5a1
flutter_downloader: b7301ae057deadd4b1650dc7c05375f10ff12c39
flutter_image_compress: 5a5e9aee05b6553048b8df1c3bc456d0afaac433
@@ -1537,7 +1537,8 @@ class MailboxDashBoardController extends ReloadableController {
_handleMessageFromNotification(response?.payload);
}
void _handleMessageFromNotification(String? payload, {bool onForeground = true}) {
void _handleMessageFromNotification(String? payload, {bool onForeground = true}) async {
await LocalNotificationManager.instance.removeNotificationBadgeForIOS();
log('MailboxDashBoardController::_handleMessageFromNotification():payload: $payload');
if (payload == null || payload.isEmpty) {
dispatchRoute(DashboardRoutes.thread);
@@ -15,6 +15,7 @@ class FcmConfiguration {
static void _initMessageListener() {
FcmReceiver.instance.onForegroundMessage();
FcmReceiver.instance.onBackgroundMessage();
FcmReceiver.instance.onMessageOpenedApp();
FcmReceiver.instance.getFcmToken();
FcmReceiver.instance.onRefreshFcmToken();
}
@@ -199,7 +199,7 @@ class EmailChangeListener extends ChangeListener {
);
}
void _showLocalNotificationForIOS(jmap.State newState, AccountId accountId) {
void _showLocalNotificationForIOS(jmap.State newState, AccountId accountId) async {
final notificationPayload = NotificationPayload(newState: newState);
log('EmailChangeListener::_showLocalNotificationForIOS():notificationPayload: $notificationPayload');
LocalNotificationManager.instance.showPushNotification(
@@ -212,6 +212,7 @@ class EmailChangeListener extends ChangeListener {
: LocalNotificationConfig.notificationMessage,
payload: notificationPayload.encodeToString,
);
await LocalNotificationManager.instance.setNotificationBadgeForIOS();
}
@override
@@ -4,10 +4,13 @@ import 'dart:io';
import 'package:core/presentation/extensions/html_extension.dart';
import 'package:core/utils/app_logger.dart';
import 'package:core/utils/platform_info.dart';
import 'package:flutter_app_badger/flutter_app_badger.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
import 'package:model/extensions/email_address_extension.dart';
import 'package:tmail_ui_user/features/push_notification/presentation/notification/local_notification_config.dart';
import 'package:tmail_ui_user/features/push_notification/presentation/utils/fcm_utils.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
@@ -162,7 +165,10 @@ class LocalNotificationManager {
}
}
Future<void> removeNotification(String id) {
Future<void> removeNotification(String id) async {
if (id.startsWith(FcmUtils.instance.platformOS)) {
await removeNotificationBadgeForIOS();
}
return _localNotificationsPlugin.cancel(id.hashCode);
}
@@ -217,4 +223,18 @@ class LocalNotificationManager {
void closeStream() {
localNotificationsController.close();
}
Future<void> setNotificationBadgeForIOS() async {
log("LocalNotificationManager::setNotificationBadgeForIOS:");
if (PlatformInfo.isIOS) {
await FlutterAppBadger.updateBadgeCount(1);
}
}
Future<void> removeNotificationBadgeForIOS() async {
log("LocalNotificationManager::removeNotificationBadgeForIOS:");
if (PlatformInfo.isIOS) {
await FlutterAppBadger.removeBadge();
}
}
}
@@ -26,6 +26,10 @@ class FcmReceiver {
FirebaseMessaging.onBackgroundMessage(handleFirebaseBackgroundMessage);
}
void onMessageOpenedApp() {
FirebaseMessaging.onMessageOpenedApp.listen(FcmService.instance.handleFirebaseMessageOpenedApp);
}
void getFcmToken() async {
try {
final currentToken = await FirebaseMessaging.instance.getToken(vapidKey: AppUtils.fcmVapidPublicKey);
@@ -4,6 +4,7 @@ import 'dart:async';
import 'package:core/utils/app_logger.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:tmail_ui_user/features/push_notification/presentation/controller/fcm_message_controller.dart';
import 'package:tmail_ui_user/features/push_notification/presentation/notification/local_notification_manager.dart';
class FcmService {
@@ -43,6 +44,11 @@ class FcmService {
}
}
void handleFirebaseMessageOpenedApp(RemoteMessage newRemoteMessage) async {
log("FcmService::handleFirebaseMessageOpenedApp:");
await LocalNotificationManager.instance.removeNotificationBadgeForIOS();
}
void handleGetToken(String? currentToken) async {
log('FcmService::handleGetToken():currentToken: $currentToken');
if (fcmTokenStreamController.isClosed) {
+8
View File
@@ -557,6 +557,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_app_badger:
dependency: "direct main"
description:
name: flutter_app_badger
sha256: "64d4a279bab862ed28850431b9b446b9820aaae0bf363322d51077419f930fa8"
url: "https://pub.dev"
source: hosted
version: "1.5.0"
flutter_appauth:
dependency: "direct main"
description:
+2
View File
@@ -201,6 +201,8 @@ dependencies:
extended_text: 10.0.1
flutter_app_badger: 1.5.0
dev_dependencies:
flutter_test:
sdk: flutter