mirror of https://github.com/vector-im/riot-web
Wait for initial profile load before displaying widget (#7556)
* wait for initial profile load before displaying jitsi Signed-off-by: Kerry Archibald <kerrya@element.io> * update comment Signed-off-by: Kerry Archibald <kerrya@element.io> * amke fn return boolean Signed-off-by: Kerry Archibald <kerrya@element.io> * listen for profile update once Signed-off-by: Kerry Archibald <kerrya@element.io> * remove unneccessary check Signed-off-by: Kerry Archibald <kerrya@element.io>pull/21833/head
parent
1f298250b9
commit
42adedc468
|
@ -44,6 +44,8 @@ import { replaceableComponent } from "../../../utils/replaceableComponent";
|
||||||
import CallHandler from '../../../CallHandler';
|
import CallHandler from '../../../CallHandler';
|
||||||
import { IApp } from "../../../stores/WidgetStore";
|
import { IApp } from "../../../stores/WidgetStore";
|
||||||
import { WidgetLayoutStore, Container } from "../../../stores/widgets/WidgetLayoutStore";
|
import { WidgetLayoutStore, Container } from "../../../stores/widgets/WidgetLayoutStore";
|
||||||
|
import { OwnProfileStore } from '../../../stores/OwnProfileStore';
|
||||||
|
import { UPDATE_EVENT } from '../../../stores/AsyncStore';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
app: IApp;
|
app: IApp;
|
||||||
|
@ -87,6 +89,8 @@ interface IState {
|
||||||
// Assume that widget has permission to load if we are the user who
|
// Assume that widget has permission to load if we are the user who
|
||||||
// added it to the room, or if explicitly granted by the user
|
// added it to the room, or if explicitly granted by the user
|
||||||
hasPermissionToLoad: boolean;
|
hasPermissionToLoad: boolean;
|
||||||
|
// Wait for user profile load to display correct name
|
||||||
|
isUserProfileReady: boolean;
|
||||||
error: Error;
|
error: Error;
|
||||||
menuDisplayed: boolean;
|
menuDisplayed: boolean;
|
||||||
widgetPageTitle: string;
|
widgetPageTitle: string;
|
||||||
|
@ -130,10 +134,22 @@ export default class AppTile extends React.Component<IProps, IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state = this.getNewState(props);
|
this.state = this.getNewState(props);
|
||||||
|
this.watchUserReady();
|
||||||
|
|
||||||
this.allowedWidgetsWatchRef = SettingsStore.watchSetting("allowedWidgets", null, this.onAllowedWidgetsChange);
|
this.allowedWidgetsWatchRef = SettingsStore.watchSetting("allowedWidgets", null, this.onAllowedWidgetsChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private watchUserReady = () => {
|
||||||
|
if (OwnProfileStore.instance.isProfileInfoFetched) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
OwnProfileStore.instance.once(UPDATE_EVENT, this.onUserReady);
|
||||||
|
};
|
||||||
|
|
||||||
|
private onUserReady = (): void => {
|
||||||
|
this.setState({ isUserProfileReady: true });
|
||||||
|
};
|
||||||
|
|
||||||
// This is a function to make the impact of calling SettingsStore slightly less
|
// This is a function to make the impact of calling SettingsStore slightly less
|
||||||
private hasPermissionToLoad = (props: IProps): boolean => {
|
private hasPermissionToLoad = (props: IProps): boolean => {
|
||||||
if (this.usingLocalWidget()) return true;
|
if (this.usingLocalWidget()) return true;
|
||||||
|
@ -160,6 +176,7 @@ export default class AppTile extends React.Component<IProps, IState> {
|
||||||
// Assume that widget has permission to load if we are the user who
|
// Assume that widget has permission to load if we are the user who
|
||||||
// added it to the room, or if explicitly granted by the user
|
// added it to the room, or if explicitly granted by the user
|
||||||
hasPermissionToLoad: this.hasPermissionToLoad(newProps),
|
hasPermissionToLoad: this.hasPermissionToLoad(newProps),
|
||||||
|
isUserProfileReady: OwnProfileStore.instance.isProfileInfoFetched,
|
||||||
error: null,
|
error: null,
|
||||||
menuDisplayed: false,
|
menuDisplayed: false,
|
||||||
widgetPageTitle: this.props.widgetPageTitle,
|
widgetPageTitle: this.props.widgetPageTitle,
|
||||||
|
@ -220,6 +237,7 @@ export default class AppTile extends React.Component<IProps, IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingsStore.unwatchSetting(this.allowedWidgetsWatchRef);
|
SettingsStore.unwatchSetting(this.allowedWidgetsWatchRef);
|
||||||
|
OwnProfileStore.instance.removeListener(UPDATE_EVENT, this.onUserReady);
|
||||||
}
|
}
|
||||||
|
|
||||||
private resetWidget(newProps: IProps): void {
|
private resetWidget(newProps: IProps): void {
|
||||||
|
@ -473,7 +491,7 @@ export default class AppTile extends React.Component<IProps, IState> {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else if (this.state.initialising) {
|
} else if (this.state.initialising || !this.state.isUserProfileReady) {
|
||||||
appTileBody = (
|
appTileBody = (
|
||||||
<div className={appTileBodyClass + (this.state.loading ? 'mx_AppLoading' : '')} style={appTileBodyStyles}>
|
<div className={appTileBodyClass + (this.state.loading ? 'mx_AppLoading' : '')} style={appTileBodyStyles}>
|
||||||
{ loadingElement }
|
{ loadingElement }
|
||||||
|
|
|
@ -28,6 +28,7 @@ import { mediaFromMxc } from "../customisations/Media";
|
||||||
interface IState {
|
interface IState {
|
||||||
displayName?: string;
|
displayName?: string;
|
||||||
avatarUrl?: string;
|
avatarUrl?: string;
|
||||||
|
fetchedAt?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const KEY_DISPLAY_NAME = "mx_profile_displayname";
|
const KEY_DISPLAY_NAME = "mx_profile_displayname";
|
||||||
|
@ -67,6 +68,10 @@ export class OwnProfileStore extends AsyncStoreWithClient<IState> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get isProfileInfoFetched(): boolean {
|
||||||
|
return !!this.state.fetchedAt;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the MXC URI of the user's avatar, or null if not present.
|
* Gets the MXC URI of the user's avatar, or null if not present.
|
||||||
*/
|
*/
|
||||||
|
@ -135,7 +140,12 @@ export class OwnProfileStore extends AsyncStoreWithClient<IState> {
|
||||||
} else {
|
} else {
|
||||||
window.localStorage.removeItem(KEY_AVATAR_URL);
|
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,
|
||||||
|
fetchedAt: Date.now(),
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
private onStateEvents = throttle(async (ev: MatrixEvent) => {
|
private onStateEvents = throttle(async (ev: MatrixEvent) => {
|
||||||
|
|
Loading…
Reference in New Issue