Refactoring push helper

This commit is contained in:
Christian Pauly 2020-05-07 11:13:54 +02:00
parent d7e2ff7ae0
commit 4ab05b4df9
4 changed files with 40 additions and 13 deletions

View File

@ -1166,6 +1166,13 @@
"unreadEvents": {}
}
},
"unreadChats": "{unreadCount} ungelesene Unterhaltungen",
"@unreadChats": {
"type": "text",
"placeholders": {
"unreadCount": {}
}
},
"unreadMessagesInChats": "{unreadEvents} ungelesene Nachrichten in {unreadChats} Chats",
"@unreadMessagesInChats": {
"type": "text",

View File

@ -1,5 +1,5 @@
{
"@@last_modified": "2020-05-07T07:52:19.301540",
"@@last_modified": "2020-05-07T11:13:43.051811",
"About": "About",
"@About": {
"type": "text",
@ -785,6 +785,11 @@
"type": "text",
"placeholders": {}
},
"Open app to read messages": "Open app to read messages",
"@Open app to read messages": {
"type": "text",
"placeholders": {}
},
"Open camera": "Open camera",
"@Open camera": {
"type": "text",
@ -1164,6 +1169,13 @@
"type": {}
}
},
"unreadChats": "{unreadCount} unread chats",
"@unreadChats": {
"type": "text",
"placeholders": {
"unreadCount": {}
}
},
"unreadMessages": "{unreadEvents} unread messages",
"@unreadMessages": {
"type": "text",

View File

@ -490,6 +490,8 @@ class L10n extends MatrixLocalizations {
String get oopsSomethingWentWrong =>
Intl.message("Oops something went wrong...");
String get openAppToReadMessages => Intl.message('Open app to read messages');
String get openCamera => Intl.message('Open camera');
String get optionalGroupName => Intl.message("(Optional) Group name");
@ -705,6 +707,12 @@ class L10n extends MatrixLocalizations {
args: [type],
);
String unreadChats(String unreadCount) => Intl.message(
"$unreadCount unread chats",
name: "unreadChats",
args: [unreadCount],
);
String unreadMessages(String unreadEvents) => Intl.message(
"$unreadEvents unread messages",
name: "unreadMessages",

View File

@ -19,6 +19,9 @@ abstract class FirebaseController {
static FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
static BuildContext context;
static const String CHANNEL_ID = 'fluffychat_push';
static const String CHANNEL_NAME = 'FluffyChat push channel';
static const String CHANNEL_DESCRIPTION = 'Push notifications for FluffyChat';
static Future<void> setupFirebase(Client client, String clientName) async {
if (Platform.isIOS) iOS_Permission();
@ -83,7 +86,7 @@ abstract class FirebaseController {
_firebaseMessaging.configure(
onMessage: _onMessage,
onBackgroundMessage: _onMessage,
onBackgroundMessage: _showDefaultNotification,
onResume: goToRoom,
onLaunch: goToRoom,
);
@ -106,7 +109,8 @@ abstract class FirebaseController {
if (context != null && Matrix.of(context).activeRoomId == roomId) {
return null;
}
final i18n = context == null ? L10n('en') : L10n.of(context);
final i18n =
context == null ? L10n(Platform.localeName) : L10n.of(context);
// Get the client
Client client;
@ -181,9 +185,7 @@ abstract class FirebaseController {
// Show notification
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'fluffychat_push',
'FluffyChat push channel',
'Push notifications for FluffyChat',
CHANNEL_ID, CHANNEL_NAME, CHANNEL_DESCRIPTION,
styleInformation: MessagingStyleInformation(
person,
conversationTitle: title,
@ -224,6 +226,7 @@ abstract class FirebaseController {
var initializationSettings = InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
await flutterLocalNotificationsPlugin.initialize(initializationSettings);
final l10n = L10n(Platform.localeName);
// Notification data and matrix data
Map<dynamic, dynamic> data = message['data'] ?? message;
@ -239,17 +242,14 @@ abstract class FirebaseController {
// Display notification
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'fluffychat_push',
'FluffyChat push channel',
'Push notifications for FluffyChat',
importance: Importance.Max,
priority: Priority.High);
CHANNEL_ID, CHANNEL_NAME, CHANNEL_DESCRIPTION,
importance: Importance.Max, priority: Priority.High);
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
final String title = "$unread unread chats";
final String title = l10n.unreadChats(unread.toString());
await flutterLocalNotificationsPlugin.show(
1, title, 'Open app to read messages', platformChannelSpecifics,
1, title, l10n.openAppToReadMessages, platformChannelSpecifics,
payload: roomID);
} catch (exception) {
debugPrint("[Push] Error while processing background notification: " +