Skip to content

Commit

Permalink
TW-1193: Logout account and try logoutSSO
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev committed Dec 29, 2023
1 parent 8b587fd commit b7a69db
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 17 deletions.
18 changes: 14 additions & 4 deletions lib/config/go_routes/go_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ abstract class AppRoutes {
state.fullPath?.startsWith('/rooms/settings') == false
? AppAdaptiveScaffold(
body: AppAdaptiveScaffoldBody(
activeRoomId: state.pathParameters['roomid'],
args: AppAdaptiveScaffoldBodyArgs(
activeRoomId: state.pathParameters['roomid'],
),
),
secondaryBody: child,
)
Expand All @@ -160,9 +162,17 @@ abstract class AppRoutes {
!_responsive.isMobile(context)
? const ChatBlank()
: AppAdaptiveScaffoldBody(
activeRoomId: state.pathParameters['roomid'],
client:
state.extra is Client? ? state.extra as Client? : null,
args: AppAdaptiveScaffoldBodyArgs(
activeRoomId: state.pathParameters['roomid'],
client: state.extra is AppAdaptiveScaffoldBodyArgs
? (state.extra as AppAdaptiveScaffoldBodyArgs).client
: null,
isLogoutMultipleAccount:
state.extra is AppAdaptiveScaffoldBodyArgs
? (state.extra as AppAdaptiveScaffoldBodyArgs)
.isLogoutMultipleAccount
: false,
),
),
),
routes: [
Expand Down
5 changes: 4 additions & 1 deletion lib/pages/chat_list/chat_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,10 @@ class ChatListController extends State<ChatList>
@override
void didUpdateWidget(covariant ChatList oldWidget) {
Logs().d(
"ChatList::didUpdateWidget(): Client ${widget.newClient?.clientName}",
"ChatList::didUpdateWidget(): OldClient $activeClient",
);
Logs().d(
"ChatList::didUpdateWidget(): NewClient ${widget.newClient?.clientName}",
);
if (widget.newClient != activeClient) {
initSetActiveClient();
Expand Down
8 changes: 5 additions & 3 deletions lib/pages/settings_dashboard/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ class SettingsController extends State<Settings> with ConnectPageMixin {
OkCancelResult.cancel) {
return;
}
await tryLogoutSso(context);
final hiveCollectionToMDatabase = getIt.get<HiveCollectionToMDatabase>();
await hiveCollectionToMDatabase.clear();
final matrix = Matrix.of(context);
if (matrix.twakeIsSupported) {
await tryLogoutSso(context);
final hiveCollectionToMDatabase = getIt.get<HiveCollectionToMDatabase>();
await hiveCollectionToMDatabase.clear();
}
await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () async {
if (matrix.backgroundPush != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:equatable/equatable.dart';
import 'package:fluffychat/config/first_column_inner_routes.dart';
import 'package:fluffychat/pages/chat_list/client_chooser_button.dart';
import 'package:fluffychat/utils/extension/build_context_extension.dart';
Expand All @@ -13,14 +14,31 @@ typedef OnCloseSearchPage = Function();
typedef OnClientSelectedSetting = Function(Object object, BuildContext context);
typedef OnDestinationSelected = Function(int index);

class AppAdaptiveScaffoldBody extends StatefulWidget {
class AppAdaptiveScaffoldBodyArgs extends Equatable {
final String? activeRoomId;
final Client? client;
final bool isLogoutMultipleAccount;

const AppAdaptiveScaffoldBody({
super.key,
const AppAdaptiveScaffoldBodyArgs({
this.activeRoomId,
this.client,
this.isLogoutMultipleAccount = false,
});

@override
List<Object?> get props => [
activeRoomId,
client,
isLogoutMultipleAccount,
];
}

class AppAdaptiveScaffoldBody extends StatefulWidget {
final AppAdaptiveScaffoldBodyArgs args;

const AppAdaptiveScaffoldBody({
super.key,
required this.args,
});

@override
Expand Down Expand Up @@ -101,17 +119,35 @@ class AppAdaptiveScaffoldBodyController extends State<AppAdaptiveScaffoldBody> {
pageController.jumpToPage(activeNavigationBar.value.index);
}

void _onLogoutMultipleAccountSuccess(
covariant AppAdaptiveScaffoldBody oldWidget,
) {
Logs().d(
'AppAdaptiveScaffoldBodyController::_onLogoutMultipleAccountSuccess():oldWidget.isLogoutMultipleAccount: ${oldWidget.args.isLogoutMultipleAccount}',
);
Logs().d(
'AppAdaptiveScaffoldBodyController::_onLogoutMultipleAccountSuccess():newIsLogoutMultipleAccount: ${widget.args.isLogoutMultipleAccount}',
);
if (oldWidget.args.isLogoutMultipleAccount !=
widget.args.isLogoutMultipleAccount &&
widget.args.isLogoutMultipleAccount) {
activeNavigationBar.value = AdaptiveDestinationEnum.rooms;
pageController.jumpToPage(AdaptiveDestinationEnum.rooms.index);
}
}

MatrixState get matrix => Matrix.of(context);

@override
void initState() {
activeRoomIdNotifier.value = widget.activeRoomId;
activeRoomIdNotifier.value = widget.args.activeRoomId;
super.initState();
}

@override
void didUpdateWidget(covariant AppAdaptiveScaffoldBody oldWidget) {
activeRoomIdNotifier.value = widget.activeRoomId;
activeRoomIdNotifier.value = widget.args.activeRoomId;
_onLogoutMultipleAccountSuccess(oldWidget);
super.didUpdateWidget(oldWidget);
}

Expand All @@ -126,6 +162,6 @@ class AppAdaptiveScaffoldBodyController extends State<AppAdaptiveScaffoldBody> {
onDestinationSelected: onDestinationSelected,
onClientSelected: clientSelected,
onOpenSettings: _onOpenSettingsPage,
client: widget.client,
client: widget.args.client,
);
}
14 changes: 11 additions & 3 deletions lib/widgets/matrix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import 'package:fluffychat/utils/twake_snackbar.dart';
import 'package:fluffychat/utils/uia_request_manager.dart';
import 'package:fluffychat/utils/url_launcher.dart';
import 'package:fluffychat/utils/voip_plugin.dart';
import 'package:fluffychat/widgets/layouts/adaptive_layout/app_adaptive_scaffold_body.dart';
import 'package:fluffychat/widgets/twake_app.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -191,8 +192,10 @@ class MatrixState extends State<Matrix>
_registerSubs(_loginClientCandidate!.clientName);
TwakeApp.router.go(
'/rooms',
extra: getClientByName(
_loginClientCandidate!.clientName,
extra: AppAdaptiveScaffoldBodyArgs(
client: getClientByName(
_loginClientCandidate!.clientName,
),
),
);
_loginClientCandidate = null;
Expand Down Expand Up @@ -369,7 +372,12 @@ class MatrixState extends State<Matrix>
);

if (state != LoginState.loggedIn) {
TwakeApp.router.go('/rooms');
TwakeApp.router.go(
'/rooms',
extra: const AppAdaptiveScaffoldBodyArgs(
isLogoutMultipleAccount: true,
),
);
}
} else {
if (state == LoginState.loggedIn) {
Expand Down

0 comments on commit b7a69db

Please sign in to comment.