refactor: make sure ensureNotSoftLoggedOut does not run multiple times
This commit is contained in:
parent
3f8a4c8189
commit
5a79aa9536
|
|
@ -1823,19 +1823,25 @@ class Client extends MatrixApi {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void>? _handleSoftLogoutFuture;
|
||||||
|
|
||||||
Future<void> _handleSoftLogout() async {
|
Future<void> _handleSoftLogout() async {
|
||||||
final onSoftLogout = this.onSoftLogout;
|
final onSoftLogout = this.onSoftLogout;
|
||||||
if (onSoftLogout == null) return;
|
if (onSoftLogout == null) return;
|
||||||
|
|
||||||
onLoginStateChanged.add(LoginState.softLoggedOut);
|
_handleSoftLogoutFuture ??= () async {
|
||||||
try {
|
onLoginStateChanged.add(LoginState.softLoggedOut);
|
||||||
await onSoftLogout(this);
|
try {
|
||||||
onLoginStateChanged.add(LoginState.loggedIn);
|
await onSoftLogout(this);
|
||||||
} catch (e, s) {
|
onLoginStateChanged.add(LoginState.loggedIn);
|
||||||
Logs().w('Unable to refresh session after soft logout', e, s);
|
} catch (e, s) {
|
||||||
await clear();
|
Logs().w('Unable to refresh session after soft logout', e, s);
|
||||||
rethrow;
|
await clear();
|
||||||
}
|
rethrow;
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
await _handleSoftLogoutFuture;
|
||||||
|
_handleSoftLogoutFuture = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if the token expires in under [expiresIn] time and calls the
|
/// Checks if the token expires in under [expiresIn] time and calls the
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue