chore: Follow up router fixes
This commit is contained in:
parent
0c69ce0552
commit
b7dac8365a
8 changed files with 54 additions and 67 deletions
|
|
@ -28,13 +28,13 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_app_badger/flutter_app_badger.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:unifiedpush/unifiedpush.dart';
|
||||
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension.dart';
|
||||
import 'package:fluffychat/utils/push_helper.dart';
|
||||
import 'package:fluffychat/widgets/fluffy_chat_app.dart';
|
||||
import '../config/app_config.dart';
|
||||
import '../config/setting_keys.dart';
|
||||
import '../widgets/matrix.dart';
|
||||
|
|
@ -53,15 +53,15 @@ class BackgroundPush {
|
|||
FlutterLocalNotificationsPlugin();
|
||||
Client client;
|
||||
MatrixState? matrix;
|
||||
BuildContext? get context => matrix?.navigatorContext;
|
||||
String? _fcmToken;
|
||||
void Function(String errorMsg, {Uri? link})? onFcmError;
|
||||
L10n? l10n;
|
||||
Store? _store;
|
||||
Store get store => _store ??= Store();
|
||||
Future<void> loadLocale() async {
|
||||
final context = matrix?.context;
|
||||
// inspired by _lookupL10n in .dart_tool/flutter_gen/gen_l10n/l10n.dart
|
||||
l10n ??= (context != null ? L10n.of(context!) : null) ??
|
||||
l10n ??= (context != null ? L10n.of(context) : null) ??
|
||||
(await L10n.delegate.load(PlatformDispatcher.instance.locale));
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +77,6 @@ class BackgroundPush {
|
|||
onRoomSync ??= client.onSync.stream
|
||||
.where((s) => s.hasRoomUpdate)
|
||||
.listen((s) => _onClearingPush(getFromServer: false));
|
||||
final context = this.context;
|
||||
firebase?.setListeners(
|
||||
onMessage: (message) => pushHelper(
|
||||
PushNotification.fromJson(
|
||||
|
|
@ -85,9 +84,7 @@ class BackgroundPush {
|
|||
),
|
||||
client: client,
|
||||
l10n: l10n,
|
||||
activeRoomId: context == null
|
||||
? null
|
||||
: GoRouterState.of(context).pathParameters['roomid'],
|
||||
activeRoomId: matrix?.activeRoomId,
|
||||
onSelectNotification: goToRoom,
|
||||
),
|
||||
);
|
||||
|
|
@ -231,7 +228,7 @@ class BackgroundPush {
|
|||
Logs().d("SetupPush");
|
||||
if (client.onLoginStateChanged.value != LoginState.loggedIn ||
|
||||
!PlatformInfos.isMobile ||
|
||||
context == null) {
|
||||
matrix == null) {
|
||||
return;
|
||||
}
|
||||
// Do not setup unifiedpush if this has been initialized by
|
||||
|
|
@ -261,7 +258,7 @@ class BackgroundPush {
|
|||
}
|
||||
|
||||
Future<void> _noFcmWarning() async {
|
||||
if (context == null) {
|
||||
if (matrix == null) {
|
||||
return;
|
||||
}
|
||||
if (await store.getItemBool(SettingKeys.showNoGoogle, true) == true) {
|
||||
|
|
@ -315,14 +312,15 @@ class BackgroundPush {
|
|||
?.content
|
||||
.tryGet<String>('type') ==
|
||||
ClientStoriesExtension.storiesRoomType;
|
||||
context?.go(['', isStory ? 'stories' : 'rooms', roomId].join('/'));
|
||||
FluffyChatApp.router
|
||||
.go(['', isStory ? 'stories' : 'rooms', roomId].join('/'));
|
||||
} catch (e, s) {
|
||||
Logs().e('[Push] Failed to open room', e, s);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setupUp() async {
|
||||
await UnifiedPush.registerAppWithDialog(context!);
|
||||
await UnifiedPush.registerAppWithDialog(matrix!.context);
|
||||
}
|
||||
|
||||
Future<void> _newUpEndpoint(String newEndpoint, String i) async {
|
||||
|
|
@ -391,14 +389,11 @@ class BackgroundPush {
|
|||
);
|
||||
// UP may strip the devices list
|
||||
data['devices'] ??= [];
|
||||
final context = this.context;
|
||||
await pushHelper(
|
||||
PushNotification.fromJson(data),
|
||||
client: client,
|
||||
l10n: l10n,
|
||||
activeRoomId: context == null
|
||||
? null
|
||||
: GoRouterState.of(context).pathParameters['roomid'],
|
||||
activeRoomId: matrix?.activeRoomId,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import 'package:fluffychat/widgets/matrix.dart';
|
|||
|
||||
extension UiaRequestManager on MatrixState {
|
||||
Future uiaRequestHandler(UiaRequest uiaRequest) async {
|
||||
final l10n = L10n.of(navigatorContext)!;
|
||||
final l10n = L10n.of(context)!;
|
||||
try {
|
||||
if (uiaRequest.state != UiaRequestState.waitForUser ||
|
||||
uiaRequest.nextStages.isEmpty) {
|
||||
|
|
@ -22,7 +22,7 @@ extension UiaRequestManager on MatrixState {
|
|||
case AuthenticationTypes.password:
|
||||
final input = cachedPassword ??
|
||||
(await showTextInputDialog(
|
||||
context: navigatorContext,
|
||||
context: context,
|
||||
title: l10n.pleaseEnterYourPassword,
|
||||
okLabel: l10n.ok,
|
||||
cancelLabel: l10n.cancel,
|
||||
|
|
@ -49,7 +49,7 @@ extension UiaRequestManager on MatrixState {
|
|||
case AuthenticationTypes.emailIdentity:
|
||||
if (currentThreepidCreds == null) {
|
||||
return uiaRequest.cancel(
|
||||
UiaException(L10n.of(navigatorContext)!.serverRequiresEmail),
|
||||
UiaException(L10n.of(context)!.serverRequiresEmail),
|
||||
);
|
||||
}
|
||||
final auth = AuthenticationThreePidCreds(
|
||||
|
|
@ -63,7 +63,7 @@ extension UiaRequestManager on MatrixState {
|
|||
if (OkCancelResult.ok ==
|
||||
await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: navigatorContext,
|
||||
context: context,
|
||||
title: l10n.weSentYouAnEmail,
|
||||
message: l10n.pleaseClickOnLink,
|
||||
okLabel: l10n.iHaveClickedOnLink,
|
||||
|
|
@ -88,7 +88,7 @@ extension UiaRequestManager on MatrixState {
|
|||
await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
message: l10n.pleaseFollowInstructionsOnWeb,
|
||||
context: navigatorContext,
|
||||
context: context,
|
||||
okLabel: l10n.next,
|
||||
cancelLabel: l10n.cancel,
|
||||
)) {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class VoipPlugin with WidgetsBindingObserver implements WebRTCDelegate {
|
|||
late VoIP voip;
|
||||
ConnectivityResult? _currentConnectivity;
|
||||
OverlayEntry? overlayEntry;
|
||||
BuildContext get context => matrix.navigatorContext;
|
||||
BuildContext get context => matrix.context;
|
||||
|
||||
void _handleNetworkChanged(ConnectivityResult result) async {
|
||||
/// Got a new connectivity status!
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue