@@ -17,6 +17,7 @@ limitations under the License.
1717import React , { useContext } from "react" ;
1818import { MatrixCapabilities } from "matrix-widget-api" ;
1919import { logger } from "matrix-js-sdk/src/logger" ;
20+ import { ApprovalOpts , WidgetLifecycle } from "@matrix-org/react-sdk-module-api/lib/lifecycles/WidgetLifecycle" ;
2021
2122import IconizedContextMenu , { IconizedContextMenuOption , IconizedContextMenuOptionList } from "./IconizedContextMenu" ;
2223import { ChevronFace } from "../../structures/ContextMenu" ;
@@ -34,8 +35,10 @@ import { WidgetType } from "../../../widgets/WidgetType";
3435import MatrixClientContext from "../../../contexts/MatrixClientContext" ;
3536import { Container , WidgetLayoutStore } from "../../../stores/widgets/WidgetLayoutStore" ;
3637import { getConfigLivestreamUrl , startJitsiAudioLivestream } from "../../../Livestream" ;
38+ import { ModuleRunner } from "../../../modules/ModuleRunner" ;
39+ import { ElementWidget } from "../../../stores/widgets/StopGapWidget" ;
3740
38- interface IProps extends React . ComponentProps < typeof IconizedContextMenu > {
41+ export interface WidgetContextMenuProps extends React . ComponentProps < typeof IconizedContextMenu > {
3942 app : IApp ;
4043 userWidget ?: boolean ;
4144 showUnpin ?: boolean ;
@@ -45,7 +48,7 @@ interface IProps extends React.ComponentProps<typeof IconizedContextMenu> {
4548 onEditClick ?( ) : void ;
4649}
4750
48- const WidgetContextMenu : React . FC < IProps > = ( {
51+ export const WidgetContextMenu : React . FC < WidgetContextMenuProps > = ( {
4952 onFinished,
5053 app,
5154 userWidget,
@@ -158,24 +161,31 @@ const WidgetContextMenu: React.FC<IProps> = ({
158161 const isLocalWidget = WidgetType . JITSI . matches ( app . type ) ;
159162 let revokeButton ;
160163 if ( ! userWidget && ! isLocalWidget && isAllowedWidget ) {
161- const onRevokeClick = ( ) : void => {
162- logger . info ( "Revoking permission for widget to load: " + app . eventId ) ;
163- const current = SettingsStore . getValue ( "allowedWidgets" , roomId ) ;
164- if ( app . eventId !== undefined ) current [ app . eventId ] = false ;
165- const level = SettingsStore . firstSupportedLevel ( "allowedWidgets" ) ;
166- SettingsStore . setValue ( "allowedWidgets" , roomId , level , current ) . catch ( ( err ) => {
167- logger . error ( err ) ;
168- // We don't really need to do anything about this - the user will just hit the button again.
169- } ) ;
170- onFinished ( ) ;
171- } ;
164+ const opts : ApprovalOpts = { approved : undefined } ;
165+ ModuleRunner . instance . invoke ( WidgetLifecycle . PreLoadRequest , opts , new ElementWidget ( app ) ) ;
166+
167+ if ( ! opts . approved ) {
168+ const onRevokeClick = ( ) : void => {
169+ logger . info ( "Revoking permission for widget to load: " + app . eventId ) ;
170+ const current = SettingsStore . getValue ( "allowedWidgets" , roomId ) ;
171+ if ( app . eventId !== undefined ) current [ app . eventId ] = false ;
172+ const level = SettingsStore . firstSupportedLevel ( "allowedWidgets" ) ;
173+ if ( ! level ) throw new Error ( "level must be defined" ) ;
174+ SettingsStore . setValue ( "allowedWidgets" , roomId ?? null , level , current ) . catch ( ( err ) => {
175+ logger . error ( err ) ;
176+ // We don't really need to do anything about this - the user will just hit the button again.
177+ } ) ;
178+ onFinished ( ) ;
179+ } ;
172180
173- revokeButton = < IconizedContextMenuOption onClick = { onRevokeClick } label = { _t ( "Revoke permissions" ) } /> ;
181+ revokeButton = < IconizedContextMenuOption onClick = { onRevokeClick } label = { _t ( "Revoke permissions" ) } /> ;
182+ }
174183 }
175184
176185 let moveLeftButton ;
177186 if ( showUnpin && widgetIndex > 0 ) {
178187 const onClick = ( ) : void => {
188+ if ( ! room ) throw new Error ( "room must be defined" ) ;
179189 WidgetLayoutStore . instance . moveWithinContainer ( room , Container . Top , app , - 1 ) ;
180190 onFinished ( ) ;
181191 } ;
@@ -207,5 +217,3 @@ const WidgetContextMenu: React.FC<IProps> = ({
207217 </ IconizedContextMenu >
208218 ) ;
209219} ;
210-
211- export default WidgetContextMenu ;
0 commit comments