chore: do not close login loading dialog until user has been redirected to chat list (#2451)
This commit is contained in:
parent
278219b163
commit
0ab43aa7f1
2 changed files with 54 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:flutter_web_auth_2/flutter_web_auth_2.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:universal_html/html.dart' as html;
|
||||
|
||||
|
|
@ -10,6 +11,7 @@ import 'package:fluffychat/config/app_config.dart';
|
|||
import 'package:fluffychat/pages/homeserver_picker/homeserver_picker.dart';
|
||||
import 'package:fluffychat/pangea/common/utils/firebase_analytics.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/widgets/fluffy_chat_app.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
Future<void> pangeaSSOLoginAction(
|
||||
|
|
@ -56,11 +58,37 @@ Future<void> pangeaSSOLoginAction(
|
|||
final token = Uri.parse(result).queryParameters['loginToken'];
|
||||
if (token?.isEmpty ?? false) return;
|
||||
|
||||
final redirect = client.onLoginStateChanged.stream
|
||||
.where((state) => state == LoginState.loggedIn)
|
||||
.first
|
||||
.then(
|
||||
(_) {
|
||||
final route = FluffyChatApp.router.state.fullPath;
|
||||
if (route == null || !route.contains("/rooms")) {
|
||||
context.go("/rooms");
|
||||
}
|
||||
},
|
||||
).timeout(const Duration(seconds: 30));
|
||||
|
||||
final loginRes = await client.login(
|
||||
LoginType.mLoginToken,
|
||||
token: token,
|
||||
initialDeviceDisplayName: PlatformInfos.clientName,
|
||||
onInitStateChanged: (state) {
|
||||
if (state == InitState.settingUpEncryption) {
|
||||
context.go("/rooms");
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
if (client.onLoginStateChanged.value == LoginState.loggedIn) {
|
||||
final route = FluffyChatApp.router.state.fullPath;
|
||||
if (route == null || !route.contains("/rooms")) {
|
||||
context.go("/rooms");
|
||||
}
|
||||
} else {
|
||||
await redirect;
|
||||
}
|
||||
|
||||
GoogleAnalytics.login(provider.name!, loginRes.userId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import 'package:fluffychat/pages/login/login.dart';
|
|||
import 'package:fluffychat/pangea/common/utils/firebase_analytics.dart';
|
||||
import 'package:fluffychat/pangea/login/widgets/p_sso_button.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/widgets/fluffy_chat_app.dart';
|
||||
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
|
|
@ -62,7 +63,21 @@ Future<void> _loginFuture({
|
|||
identifier = AuthenticationUserIdentifier(user: username);
|
||||
}
|
||||
|
||||
final loginRes = await matrix.getLoginClient().login(
|
||||
final client = matrix.getLoginClient();
|
||||
|
||||
final redirect = client.onLoginStateChanged.stream
|
||||
.where((state) => state == LoginState.loggedIn)
|
||||
.first
|
||||
.then(
|
||||
(_) {
|
||||
final route = FluffyChatApp.router.state.fullPath;
|
||||
if (route == null || !route.contains("/rooms")) {
|
||||
context.go("/rooms");
|
||||
}
|
||||
},
|
||||
).timeout(const Duration(seconds: 30));
|
||||
|
||||
final loginRes = await client.login(
|
||||
LoginType.mLoginPassword,
|
||||
identifier: identifier,
|
||||
// To stay compatible with older server versions
|
||||
|
|
@ -78,5 +93,15 @@ Future<void> _loginFuture({
|
|||
}
|
||||
},
|
||||
);
|
||||
|
||||
if (client.onLoginStateChanged.value == LoginState.loggedIn) {
|
||||
final route = FluffyChatApp.router.state.fullPath;
|
||||
if (route == null || !route.contains("/rooms")) {
|
||||
context.go("/rooms");
|
||||
}
|
||||
} else {
|
||||
await redirect;
|
||||
}
|
||||
|
||||
GoogleAnalytics.login("pangea", loginRes.userId);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue