Refactoring push helper
This commit is contained in:
parent
d7e2ff7ae0
commit
4ab05b4df9
|
@ -1166,6 +1166,13 @@
|
||||||
"unreadEvents": {}
|
"unreadEvents": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"unreadChats": "{unreadCount} ungelesene Unterhaltungen",
|
||||||
|
"@unreadChats": {
|
||||||
|
"type": "text",
|
||||||
|
"placeholders": {
|
||||||
|
"unreadCount": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
"unreadMessagesInChats": "{unreadEvents} ungelesene Nachrichten in {unreadChats} Chats",
|
"unreadMessagesInChats": "{unreadEvents} ungelesene Nachrichten in {unreadChats} Chats",
|
||||||
"@unreadMessagesInChats": {
|
"@unreadMessagesInChats": {
|
||||||
"type": "text",
|
"type": "text",
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"@@last_modified": "2020-05-07T07:52:19.301540",
|
"@@last_modified": "2020-05-07T11:13:43.051811",
|
||||||
"About": "About",
|
"About": "About",
|
||||||
"@About": {
|
"@About": {
|
||||||
"type": "text",
|
"type": "text",
|
||||||
|
@ -785,6 +785,11 @@
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"placeholders": {}
|
"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": "Open camera",
|
||||||
"@Open camera": {
|
"@Open camera": {
|
||||||
"type": "text",
|
"type": "text",
|
||||||
|
@ -1164,6 +1169,13 @@
|
||||||
"type": {}
|
"type": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"unreadChats": "{unreadCount} unread chats",
|
||||||
|
"@unreadChats": {
|
||||||
|
"type": "text",
|
||||||
|
"placeholders": {
|
||||||
|
"unreadCount": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
"unreadMessages": "{unreadEvents} unread messages",
|
"unreadMessages": "{unreadEvents} unread messages",
|
||||||
"@unreadMessages": {
|
"@unreadMessages": {
|
||||||
"type": "text",
|
"type": "text",
|
||||||
|
|
|
@ -490,6 +490,8 @@ class L10n extends MatrixLocalizations {
|
||||||
String get oopsSomethingWentWrong =>
|
String get oopsSomethingWentWrong =>
|
||||||
Intl.message("Oops something went wrong...");
|
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 openCamera => Intl.message('Open camera');
|
||||||
|
|
||||||
String get optionalGroupName => Intl.message("(Optional) Group name");
|
String get optionalGroupName => Intl.message("(Optional) Group name");
|
||||||
|
@ -705,6 +707,12 @@ class L10n extends MatrixLocalizations {
|
||||||
args: [type],
|
args: [type],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
String unreadChats(String unreadCount) => Intl.message(
|
||||||
|
"$unreadCount unread chats",
|
||||||
|
name: "unreadChats",
|
||||||
|
args: [unreadCount],
|
||||||
|
);
|
||||||
|
|
||||||
String unreadMessages(String unreadEvents) => Intl.message(
|
String unreadMessages(String unreadEvents) => Intl.message(
|
||||||
"$unreadEvents unread messages",
|
"$unreadEvents unread messages",
|
||||||
name: "unreadMessages",
|
name: "unreadMessages",
|
||||||
|
|
|
@ -19,6 +19,9 @@ abstract class FirebaseController {
|
||||||
static FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
|
static FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
|
||||||
FlutterLocalNotificationsPlugin();
|
FlutterLocalNotificationsPlugin();
|
||||||
static BuildContext context;
|
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 {
|
static Future<void> setupFirebase(Client client, String clientName) async {
|
||||||
if (Platform.isIOS) iOS_Permission();
|
if (Platform.isIOS) iOS_Permission();
|
||||||
|
@ -83,7 +86,7 @@ abstract class FirebaseController {
|
||||||
|
|
||||||
_firebaseMessaging.configure(
|
_firebaseMessaging.configure(
|
||||||
onMessage: _onMessage,
|
onMessage: _onMessage,
|
||||||
onBackgroundMessage: _onMessage,
|
onBackgroundMessage: _showDefaultNotification,
|
||||||
onResume: goToRoom,
|
onResume: goToRoom,
|
||||||
onLaunch: goToRoom,
|
onLaunch: goToRoom,
|
||||||
);
|
);
|
||||||
|
@ -106,7 +109,8 @@ abstract class FirebaseController {
|
||||||
if (context != null && Matrix.of(context).activeRoomId == roomId) {
|
if (context != null && Matrix.of(context).activeRoomId == roomId) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final i18n = context == null ? L10n('en') : L10n.of(context);
|
final i18n =
|
||||||
|
context == null ? L10n(Platform.localeName) : L10n.of(context);
|
||||||
|
|
||||||
// Get the client
|
// Get the client
|
||||||
Client client;
|
Client client;
|
||||||
|
@ -181,9 +185,7 @@ abstract class FirebaseController {
|
||||||
|
|
||||||
// Show notification
|
// Show notification
|
||||||
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
|
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
|
||||||
'fluffychat_push',
|
CHANNEL_ID, CHANNEL_NAME, CHANNEL_DESCRIPTION,
|
||||||
'FluffyChat push channel',
|
|
||||||
'Push notifications for FluffyChat',
|
|
||||||
styleInformation: MessagingStyleInformation(
|
styleInformation: MessagingStyleInformation(
|
||||||
person,
|
person,
|
||||||
conversationTitle: title,
|
conversationTitle: title,
|
||||||
|
@ -224,6 +226,7 @@ abstract class FirebaseController {
|
||||||
var initializationSettings = InitializationSettings(
|
var initializationSettings = InitializationSettings(
|
||||||
initializationSettingsAndroid, initializationSettingsIOS);
|
initializationSettingsAndroid, initializationSettingsIOS);
|
||||||
await flutterLocalNotificationsPlugin.initialize(initializationSettings);
|
await flutterLocalNotificationsPlugin.initialize(initializationSettings);
|
||||||
|
final l10n = L10n(Platform.localeName);
|
||||||
|
|
||||||
// Notification data and matrix data
|
// Notification data and matrix data
|
||||||
Map<dynamic, dynamic> data = message['data'] ?? message;
|
Map<dynamic, dynamic> data = message['data'] ?? message;
|
||||||
|
@ -239,17 +242,14 @@ abstract class FirebaseController {
|
||||||
|
|
||||||
// Display notification
|
// Display notification
|
||||||
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
|
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
|
||||||
'fluffychat_push',
|
CHANNEL_ID, CHANNEL_NAME, CHANNEL_DESCRIPTION,
|
||||||
'FluffyChat push channel',
|
importance: Importance.Max, priority: Priority.High);
|
||||||
'Push notifications for FluffyChat',
|
|
||||||
importance: Importance.Max,
|
|
||||||
priority: Priority.High);
|
|
||||||
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
|
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
|
||||||
var platformChannelSpecifics = NotificationDetails(
|
var platformChannelSpecifics = NotificationDetails(
|
||||||
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
|
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
|
||||||
final String title = "$unread unread chats";
|
final String title = l10n.unreadChats(unread.toString());
|
||||||
await flutterLocalNotificationsPlugin.show(
|
await flutterLocalNotificationsPlugin.show(
|
||||||
1, title, 'Open app to read messages', platformChannelSpecifics,
|
1, title, l10n.openAppToReadMessages, platformChannelSpecifics,
|
||||||
payload: roomID);
|
payload: roomID);
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
debugPrint("[Push] Error while processing background notification: " +
|
debugPrint("[Push] Error while processing background notification: " +
|
||||||
|
|
Loading…
Reference in a new issue