Merge pull request #5770 from matrix-org/dbkr/jitsi_display_name
Fix username showing instead of display name in Jitsi widgets
This commit is contained in:
commit
8a765cf67a
1 changed files with 20 additions and 1 deletions
|
@ -29,13 +29,22 @@ interface IState {
|
||||||
avatarUrl?: string;
|
avatarUrl?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const KEY_DISPLAY_NAME = "mx_profile_displayname";
|
||||||
|
const KEY_AVATAR_URL = "mx_profile_avatar_url";
|
||||||
|
|
||||||
export class OwnProfileStore extends AsyncStoreWithClient<IState> {
|
export class OwnProfileStore extends AsyncStoreWithClient<IState> {
|
||||||
private static internalInstance = new OwnProfileStore();
|
private static internalInstance = new OwnProfileStore();
|
||||||
|
|
||||||
private monitoredUser: User;
|
private monitoredUser: User;
|
||||||
|
|
||||||
private constructor() {
|
private constructor() {
|
||||||
super(defaultDispatcher, {});
|
// 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
|
||||||
|
super(defaultDispatcher, {
|
||||||
|
displayName: window.localStorage.getItem(KEY_DISPLAY_NAME),
|
||||||
|
avatarUrl: window.localStorage.getItem(KEY_AVATAR_URL),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static get instance(): OwnProfileStore {
|
public static get instance(): OwnProfileStore {
|
||||||
|
@ -115,6 +124,16 @@ export class OwnProfileStore extends AsyncStoreWithClient<IState> {
|
||||||
// We specifically do not use the User object we stored for profile info as it
|
// 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).
|
// could easily be wrong (such as per-room instead of global profile).
|
||||||
const profileInfo = await this.matrixClient.getProfileInfo(this.matrixClient.getUserId());
|
const profileInfo = await this.matrixClient.getProfileInfo(this.matrixClient.getUserId());
|
||||||
|
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 {
|
||||||
|
window.localStorage.removeItem(KEY_AVATAR_URL);
|
||||||
|
}
|
||||||
await this.updateState({displayName: profileInfo.displayname, avatarUrl: profileInfo.avatar_url});
|
await this.updateState({displayName: profileInfo.displayname, avatarUrl: profileInfo.avatar_url});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue