Handle own profile 404 (#11319)
This commit is contained in:
parent
a47ee92094
commit
e33a7e41a4
2 changed files with 110 additions and 2 deletions
|
@ -19,6 +19,7 @@ import { User, UserEvent } from "matrix-js-sdk/src/models/user";
|
|||
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
|
||||
import { throttle } from "lodash";
|
||||
import { EventType } from "matrix-js-sdk/src/@types/event";
|
||||
import { MatrixError } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { ActionPayload } from "../dispatcher/payloads";
|
||||
import { AsyncStoreWithClient } from "./AsyncStoreWithClient";
|
||||
|
@ -45,7 +46,7 @@ export class OwnProfileStore extends AsyncStoreWithClient<IState> {
|
|||
|
||||
private monitoredUser: User | null = null;
|
||||
|
||||
private constructor() {
|
||||
public constructor() {
|
||||
// seed from localstorage because otherwise we won't get these values until a whole network
|
||||
// round-trip after the client is ready, and we often load widgets in that time, and we'd
|
||||
// and up passing them an incorrect display name
|
||||
|
@ -136,12 +137,32 @@ export class OwnProfileStore extends AsyncStoreWithClient<IState> {
|
|||
if (!this.matrixClient) return;
|
||||
// We specifically do not use the User object we stored for profile info as it
|
||||
// could easily be wrong (such as per-room instead of global profile).
|
||||
const profileInfo = await this.matrixClient.getProfileInfo(this.matrixClient.getSafeUserId());
|
||||
|
||||
let profileInfo: { displayname?: string; avatar_url?: string } = {
|
||||
displayname: undefined,
|
||||
avatar_url: undefined,
|
||||
};
|
||||
|
||||
try {
|
||||
profileInfo = await this.matrixClient.getProfileInfo(this.matrixClient.getSafeUserId());
|
||||
} catch (error: unknown) {
|
||||
if (!(error instanceof MatrixError) || error.errcode !== "M_NOT_FOUND") {
|
||||
/**
|
||||
* Raise any other error than M_NOT_FOUND.
|
||||
* M_NOT_FOUND could occur if there is no user profile.
|
||||
* {@link https://spec.matrix.org/v1.7/client-server-api/#get_matrixclientv3profileuserid}
|
||||
* We should then assume an empty profile, emit UPDATE_EVENT etc..
|
||||
*/
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
if (profileInfo.displayname) {
|
||||
window.localStorage.setItem(KEY_DISPLAY_NAME, profileInfo.displayname);
|
||||
} else {
|
||||
window.localStorage.removeItem(KEY_DISPLAY_NAME);
|
||||
}
|
||||
|
||||
if (profileInfo.avatar_url) {
|
||||
window.localStorage.setItem(KEY_AVATAR_URL, profileInfo.avatar_url);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue