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

Implement RequiresClient capability for widgets #7005

Merged
merged 10 commits into from
Oct 28, 2021
11 changes: 10 additions & 1 deletion src/components/views/elements/AppTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ interface IState {
error: Error;
menuDisplayed: boolean;
widgetPageTitle: string;
requiresClient: boolean;
}

import { logger } from "matrix-js-sdk/src/logger";
Expand Down Expand Up @@ -116,6 +117,7 @@ export default class AppTile extends React.Component<IProps, IState> {
this.sgWidget = new StopGapWidget(this.props);
this.sgWidget.on("preparing", this.onWidgetPrepared);
this.sgWidget.on("ready", this.onWidgetReady);
this.sgWidget.on("capabilities_renegotiated", this.onWidgetCapabilitesRenegotiating);
} catch (e) {
logger.log("Failed to construct widget", e);
this.sgWidget = null;
Expand Down Expand Up @@ -155,6 +157,7 @@ export default class AppTile extends React.Component<IProps, IState> {
error: null,
menuDisplayed: false,
widgetPageTitle: this.props.widgetPageTitle,
requiresClient: true,
jryans marked this conversation as resolved.
Show resolved Hide resolved
};
}

Expand Down Expand Up @@ -297,6 +300,12 @@ export default class AppTile extends React.Component<IProps, IState> {
}
};

private onWidgetCapabilitesRenegotiating = (): void => {
this.setState({
jryans marked this conversation as resolved.
Show resolved Hide resolved
requiresClient: this.sgWidget.widgetApi.hasCapability(MatrixCapabilities.RequiresClient),
});
};

private onAction = (payload): void => {
if (payload.widgetId === this.props.app.id) {
switch (payload.action) {
Expand Down Expand Up @@ -512,7 +521,7 @@ export default class AppTile extends React.Component<IProps, IState> {
{ this.props.showTitle && this.getTileTitle() }
</span>
<span className="mx_AppTileMenuBarWidgets">
{ this.props.showPopout && <AccessibleButton
{ (this.props.showPopout && !this.state.requiresClient) && <AccessibleButton
className="mx_AppTileMenuBar_iconButton mx_AppTileMenuBar_iconButton_popout"
title={_t('Popout widget')}
onClick={this.onPopoutWidgetClick}
Expand Down
5 changes: 3 additions & 2 deletions src/stores/widgets/StopGapWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class ElementWidget extends Widget {
};
}

public getCompleteUrl(params: ITemplateParams, asPopout=false): string {
public getCompleteUrl(params: ITemplateParams, asPopout = false): string {
return runTemplate(asPopout ? this.popoutTemplateUrl : this.templateUrl, {
...this.rawDefinition,
data: this.rawData,
Expand All @@ -149,7 +149,7 @@ export class StopGapWidget extends EventEmitter {
private scalarToken: string;
private roomId?: string;
private kind: WidgetKind;
private readUpToMap: {[roomId: string]: string} = {}; // room ID to event ID
private readUpToMap: { [roomId: string]: string } = {}; // room ID to event ID

constructor(private appTileProps: IAppTileProps) {
super();
Expand Down Expand Up @@ -262,6 +262,7 @@ export class StopGapWidget extends EventEmitter {
this.messaging = new ClientWidgetApi(this.mockWidget, iframe, driver);
this.messaging.on("preparing", () => this.emit("preparing"));
this.messaging.on("ready", () => this.emit("ready"));
this.messaging.on("capabilities_renegotiated", () => this.emit("capabilities_renegotiated"));
this.messaging.on(`action:${WidgetApiFromWidgetAction.OpenModalWidget}`, this.onOpenModal);
WidgetMessagingStore.instance.storeMessaging(this.mockWidget, this.messaging);

Expand Down
4 changes: 3 additions & 1 deletion src/stores/widgets/StopGapWidgetDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ export class StopGapWidgetDriver extends WidgetDriver {
// Always allow screenshots to be taken because it's a client-induced flow. The widget can't
// spew screenshots at us and can't request screenshots of us, so it's up to us to provide the
// button if the widget says it supports screenshots.
this.allowedCapabilities = new Set([...allowedCapabilities, MatrixCapabilities.Screenshots]);
this.allowedCapabilities = new Set([...allowedCapabilities,
MatrixCapabilities.Screenshots,
MatrixCapabilities.RequiresClient]);

// Grant the permissions that are specific to given widget types
if (WidgetType.JITSI.matches(this.forWidget.type) && forWidgetKind === WidgetKind.Room) {
Expand Down