align app with main repo

This commit is contained in:
Salvatore Giordano
2021-02-01 10:18:43 +01:00
parent d1a7329824
commit f12ddb6a36
11 changed files with 449 additions and 344 deletions
+37 -5
View File
@@ -1,9 +1,11 @@
import 'dart:io';
import 'package:flutter_apns/flutter_apns.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart'
hide Message;
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
void showLocalNotification(Event event) async {
if (event.message == null) return;
void showLocalNotification(Message message, ChannelModel channel) async {
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
final initializationSettingsAndroid =
AndroidInitializationSettings('launch_background');
@@ -14,9 +16,9 @@ void showLocalNotification(Event event) async {
);
await flutterLocalNotificationsPlugin.initialize(initializationSettings);
await flutterLocalNotificationsPlugin.show(
event.message.id.hashCode,
event.message.user.name,
event.message.text,
message.id.hashCode,
'${message.user.name} @ ${channel.name}',
message.text,
NotificationDetails(
android: AndroidNotificationDetails(
'message channel',
@@ -29,3 +31,33 @@ void showLocalNotification(Event event) async {
),
);
}
Future backgroundHandler(Map<String, dynamic> notification) async {
print('new notification ${notification}');
final messageId = notification['data']['id'];
final notificationData =
await NotificationService.getAndStoreMessage(messageId);
showLocalNotification(
notificationData.message,
notificationData.channel,
);
}
void initNotifications(Client client) {
final connector = createPushConnector();
connector.configure(
onBackgroundMessage: backgroundHandler,
);
connector.requestNotificationPermissions();
connector.token.addListener(() {
if (connector.token.value != null) {
client.addDevice(
connector.token.value,
Platform.isAndroid ? PushProvider.firebase : PushProvider.apn,
);
}
});
}