Skip to content

Commit

Permalink
TW-1878: Fix can't open notification when open Media in chat details
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev authored and hoangdat committed Sep 13, 2024
1 parent 2c905f8 commit 5558fd5
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 20 deletions.
22 changes: 11 additions & 11 deletions lib/pages/chat_list/receive_sharing_intent_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,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';
Expand Down Expand Up @@ -40,11 +42,17 @@ mixin ReceiveSharingIntentMixin<T extends StatefulWidget> on State<T> {
}

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(
Expand All @@ -54,14 +62,6 @@ mixin ReceiveSharingIntentMixin<T extends StatefulWidget> on State<T> {
);
}

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)) {
Expand Down
32 changes: 24 additions & 8 deletions lib/utils/background_push.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -626,21 +628,35 @@ class BackgroundPush {
);
}

void _clearAllNavigatorAvailable({
Future<void> _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<void> _clearAllNavigatorAvailable({
String? roomId,
}) {
}) async {
Logs().d(
"BackgroundPush:: - Current active room id ${TwakeApp.router.activeRoomId}",
);
if (isCurrentRoomActive(roomId)) {
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -151,6 +152,14 @@ class AppAdaptiveScaffoldBodyController extends State<AppAdaptiveScaffoldBody>
});
}

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
Expand Down Expand Up @@ -185,6 +194,10 @@ class AppAdaptiveScaffoldBodyController extends State<AppAdaptiveScaffoldBody>
widget.args is SwitchActiveAccountBodyArgs) {
_handleSwitchAccount(oldWidget);
}

if (widget.args is ReceiveContentArgs) {
_handleReceiveContent(widget.args as ReceiveContentArgs);
}
super.didUpdateWidget(oldWidget);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
17 changes: 17 additions & 0 deletions lib/widgets/layouts/agruments/receive_content_args.dart
Original file line number Diff line number Diff line change
@@ -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<Object?> get props => [
newActiveClient,
activeDestination,
];
}
6 changes: 6 additions & 0 deletions lib/widgets/twake_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 5558fd5

Please sign in to comment.