Refactoring
This commit is contained in:
parent
a861f221a3
commit
6513b0eac7
2 changed files with 5 additions and 52 deletions
|
@ -36,7 +36,6 @@ class I18n {
|
||||||
}
|
}
|
||||||
|
|
||||||
static I18n of(BuildContext context) {
|
static I18n of(BuildContext context) {
|
||||||
if (context == null) return I18n('en');
|
|
||||||
return Localizations.of<I18n>(context, I18n);
|
return Localizations.of<I18n>(context, I18n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,6 +108,7 @@ 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 ? I18n('en') : I18n.of(context);
|
||||||
|
|
||||||
// Get the client
|
// Get the client
|
||||||
Client client;
|
Client client;
|
||||||
|
@ -154,9 +155,9 @@ abstract class FirebaseController {
|
||||||
|
|
||||||
// Calculate title
|
// Calculate title
|
||||||
final String title = unread > 1
|
final String title = unread > 1
|
||||||
? I18n.of(context)
|
? i18n.unreadMessagesInChats(
|
||||||
.unreadMessagesInChats(unreadEvents.toString(), unread.toString())
|
unreadEvents.toString(), unread.toString())
|
||||||
: I18n.of(context).unreadMessages(unreadEvents.toString());
|
: i18n.unreadMessages(unreadEvents.toString());
|
||||||
|
|
||||||
// Calculate the body
|
// Calculate the body
|
||||||
final String body = event.getLocalizedBody(context,
|
final String body = event.getLocalizedBody(context,
|
||||||
|
@ -195,7 +196,7 @@ abstract class FirebaseController {
|
||||||
),
|
),
|
||||||
importance: Importance.Max,
|
importance: Importance.Max,
|
||||||
priority: Priority.High,
|
priority: Priority.High,
|
||||||
ticker: I18n.of(context).newMessageInFluffyChat);
|
ticker: i18n.newMessageInFluffyChat);
|
||||||
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
|
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
|
||||||
var platformChannelSpecifics = NotificationDetails(
|
var platformChannelSpecifics = NotificationDetails(
|
||||||
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
|
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
|
||||||
|
@ -205,57 +206,10 @@ abstract class FirebaseController {
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
debugPrint("[Push] Error while processing notification: " +
|
debugPrint("[Push] Error while processing notification: " +
|
||||||
exception.toString());
|
exception.toString());
|
||||||
return _handleOnBackgroundMessage(message);
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<dynamic> _handleOnBackgroundMessage(
|
|
||||||
Map<String, dynamic> message) async {
|
|
||||||
try {
|
|
||||||
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
|
||||||
FlutterLocalNotificationsPlugin();
|
|
||||||
// Init notifications framework
|
|
||||||
var initializationSettingsAndroid =
|
|
||||||
AndroidInitializationSettings('notifications_icon');
|
|
||||||
var initializationSettingsIOS = IOSInitializationSettings();
|
|
||||||
var initializationSettings = InitializationSettings(
|
|
||||||
initializationSettingsAndroid, initializationSettingsIOS);
|
|
||||||
await flutterLocalNotificationsPlugin.initialize(initializationSettings);
|
|
||||||
|
|
||||||
// Notification data and matrix data
|
|
||||||
Map<dynamic, dynamic> data = message['data'] ?? message;
|
|
||||||
String eventID = data["event_id"];
|
|
||||||
String roomID = data["room_id"];
|
|
||||||
final int unread = data.containsKey("counts")
|
|
||||||
? json.decode(data["counts"])["unread"]
|
|
||||||
: 1;
|
|
||||||
await flutterLocalNotificationsPlugin.cancelAll();
|
|
||||||
if (unread == 0 || roomID == null || eventID == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Display notification
|
|
||||||
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
|
|
||||||
'fluffychat_push',
|
|
||||||
'FluffyChat push channel',
|
|
||||||
'Push notifications for FluffyChat',
|
|
||||||
importance: Importance.Max,
|
|
||||||
priority: Priority.High);
|
|
||||||
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
|
|
||||||
var platformChannelSpecifics = NotificationDetails(
|
|
||||||
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
|
|
||||||
final String title = "$unread ungelesene Unterhaltungen";
|
|
||||||
await flutterLocalNotificationsPlugin.show(1, title,
|
|
||||||
'App öffnen, um Nachricht zu entschlüsseln', platformChannelSpecifics,
|
|
||||||
payload: roomID);
|
|
||||||
} catch (exception) {
|
|
||||||
debugPrint("[Push] Error while processing background notification: " +
|
|
||||||
exception.toString());
|
|
||||||
}
|
|
||||||
return Future<void>.value();
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<String> downloadAndSaveAvatar(Uri content, Client client,
|
static Future<String> downloadAndSaveAvatar(Uri content, Client client,
|
||||||
{int width, int height}) async {
|
{int width, int height}) async {
|
||||||
final bool thumbnail = width == null && height == null ? false : true;
|
final bool thumbnail = width == null && height == null ? false : true;
|
||||||
|
|
Loading…
Add table
Reference in a new issue