fix: Click on notification does not open room

This commit is contained in:
krille-chan 2023-08-06 17:42:28 +02:00
parent 8e6ab8a7b3
commit 39adb55b3d
No known key found for this signature in database
3 changed files with 15 additions and 19 deletions

View file

@ -36,6 +36,7 @@ import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension.
import 'package:fluffychat/utils/push_helper.dart';
import '../config/app_config.dart';
import '../config/setting_keys.dart';
import '../widgets/fluffy_chat_app.dart';
import 'famedlysdk_store.dart';
import 'platform_infos.dart';
@ -51,7 +52,7 @@ class BackgroundPush {
FlutterLocalNotificationsPlugin();
Client client;
BuildContext? context;
GlobalKey<VRouterState>? router;
GlobalKey<VRouterState> get router => FluffyChatApp.routerKey;
String? _fcmToken;
void Function(String errorMsg, {Uri? link})? onFcmError;
L10n? l10n;
@ -82,7 +83,7 @@ class BackgroundPush {
),
client: client,
l10n: l10n,
activeRoomId: router?.currentState?.pathParameters['roomid'],
activeRoomId: router.currentState?.pathParameters['roomid'],
onSelectNotification: goToRoom,
),
);
@ -103,15 +104,12 @@ class BackgroundPush {
factory BackgroundPush(
Client client,
BuildContext context,
GlobalKey<VRouterState>? router, {
BuildContext context, {
final void Function(String errorMsg, {Uri? link})? onFcmError,
}) {
final instance = BackgroundPush.clientOnly(client);
instance.context = context;
// ignore: prefer_initializing_formals
instance.router = router;
// ignore: prefer_initializing_formals
instance.onFcmError = onFcmError;
return instance;
}
@ -233,7 +231,7 @@ class BackgroundPush {
if (details == null ||
!details.didNotificationLaunchApp ||
_wentToRoomOnStartup ||
router == null) {
router.currentState == null) {
return;
}
_wentToRoomOnStartup = true;
@ -285,7 +283,7 @@ class BackgroundPush {
try {
final roomId = response?.payload;
Logs().v('[Push] Attempting to go to room $roomId...');
if (router == null || roomId == null) {
if (router.currentState == null || roomId == null) {
return;
}
await client.roomsLoading;
@ -296,7 +294,7 @@ class BackgroundPush {
?.content
.tryGet<String>('type') ==
ClientStoriesExtension.storiesRoomType;
router!.currentState!.toSegments([isStory ? 'stories' : 'rooms', roomId]);
router.currentState!.toSegments([isStory ? 'stories' : 'rooms', roomId]);
} catch (e, s) {
Logs().e('[Push] Failed to open room', e, s);
}
@ -376,7 +374,7 @@ class BackgroundPush {
PushNotification.fromJson(data),
client: client,
l10n: l10n,
activeRoomId: router?.currentState?.pathParameters['roomid'],
activeRoomId: router.currentState?.pathParameters['roomid'],
);
}

View file

@ -78,7 +78,6 @@ class FluffyChatAppState extends State<FluffyChatApp> {
builder: (context, child) => Matrix(
key: FluffyChatApp.matrixKey,
context: context,
router: FluffyChatApp.routerKey,
clients: widget.clients,
child: child,
),

View file

@ -33,6 +33,7 @@ import '../pages/key_verification/key_verification_dialog.dart';
import '../utils/account_bundles.dart';
import '../utils/background_push.dart';
import '../utils/famedlysdk_store.dart';
import 'fluffy_chat_app.dart';
import 'local_notifications_extension.dart';
// import 'package:flutter_secure_storage/flutter_secure_storage.dart';
@ -40,7 +41,7 @@ import 'local_notifications_extension.dart';
class Matrix extends StatefulWidget {
final Widget? child;
final GlobalKey<VRouterState>? router;
GlobalKey<VRouterState> get router => FluffyChatApp.routerKey;
final BuildContext context;
@ -50,7 +51,6 @@ class Matrix extends StatefulWidget {
const Matrix({
this.child,
required this.router,
required this.context,
required this.clients,
this.queryParameters,
@ -177,7 +177,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
ClientManager.addClientNameToStore(_loginClientCandidate!.clientName);
_registerSubs(_loginClientCandidate!.clientName);
_loginClientCandidate = null;
widget.router!.currentState!.to('/rooms');
widget.router.currentState!.to('/rooms');
});
return candidate;
}
@ -334,15 +334,15 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
);
if (state != LoginState.loggedIn) {
widget.router?.currentState?.to(
widget.router.currentState?.to(
'/rooms',
queryParameters: widget.router?.currentState?.queryParameters ?? {},
queryParameters: widget.router.currentState?.queryParameters ?? {},
);
}
} else {
widget.router?.currentState?.to(
widget.router.currentState?.to(
state == LoginState.loggedIn ? '/rooms' : '/home',
queryParameters: widget.router?.currentState?.queryParameters ?? {},
queryParameters: widget.router.currentState?.queryParameters ?? {},
);
}
});
@ -407,7 +407,6 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
backgroundPush = BackgroundPush(
client,
context,
widget.router,
onFcmError: (errorMsg, {Uri? link}) async {
final result = await showOkCancelAlertDialog(
barrierDismissible: true,