@@ -208,7 +208,10 @@ function successSync(value: any): RunResult {
208
208
209
209
const isCurrentLocalRoom = ( ) : boolean => {
210
210
const cli = MatrixClientPeg . get ( ) ;
211
- const room = cli . getRoom ( SdkContextClass . instance . roomViewStore . getRoomId ( ) ) ;
211
+ const roomId = SdkContextClass . instance . roomViewStore . getRoomId ( ) ;
212
+ if ( ! roomId ) return false ;
213
+ const room = cli . getRoom ( roomId ) ;
214
+ if ( ! room ) return false ;
212
215
return isLocalRoom ( room ) ;
213
216
} ;
214
217
@@ -873,7 +876,9 @@ export const Commands = [
873
876
description : _td ( "Define the power level of a user" ) ,
874
877
isEnabled ( ) : boolean {
875
878
const cli = MatrixClientPeg . get ( ) ;
876
- const room = cli . getRoom ( SdkContextClass . instance . roomViewStore . getRoomId ( ) ) ;
879
+ const roomId = SdkContextClass . instance . roomViewStore . getRoomId ( ) ;
880
+ if ( ! roomId ) return false ;
881
+ const room = cli . getRoom ( roomId ) ;
877
882
return (
878
883
! ! room ?. currentState . maySendStateEvent ( EventType . RoomPowerLevels , cli . getUserId ( ) ! ) &&
879
884
! isLocalRoom ( room )
@@ -897,7 +902,10 @@ export const Commands = [
897
902
) ;
898
903
}
899
904
const member = room . getMember ( userId ) ;
900
- if ( ! member || getEffectiveMembership ( member . membership ) === EffectiveMembership . Leave ) {
905
+ if (
906
+ ! member ?. membership ||
907
+ getEffectiveMembership ( member . membership ) === EffectiveMembership . Leave
908
+ ) {
901
909
return reject ( newTranslatableError ( "Could not find user in room" ) ) ;
902
910
}
903
911
const powerLevelEvent = room . currentState . getStateEvents ( "m.room.power_levels" , "" ) ;
@@ -916,7 +924,9 @@ export const Commands = [
916
924
description : _td ( "Deops user with given id" ) ,
917
925
isEnabled ( ) : boolean {
918
926
const cli = MatrixClientPeg . get ( ) ;
919
- const room = cli . getRoom ( SdkContextClass . instance . roomViewStore . getRoomId ( ) ) ;
927
+ const roomId = SdkContextClass . instance . roomViewStore . getRoomId ( ) ;
928
+ if ( ! roomId ) return false ;
929
+ const room = cli . getRoom ( roomId ) ;
920
930
return (
921
931
! ! room ?. currentState . maySendStateEvent ( EventType . RoomPowerLevels , cli . getUserId ( ) ! ) &&
922
932
! isLocalRoom ( room )
@@ -973,11 +983,12 @@ export const Commands = [
973
983
// We use parse5, which doesn't render/create a DOM node. It instead runs
974
984
// some superfast regex over the text so we don't have to.
975
985
const embed = parseHtml ( widgetUrl ) ;
976
- if ( embed && embed . childNodes && embed . childNodes . length === 1 ) {
986
+ if ( embed ? .childNodes ? .length === 1 ) {
977
987
const iframe = embed . childNodes [ 0 ] as ChildElement ;
978
988
if ( iframe . tagName . toLowerCase ( ) === "iframe" && iframe . attrs ) {
979
989
const srcAttr = iframe . attrs . find ( ( a ) => a . name === "src" ) ;
980
990
logger . log ( "Pulling URL out of iframe (embed code)" ) ;
991
+ if ( ! srcAttr ) return reject ( newTranslatableError ( "iframe has no src attribute" ) ) ;
981
992
widgetUrl = srcAttr . value ;
982
993
}
983
994
}
@@ -1240,6 +1251,7 @@ export const Commands = [
1240
1251
}
1241
1252
1242
1253
const roomId = await ensureDMExists ( MatrixClientPeg . get ( ) , userId ) ;
1254
+ if ( ! roomId ) throw new Error ( "Failed to ensure DM exists" ) ;
1243
1255
1244
1256
dis . dispatch < ViewRoomPayload > ( {
1245
1257
action : Action . ViewRoom ,
@@ -1267,6 +1279,8 @@ export const Commands = [
1267
1279
( async ( ) : Promise < void > => {
1268
1280
const cli = MatrixClientPeg . get ( ) ;
1269
1281
const roomId = await ensureDMExists ( cli , userId ) ;
1282
+ if ( ! roomId ) throw new Error ( "Failed to ensure DM exists" ) ;
1283
+
1270
1284
dis . dispatch < ViewRoomPayload > ( {
1271
1285
action : Action . ViewRoom ,
1272
1286
room_id : roomId ,
@@ -1323,6 +1337,7 @@ export const Commands = [
1323
1337
isEnabled : ( ) => ! isCurrentLocalRoom ( ) ,
1324
1338
runFn : function ( roomId , args ) {
1325
1339
const room = MatrixClientPeg . get ( ) . getRoom ( roomId ) ;
1340
+ if ( ! room ) return reject ( newTranslatableError ( "Could not find room" ) ) ;
1326
1341
return success ( guessAndSetDMRoom ( room , true ) ) ;
1327
1342
} ,
1328
1343
renderingTypes : [ TimelineRenderingType . Room ] ,
@@ -1334,6 +1349,7 @@ export const Commands = [
1334
1349
isEnabled : ( ) => ! isCurrentLocalRoom ( ) ,
1335
1350
runFn : function ( roomId , args ) {
1336
1351
const room = MatrixClientPeg . get ( ) . getRoom ( roomId ) ;
1352
+ if ( ! room ) return reject ( newTranslatableError ( "Could not find room" ) ) ;
1337
1353
return success ( guessAndSetDMRoom ( room , false ) ) ;
1338
1354
} ,
1339
1355
renderingTypes : [ TimelineRenderingType . Room ] ,
0 commit comments