diff --git a/src/AddThreepid.ts b/src/AddThreepid.ts index 7e53bd79a2..34ba9d51ed 100644 --- a/src/AddThreepid.ts +++ b/src/AddThreepid.ts @@ -201,7 +201,7 @@ export default class AddThreepid { // implemented it without, so this may just succeed and that's OK. return [true]; } catch (err) { - if (!(err instanceof MatrixError) || err.httpStatus !== 401 || !err.data || !err.data.flows) { + if (!(err instanceof MatrixError) || err.httpStatus !== 401 || !err.data?.flows) { // doesn't look like an interactive-auth failure throw err; } @@ -300,7 +300,7 @@ export default class AddThreepid { // implemented it without, so this may just succeed and that's OK. return [true]; } catch (err) { - if (!(err instanceof MatrixError) || err.httpStatus !== 401 || !err.data || !err.data.flows) { + if (!(err instanceof MatrixError) || err.httpStatus !== 401 || !err.data?.flows) { // doesn't look like an interactive-auth failure throw err; } diff --git a/src/Avatar.ts b/src/Avatar.ts index 5821647ea8..a78aa4d03b 100644 --- a/src/Avatar.ts +++ b/src/Avatar.ts @@ -68,7 +68,7 @@ function isValidHexColor(color: string): boolean { return ( typeof color === "string" && (color.length === 7 || color.length === 9) && - color.charAt(0) === "#" && + color.startsWith("#") && !color .slice(1) .split("") diff --git a/src/ContentMessages.ts b/src/ContentMessages.ts index 07c5491f51..b7f67321c1 100644 --- a/src/ContentMessages.ts +++ b/src/ContentMessages.ts @@ -396,11 +396,7 @@ export default class ContentMessages { } public getUploadLimit(): number | null { - if (this.mediaConfig !== null && this.mediaConfig["m.upload.size"] !== undefined) { - return this.mediaConfig["m.upload.size"]; - } else { - return null; - } + return this.mediaConfig?.["m.upload.size"] ?? null; } public async sendContentListToRoom( @@ -578,7 +574,7 @@ export default class ContentMessages { logger.error(e); content.msgtype = MsgType.File; } - } else if (file.type.indexOf("audio/") === 0) { + } else if (file.type.startsWith("audio/")) { content.msgtype = MsgType.Audio; try { const audioInfo = await infoForAudioFile(file); @@ -588,7 +584,7 @@ export default class ContentMessages { logger.error(e); content.msgtype = MsgType.File; } - } else if (file.type.indexOf("video/") === 0) { + } else if (file.type.startsWith("video/")) { content.msgtype = MsgType.Video; try { const videoInfo = await infoForVideoFile(matrixClient, roomId, file); @@ -648,11 +644,7 @@ export default class ContentMessages { } private isFileSizeAcceptable(file: File): boolean { - if ( - this.mediaConfig !== null && - this.mediaConfig["m.upload.size"] !== undefined && - file.size > this.mediaConfig["m.upload.size"] - ) { + if (this.mediaConfig?.["m.upload.size"] !== undefined && file.size > this.mediaConfig["m.upload.size"]) { return false; } return true; diff --git a/src/IdentityAuthClient.tsx b/src/IdentityAuthClient.tsx index 3b78d9e570..8963b6bcf2 100644 --- a/src/IdentityAuthClient.tsx +++ b/src/IdentityAuthClient.tsx @@ -170,7 +170,7 @@ export default class IdentityAuthClient { // XXX: The spec is `token`, but we used `access_token` for a Sydent release. const { access_token: accessToken, token } = await this.identityClient.registerWithIdentityServer(hsOpenIdToken); - const identityAccessToken = token ? token : accessToken; + const identityAccessToken = token || accessToken; if (check) await this.checkToken(identityAccessToken); return identityAccessToken; } diff --git a/src/Lifecycle.ts b/src/Lifecycle.ts index 39d93dec11..89faa9e0e9 100644 --- a/src/Lifecycle.ts +++ b/src/Lifecycle.ts @@ -661,7 +661,7 @@ export async function setLoggedIn(credentials: IMatrixClientCreds): Promise string | null> = { [MsgType.KeyVerificationRequest]: (event: MatrixEvent) => { - const name = (event.sender || {}).name; + const name = event.sender?.name; return _t("notifier|m.key.verification.request", { name }); }, [M_LOCATION.name]: (event: MatrixEvent) => { @@ -233,7 +233,7 @@ class NotifierClass extends TypedEventEmitter void, ): Promise { const inviter = new MultiInviter(client, roomId, progressCallback); - return inviter.invite(addresses, undefined).then((states) => Promise.resolve({ states, inviter })); + return inviter.invite(addresses).then((states) => Promise.resolve({ states, inviter })); } export function showStartChatInviteDialog(initialText = ""): void { @@ -104,7 +104,7 @@ export function inviteUsersToRoom( logger.error(err.stack); Modal.createDialog(ErrorDialog, { title: _t("invite|failed_title"), - description: err && err.message ? err.message : _t("invite|failed_generic"), + description: err?.message ?? _t("invite|failed_generic"), }); }); } diff --git a/src/SlashCommands.tsx b/src/SlashCommands.tsx index 7375cba568..0215d5d689 100644 --- a/src/SlashCommands.tsx +++ b/src/SlashCommands.tsx @@ -450,7 +450,7 @@ export const Commands = [ const matches = args.match(/^(\S+)$/); if (matches) { let roomAlias = matches[1]; - if (roomAlias[0] !== "#") return reject(this.getUsage()); + if (!roomAlias.startsWith("#")) return reject(this.getUsage()); if (!roomAlias.includes(":")) { roomAlias += ":" + cli.getDomain(); @@ -994,7 +994,7 @@ Commands.forEach((cmd) => { export function parseCommandString(input: string): { cmd?: string; args?: string } { // trim any trailing whitespace, as it can confuse the parser for IRC-style commands input = input.trimEnd(); - if (input[0] !== "/") return {}; // not a command + if (input.startsWith("/")) return {}; // not a command const bits = input.match(/^(\S+?)(?:[ \n]+((.|\n)*))?$/); let cmd: string; diff --git a/src/SlidingSyncManager.ts b/src/SlidingSyncManager.ts index 578a175749..8137ecd15e 100644 --- a/src/SlidingSyncManager.ts +++ b/src/SlidingSyncManager.ts @@ -72,27 +72,23 @@ const DEFAULT_ROOM_SUBSCRIPTION_INFO = { }; // lazy load room members so rooms like Matrix HQ don't take forever to load const UNENCRYPTED_SUBSCRIPTION_NAME = "unencrypted"; -const UNENCRYPTED_SUBSCRIPTION = Object.assign( - { - required_state: [ - [MSC3575_WILDCARD, MSC3575_WILDCARD], // all events - [EventType.RoomMember, MSC3575_STATE_KEY_ME], // except for m.room.members, get our own membership - [EventType.RoomMember, MSC3575_STATE_KEY_LAZY], // ...and lazy load the rest. - ], - }, - DEFAULT_ROOM_SUBSCRIPTION_INFO, -); +const UNENCRYPTED_SUBSCRIPTION = { + required_state: [ + [MSC3575_WILDCARD, MSC3575_WILDCARD], // all events + [EventType.RoomMember, MSC3575_STATE_KEY_ME], // except for m.room.members, get our own membership + [EventType.RoomMember, MSC3575_STATE_KEY_LAZY], // ...and lazy load the rest. + ], + ...DEFAULT_ROOM_SUBSCRIPTION_INFO, +}; // we need all the room members in encrypted rooms because we need to know which users to encrypt // messages for. -const ENCRYPTED_SUBSCRIPTION = Object.assign( - { - required_state: [ - [MSC3575_WILDCARD, MSC3575_WILDCARD], // all events - ], - }, - DEFAULT_ROOM_SUBSCRIPTION_INFO, -); +const ENCRYPTED_SUBSCRIPTION = { + required_state: [ + [MSC3575_WILDCARD, MSC3575_WILDCARD], // all events + ], + ...DEFAULT_ROOM_SUBSCRIPTION_INFO, +}; export type PartialSlidingSyncRequest = { filters?: MSC3575Filter; @@ -199,10 +195,10 @@ export class SlidingSyncManager { [EventType.RoomMember, MSC3575_STATE_KEY_ME], // lets the client calculate that we are in fact in the room ], }, + ...updateArgs, }; - list = Object.assign(list, updateArgs); } else { - const updatedList = Object.assign({}, list, updateArgs); + const updatedList = { ...list, ...updateArgs }; // cannot use objectHasDiff as we need to do deep diff checking if (JSON.stringify(list) === JSON.stringify(updatedList)) { logger.debug("list matches, not sending, update => ", updateArgs); diff --git a/src/Terms.ts b/src/Terms.ts index ee5ddfd854..868e2428c6 100644 --- a/src/Terms.ts +++ b/src/Terms.ts @@ -102,13 +102,8 @@ export async function startTermsFlow( }); // fetch the set of agreed policy URLs from account data - const currentAcceptedTerms = await client.getAccountData("m.accepted_terms"); - let agreedUrlSet: Set; - if (!currentAcceptedTerms || !currentAcceptedTerms.getContent() || !currentAcceptedTerms.getContent().accepted) { - agreedUrlSet = new Set(); - } else { - agreedUrlSet = new Set(currentAcceptedTerms.getContent().accepted); - } + const currentAcceptedTerms = client.getAccountData("m.accepted_terms")?.getContent(); + const agreedUrlSet = new Set(currentAcceptedTerms?.accepted || []); // remove any policies the user has already agreed to and any services where // they've already agreed to all the policies diff --git a/src/actions/RoomListActions.ts b/src/actions/RoomListActions.ts index 1b693ba4dd..578226986d 100644 --- a/src/actions/RoomListActions.ts +++ b/src/actions/RoomListActions.ts @@ -79,7 +79,7 @@ export default class RoomListActions { logger.error("Failed to set DM tag " + err); Modal.createDialog(ErrorDialog, { title: _t("room_list|failed_set_dm_tag"), - description: err && err.message ? err.message : _t("invite|failed_generic"), + description: err?.message ?? _t("invite|failed_generic"), }); }); } @@ -95,7 +95,7 @@ export default class RoomListActions { logger.error("Failed to remove tag " + oldTag + " from room: " + err); Modal.createDialog(ErrorDialog, { title: _t("room_list|failed_remove_tag", { tagName: oldTag }), - description: err && err.message ? err.message : _t("invite|failed_generic"), + description: err?.message ?? _t("invite|failed_generic"), }); }); @@ -108,7 +108,7 @@ export default class RoomListActions { logger.error("Failed to add tag " + newTag + " to room: " + err); Modal.createDialog(ErrorDialog, { title: _t("room_list|failed_add_tag", { tagName: newTag }), - description: err && err.message ? err.message : _t("invite|failed_generic"), + description: err?.message ?? _t("invite|failed_generic"), }); throw err; diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index 8b23455967..fc1b5d970d 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -1317,7 +1317,7 @@ export default class MatrixChat extends React.PureComponent { const errCode = err.errcode || _td("error|unknown_error_code"); Modal.createDialog(ErrorDialog, { title: _t("error_dialog|forget_room_failed", { errCode }), - description: err && err.message ? err.message : _t("invite|failed_generic"), + description: err?.message ?? _t("invite|failed_generic"), }); }); } diff --git a/src/components/views/dialogs/RoomUpgradeDialog.tsx b/src/components/views/dialogs/RoomUpgradeDialog.tsx index 0935fca19f..337c1a334c 100644 --- a/src/components/views/dialogs/RoomUpgradeDialog.tsx +++ b/src/components/views/dialogs/RoomUpgradeDialog.tsx @@ -52,8 +52,7 @@ export default class RoomUpgradeDialog extends React.Component { .catch((err) => { Modal.createDialog(ErrorDialog, { title: _t("room_settings|advanced|error_upgrade_title"), - description: - err && err.message ? err.message : _t("room_settings|advanced|error_upgrade_description"), + description: err?.message ?? _t("room_settings|advanced|error_upgrade_description"), }); }) .finally(() => { diff --git a/src/components/views/right_panel/UserInfo.tsx b/src/components/views/right_panel/UserInfo.tsx index 73bb818bb5..e81f667da9 100644 --- a/src/components/views/right_panel/UserInfo.tsx +++ b/src/components/views/right_panel/UserInfo.tsx @@ -725,7 +725,7 @@ export const RoomKickButton = ({ logger.error("Kick error: " + err); Modal.createDialog(ErrorDialog, { title: _t("user_info|error_kicking_user"), - description: err && err.message ? err.message : "Operation failed", + description: err?.message ?? "Operation failed", }); }, ) diff --git a/src/components/views/settings/AddRemoveThreepids.tsx b/src/components/views/settings/AddRemoveThreepids.tsx index 4535400c33..8b2b61bb9a 100644 --- a/src/components/views/settings/AddRemoveThreepids.tsx +++ b/src/components/views/settings/AddRemoveThreepids.tsx @@ -74,7 +74,7 @@ const ExistingThreepid: React.FC = ({ mode, threepid, onC logger.error("Unable to remove contact information: " + err); Modal.createDialog(ErrorDialog, { title: _t("settings|general|error_remove_3pid"), - description: err && err.message ? err.message : _t("invite|failed_generic"), + description: err?.message ?? _t("invite|failed_generic"), }); }); },