feat: Notification actions on android
This commit is contained in:
parent
662a4ee17d
commit
2e07b7bcf1
4 changed files with 112 additions and 26 deletions
|
|
@ -32,6 +32,7 @@ import 'package:unifiedpush/unifiedpush.dart';
|
|||
import 'package:unifiedpush_ui/unifiedpush_ui.dart';
|
||||
|
||||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/utils/notification_background_handler.dart';
|
||||
import 'package:fluffychat/utils/push_helper.dart';
|
||||
import 'package:fluffychat/widgets/fluffy_chat_app.dart';
|
||||
import '../config/app_config.dart';
|
||||
|
|
@ -77,7 +78,12 @@ class BackgroundPush {
|
|||
android: AndroidInitializationSettings('notifications_icon'),
|
||||
iOS: DarwinInitializationSettings(),
|
||||
),
|
||||
onDidReceiveNotificationResponse: goToRoom,
|
||||
onDidReceiveNotificationResponse: (response) => notificationTap(
|
||||
response,
|
||||
client: client,
|
||||
router: FluffyChatApp.router,
|
||||
),
|
||||
onDidReceiveBackgroundNotificationResponse: notificationTapBackground,
|
||||
);
|
||||
Logs().v('Flutter Local Notifications initialized');
|
||||
//<GOOGLE_SERVICES>firebase.setListeners(
|
||||
|
|
@ -278,7 +284,14 @@ class BackgroundPush {
|
|||
return;
|
||||
}
|
||||
_wentToRoomOnStartup = true;
|
||||
goToRoom(details.notificationResponse);
|
||||
final response = details.notificationResponse;
|
||||
if (response != null) {
|
||||
notificationTap(
|
||||
response,
|
||||
client: client,
|
||||
router: FluffyChatApp.router,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -323,30 +336,6 @@ class BackgroundPush {
|
|||
);
|
||||
}
|
||||
|
||||
Future<void> goToRoom(NotificationResponse? response) async {
|
||||
try {
|
||||
final roomId = response?.payload;
|
||||
Logs().v('[Push] Attempting to go to room $roomId...');
|
||||
if (roomId == null) {
|
||||
return;
|
||||
}
|
||||
await client.roomsLoading;
|
||||
await client.accountDataLoading;
|
||||
if (client.getRoomById(roomId) == null) {
|
||||
await client
|
||||
.waitForRoomInSync(roomId)
|
||||
.timeout(const Duration(seconds: 30));
|
||||
}
|
||||
FluffyChatApp.router.go(
|
||||
client.getRoomById(roomId)?.membership == Membership.invite
|
||||
? '/rooms'
|
||||
: '/rooms/$roomId',
|
||||
);
|
||||
} catch (e, s) {
|
||||
Logs().e('[Push] Failed to open room', e, s);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setupUp() async {
|
||||
await UnifiedPushUi(matrix!.context, ["default"], UPFunctions())
|
||||
.registerAppWithDialog();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue