Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Fix left panel widgets causing app crashes (again) #7814

Merged
merged 2 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/components/views/elements/AppTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export default class AppTile extends React.Component<IProps, IState> {
};

private onRoomViewStoreUpdate = () => {
if (this.props.room.roomId == RoomViewStore.getRoomId()) return;
if (this.props.room?.roomId === RoomViewStore.getRoomId()) return;
const isActiveWidget = ActiveWidgetStore.instance.getWidgetPersistence(this.props.app.id);
// Stop the widget if it's not the active (persistent) widget and it's not a user widget
if (!isActiveWidget && !this.props.userWidget) {
Expand All @@ -186,7 +186,7 @@ export default class AppTile extends React.Component<IProps, IState> {
const isActiveWidget = ActiveWidgetStore.instance.getWidgetPersistence(this.props.app.id);
if (isActiveWidget) {
// We just left the room that the active widget was from.
if (RoomViewStore.getRoomId() !== this.props.room.roomId) {
if (this.props.room && RoomViewStore.getRoomId() !== this.props.room.roomId) {
// If we are not actively looking at the room then destroy this widget entirely.
this.endWidgetActions();
} else if (WidgetType.JITSI.matches(this.props.app.type)) {
Expand All @@ -200,7 +200,7 @@ export default class AppTile extends React.Component<IProps, IState> {
}

private onMyMembership = (room: Room, membership: string): void => {
if (membership === "leave" && room.roomId === this.props.room.roomId) {
if (membership === "leave" && room.roomId === this.props.room?.roomId) {
this.onUserLeftRoom();
}
};
Expand Down Expand Up @@ -376,7 +376,7 @@ export default class AppTile extends React.Component<IProps, IState> {
this.iframe.src = 'about:blank';
}

if (WidgetType.JITSI.matches(this.props.app.type)) {
if (WidgetType.JITSI.matches(this.props.app.type) && this.props.room) {
CallHandler.instance.hangupCallApp(this.props.room.roomId);
}

Expand Down Expand Up @@ -432,7 +432,7 @@ export default class AppTile extends React.Component<IProps, IState> {
};

private grantWidgetPermission = (): void => {
const roomId = this.props.room.roomId;
const roomId = this.props.room?.roomId;
logger.info("Granting permission for widget to load: " + this.props.app.eventId);
const current = SettingsStore.getValue("allowedWidgets", roomId);
current[this.props.app.eventId] = true;
Expand Down Expand Up @@ -509,6 +509,7 @@ export default class AppTile extends React.Component<IProps, IState> {
};

private onToggleMaximisedClick = (): void => {
if (!this.props.room) return; // ignore action - it shouldn't even be visible
const targetContainer =
WidgetLayoutStore.instance.isInContainer(this.props.room, this.props.app, Container.Center)
? Container.Right
Expand All @@ -517,6 +518,7 @@ export default class AppTile extends React.Component<IProps, IState> {
};

private onTogglePinnedClick = (): void => {
if (!this.props.room) return; // ignore action - it shouldn't even be visible
const targetContainer =
WidgetLayoutStore.instance.isInContainer(this.props.room, this.props.app, Container.Top)
? Container.Right
Expand Down
7 changes: 4 additions & 3 deletions src/stores/widgets/WidgetLayoutStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import { Room } from "matrix-js-sdk/src/models/room";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { Optional } from "matrix-events-sdk";

import SettingsStore from "../../settings/SettingsStore";
import WidgetStore, { IApp } from "../WidgetStore";
Expand Down Expand Up @@ -345,15 +346,15 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
}
}

public getContainerWidgets(room: Room, container: Container): IApp[] {
public getContainerWidgets(room: Optional<Room>, container: Container): IApp[] {
return this.byRoom[room?.roomId]?.[container]?.ordered || [];
}

public isInContainer(room: Room, widget: IApp, container: Container): boolean {
public isInContainer(room: Optional<Room>, widget: IApp, container: Container): boolean {
return this.getContainerWidgets(room, container).some(w => w.id === widget.id);
}

public isVisibleOnScreen(room: Room, widgetId: string) {
public isVisibleOnScreen(room: Optional<Room>, widgetId: string) {
const wId = widgetId;
const inRightPanel =
(RightPanelStore.instance.currentCard.phase == RightPanelPhases.Widget &&
Expand Down