Apply strictNullChecks to src/stores/widgets/* (#10324)

* Apply `strictNullChecks` to src/stores/widgets/*

* Iterate

* Iterate
This commit is contained in:
Michael Telatynski 2023-03-08 11:48:58 +00:00 committed by GitHub
parent 0c1c3f1cde
commit c0e40217f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 59 additions and 55 deletions

View file

@ -67,7 +67,7 @@ export const WidgetContextMenu: React.FC<IProps> = ({
if (getConfigLivestreamUrl() && WidgetType.JITSI.matches(app.type)) {
const onStreamAudioClick = async (): Promise<void> => {
try {
await startJitsiAudioLivestream(widgetMessaging, roomId);
await startJitsiAudioLivestream(widgetMessaging!, roomId);
} catch (err) {
logger.error("Failed to start livestream", err);
// XXX: won't i18n well, but looks like widget api only support 'message'?
@ -84,7 +84,7 @@ export const WidgetContextMenu: React.FC<IProps> = ({
);
}
const pinnedWidgets = WidgetLayoutStore.instance.getContainerWidgets(room, Container.Top);
const pinnedWidgets = room ? WidgetLayoutStore.instance.getContainerWidgets(room, Container.Top) : [];
const widgetIndex = pinnedWidgets.findIndex((widget) => widget.id === app.id);
let editButton;
@ -196,6 +196,7 @@ export const WidgetContextMenu: React.FC<IProps> = ({
let moveRightButton;
if (showUnpin && widgetIndex < pinnedWidgets.length - 1) {
const onClick = (): void => {
if (!room) throw new Error("room must be defined");
WidgetLayoutStore.instance.moveWithinContainer(room, Container.Top, app, 1);
onFinished();
};

View file

@ -99,7 +99,7 @@ interface IState {
hasPermissionToLoad: boolean;
// Wait for user profile load to display correct name
isUserProfileReady: boolean;
error: Error;
error: Error | null;
menuDisplayed: boolean;
requiresClient: boolean;
}
@ -124,7 +124,7 @@ export default class AppTile extends React.Component<IProps, IState> {
private iframe: HTMLIFrameElement; // ref to the iframe (callback style)
private allowedWidgetsWatchRef: string;
private persistKey: string;
private sgWidget: StopGapWidget;
private sgWidget: StopGapWidget | null;
private dispatcherRef: string;
private unmounted: boolean;
@ -202,7 +202,7 @@ export default class AppTile extends React.Component<IProps, IState> {
private determineInitialRequiresClientState(): boolean {
try {
const mockWidget = new ElementWidget(this.props.app);
const widgetApi = WidgetMessagingStore.instance.getMessaging(mockWidget, this.props.room.roomId);
const widgetApi = WidgetMessagingStore.instance.getMessaging(mockWidget, this.props.room?.roomId);
if (widgetApi) {
// Load value from existing API to prevent resetting the requiresClient value on layout changes.
return widgetApi.hasCapability(ElementWidgetCapabilities.RequiresClient);
@ -310,9 +310,9 @@ export default class AppTile extends React.Component<IProps, IState> {
}
private setupSgListeners(): void {
this.sgWidget.on("preparing", this.onWidgetPreparing);
this.sgWidget?.on("preparing", this.onWidgetPreparing);
// emits when the capabilities have been set up or changed
this.sgWidget.on("capabilitiesNotified", this.onWidgetCapabilitiesNotified);
this.sgWidget?.on("capabilitiesNotified", this.onWidgetCapabilitiesNotified);
}
private stopSgListeners(): void {
@ -336,7 +336,7 @@ export default class AppTile extends React.Component<IProps, IState> {
}
private startWidget(): void {
this.sgWidget.prepare().then(() => {
this.sgWidget?.prepare().then(() => {
if (this.unmounted) return;
this.setState({ initialising: false });
});
@ -406,7 +406,7 @@ export default class AppTile extends React.Component<IProps, IState> {
private onWidgetCapabilitiesNotified = (): void => {
this.setState({
requiresClient: this.sgWidget.widgetApi.hasCapability(ElementWidgetCapabilities.RequiresClient),
requiresClient: !!this.sgWidget?.widgetApi?.hasCapability(ElementWidgetCapabilities.RequiresClient),
});
};
@ -415,7 +415,7 @@ export default class AppTile extends React.Component<IProps, IState> {
case "m.sticker":
if (
payload.widgetId === this.props.app.id &&
this.sgWidget.widgetApi.hasCapability(MatrixCapabilities.StickerSending)
this.sgWidget?.widgetApi?.hasCapability(MatrixCapabilities.StickerSending)
) {
dis.dispatch({
action: "post_sticker_message",
@ -444,8 +444,8 @@ export default class AppTile extends React.Component<IProps, IState> {
logger.info("Granting permission for widget to load: " + this.props.app.eventId);
const current = SettingsStore.getValue("allowedWidgets", roomId);
if (this.props.app.eventId !== undefined) current[this.props.app.eventId] = true;
const level = SettingsStore.firstSupportedLevel("allowedWidgets");
SettingsStore.setValue("allowedWidgets", roomId, level, current)
const level = SettingsStore.firstSupportedLevel("allowedWidgets")!;
SettingsStore.setValue("allowedWidgets", roomId ?? null, level, current)
.then(() => {
this.setState({ hasPermissionToLoad: true });
@ -501,7 +501,7 @@ export default class AppTile extends React.Component<IProps, IState> {
this.resetWidget(this.props);
this.startMessaging();
if (this.iframe) {
if (this.iframe && this.sgWidget) {
// Reload iframe
this.iframe.src = this.sgWidget.embedUrl;
}
@ -519,7 +519,7 @@ export default class AppTile extends React.Component<IProps, IState> {
// window.open(this._getPopoutUrl(), '_blank', 'noopener=yes');
Object.assign(document.createElement("a"), {
target: "_blank",
href: this.sgWidget.popoutUrl,
href: this.sgWidget?.popoutUrl,
rel: "noreferrer noopener",
}).click();
};
@ -676,7 +676,7 @@ export default class AppTile extends React.Component<IProps, IState> {
if (this.state.menuDisplayed) {
contextMenu = (
<WidgetContextMenu
{...aboveLeftOf(this.contextMenuButton.current.getBoundingClientRect(), null)}
{...aboveLeftOf(this.contextMenuButton.current.getBoundingClientRect())}
app={this.props.app}
onFinished={this.closeContextMenu}
showUnpin={!this.props.userWidget}