@@ -19,6 +19,7 @@ limitations under the License.
19
19
20
20
import * as React from 'react' ;
21
21
import { User } from "matrix-js-sdk/src/models/user" ;
22
+ import { EventType } from "matrix-js-sdk/src/@types/event" ;
22
23
23
24
import * as ContentHelpers from 'matrix-js-sdk/src/content-helpers' ;
24
25
import { MatrixClientPeg } from './MatrixClientPeg' ;
@@ -58,6 +59,7 @@ import SlashCommandHelpDialog from "./components/views/dialogs/SlashCommandHelpD
58
59
import { logger } from "matrix-js-sdk/src/logger" ;
59
60
import { shouldShowComponent } from "./customisations/helpers/UIComponents" ;
60
61
import { TimelineRenderingType } from './contexts/RoomContext' ;
62
+ import RoomViewStore from "./stores/RoomViewStore" ;
61
63
62
64
// XXX: workaround for https://github.com/microsoft/TypeScript/issues/31816
63
65
interface HTMLInputEvent extends Event {
@@ -748,6 +750,11 @@ export const Commands = [
748
750
command : 'op' ,
749
751
args : '<user-id> [<power-level>]' ,
750
752
description : _td ( 'Define the power level of a user' ) ,
753
+ isEnabled ( ) : boolean {
754
+ const cli = MatrixClientPeg . get ( ) ;
755
+ const room = cli . getRoom ( RoomViewStore . getRoomId ( ) ) ;
756
+ return room ?. currentState . maySendStateEvent ( EventType . RoomPowerLevels , cli . getUserId ( ) ) ;
757
+ } ,
751
758
runFn : function ( roomId , args ) {
752
759
if ( args ) {
753
760
const matches = args . match ( / ^ ( \S + ?) ( + ( - ? \d + ) ) ? $ / ) ;
@@ -779,6 +786,11 @@ export const Commands = [
779
786
command : 'deop' ,
780
787
args : '<user-id>' ,
781
788
description : _td ( 'Deops user with given id' ) ,
789
+ isEnabled ( ) : boolean {
790
+ const cli = MatrixClientPeg . get ( ) ;
791
+ const room = cli . getRoom ( RoomViewStore . getRoomId ( ) ) ;
792
+ return room ?. currentState . maySendStateEvent ( EventType . RoomPowerLevels , cli . getUserId ( ) ) ;
793
+ } ,
782
794
runFn : function ( roomId , args ) {
783
795
if ( args ) {
784
796
const matches = args . match ( / ^ ( \S + ) $ / ) ;
0 commit comments