fix: make pangea login state listener trigger on login (#3464)
This commit is contained in:
parent
e9af147257
commit
ab64e09506
2 changed files with 19 additions and 30 deletions
|
|
@ -58,7 +58,7 @@ class PangeaController {
|
|||
int? randomint;
|
||||
PangeaController({required this.matrix, required this.matrixState}) {
|
||||
_setup();
|
||||
_subscribeToStreams();
|
||||
_setLanguageStream();
|
||||
randomint = Random().nextInt(2000);
|
||||
}
|
||||
|
||||
|
|
@ -157,7 +157,7 @@ class PangeaController {
|
|||
}
|
||||
|
||||
/// check user information if not found then redirect to Date of birth page
|
||||
_handleLoginStateChange(LoginState state, String? userID) {
|
||||
void handleLoginStateChange(LoginState state, String? userID) {
|
||||
switch (state) {
|
||||
case LoginState.loggedOut:
|
||||
case LoginState.softLoggedOut:
|
||||
|
|
@ -173,6 +173,9 @@ class PangeaController {
|
|||
putAnalytics.initialize();
|
||||
getAnalytics.initialize();
|
||||
_setLanguageStream();
|
||||
|
||||
userController.reinitialize();
|
||||
subscriptionController.reinitialize();
|
||||
break;
|
||||
}
|
||||
if (state != LoginState.loggedIn) {
|
||||
|
|
@ -196,13 +199,6 @@ class PangeaController {
|
|||
await getAnalytics.initialize();
|
||||
}
|
||||
|
||||
void _subscribeToStreams() {
|
||||
final userID = matrixState.client.userID;
|
||||
matrixState.client.onLoginStateChanged.stream
|
||||
.listen((state) => _handleLoginStateChange(state, userID));
|
||||
_setLanguageStream();
|
||||
}
|
||||
|
||||
void _setLanguageStream() {
|
||||
_languageStream?.cancel();
|
||||
_languageStream = userController.stateStream.listen((update) {
|
||||
|
|
|
|||
|
|
@ -178,6 +178,12 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
.where((l) => l == LoginState.loggedIn)
|
||||
.first
|
||||
.then((_) {
|
||||
// #Pangea
|
||||
MatrixState.pangeaController.handleLoginStateChange(
|
||||
LoginState.loggedIn,
|
||||
_loginClientCandidate!.userID,
|
||||
);
|
||||
// Pangea#
|
||||
if (!widget.clients.contains(_loginClientCandidate)) {
|
||||
widget.clients.add(_loginClientCandidate!);
|
||||
}
|
||||
|
|
@ -312,6 +318,12 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
});
|
||||
onLoginStateChanged[name] ??=
|
||||
c.onLoginStateChanged.stream.listen((state) async {
|
||||
// #Pangea
|
||||
MatrixState.pangeaController.handleLoginStateChange(
|
||||
state,
|
||||
c.userID,
|
||||
);
|
||||
// Pangea#
|
||||
final loggedInWithMultipleClients = widget.clients.length > 1;
|
||||
if (state == LoginState.loggedOut) {
|
||||
_cancelSubs(c.clientName);
|
||||
|
|
@ -335,27 +347,8 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
FluffyChatApp.router.go('/rooms');
|
||||
}
|
||||
} else {
|
||||
// #Pangea
|
||||
if (state == LoginState.loggedIn) {
|
||||
final futures = [
|
||||
pangeaController.userController.reinitialize(),
|
||||
pangeaController.subscriptionController.reinitialize(),
|
||||
];
|
||||
await Future.wait(futures);
|
||||
}
|
||||
String routeDestination;
|
||||
if (state == LoginState.loggedIn) {
|
||||
routeDestination =
|
||||
await pangeaController.userController.isUserDataAvailableAndL2Set
|
||||
? '/rooms'
|
||||
: "/user_age";
|
||||
} else {
|
||||
routeDestination = '/home';
|
||||
}
|
||||
FluffyChatApp.router.go(routeDestination);
|
||||
// FluffyChatApp.router
|
||||
// .go(state == LoginState.loggedIn ? '/rooms' : '/home');
|
||||
// Pangea#
|
||||
FluffyChatApp.router
|
||||
.go(state == LoginState.loggedIn ? '/rooms' : '/home');
|
||||
}
|
||||
});
|
||||
onUiaRequest[name] ??= c.onUiaRequest.stream.listen(uiaRequestHandler);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue