Use MatrixClientPeg::safeGet for strict typing (#10989)

This commit is contained in:
Michael Telatynski 2023-06-21 17:29:44 +01:00 committed by GitHub
parent d64018ce26
commit 9b5b053148
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
60 changed files with 225 additions and 203 deletions

View file

@ -278,7 +278,7 @@ export function handleInvalidStoreError(e: InvalidStoreError): Promise<void> | v
}
})
.then(() => {
return MatrixClientPeg.get().store.deleteAllData();
return MatrixClientPeg.safeGet().store.deleteAllData();
})
.then(() => {
PlatformPeg.get()?.reload();
@ -541,8 +541,8 @@ export async function setLoggedIn(credentials: IMatrixClientCreds): Promise<Matr
* @returns {Promise} promise which resolves to the new MatrixClient once it has been started
*/
export async function hydrateSession(credentials: IMatrixClientCreds): Promise<MatrixClient> {
const oldUserId = MatrixClientPeg.get().getUserId();
const oldDeviceId = MatrixClientPeg.get().getDeviceId();
const oldUserId = MatrixClientPeg.safeGet().getUserId();
const oldDeviceId = MatrixClientPeg.safeGet().getDeviceId();
stopMatrixClient(); // unsets MatrixClientPeg.get()
localStorage.removeItem("mx_soft_logout");
@ -603,7 +603,7 @@ async function doSetLoggedIn(credentials: IMatrixClientCreds, clearStorageEnable
}
MatrixClientPeg.replaceUsingCreds(credentials);
const client = MatrixClientPeg.get();
const client = MatrixClientPeg.safeGet();
setSentryUser(credentials.userId);
@ -724,7 +724,7 @@ export function logout(): void {
PosthogAnalytics.instance.logout();
if (MatrixClientPeg.get().isGuest()) {
if (MatrixClientPeg.get()!.isGuest()) {
// logout doesn't work for guest sessions
// Also we sometimes want to re-log in a guest session if we abort the login.
// defer until next tick because it calls a synchronous dispatch, and we are likely here from a dispatch.
@ -733,7 +733,7 @@ export function logout(): void {
}
_isLoggingOut = true;
const client = MatrixClientPeg.get();
const client = MatrixClientPeg.get()!;
PlatformPeg.get()?.destroyPickleKey(client.getSafeUserId(), client.getDeviceId() ?? "");
client.logout(true).then(onLoggedOut, (err) => {
// Just throwing an error here is going to be very unhelpful