Skip to content

Commit

Permalink
Clean up isAccountExpired
Browse files Browse the repository at this point in the history
  • Loading branch information
estellecomment committed Apr 9, 2024
1 parent 44c9e96 commit 07f4fe7
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/tchap/util/TchapUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { findMapStyleUrl } from "matrix-react-sdk/src/utils/location";

import TchapApi from "./TchapApi";
import { ClientConfig } from "~tchap-web/yarn-linked-dependencies/matrix-js-sdk/src/autodiscovery";
import { MatrixError } from "~tchap-web/yarn-linked-dependencies/matrix-js-sdk/src/http-api";

/**
* Tchap utils.
Expand Down Expand Up @@ -220,19 +221,20 @@ export default class TchapUtils {
}

/**
* Verify if the account is expired.
* It executes an API call and check that it receives a ORG_MATRIX_EXPIRED_ACCOUNT
* The API invoked is getProfileInfo()
* @param matrixId the account matrix Id
* Verify if the currently logged in account is expired.
* It executes an API call (to getProfileInfo) and checks whether the call throws a ORG_MATRIX_EXPIRED_ACCOUNT
* @returns true if account is expired, false otherwise
*/
static async isAccountExpired(matrixId?: string): Promise<boolean> {
static async isAccountExpired(): Promise<boolean> {
const client = MatrixClientPeg.safeGet(); // todo(estelle) throws if client is not logged in. Is that what we want ?
const matrixId: string | null = client.credentials.userId;
if (!matrixId) {
matrixId = MatrixClientPeg.getCredentials().userId;
// throw ? return ? todo(estelle)
}
try {
await MatrixClientPeg.get().getProfileInfo(matrixId);
} catch (err) {
await client.getProfileInfo(matrixId!);
} catch (error) {
const err = error as MatrixError;
if (err.errcode === "ORG_MATRIX_EXPIRED_ACCOUNT") {
return true;
}
Expand Down

0 comments on commit 07f4fe7

Please sign in to comment.