diff --git a/lib/pages/chat_list/receive_sharing_intent_mixin.dart b/lib/pages/chat_list/receive_sharing_intent_mixin.dart index 838da4d041..537faf38e6 100644 --- a/lib/pages/chat_list/receive_sharing_intent_mixin.dart +++ b/lib/pages/chat_list/receive_sharing_intent_mixin.dart @@ -3,6 +3,8 @@ import 'package:fluffychat/pages/share/share.dart'; import 'package:fluffychat/presentation/extensions/shared_media_file_extension.dart'; import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/url_launcher.dart'; +import 'package:fluffychat/widgets/layouts/agruments/receive_content_args.dart'; +import 'package:fluffychat/widgets/layouts/enum/adaptive_destinations_enum.dart'; import 'package:fluffychat/widgets/twake_app.dart'; import 'package:fluffychat/widgets/matrix.dart'; import 'package:flutter/material.dart'; @@ -40,11 +42,17 @@ mixin ReceiveSharingIntentMixin on State { } void openSharePage() { - if (isCurrentPageIsNotRooms()) { + if (TwakeApp.isCurrentPageIsNotRooms()) { return; } - if (isCurrentPageIsInRooms()) { - TwakeApp.router.go('/rooms'); + if (TwakeApp.isCurrentPageIsInRooms()) { + TwakeApp.router.go( + '/rooms', + extra: ReceiveContentArgs( + newActiveClient: matrixState.client, + activeDestination: AdaptiveDestinationEnum.rooms, + ), + ); } Navigator.of(TwakeApp.routerKey.currentContext!).push( @@ -54,14 +62,6 @@ mixin ReceiveSharingIntentMixin on State { ); } - bool isCurrentPageIsInRooms() => - TwakeApp.router.routeInformationProvider.value.uri.path - .startsWith('/rooms/'); - - bool isCurrentPageIsNotRooms() => - !TwakeApp.router.routeInformationProvider.value.uri.path - .startsWith('/rooms'); - void _processIncomingSharedText(String? text) { if (text == null) return; if (_intentOpenApp(text)) { diff --git a/lib/utils/background_push.dart b/lib/utils/background_push.dart index e91a0e454c..1387ba1631 100644 --- a/lib/utils/background_push.dart +++ b/lib/utils/background_push.dart @@ -27,6 +27,8 @@ import 'package:fluffychat/presentation/extensions/client_extension.dart'; import 'package:fluffychat/presentation/extensions/go_router_extensions.dart'; import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension.dart'; import 'package:fluffychat/utils/push_helper.dart'; +import 'package:fluffychat/widgets/layouts/agruments/receive_content_args.dart'; +import 'package:fluffychat/widgets/layouts/enum/adaptive_destinations_enum.dart'; import 'package:fluffychat/widgets/twake_app.dart'; import 'package:fluffychat/widgets/matrix.dart'; import 'package:flutter/material.dart'; @@ -387,7 +389,7 @@ class BackgroundPush { }) async { try { Logs().v('[Push] Attempting to go to room $roomId...'); - _clearAllNavigatorAvailable(roomId: roomId); + await _clearAllNavigatorAvailable(roomId: roomId); if (_matrixState == null || roomId == null) { return; } @@ -626,9 +628,27 @@ class BackgroundPush { ); } - void _clearAllNavigatorAvailable({ + Future _handleInnerNavigation() async { + if (TwakeApp.isCurrentPageIsNotRooms()) { + return; + } + + if (TwakeApp.isCurrentPageIsInRooms()) { + Logs().d("BackgroundPush::_handleInnerNavigation(): CurrentRoomActive"); + TwakeApp.router.go( + '/rooms', + extra: ReceiveContentArgs( + newActiveClient: client, + activeDestination: AdaptiveDestinationEnum.rooms, + ), + ); + await Future.delayed(const Duration(milliseconds: 500)); + } + } + + Future _clearAllNavigatorAvailable({ String? roomId, - }) { + }) async { Logs().d( "BackgroundPush:: - Current active room id ${TwakeApp.router.activeRoomId}", ); @@ -636,11 +656,7 @@ class BackgroundPush { return; } - final canPopNavigation = TwakeApp.router.routerDelegate.canPop(); - Logs().d("BackgroundPush:: - Can pop other Navigation $canPopNavigation"); - if (canPopNavigation) { - TwakeApp.router.routerDelegate.pop(); - } + await _handleInnerNavigation(); } void _handleRedirectRoom( diff --git a/lib/widgets/layouts/adaptive_layout/app_adaptive_scaffold_body.dart b/lib/widgets/layouts/adaptive_layout/app_adaptive_scaffold_body.dart index 5ed048d058..b9520d3de3 100644 --- a/lib/widgets/layouts/adaptive_layout/app_adaptive_scaffold_body.dart +++ b/lib/widgets/layouts/adaptive_layout/app_adaptive_scaffold_body.dart @@ -11,6 +11,7 @@ import 'package:fluffychat/widgets/layouts/adaptive_layout/app_adaptive_scaffold import 'package:fluffychat/widgets/layouts/agruments/app_adaptive_scaffold_body_args.dart'; import 'package:fluffychat/widgets/layouts/agruments/logged_in_other_account_body_args.dart'; import 'package:fluffychat/widgets/layouts/agruments/logout_body_args.dart'; +import 'package:fluffychat/widgets/layouts/agruments/receive_content_args.dart'; import 'package:fluffychat/widgets/layouts/agruments/switch_active_account_body_args.dart'; import 'package:fluffychat/widgets/layouts/enum/adaptive_destinations_enum.dart'; import 'package:fluffychat/widgets/matrix.dart'; @@ -151,6 +152,14 @@ class AppAdaptiveScaffoldBodyController extends State }); } + void _handleReceiveContent(ReceiveContentArgs args) { + if (args.activeDestination == null) return; + if (args.activeDestination != AdaptiveDestinationEnum.rooms) { + activeNavigationBarNotifier.value = AdaptiveDestinationEnum.rooms; + pageController.jumpToPage(AdaptiveDestinationEnum.rooms.index); + } + } + MatrixState get matrix => Matrix.of(context); @override @@ -185,6 +194,10 @@ class AppAdaptiveScaffoldBodyController extends State widget.args is SwitchActiveAccountBodyArgs) { _handleSwitchAccount(oldWidget); } + + if (widget.args is ReceiveContentArgs) { + _handleReceiveContent(widget.args as ReceiveContentArgs); + } super.didUpdateWidget(oldWidget); } diff --git a/lib/widgets/layouts/agruments/app_adaptive_scaffold_body_args.dart b/lib/widgets/layouts/agruments/app_adaptive_scaffold_body_args.dart index c35cdc65d7..62f2bd2796 100644 --- a/lib/widgets/layouts/agruments/app_adaptive_scaffold_body_args.dart +++ b/lib/widgets/layouts/agruments/app_adaptive_scaffold_body_args.dart @@ -1,7 +1,7 @@ import 'package:equatable/equatable.dart'; import 'package:matrix/matrix.dart'; -abstract class AbsAppAdaptiveScaffoldBodyArgs extends Equatable { +abstract class AbsAppAdaptiveScaffoldBodyArgs with EquatableMixin { final Client? newActiveClient; const AbsAppAdaptiveScaffoldBodyArgs({ diff --git a/lib/widgets/layouts/agruments/receive_content_args.dart b/lib/widgets/layouts/agruments/receive_content_args.dart new file mode 100644 index 0000000000..c61cc5121b --- /dev/null +++ b/lib/widgets/layouts/agruments/receive_content_args.dart @@ -0,0 +1,17 @@ +import 'package:fluffychat/widgets/layouts/agruments/app_adaptive_scaffold_body_args.dart'; +import 'package:fluffychat/widgets/layouts/enum/adaptive_destinations_enum.dart'; + +class ReceiveContentArgs extends AbsAppAdaptiveScaffoldBodyArgs { + const ReceiveContentArgs({ + required super.newActiveClient, + this.activeDestination, + }); + + final AdaptiveDestinationEnum? activeDestination; + + @override + List get props => [ + newActiveClient, + activeDestination, + ]; +} diff --git a/lib/widgets/twake_app.dart b/lib/widgets/twake_app.dart index f998ad1de1..b3e3a9e175 100644 --- a/lib/widgets/twake_app.dart +++ b/lib/widgets/twake_app.dart @@ -44,6 +44,12 @@ class TwakeApp extends StatefulWidget { }, ); + static bool isCurrentPageIsInRooms() => + router.routeInformationProvider.value.uri.path.startsWith('/rooms/'); + + static bool isCurrentPageIsNotRooms() => + !router.routeInformationProvider.value.uri.path.startsWith('/rooms'); + @override TwakeAppState createState() => TwakeAppState(); }