@@ -69,6 +69,7 @@ import { ViewRoomPayload } from "./dispatcher/payloads/ViewRoomPayload";
69
69
import VoipUserMapper from './VoipUserMapper' ;
70
70
import { htmlSerializeFromMdIfNeeded } from './editor/serialize' ;
71
71
import { leaveRoomBehaviour } from "./utils/leave-behaviour" ;
72
+ import { isLocalRoom } from './utils/localRoom/isLocalRoom' ;
72
73
73
74
// XXX: workaround for https://github.com/microsoft/TypeScript/issues/31816
74
75
interface HTMLInputEvent extends Event {
@@ -206,6 +207,12 @@ function successSync(value: any) {
206
207
return success ( Promise . resolve ( value ) ) ;
207
208
}
208
209
210
+ const isCurrentLocalRoom = ( ) : boolean => {
211
+ const cli = MatrixClientPeg . get ( ) ;
212
+ const room = cli . getRoom ( RoomViewStore . instance . getRoomId ( ) ) ;
213
+ return isLocalRoom ( room ) ;
214
+ } ;
215
+
209
216
/* Disable the "unexpected this" error for these commands - all of the run
210
217
* functions are called with `this` bound to the Command instance.
211
218
*/
@@ -297,6 +304,7 @@ export const Commands = [
297
304
command : 'upgraderoom' ,
298
305
args : '<new_version>' ,
299
306
description : _td ( 'Upgrades a room to a new version' ) ,
307
+ isEnabled : ( ) => ! isCurrentLocalRoom ( ) ,
300
308
runFn : function ( roomId , args ) {
301
309
if ( args ) {
302
310
const cli = MatrixClientPeg . get ( ) ;
@@ -380,6 +388,7 @@ export const Commands = [
380
388
aliases : [ 'roomnick' ] ,
381
389
args : '<display_name>' ,
382
390
description : _td ( 'Changes your display nickname in the current room only' ) ,
391
+ isEnabled : ( ) => ! isCurrentLocalRoom ( ) ,
383
392
runFn : function ( roomId , args ) {
384
393
if ( args ) {
385
394
const cli = MatrixClientPeg . get ( ) ;
@@ -399,6 +408,7 @@ export const Commands = [
399
408
command : 'roomavatar' ,
400
409
args : '[<mxc_url>]' ,
401
410
description : _td ( 'Changes the avatar of the current room' ) ,
411
+ isEnabled : ( ) => ! isCurrentLocalRoom ( ) ,
402
412
runFn : function ( roomId , args ) {
403
413
let promise = Promise . resolve ( args ) ;
404
414
if ( ! args ) {
@@ -417,6 +427,7 @@ export const Commands = [
417
427
command : 'myroomavatar' ,
418
428
args : '[<mxc_url>]' ,
419
429
description : _td ( 'Changes your avatar in this current room only' ) ,
430
+ isEnabled : ( ) => ! isCurrentLocalRoom ( ) ,
420
431
runFn : function ( roomId , args ) {
421
432
const cli = MatrixClientPeg . get ( ) ;
422
433
const room = cli . getRoom ( roomId ) ;
@@ -462,6 +473,7 @@ export const Commands = [
462
473
command : 'topic' ,
463
474
args : '[<topic>]' ,
464
475
description : _td ( 'Gets or sets the room topic' ) ,
476
+ isEnabled : ( ) => ! isCurrentLocalRoom ( ) ,
465
477
runFn : function ( roomId , args ) {
466
478
const cli = MatrixClientPeg . get ( ) ;
467
479
if ( args ) {
@@ -498,6 +510,7 @@ export const Commands = [
498
510
command : 'roomname' ,
499
511
args : '<name>' ,
500
512
description : _td ( 'Sets the room name' ) ,
513
+ isEnabled : ( ) => ! isCurrentLocalRoom ( ) ,
501
514
runFn : function ( roomId , args ) {
502
515
if ( args ) {
503
516
return success ( MatrixClientPeg . get ( ) . setRoomName ( roomId , args ) ) ;
@@ -512,7 +525,7 @@ export const Commands = [
512
525
args : '<user-id> [<reason>]' ,
513
526
description : _td ( 'Invites user with given id to current room' ) ,
514
527
analyticsName : "Invite" ,
515
- isEnabled : ( ) => shouldShowComponent ( UIComponent . InviteUsers ) ,
528
+ isEnabled : ( ) => ! isCurrentLocalRoom ( ) && shouldShowComponent ( UIComponent . InviteUsers ) ,
516
529
runFn : function ( roomId , args ) {
517
530
if ( args ) {
518
531
const [ address , reason ] = args . split ( / \s + ( .+ ) / ) ;
@@ -694,6 +707,7 @@ export const Commands = [
694
707
args : '[<room-address>]' ,
695
708
description : _td ( 'Leave room' ) ,
696
709
analyticsName : "Part" ,
710
+ isEnabled : ( ) => ! isCurrentLocalRoom ( ) ,
697
711
runFn : function ( roomId , args ) {
698
712
const cli = MatrixClientPeg . get ( ) ;
699
713
@@ -746,6 +760,7 @@ export const Commands = [
746
760
aliases : [ "kick" ] ,
747
761
args : '<user-id> [reason]' ,
748
762
description : _td ( 'Removes user with given id from this room' ) ,
763
+ isEnabled : ( ) => ! isCurrentLocalRoom ( ) ,
749
764
runFn : function ( roomId , args ) {
750
765
if ( args ) {
751
766
const matches = args . match ( / ^ ( \S + ?) ( + ( .* ) ) ? $ / ) ;
@@ -762,6 +777,7 @@ export const Commands = [
762
777
command : 'ban' ,
763
778
args : '<user-id> [reason]' ,
764
779
description : _td ( 'Bans user with given id' ) ,
780
+ isEnabled : ( ) => ! isCurrentLocalRoom ( ) ,
765
781
runFn : function ( roomId , args ) {
766
782
if ( args ) {
767
783
const matches = args . match ( / ^ ( \S + ?) ( + ( .* ) ) ? $ / ) ;
@@ -778,6 +794,7 @@ export const Commands = [
778
794
command : 'unban' ,
779
795
args : '<user-id>' ,
780
796
description : _td ( 'Unbans user with given ID' ) ,
797
+ isEnabled : ( ) => ! isCurrentLocalRoom ( ) ,
781
798
runFn : function ( roomId , args ) {
782
799
if ( args ) {
783
800
const matches = args . match ( / ^ ( \S + ) $ / ) ;
@@ -857,7 +874,8 @@ export const Commands = [
857
874
isEnabled ( ) : boolean {
858
875
const cli = MatrixClientPeg . get ( ) ;
859
876
const room = cli . getRoom ( RoomViewStore . instance . getRoomId ( ) ) ;
860
- return room ?. currentState . maySendStateEvent ( EventType . RoomPowerLevels , cli . getUserId ( ) ) ;
877
+ return room ?. currentState . maySendStateEvent ( EventType . RoomPowerLevels , cli . getUserId ( ) )
878
+ && ! isLocalRoom ( room ) ;
861
879
} ,
862
880
runFn : function ( roomId , args ) {
863
881
if ( args ) {
@@ -897,7 +915,8 @@ export const Commands = [
897
915
isEnabled ( ) : boolean {
898
916
const cli = MatrixClientPeg . get ( ) ;
899
917
const room = cli . getRoom ( RoomViewStore . instance . getRoomId ( ) ) ;
900
- return room ?. currentState . maySendStateEvent ( EventType . RoomPowerLevels , cli . getUserId ( ) ) ;
918
+ return room ?. currentState . maySendStateEvent ( EventType . RoomPowerLevels , cli . getUserId ( ) )
919
+ && ! isLocalRoom ( room ) ;
901
920
} ,
902
921
runFn : function ( roomId , args ) {
903
922
if ( args ) {
@@ -936,7 +955,9 @@ export const Commands = [
936
955
command : 'addwidget' ,
937
956
args : '<url | embed code | Jitsi url>' ,
938
957
description : _td ( 'Adds a custom widget by URL to the room' ) ,
939
- isEnabled : ( ) => SettingsStore . getValue ( UIFeature . Widgets ) && shouldShowComponent ( UIComponent . AddIntegrations ) ,
958
+ isEnabled : ( ) => SettingsStore . getValue ( UIFeature . Widgets )
959
+ && shouldShowComponent ( UIComponent . AddIntegrations )
960
+ && ! isCurrentLocalRoom ( ) ,
940
961
runFn : function ( roomId , widgetUrl ) {
941
962
if ( ! widgetUrl ) {
942
963
return reject ( newTranslatableError ( "Please supply a widget URL or embed code" ) ) ;
@@ -1059,6 +1080,7 @@ export const Commands = [
1059
1080
new Command ( {
1060
1081
command : 'discardsession' ,
1061
1082
description : _td ( 'Forces the current outbound group session in an encrypted room to be discarded' ) ,
1083
+ isEnabled : ( ) => ! isCurrentLocalRoom ( ) ,
1062
1084
runFn : function ( roomId ) {
1063
1085
try {
1064
1086
MatrixClientPeg . get ( ) . forceDiscardSession ( roomId ) ;
@@ -1074,7 +1096,7 @@ export const Commands = [
1074
1096
command : 'remakeolm' ,
1075
1097
description : _td ( 'Developer command: Discards the current outbound group session and sets up new Olm sessions' ) ,
1076
1098
isEnabled : ( ) => {
1077
- return SettingsStore . getValue ( "developerMode" ) ;
1099
+ return SettingsStore . getValue ( "developerMode" ) && ! isCurrentLocalRoom ( ) ;
1078
1100
} ,
1079
1101
runFn : ( roomId ) => {
1080
1102
try {
@@ -1125,6 +1147,7 @@ export const Commands = [
1125
1147
command : "whois" ,
1126
1148
description : _td ( "Displays information about a user" ) ,
1127
1149
args : "<user-id>" ,
1150
+ isEnabled : ( ) => ! isCurrentLocalRoom ( ) ,
1128
1151
runFn : function ( roomId , userId ) {
1129
1152
if ( ! userId || ! userId . startsWith ( "@" ) || ! userId . includes ( ":" ) ) {
1130
1153
return reject ( this . getUsage ( ) ) ;
@@ -1160,7 +1183,7 @@ export const Commands = [
1160
1183
description : _td ( "Switches to this room's virtual room, if it has one" ) ,
1161
1184
category : CommandCategories . advanced ,
1162
1185
isEnabled ( ) : boolean {
1163
- return CallHandler . instance . getSupportsVirtualRooms ( ) ;
1186
+ return CallHandler . instance . getSupportsVirtualRooms ( ) && ! isCurrentLocalRoom ( ) ;
1164
1187
} ,
1165
1188
runFn : ( roomId ) => {
1166
1189
return success ( ( async ( ) => {
@@ -1244,6 +1267,7 @@ export const Commands = [
1244
1267
command : "holdcall" ,
1245
1268
description : _td ( "Places the call in the current room on hold" ) ,
1246
1269
category : CommandCategories . other ,
1270
+ isEnabled : ( ) => ! isCurrentLocalRoom ( ) ,
1247
1271
runFn : function ( roomId , args ) {
1248
1272
const call = CallHandler . instance . getCallForRoom ( roomId ) ;
1249
1273
if ( ! call ) {
@@ -1258,6 +1282,7 @@ export const Commands = [
1258
1282
command : "unholdcall" ,
1259
1283
description : _td ( "Takes the call in the current room off hold" ) ,
1260
1284
category : CommandCategories . other ,
1285
+ isEnabled : ( ) => ! isCurrentLocalRoom ( ) ,
1261
1286
runFn : function ( roomId , args ) {
1262
1287
const call = CallHandler . instance . getCallForRoom ( roomId ) ;
1263
1288
if ( ! call ) {
@@ -1272,6 +1297,7 @@ export const Commands = [
1272
1297
command : "converttodm" ,
1273
1298
description : _td ( "Converts the room to a DM" ) ,
1274
1299
category : CommandCategories . other ,
1300
+ isEnabled : ( ) => ! isCurrentLocalRoom ( ) ,
1275
1301
runFn : function ( roomId , args ) {
1276
1302
const room = MatrixClientPeg . get ( ) . getRoom ( roomId ) ;
1277
1303
return success ( guessAndSetDMRoom ( room , true ) ) ;
@@ -1282,6 +1308,7 @@ export const Commands = [
1282
1308
command : "converttoroom" ,
1283
1309
description : _td ( "Converts the DM to a room" ) ,
1284
1310
category : CommandCategories . other ,
1311
+ isEnabled : ( ) => ! isCurrentLocalRoom ( ) ,
1285
1312
runFn : function ( roomId , args ) {
1286
1313
const room = MatrixClientPeg . get ( ) . getRoom ( roomId ) ;
1287
1314
return success ( guessAndSetDMRoom ( room , false ) ) ;
0 commit comments