Skip to content

Commit 39adb55

Browse files
committed
fix: Click on notification does not open room
1 parent 8e6ab8a commit 39adb55

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

lib/utils/background_push.dart

+8-10
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension.
3636
import 'package:fluffychat/utils/push_helper.dart';
3737
import '../config/app_config.dart';
3838
import '../config/setting_keys.dart';
39+
import '../widgets/fluffy_chat_app.dart';
3940
import 'famedlysdk_store.dart';
4041
import 'platform_infos.dart';
4142

@@ -51,7 +52,7 @@ class BackgroundPush {
5152
FlutterLocalNotificationsPlugin();
5253
Client client;
5354
BuildContext? context;
54-
GlobalKey<VRouterState>? router;
55+
GlobalKey<VRouterState> get router => FluffyChatApp.routerKey;
5556
String? _fcmToken;
5657
void Function(String errorMsg, {Uri? link})? onFcmError;
5758
L10n? l10n;
@@ -82,7 +83,7 @@ class BackgroundPush {
8283
),
8384
client: client,
8485
l10n: l10n,
85-
activeRoomId: router?.currentState?.pathParameters['roomid'],
86+
activeRoomId: router.currentState?.pathParameters['roomid'],
8687
onSelectNotification: goToRoom,
8788
),
8889
);
@@ -103,15 +104,12 @@ class BackgroundPush {
103104

104105
factory BackgroundPush(
105106
Client client,
106-
BuildContext context,
107-
GlobalKey<VRouterState>? router, {
107+
BuildContext context, {
108108
final void Function(String errorMsg, {Uri? link})? onFcmError,
109109
}) {
110110
final instance = BackgroundPush.clientOnly(client);
111111
instance.context = context;
112112
// ignore: prefer_initializing_formals
113-
instance.router = router;
114-
// ignore: prefer_initializing_formals
115113
instance.onFcmError = onFcmError;
116114
return instance;
117115
}
@@ -233,7 +231,7 @@ class BackgroundPush {
233231
if (details == null ||
234232
!details.didNotificationLaunchApp ||
235233
_wentToRoomOnStartup ||
236-
router == null) {
234+
router.currentState == null) {
237235
return;
238236
}
239237
_wentToRoomOnStartup = true;
@@ -285,7 +283,7 @@ class BackgroundPush {
285283
try {
286284
final roomId = response?.payload;
287285
Logs().v('[Push] Attempting to go to room $roomId...');
288-
if (router == null || roomId == null) {
286+
if (router.currentState == null || roomId == null) {
289287
return;
290288
}
291289
await client.roomsLoading;
@@ -296,7 +294,7 @@ class BackgroundPush {
296294
?.content
297295
.tryGet<String>('type') ==
298296
ClientStoriesExtension.storiesRoomType;
299-
router!.currentState!.toSegments([isStory ? 'stories' : 'rooms', roomId]);
297+
router.currentState!.toSegments([isStory ? 'stories' : 'rooms', roomId]);
300298
} catch (e, s) {
301299
Logs().e('[Push] Failed to open room', e, s);
302300
}
@@ -376,7 +374,7 @@ class BackgroundPush {
376374
PushNotification.fromJson(data),
377375
client: client,
378376
l10n: l10n,
379-
activeRoomId: router?.currentState?.pathParameters['roomid'],
377+
activeRoomId: router.currentState?.pathParameters['roomid'],
380378
);
381379
}
382380

lib/widgets/fluffy_chat_app.dart

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ class FluffyChatAppState extends State<FluffyChatApp> {
7878
builder: (context, child) => Matrix(
7979
key: FluffyChatApp.matrixKey,
8080
context: context,
81-
router: FluffyChatApp.routerKey,
8281
clients: widget.clients,
8382
child: child,
8483
),

lib/widgets/matrix.dart

+7-8
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ import '../pages/key_verification/key_verification_dialog.dart';
3333
import '../utils/account_bundles.dart';
3434
import '../utils/background_push.dart';
3535
import '../utils/famedlysdk_store.dart';
36+
import 'fluffy_chat_app.dart';
3637
import 'local_notifications_extension.dart';
3738

3839
// import 'package:flutter_secure_storage/flutter_secure_storage.dart';
3940

4041
class Matrix extends StatefulWidget {
4142
final Widget? child;
4243

43-
final GlobalKey<VRouterState>? router;
44+
GlobalKey<VRouterState> get router => FluffyChatApp.routerKey;
4445

4546
final BuildContext context;
4647

@@ -50,7 +51,6 @@ class Matrix extends StatefulWidget {
5051

5152
const Matrix({
5253
this.child,
53-
required this.router,
5454
required this.context,
5555
required this.clients,
5656
this.queryParameters,
@@ -177,7 +177,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
177177
ClientManager.addClientNameToStore(_loginClientCandidate!.clientName);
178178
_registerSubs(_loginClientCandidate!.clientName);
179179
_loginClientCandidate = null;
180-
widget.router!.currentState!.to('/rooms');
180+
widget.router.currentState!.to('/rooms');
181181
});
182182
return candidate;
183183
}
@@ -334,15 +334,15 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
334334
);
335335

336336
if (state != LoginState.loggedIn) {
337-
widget.router?.currentState?.to(
337+
widget.router.currentState?.to(
338338
'/rooms',
339-
queryParameters: widget.router?.currentState?.queryParameters ?? {},
339+
queryParameters: widget.router.currentState?.queryParameters ?? {},
340340
);
341341
}
342342
} else {
343-
widget.router?.currentState?.to(
343+
widget.router.currentState?.to(
344344
state == LoginState.loggedIn ? '/rooms' : '/home',
345-
queryParameters: widget.router?.currentState?.queryParameters ?? {},
345+
queryParameters: widget.router.currentState?.queryParameters ?? {},
346346
);
347347
}
348348
});
@@ -407,7 +407,6 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
407407
backgroundPush = BackgroundPush(
408408
client,
409409
context,
410-
widget.router,
411410
onFcmError: (errorMsg, {Uri? link}) async {
412411
final result = await showOkCancelAlertDialog(
413412
barrierDismissible: true,

0 commit comments

Comments
 (0)