From 31a28b1a9e486e447931c5975926cbdce72dc959 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Thu, 1 Apr 2021 13:26:36 +0100 Subject: [PATCH 01/33] Update extensions for some files with types This migrates one bucket of files using some amount of Flow typing to mark them as TypeScript instead. The remaining type errors are fixed in subsequent commits. --- src/{ScalarAuthClient.js => ScalarAuthClient.ts} | 0 .../{ManageEventIndexDialog.js => ManageEventIndexDialog.tsx} | 0 .../structures/auth/{SoftLogout.js => SoftLogout.tsx} | 0 src/components/views/rooms/{EventTile.js => EventTile.tsx} | 0 .../views/rooms/{MessageComposer.js => MessageComposer.tsx} | 0 .../rooms/{ThirdPartyMemberInfo.js => ThirdPartyMemberInfo.tsx} | 0 .../settings/{E2eAdvancedPanel.js => E2eAdvancedPanel.tsx} | 0 .../views/settings/{EventIndexPanel.js => EventIndexPanel.tsx} | 0 .../views/settings/{SetIdServer.js => SetIdServer.tsx} | 0 .../room/{RolesRoomSettingsTab.js => RolesRoomSettingsTab.tsx} | 0 .../{SecurityRoomSettingsTab.js => SecurityRoomSettingsTab.tsx} | 0 .../user/{HelpUserSettingsTab.js => HelpUserSettingsTab.tsx} | 2 +- .../{MjolnirUserSettingsTab.js => MjolnirUserSettingsTab.tsx} | 0 ...erencesUserSettingsTab.js => PreferencesUserSettingsTab.tsx} | 0 src/indexing/{EventIndexPeg.js => EventIndexPeg.ts} | 0 src/mjolnir/{BanList.js => BanList.ts} | 0 src/mjolnir/{ListRule.js => ListRule.ts} | 0 src/mjolnir/{Mjolnir.js => Mjolnir.ts} | 0 src/stores/{TypingStore.js => TypingStore.ts} | 0 src/stores/{WidgetEchoStore.js => WidgetEchoStore.ts} | 0 src/utils/{AutoDiscoveryUtils.js => AutoDiscoveryUtils.tsx} | 0 src/utils/{MatrixGlob.js => MatrixGlob.ts} | 0 src/utils/{StorageManager.js => StorageManager.ts} | 0 src/utils/{TypeUtils.js => TypeUtils.ts} | 0 ...ntPermalinkConstructor.js => ElementPermalinkConstructor.ts} | 0 .../{PermalinkConstructor.js => PermalinkConstructor.ts} | 0 src/utils/permalinks/{Permalinks.js => Permalinks.ts} | 0 ...{SpecPermalinkConstructor.js => SpecPermalinkConstructor.ts} | 0 28 files changed, 1 insertion(+), 1 deletion(-) rename src/{ScalarAuthClient.js => ScalarAuthClient.ts} (100%) rename src/async-components/views/dialogs/eventindex/{ManageEventIndexDialog.js => ManageEventIndexDialog.tsx} (100%) rename src/components/structures/auth/{SoftLogout.js => SoftLogout.tsx} (100%) rename src/components/views/rooms/{EventTile.js => EventTile.tsx} (100%) rename src/components/views/rooms/{MessageComposer.js => MessageComposer.tsx} (100%) rename src/components/views/rooms/{ThirdPartyMemberInfo.js => ThirdPartyMemberInfo.tsx} (100%) rename src/components/views/settings/{E2eAdvancedPanel.js => E2eAdvancedPanel.tsx} (100%) rename src/components/views/settings/{EventIndexPanel.js => EventIndexPanel.tsx} (100%) rename src/components/views/settings/{SetIdServer.js => SetIdServer.tsx} (100%) rename src/components/views/settings/tabs/room/{RolesRoomSettingsTab.js => RolesRoomSettingsTab.tsx} (100%) rename src/components/views/settings/tabs/room/{SecurityRoomSettingsTab.js => SecurityRoomSettingsTab.tsx} (100%) rename src/components/views/settings/tabs/user/{HelpUserSettingsTab.js => HelpUserSettingsTab.tsx} (99%) rename src/components/views/settings/tabs/user/{MjolnirUserSettingsTab.js => MjolnirUserSettingsTab.tsx} (100%) rename src/components/views/settings/tabs/user/{PreferencesUserSettingsTab.js => PreferencesUserSettingsTab.tsx} (100%) rename src/indexing/{EventIndexPeg.js => EventIndexPeg.ts} (100%) rename src/mjolnir/{BanList.js => BanList.ts} (100%) rename src/mjolnir/{ListRule.js => ListRule.ts} (100%) rename src/mjolnir/{Mjolnir.js => Mjolnir.ts} (100%) rename src/stores/{TypingStore.js => TypingStore.ts} (100%) rename src/stores/{WidgetEchoStore.js => WidgetEchoStore.ts} (100%) rename src/utils/{AutoDiscoveryUtils.js => AutoDiscoveryUtils.tsx} (100%) rename src/utils/{MatrixGlob.js => MatrixGlob.ts} (100%) rename src/utils/{StorageManager.js => StorageManager.ts} (100%) rename src/utils/{TypeUtils.js => TypeUtils.ts} (100%) rename src/utils/permalinks/{ElementPermalinkConstructor.js => ElementPermalinkConstructor.ts} (100%) rename src/utils/permalinks/{PermalinkConstructor.js => PermalinkConstructor.ts} (100%) rename src/utils/permalinks/{Permalinks.js => Permalinks.ts} (100%) rename src/utils/permalinks/{SpecPermalinkConstructor.js => SpecPermalinkConstructor.ts} (100%) diff --git a/src/ScalarAuthClient.js b/src/ScalarAuthClient.ts similarity index 100% rename from src/ScalarAuthClient.js rename to src/ScalarAuthClient.ts diff --git a/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.js b/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx similarity index 100% rename from src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.js rename to src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx diff --git a/src/components/structures/auth/SoftLogout.js b/src/components/structures/auth/SoftLogout.tsx similarity index 100% rename from src/components/structures/auth/SoftLogout.js rename to src/components/structures/auth/SoftLogout.tsx diff --git a/src/components/views/rooms/EventTile.js b/src/components/views/rooms/EventTile.tsx similarity index 100% rename from src/components/views/rooms/EventTile.js rename to src/components/views/rooms/EventTile.tsx diff --git a/src/components/views/rooms/MessageComposer.js b/src/components/views/rooms/MessageComposer.tsx similarity index 100% rename from src/components/views/rooms/MessageComposer.js rename to src/components/views/rooms/MessageComposer.tsx diff --git a/src/components/views/rooms/ThirdPartyMemberInfo.js b/src/components/views/rooms/ThirdPartyMemberInfo.tsx similarity index 100% rename from src/components/views/rooms/ThirdPartyMemberInfo.js rename to src/components/views/rooms/ThirdPartyMemberInfo.tsx diff --git a/src/components/views/settings/E2eAdvancedPanel.js b/src/components/views/settings/E2eAdvancedPanel.tsx similarity index 100% rename from src/components/views/settings/E2eAdvancedPanel.js rename to src/components/views/settings/E2eAdvancedPanel.tsx diff --git a/src/components/views/settings/EventIndexPanel.js b/src/components/views/settings/EventIndexPanel.tsx similarity index 100% rename from src/components/views/settings/EventIndexPanel.js rename to src/components/views/settings/EventIndexPanel.tsx diff --git a/src/components/views/settings/SetIdServer.js b/src/components/views/settings/SetIdServer.tsx similarity index 100% rename from src/components/views/settings/SetIdServer.js rename to src/components/views/settings/SetIdServer.tsx diff --git a/src/components/views/settings/tabs/room/RolesRoomSettingsTab.js b/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx similarity index 100% rename from src/components/views/settings/tabs/room/RolesRoomSettingsTab.js rename to src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx diff --git a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.js b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx similarity index 100% rename from src/components/views/settings/tabs/room/SecurityRoomSettingsTab.js rename to src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx diff --git a/src/components/views/settings/tabs/user/HelpUserSettingsTab.js b/src/components/views/settings/tabs/user/HelpUserSettingsTab.tsx similarity index 99% rename from src/components/views/settings/tabs/user/HelpUserSettingsTab.js rename to src/components/views/settings/tabs/user/HelpUserSettingsTab.tsx index e16ee686f5..05f14cebc8 100644 --- a/src/components/views/settings/tabs/user/HelpUserSettingsTab.js +++ b/src/components/views/settings/tabs/user/HelpUserSettingsTab.tsx @@ -23,7 +23,7 @@ import AccessibleButton from "../../../elements/AccessibleButton"; import SdkConfig from "../../../../../SdkConfig"; import createRoom from "../../../../../createRoom"; import Modal from "../../../../../Modal"; -import * as sdk from "../../../../../"; +import * as sdk from "../../../../.."; import PlatformPeg from "../../../../../PlatformPeg"; import * as KeyboardShortcuts from "../../../../../accessibility/KeyboardShortcuts"; import UpdateCheckButton from "../../UpdateCheckButton"; diff --git a/src/components/views/settings/tabs/user/MjolnirUserSettingsTab.js b/src/components/views/settings/tabs/user/MjolnirUserSettingsTab.tsx similarity index 100% rename from src/components/views/settings/tabs/user/MjolnirUserSettingsTab.js rename to src/components/views/settings/tabs/user/MjolnirUserSettingsTab.tsx diff --git a/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.js b/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx similarity index 100% rename from src/components/views/settings/tabs/user/PreferencesUserSettingsTab.js rename to src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx diff --git a/src/indexing/EventIndexPeg.js b/src/indexing/EventIndexPeg.ts similarity index 100% rename from src/indexing/EventIndexPeg.js rename to src/indexing/EventIndexPeg.ts diff --git a/src/mjolnir/BanList.js b/src/mjolnir/BanList.ts similarity index 100% rename from src/mjolnir/BanList.js rename to src/mjolnir/BanList.ts diff --git a/src/mjolnir/ListRule.js b/src/mjolnir/ListRule.ts similarity index 100% rename from src/mjolnir/ListRule.js rename to src/mjolnir/ListRule.ts diff --git a/src/mjolnir/Mjolnir.js b/src/mjolnir/Mjolnir.ts similarity index 100% rename from src/mjolnir/Mjolnir.js rename to src/mjolnir/Mjolnir.ts diff --git a/src/stores/TypingStore.js b/src/stores/TypingStore.ts similarity index 100% rename from src/stores/TypingStore.js rename to src/stores/TypingStore.ts diff --git a/src/stores/WidgetEchoStore.js b/src/stores/WidgetEchoStore.ts similarity index 100% rename from src/stores/WidgetEchoStore.js rename to src/stores/WidgetEchoStore.ts diff --git a/src/utils/AutoDiscoveryUtils.js b/src/utils/AutoDiscoveryUtils.tsx similarity index 100% rename from src/utils/AutoDiscoveryUtils.js rename to src/utils/AutoDiscoveryUtils.tsx diff --git a/src/utils/MatrixGlob.js b/src/utils/MatrixGlob.ts similarity index 100% rename from src/utils/MatrixGlob.js rename to src/utils/MatrixGlob.ts diff --git a/src/utils/StorageManager.js b/src/utils/StorageManager.ts similarity index 100% rename from src/utils/StorageManager.js rename to src/utils/StorageManager.ts diff --git a/src/utils/TypeUtils.js b/src/utils/TypeUtils.ts similarity index 100% rename from src/utils/TypeUtils.js rename to src/utils/TypeUtils.ts diff --git a/src/utils/permalinks/ElementPermalinkConstructor.js b/src/utils/permalinks/ElementPermalinkConstructor.ts similarity index 100% rename from src/utils/permalinks/ElementPermalinkConstructor.js rename to src/utils/permalinks/ElementPermalinkConstructor.ts diff --git a/src/utils/permalinks/PermalinkConstructor.js b/src/utils/permalinks/PermalinkConstructor.ts similarity index 100% rename from src/utils/permalinks/PermalinkConstructor.js rename to src/utils/permalinks/PermalinkConstructor.ts diff --git a/src/utils/permalinks/Permalinks.js b/src/utils/permalinks/Permalinks.ts similarity index 100% rename from src/utils/permalinks/Permalinks.js rename to src/utils/permalinks/Permalinks.ts diff --git a/src/utils/permalinks/SpecPermalinkConstructor.js b/src/utils/permalinks/SpecPermalinkConstructor.ts similarity index 100% rename from src/utils/permalinks/SpecPermalinkConstructor.js rename to src/utils/permalinks/SpecPermalinkConstructor.ts From 9c3bd12830e7ba1775202649f7030e590d6847be Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Fri, 23 Apr 2021 15:47:01 +0100 Subject: [PATCH 02/33] Copy indent rule to TS as well --- .eslintrc.js | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.js b/.eslintrc.js index 99695b7a03..09fd8de74f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -30,6 +30,7 @@ module.exports = { "@typescript-eslint/ban-ts-comment": "off", "quotes": "off", + "indent": "off", "no-extra-boolean-cast": "off", }, }], From 0e92251f70e92a983e3bff3418c32fc5d9572bca Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Thu, 1 Apr 2021 14:15:21 +0100 Subject: [PATCH 03/33] Fix simple lint errors --- src/@types/common.ts | 1 + src/CallHandler.tsx | 2 +- src/KeyBindingsManager.ts | 6 ++-- src/ScalarAuthClient.ts | 6 ++-- src/components/views/rooms/EventTile.tsx | 6 +++- .../views/rooms/MessageComposer.tsx | 4 ++- .../views/settings/EventIndexPanel.tsx | 3 +- .../tabs/user/HelpUserSettingsTab.tsx | 34 +++++++++---------- 8 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/@types/common.ts b/src/@types/common.ts index b887bd4090..e5503a0b68 100644 --- a/src/@types/common.ts +++ b/src/@types/common.ts @@ -17,6 +17,7 @@ limitations under the License. import { JSXElementConstructor } from "react"; // Based on https://stackoverflow.com/a/53229857/3532235 +// eslint-disable-next-line @typescript-eslint/type-annotation-spacing export type Without = {[P in Exclude] ? : never}; export type XOR = (T | U) extends object ? (Without & U) | (Without & T) : T | U; export type Writeable = { -readonly [P in keyof T]: T[P] }; diff --git a/src/CallHandler.tsx b/src/CallHandler.tsx index be687a4474..237b323ce7 100644 --- a/src/CallHandler.tsx +++ b/src/CallHandler.tsx @@ -673,7 +673,7 @@ export default class CallHandler { call.placeScreenSharingCall( remoteElement, localElement, - async () : Promise => { + async (): Promise => { const {finished} = Modal.createDialog(DesktopCapturerSourcePicker); const [source] = await finished; return source; diff --git a/src/KeyBindingsManager.ts b/src/KeyBindingsManager.ts index d862f10c02..aac14bde20 100644 --- a/src/KeyBindingsManager.ts +++ b/src/KeyBindingsManager.ts @@ -231,8 +231,10 @@ export class KeyBindingsManager { /** * Finds a matching KeyAction for a given KeyboardEvent */ - private getAction(getters: KeyBindingGetter[], ev: KeyboardEvent | React.KeyboardEvent) - : T | undefined { + private getAction( + getters: KeyBindingGetter[], + ev: KeyboardEvent | React.KeyboardEvent, + ): T | undefined { for (const getter of getters) { const bindings = getter(); const binding = bindings.find(it => isKeyComboMatch(ev, it.keyCombo, isMac)); diff --git a/src/ScalarAuthClient.ts b/src/ScalarAuthClient.ts index 200b4fd7b9..408a264138 100644 --- a/src/ScalarAuthClient.ts +++ b/src/ScalarAuthClient.ts @@ -194,7 +194,7 @@ export default class ScalarAuthClient { if (err) { reject(err); } else if (response.statusCode / 100 !== 2) { - reject({statusCode: response.statusCode}); + reject(new Error(`Scalar request failed: ${response.statusCode}`)); } else if (!body || !body.scalar_token) { reject(new Error("Missing scalar_token in response")); } else { @@ -218,7 +218,7 @@ export default class ScalarAuthClient { if (err) { reject(err); } else if (response.statusCode / 100 !== 2) { - reject({statusCode: response.statusCode}); + reject(new Error(`Scalar request failed: ${response.statusCode}`)); } else if (!body) { reject(new Error("Missing page title in response")); } else { @@ -257,7 +257,7 @@ export default class ScalarAuthClient { if (err) { reject(err); } else if (response.statusCode / 100 !== 2) { - reject({statusCode: response.statusCode}); + reject(new Error(`Scalar request failed: ${response.statusCode}`)); } else if (!body) { reject(new Error("Failed to set widget assets state")); } else { diff --git a/src/components/views/rooms/EventTile.tsx b/src/components/views/rooms/EventTile.tsx index f6fb83c064..b63a06f751 100644 --- a/src/components/views/rooms/EventTile.tsx +++ b/src/components/views/rooms/EventTile.tsx @@ -1182,7 +1182,11 @@ function E2ePadlockUnknown(props) { function E2ePadlockUnauthenticated(props) { return ( - + ); } diff --git a/src/components/views/rooms/MessageComposer.tsx b/src/components/views/rooms/MessageComposer.tsx index 5178d52305..90f4a4ca48 100644 --- a/src/components/views/rooms/MessageComposer.tsx +++ b/src/components/views/rooms/MessageComposer.tsx @@ -394,7 +394,9 @@ export default class MessageComposer extends React.Component { controls.push(
- + {_t("This room has been replaced and is no longer active.")}
diff --git a/src/components/views/settings/EventIndexPanel.tsx b/src/components/views/settings/EventIndexPanel.tsx index d1a02de16d..3862ffa155 100644 --- a/src/components/views/settings/EventIndexPanel.tsx +++ b/src/components/views/settings/EventIndexPanel.tsx @@ -124,13 +124,12 @@ export default class EventIndexPanel extends React.Component { } _confirmEventStoreReset = () => { - const self = this; const { close } = Modal.createDialog(SeshatResetDialog, { onFinished: async (success) => { if (success) { await SettingsStore.setValue('enableEventIndexing', null, SettingLevel.DEVICE, false); await EventIndexPeg.deleteEventIndex(); - await self._onEnable(); + await this._onEnable(); close(); } }, diff --git a/src/components/views/settings/tabs/user/HelpUserSettingsTab.tsx b/src/components/views/settings/tabs/user/HelpUserSettingsTab.tsx index 05f14cebc8..ca9629179d 100644 --- a/src/components/views/settings/tabs/user/HelpUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/HelpUserSettingsTab.tsx @@ -122,28 +122,28 @@ export default class HelpUserSettingsTab extends React.Component { {_t("Credits")}
From d7e6f4b4b5ca1cd0898b7b9f49469f5f382ef77d Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Tue, 6 Apr 2021 12:26:50 +0100 Subject: [PATCH 04/33] Add basic types --- src/@types/global.d.ts | 8 +- src/Login.ts | 7 +- src/ScalarAuthClient.ts | 15 +- src/{Terms.js => Terms.ts} | 45 ++- .../eventindex/ManageEventIndexDialog.tsx | 24 +- src/components/structures/auth/Login.tsx | 4 +- .../structures/auth/Registration.tsx | 4 +- src/components/structures/auth/SoftLogout.tsx | 41 ++- .../views/dialogs/ServerPickerDialog.tsx | 6 +- .../views/elements/ServerPicker.tsx | 4 +- src/components/views/rooms/EventTile.tsx | 261 ++++++++++-------- .../views/rooms/MessageComposer.tsx | 129 ++++----- .../views/rooms/ThirdPartyMemberInfo.tsx | 23 +- .../views/settings/EventIndexPanel.tsx | 19 +- src/components/views/settings/SetIdServer.tsx | 35 ++- .../tabs/room/RolesRoomSettingsTab.tsx | 28 +- .../tabs/room/SecurityRoomSettingsTab.tsx | 43 +-- .../tabs/user/HelpUserSettingsTab.tsx | 25 +- .../tabs/user/MjolnirUserSettingsTab.tsx | 14 +- .../tabs/user/PreferencesUserSettingsTab.tsx | 26 +- src/indexing/BaseEventIndexManager.ts | 6 +- src/indexing/EventIndexPeg.ts | 17 +- src/stores/TypingStore.ts | 16 +- src/stores/WidgetEchoStore.ts | 14 +- src/utils/AutoDiscoveryUtils.tsx | 32 ++- src/utils/StorageManager.ts | 8 +- src/utils/{Timer.js => Timer.ts} | 11 +- .../permalinks/ElementPermalinkConstructor.ts | 6 +- src/utils/permalinks/Permalinks.ts | 11 +- 29 files changed, 542 insertions(+), 340 deletions(-) rename src/{Terms.js => Terms.ts} (87%) rename src/utils/{Timer.js => Timer.ts} (91%) diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index ee0963e537..6470501769 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -1,5 +1,5 @@ /* -Copyright 2020 The Matrix.org Foundation C.I.C. +Copyright 2020-2021 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -40,6 +40,8 @@ import { WidgetLayoutStore } from "../stores/widgets/WidgetLayoutStore"; import VoipUserMapper from "../VoipUserMapper"; import {SpaceStoreClass} from "../stores/SpaceStore"; import {VoiceRecording} from "../voice/VoiceRecording"; +import TypingStore from "../stores/TypingStore"; +import { EventIndexPeg } from "../indexing/EventIndexPeg"; declare global { interface Window { @@ -72,11 +74,15 @@ declare global { mxVoipUserMapper: VoipUserMapper; mxSpaceStore: SpaceStoreClass; mxVoiceRecorder: typeof VoiceRecording; + mxTypingStore: TypingStore; + mxEventIndexPeg: EventIndexPeg; } interface Document { // https://developer.mozilla.org/en-US/docs/Web/API/Document/hasStorageAccess hasStorageAccess?: () => Promise; + // https://developer.mozilla.org/en-US/docs/Web/API/Document/requestStorageAccess + requestStorageAccess?: () => Promise; // Safari & IE11 only have this prefixed: we used prefixed versions // previously so let's continue to support them for now diff --git a/src/Login.ts b/src/Login.ts index db3c4c11e4..d584df7dfe 100644 --- a/src/Login.ts +++ b/src/Login.ts @@ -1,9 +1,6 @@ /* -Copyright 2015, 2016 OpenMarket Ltd -Copyright 2017 Vector Creations Ltd -Copyright 2018 New Vector Ltd +Copyright 2015-2021 The Matrix.org Foundation C.I.C. Copyright 2019 Michael Telatynski <7t3chguy@gmail.com> -Copyright 2020 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -59,7 +56,7 @@ export type LoginFlow = ISSOFlow | IPasswordFlow; // TODO: Move this to JS SDK /* eslint-disable camelcase */ interface ILoginParams { - identifier?: string; + identifier?: object; password?: string; token?: string; device_id?: string; diff --git a/src/ScalarAuthClient.ts b/src/ScalarAuthClient.ts index 408a264138..3c63bf8047 100644 --- a/src/ScalarAuthClient.ts +++ b/src/ScalarAuthClient.ts @@ -1,6 +1,5 @@ /* -Copyright 2016 OpenMarket Ltd -Copyright 2019 The Matrix.org Foundation C.I.C. +Copyright 2016, 2019, 2021 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -17,7 +16,7 @@ limitations under the License. import url from 'url'; import SettingsStore from "./settings/SettingsStore"; -import { Service, startTermsFlow, TermsNotSignedError } from './Terms'; +import { Service, startTermsFlow, TermsInteractionCallback, TermsNotSignedError } from './Terms'; import {MatrixClientPeg} from "./MatrixClientPeg"; import request from "browser-request"; @@ -31,6 +30,12 @@ const imApiVersion = "1.1"; // TODO: Generify the name of this class and all components within - it's not just for Scalar. export default class ScalarAuthClient { + private apiUrl: string; + private uiUrl: string; + private scalarToken: string; + private termsInteractionCallback: TermsInteractionCallback; + private isDefaultManager: boolean; + constructor(apiUrl, uiUrl) { this.apiUrl = apiUrl; this.uiUrl = uiUrl; @@ -154,7 +159,7 @@ export default class ScalarAuthClient { parsedImRestUrl.pathname = ''; return startTermsFlow([new Service( SERVICE_TYPES.IM, - parsedImRestUrl.format(), + url.format(parsedImRestUrl), token, )], this.termsInteractionCallback).then(() => { return token; @@ -243,7 +248,7 @@ export default class ScalarAuthClient { disableWidgetAssets(widgetType: WidgetType, widgetId) { let url = this.apiUrl + '/widgets/set_assets_state'; url = this.getStarterLink(url); - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { request({ method: 'GET', // XXX: Actions shouldn't be GET requests uri: url, diff --git a/src/Terms.js b/src/Terms.ts similarity index 87% rename from src/Terms.js rename to src/Terms.ts index 6ae89f9a2c..382e2d9782 100644 --- a/src/Terms.js +++ b/src/Terms.ts @@ -1,5 +1,5 @@ /* -Copyright 2019 The Matrix.org Foundation C.I.C. +Copyright 2019, 2021 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ limitations under the License. import classNames from 'classnames'; import {MatrixClientPeg} from './MatrixClientPeg'; -import * as sdk from './'; +import * as sdk from '.'; import Modal from './Modal'; export class TermsNotSignedError extends Error {} @@ -27,6 +27,10 @@ export class TermsNotSignedError extends Error {} * require agreement from the user before the user can use that service. */ export class Service { + public serviceType: string; + public baseUrl: string; + public accessToken: string; + /** * @param {MatrixClient.SERVICE_TYPES} serviceType The type of service * @param {string} baseUrl The Base URL of the service (ie. before '/_matrix') @@ -39,6 +43,26 @@ export class Service { } } +interface Policy { + // @ts-ignore: No great way to express indexed types together with other keys + version: string; + [lang: string]: { + url: string; + }; +} +type Policies = { + [policy: string]: Policy, +}; + +export type TermsInteractionCallback = ( + policiesAndServicePairs: { + service: Service, + policies: Policies, + }[], + agreedUrls: string[], + extraClassNames?: string, +) => Promise; + /** * Start a flow where the user is presented with terms & conditions for some services * @@ -51,8 +75,8 @@ export class Service { * if they cancel. */ export async function startTermsFlow( - services, - interactionCallback = dialogTermsInteractionCallback, + services: Service[], + interactionCallback: TermsInteractionCallback = dialogTermsInteractionCallback, ) { const termsPromises = services.map( (s) => MatrixClientPeg.get().getTerms(s.serviceType, s.baseUrl), @@ -77,7 +101,7 @@ export async function startTermsFlow( * } */ - const terms = await Promise.all(termsPromises); + const terms: { policies: Policies }[] = await Promise.all(termsPromises); const policiesAndServicePairs = terms.map((t, i) => { return { 'service': services[i], 'policies': t.policies }; }); // fetch the set of agreed policy URLs from account data @@ -158,10 +182,13 @@ export async function startTermsFlow( } export function dialogTermsInteractionCallback( - policiesAndServicePairs, - agreedUrls, - extraClassNames, -) { + policiesAndServicePairs: { + service: Service, + policies: { [policy: string]: Policy }, + }[], + agreedUrls: string[], + extraClassNames?: string, +): Promise { return new Promise((resolve, reject) => { console.log("Terms that need agreement", policiesAndServicePairs); const TermsDialog = sdk.getComponent("views.dialogs.TermsDialog"); diff --git a/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx b/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx index be3368b87b..783d40081a 100644 --- a/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx +++ b/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx @@ -1,5 +1,5 @@ /* -Copyright 2020 The Matrix.org Foundation C.I.C. +Copyright 2020-2021 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ limitations under the License. import React from 'react'; import * as sdk from '../../../../index'; -import PropTypes from 'prop-types'; import { _t } from '../../../../languageHandler'; import SdkConfig from '../../../../SdkConfig'; import SettingsStore from "../../../../settings/SettingsStore"; @@ -26,14 +25,23 @@ import {formatBytes, formatCountLong} from "../../../../utils/FormattingUtils"; import EventIndexPeg from "../../../../indexing/EventIndexPeg"; import {SettingLevel} from "../../../../settings/SettingLevel"; +interface IProps { + onFinished: (boolean) => {}, +} + +interface IState { + eventIndexSize: number; + eventCount: number; + crawlingRoomsCount: number; + roomCount: number; + currentRoom: string; + crawlerSleepTime: number; +} + /* * Allows the user to introspect the event index state and disable it. */ -export default class ManageEventIndexDialog extends React.Component { - static propTypes = { - onFinished: PropTypes.func.isRequired, - }; - +export default class ManageEventIndexDialog extends React.Component { constructor(props) { super(props); @@ -84,7 +92,7 @@ export default class ManageEventIndexDialog extends React.Component { } } - async componentDidMount(): void { + async componentDidMount(): Promise { let eventIndexSize = 0; let crawlingRoomsCount = 0; let roomCount = 0; diff --git a/src/components/structures/auth/Login.tsx b/src/components/structures/auth/Login.tsx index 3ab73fb9ac..34a5410928 100644 --- a/src/components/structures/auth/Login.tsx +++ b/src/components/structures/auth/Login.tsx @@ -1,5 +1,5 @@ /* -Copyright 2015, 2016, 2017, 2018, 2019 The Matrix.org Foundation C.I.C. +Copyright 2015-2021 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -94,7 +94,7 @@ interface IState { // be seeing. serverIsAlive: boolean; serverErrorIsFatal: boolean; - serverDeadError: string; + serverDeadError?: ReactNode; } /* diff --git a/src/components/structures/auth/Registration.tsx b/src/components/structures/auth/Registration.tsx index 73955e7832..96fb9bdc82 100644 --- a/src/components/structures/auth/Registration.tsx +++ b/src/components/structures/auth/Registration.tsx @@ -1,5 +1,5 @@ /* -Copyright 2015, 2016, 2017, 2018, 2019, 2020 The Matrix.org Foundation C.I.C. +Copyright 2015-2021 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -95,7 +95,7 @@ interface IState { // be seeing. serverIsAlive: boolean; serverErrorIsFatal: boolean; - serverDeadError: string; + serverDeadError?: ReactNode; // Our matrix client - part of state because we can't render the UI auth // component without it. diff --git a/src/components/structures/auth/SoftLogout.tsx b/src/components/structures/auth/SoftLogout.tsx index 08db3b2efe..6b24535657 100644 --- a/src/components/structures/auth/SoftLogout.tsx +++ b/src/components/structures/auth/SoftLogout.tsx @@ -1,5 +1,5 @@ /* -Copyright 2019 The Matrix.org Foundation C.I.C. +Copyright 2019-2021 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,14 +15,13 @@ limitations under the License. */ import React from 'react'; -import PropTypes from 'prop-types'; import {_t} from '../../../languageHandler'; import * as sdk from '../../../index'; import dis from '../../../dispatcher/dispatcher'; import * as Lifecycle from '../../../Lifecycle'; import Modal from '../../../Modal'; import {MatrixClientPeg} from "../../../MatrixClientPeg"; -import {sendLoginRequest} from "../../../Login"; +import {ISSOFlow, LoginFlow, sendLoginRequest} from "../../../Login"; import AuthPage from "../../views/auth/AuthPage"; import {SSO_HOMESERVER_URL_KEY, SSO_ID_SERVER_URL_KEY} from "../../../BasePlatform"; import SSOButtons from "../../views/elements/SSOButtons"; @@ -42,26 +41,38 @@ const FLOWS_TO_VIEWS = { "m.login.sso": LOGIN_VIEW.SSO, }; -@replaceableComponent("structures.auth.SoftLogout") -export default class SoftLogout extends React.Component { - static propTypes = { - // Query parameters from MatrixChat - realQueryParams: PropTypes.object, // {loginToken} - - // Called when the SSO login completes - onTokenLoginCompleted: PropTypes.func, +interface IProps { + // Query parameters from MatrixChat + realQueryParams: { + loginToken?: string; }; + fragmentAfterLogin?: string; - constructor() { - super(); + // Called when the SSO login completes + onTokenLoginCompleted: () => void, +} + +interface IState { + loginView: number; + keyBackupNeeded: boolean; + busy: boolean; + password: string; + errorText: string; + flows: LoginFlow[]; +} + +@replaceableComponent("structures.auth.SoftLogout") +export default class SoftLogout extends React.Component { + constructor(props) { + super(props); this.state = { loginView: LOGIN_VIEW.LOADING, keyBackupNeeded: true, // assume we do while we figure it out (see componentDidMount) - busy: false, password: "", errorText: "", + flows: [], }; } @@ -247,7 +258,7 @@ export default class SoftLogout extends React.Component { } // else we already have a message and should use it (key backup warning) const loginType = this.state.loginView === LOGIN_VIEW.CAS ? "cas" : "sso"; - const flow = this.state.flows.find(flow => flow.type === "m.login." + loginType); + const flow = this.state.flows.find(flow => flow.type === "m.login." + loginType) as ISSOFlow; return (
diff --git a/src/components/views/dialogs/ServerPickerDialog.tsx b/src/components/views/dialogs/ServerPickerDialog.tsx index 4abc0a88b1..62a2b95c68 100644 --- a/src/components/views/dialogs/ServerPickerDialog.tsx +++ b/src/components/views/dialogs/ServerPickerDialog.tsx @@ -1,5 +1,5 @@ /* -Copyright 2020 The Matrix.org Foundation C.I.C. +Copyright 2020-2021 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -110,7 +110,7 @@ export default class ServerPickerDialog extends React.PureComponent diff --git a/src/components/views/elements/ServerPicker.tsx b/src/components/views/elements/ServerPicker.tsx index 4551a49deb..9f06e2618c 100644 --- a/src/components/views/elements/ServerPicker.tsx +++ b/src/components/views/elements/ServerPicker.tsx @@ -1,5 +1,5 @@ /* -Copyright 2020 The Matrix.org Foundation C.I.C. +Copyright 2020-2021 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -67,7 +67,7 @@ const ServerPicker = ({ title, dialogTitle, serverConfig, onServerConfigChange } ; } - let serverName = serverConfig.isNameResolvable ? serverConfig.hsName : serverConfig.hsUrl; + let serverName: React.ReactNode = serverConfig.isNameResolvable ? serverConfig.hsName : serverConfig.hsUrl; if (serverConfig.hsNameIsDifferent) { serverName =
+ mxEvent={this.props.mxEvent} + highlights={this.props.highlights} + highlightLink={this.props.highlightLink} + showUrlPreview={this.props.showUrlPreview} + onHeightChanged={this.props.onHeightChanged} + />
); @@ -1063,12 +1065,13 @@ export default class EventTile extends React.Component {
+ mxEvent={this.props.mxEvent} + highlights={this.props.highlights} + highlightLink={this.props.highlightLink} + showUrlPreview={this.props.showUrlPreview} + tileShape={this.props.tileShape} + onHeightChanged={this.props.onHeightChanged} + />
{ { groupPadlock } { thread } + mxEvent={this.props.mxEvent} + highlights={this.props.highlights} + highlightLink={this.props.highlightLink} + onHeightChanged={this.props.onHeightChanged} + replacingEventId={this.props.replacingEventId} + showUrlPreview={false} + />
); @@ -1136,14 +1140,15 @@ export default class EventTile extends React.Component { { groupPadlock } { thread } + mxEvent={this.props.mxEvent} + replacingEventId={this.props.replacingEventId} + editState={this.props.editState} + highlights={this.props.highlights} + highlightLink={this.props.highlightLink} + showUrlPreview={this.props.showUrlPreview} + permalinkCreator={this.props.permalinkCreator} + onHeightChanged={this.props.onHeightChanged} + /> { keyRequestInfo } { reactionsRow } { actionBar } diff --git a/src/components/views/settings/EventIndexPanel.tsx b/src/components/views/settings/EventIndexPanel.tsx index 8ea2832405..c97b436854 100644 --- a/src/components/views/settings/EventIndexPanel.tsx +++ b/src/components/views/settings/EventIndexPanel.tsx @@ -153,18 +153,17 @@ export default class EventIndexPanel extends React.Component<{}, IState> { if (EventIndexPeg.get() !== null) { eventIndexingSettings = (
-
- {_t("Securely cache encrypted messages locally for them " + - "to appear in search results, using %(size)s to store messages from %(rooms)s rooms.", - { - size: formatBytes(this.state.eventIndexSize, 0), - // This drives the singular / plural string - // selection for "room" / "rooms" only. - count: this.state.roomCount, - rooms: formatCountLong(this.state.roomCount), - }, - )} -
+
{_t( + "Securely cache encrypted messages locally for them " + + "to appear in search results, using %(size)s to store messages from %(rooms)s rooms.", + { + size: formatBytes(this.state.eventIndexSize, 0), + // This drives the singular / plural string + // selection for "room" / "rooms" only. + count: this.state.roomCount, + rooms: formatCountLong(this.state.roomCount), + }, + )}
{_t("Manage")} @@ -175,10 +174,10 @@ export default class EventIndexPanel extends React.Component<{}, IState> { } else if (!this.state.eventIndexingEnabled && EventIndexPeg.supportIsInstalled()) { eventIndexingSettings = (
-
- {_t( "Securely cache encrypted messages locally for them to " + - "appear in search results.")} -
+
{_t( + "Securely cache encrypted messages locally for them to " + + "appear in search results.", + )}
@@ -196,40 +195,36 @@ export default class EventIndexPanel extends React.Component<{}, IState> { ); eventIndexingSettings = ( - ); } else if (!EventIndexPeg.platformHasSupport()) { eventIndexingSettings = ( -
+
{_t( + "%(brand)s can't securely cache encrypted messages locally " + + "while running in a web browser. Use %(brand)s Desktop " + + "for encrypted messages to appear in search results.", { - _t( "%(brand)s can't securely cache encrypted messages locally " + - "while running in a web browser. Use %(brand)s Desktop " + - "for encrypted messages to appear in search results.", - { - brand, - }, - { - 'desktopLink': (sub) => {sub}, - }, - ) - } -
+ brand, + }, + { + desktopLink: sub => {sub}, + }, + )}
); } else { eventIndexingSettings = ( @@ -241,19 +236,18 @@ export default class EventIndexPanel extends React.Component<{}, IState> { }

{EventIndexPeg.error && ( -
- {_t("Advanced")} - - {EventIndexPeg.error.message} - -

- - {_t("Reset")} - -

-
+
+ {_t("Advanced")} + + {EventIndexPeg.error.message} + +

+ + {_t("Reset")} + +

+
)} -
); } diff --git a/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx index 8b791b5634..f5fd537918 100644 --- a/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx @@ -87,8 +87,10 @@ export class BannedUser extends React.Component { if (this.props.canUnban) { unbanButton = ( - + { _t('Unban') } ); @@ -345,8 +347,9 @@ export default class RolesRoomSettingsTab extends React.Component { if (sender) bannedBy = sender.name; return ( + member={member} reason={banEvent.reason} + by={bannedBy} + /> ); })} diff --git a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx index f238a76ed7..a8cd920eb2 100644 --- a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx @@ -113,10 +113,9 @@ export default class SecurityRoomSettingsTab extends React.ComponentLearn more about encryption.", {}, { - 'a': (sub) => { - return {sub}; - }, + a: sub => {sub}, }, ), onFinished: (confirm) => { @@ -385,7 +384,8 @@ export default class SecurityRoomSettingsTab extends React.Component{_t("Once enabled, encryption cannot be disabled.")}
+ label={_t("Encrypted")} disabled={!canEnableEncryption} + />
{encryptionSettings}
diff --git a/src/components/views/settings/tabs/user/HelpUserSettingsTab.tsx b/src/components/views/settings/tabs/user/HelpUserSettingsTab.tsx index c982de6713..b620088096 100644 --- a/src/components/views/settings/tabs/user/HelpUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/HelpUserSettingsTab.tsx @@ -215,28 +215,27 @@ export default class HelpUserSettingsTab extends React.Component
{_t('Bug reporting')}
- { - _t( "If you've submitted a bug via GitHub, debug logs can help " + - "us track down the problem. Debug logs contain application " + - "usage data including your username, the IDs or aliases of " + - "the rooms or groups you have visited and the usernames of " + - "other users. They do not contain messages.", - ) - } + {_t( + "If you've submitted a bug via GitHub, debug logs can help " + + "us track down the problem. Debug logs contain application " + + "usage data including your username, the IDs or aliases of " + + "the rooms or groups you have visited and the usernames of " + + "other users. They do not contain messages.", + )}
{_t("Submit debug logs")}
- { - _t( "To report a Matrix-related security issue, please read the Matrix.org " + - "Security Disclosure Policy.", {}, - { - 'a': (sub) => - {sub}, - }) - } + {_t( + "To report a Matrix-related security issue, please read the Matrix.org " + + "Security Disclosure Policy.", {}, + { + a: sub => {sub}, + }, + )}
); @@ -272,7 +271,8 @@ export default class HelpUserSettingsTab extends React.Component {_t("Identity Server is")} {MatrixClientPeg.get().getIdentityServerUrl()}
{_t("Access Token:") + ' '} + data-spoiler={MatrixClientPeg.get().getAccessToken()} + > <{ _t("click to reveal") }>
From b8a915bb763c6848ab0c17a666c03b6eb28ae25c Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 26 Apr 2021 14:02:53 +0100 Subject: [PATCH 06/33] Tweak private / underscores for fields and methods --- src/ScalarAuthClient.ts | 22 +-- .../eventindex/ManageEventIndexDialog.tsx | 8 +- src/components/structures/auth/SoftLogout.tsx | 8 +- src/components/views/rooms/EventTile.tsx | 113 ++++++++------- .../views/rooms/MessageComposer.tsx | 18 +-- .../views/settings/EventIndexPanel.tsx | 14 +- src/components/views/settings/SetIdServer.tsx | 42 +++--- .../tabs/room/RolesRoomSettingsTab.tsx | 26 ++-- .../tabs/room/SecurityRoomSettingsTab.tsx | 46 +++--- .../tabs/user/HelpUserSettingsTab.tsx | 24 ++-- .../tabs/user/MjolnirUserSettingsTab.tsx | 40 +++--- .../tabs/user/PreferencesUserSettingsTab.tsx | 38 ++--- src/stores/TypingStore.ts | 10 +- src/stores/WidgetEchoStore.ts | 16 +-- src/utils/Timer.ts | 72 +++++----- .../permalinks/ElementPermalinkConstructor.ts | 20 +-- src/utils/permalinks/Permalinks.ts | 132 +++++++++--------- 17 files changed, 324 insertions(+), 325 deletions(-) diff --git a/src/ScalarAuthClient.ts b/src/ScalarAuthClient.ts index 3c63bf8047..c59136263d 100644 --- a/src/ScalarAuthClient.ts +++ b/src/ScalarAuthClient.ts @@ -51,7 +51,7 @@ export default class ScalarAuthClient { this.isDefaultManager = apiUrl === configApiUrl && configUiUrl === uiUrl; } - _writeTokenToStore() { + private writeTokenToStore() { window.localStorage.setItem("mx_scalar_token_at_" + this.apiUrl, this.scalarToken); if (this.isDefaultManager) { // We remove the old token from storage to migrate upwards. This is safe @@ -61,7 +61,7 @@ export default class ScalarAuthClient { } } - _readTokenFromStore() { + private readTokenFromStore() { let token = window.localStorage.getItem("mx_scalar_token_at_" + this.apiUrl); if (!token && this.isDefaultManager) { token = window.localStorage.getItem("mx_scalar_token"); @@ -69,9 +69,9 @@ export default class ScalarAuthClient { return token; } - _readToken() { + private readToken() { if (this.scalarToken) return this.scalarToken; - return this._readTokenFromStore(); + return this.readTokenFromStore(); } setTermsInteractionCallback(callback) { @@ -90,12 +90,12 @@ export default class ScalarAuthClient { // Returns a promise that resolves to a scalar_token string getScalarToken() { - const token = this._readToken(); + const token = this.readToken(); if (!token) { return this.registerForToken(); } else { - return this._checkToken(token).catch((e) => { + return this.checkToken(token).catch((e) => { if (e instanceof TermsNotSignedError) { // retrying won't help this throw e; @@ -105,7 +105,7 @@ export default class ScalarAuthClient { } } - _getAccountName(token) { + private getAccountName(token) { const url = this.apiUrl + "/account"; return new Promise(function(resolve, reject) { @@ -130,8 +130,8 @@ export default class ScalarAuthClient { }); } - _checkToken(token) { - return this._getAccountName(token).then(userId => { + private checkToken(token) { + return this.getAccountName(token).then(userId => { const me = MatrixClientPeg.get().getUserId(); if (userId !== me) { throw new Error("Scalar token is owned by someone else: " + me); @@ -177,10 +177,10 @@ export default class ScalarAuthClient { return this.exchangeForScalarToken(tokenObject); }).then((token) => { // Validate it (this mostly checks to see if the IM needs us to agree to some terms) - return this._checkToken(token); + return this.checkToken(token); }).then((token) => { this.scalarToken = token; - this._writeTokenToStore(); + this.writeTokenToStore(); return token; }); } diff --git a/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx b/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx index fd592e6357..8864e043aa 100644 --- a/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx +++ b/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx @@ -131,14 +131,14 @@ export default class ManageEventIndexDialog extends React.Component { + private onDisable = async () => { Modal.createTrackedDialogAsync("Disable message search", "Disable message search", import("./DisableEventIndexDialog"), null, null, /* priority = */ false, /* static = */ true, ); }; - _onCrawlerSleepTimeChange = (e) => { + private onCrawlerSleepTimeChange = (e) => { this.setState({crawlerSleepTime: e.target.value}); SettingsStore.setValue("crawlerSleepTime", null, SettingLevel.DEVICE, e.target.value); }; @@ -177,7 +177,7 @@ export default class ManageEventIndexDialog extends React.Component + onChange={this.onCrawlerSleepTimeChange} />
); @@ -196,7 +196,7 @@ export default class ManageEventIndexDialog extends React.Component diff --git a/src/components/structures/auth/SoftLogout.tsx b/src/components/structures/auth/SoftLogout.tsx index 6b24535657..fa9207efdd 100644 --- a/src/components/structures/auth/SoftLogout.tsx +++ b/src/components/structures/auth/SoftLogout.tsx @@ -83,7 +83,7 @@ export default class SoftLogout extends React.Component { return; } - this._initLogin(); + this.initLogin(); const cli = MatrixClientPeg.get(); if (cli.isCryptoEnabled()) { @@ -105,7 +105,7 @@ export default class SoftLogout extends React.Component { }); }; - async _initLogin() { + private async initLogin() { const queryParams = this.props.realQueryParams; const hasAllParams = queryParams && queryParams['loginToken']; if (hasAllParams) { @@ -200,7 +200,7 @@ export default class SoftLogout extends React.Component { }); } - _renderSignInSection() { + private renderSignInSection() { if (this.state.loginView === LOGIN_VIEW.LOADING) { const Spinner = sdk.getComponent("elements.Spinner"); return ; @@ -300,7 +300,7 @@ export default class SoftLogout extends React.Component {

{_t("Sign in")}

- {this._renderSignInSection()} + {this.renderSignInSection()}

{_t("Clear personal data")}

diff --git a/src/components/views/rooms/EventTile.tsx b/src/components/views/rooms/EventTile.tsx index f2b70fd093..33bc4951a8 100644 --- a/src/components/views/rooms/EventTile.tsx +++ b/src/components/views/rooms/EventTile.tsx @@ -293,10 +293,10 @@ interface IState { @replaceableComponent("views.rooms.EventTile") export default class EventTile extends React.Component { - private _suppressReadReceiptAnimation: boolean; - private _isListeningForReceipts: boolean; - private _tile = React.createRef(); - private _replyThread = React.createRef(); + private suppressReadReceiptAnimation: boolean; + private isListeningForReceipts: boolean; + private tile = React.createRef(); + private replyThread = React.createRef(); static defaultProps = { // no-op function because onHeightChanged is optional yet some sub-components assume its existence @@ -323,23 +323,22 @@ export default class EventTile extends React.Component { }; // don't do RR animations until we are mounted - this._suppressReadReceiptAnimation = true; + this.suppressReadReceiptAnimation = true; // Throughout the component we manage a read receipt listener to see if our tile still // qualifies for a "sent" or "sending" state (based on their relevant conditions). We // don't want to over-subscribe to the read receipt events being fired, so we use a flag // to determine if we've already subscribed and use a combination of other flags to find // out if we should even be subscribed at all. - this._isListeningForReceipts = false; + this.isListeningForReceipts = false; } /** * When true, the tile qualifies for some sort of special read receipt. This could be a 'sending' * or 'sent' receipt, for example. * @returns {boolean} - * @private */ - get _isEligibleForSpecialReceipt() { + private get isEligibleForSpecialReceipt() { // First, if there are other read receipts then just short-circuit this. if (this.props.readReceipts && this.props.readReceipts.length > 0) return false; if (!this.props.mxEvent) return false; @@ -368,9 +367,9 @@ export default class EventTile extends React.Component { return true; } - get _shouldShowSentReceipt() { + private get shouldShowSentReceipt() { // If we're not even eligible, don't show the receipt. - if (!this._isEligibleForSpecialReceipt) return false; + if (!this.isEligibleForSpecialReceipt) return false; // We only show the 'sent' receipt on the last successful event. if (!this.props.lastSuccessful) return false; @@ -388,9 +387,9 @@ export default class EventTile extends React.Component { return true; } - get _shouldShowSendingReceipt() { + private get shouldShowSendingReceipt() { // If we're not even eligible, don't show the receipt. - if (!this._isEligibleForSpecialReceipt) return false; + if (!this.isEligibleForSpecialReceipt) return false; // Check the event send status to see if we are pending. Null/undefined status means the // message was sent, so check for that and 'sent' explicitly. @@ -404,22 +403,22 @@ export default class EventTile extends React.Component { // TODO: [REACT-WARNING] Move into constructor // eslint-disable-next-line camelcase UNSAFE_componentWillMount() { - this._verifyEvent(this.props.mxEvent); + this.verifyEvent(this.props.mxEvent); } componentDidMount() { - this._suppressReadReceiptAnimation = false; + this.suppressReadReceiptAnimation = false; const client = this.context; client.on("deviceVerificationChanged", this.onDeviceVerificationChanged); client.on("userTrustStatusChanged", this.onUserVerificationChanged); - this.props.mxEvent.on("Event.decrypted", this._onDecrypted); + this.props.mxEvent.on("Event.decrypted", this.onDecrypted); if (this.props.showReactions) { - this.props.mxEvent.on("Event.relationsCreated", this._onReactionsCreated); + this.props.mxEvent.on("Event.relationsCreated", this.onReactionsCreated); } - if (this._shouldShowSentReceipt || this._shouldShowSendingReceipt) { - client.on("Room.receipt", this._onRoomReceipt); - this._isListeningForReceipts = true; + if (this.shouldShowSentReceipt || this.shouldShowSendingReceipt) { + client.on("Room.receipt", this.onRoomReceipt); + this.isListeningForReceipts = true; } } @@ -429,7 +428,7 @@ export default class EventTile extends React.Component { // re-check the sender verification as outgoing events progress through // the send process. if (nextProps.eventSendStatus !== this.props.eventSendStatus) { - this._verifyEvent(nextProps.mxEvent); + this.verifyEvent(nextProps.mxEvent); } } @@ -438,35 +437,35 @@ export default class EventTile extends React.Component { return true; } - return !this._propsEqual(this.props, nextProps); + return !this.propsEqual(this.props, nextProps); } componentWillUnmount() { const client = this.context; client.removeListener("deviceVerificationChanged", this.onDeviceVerificationChanged); client.removeListener("userTrustStatusChanged", this.onUserVerificationChanged); - client.removeListener("Room.receipt", this._onRoomReceipt); - this._isListeningForReceipts = false; - this.props.mxEvent.removeListener("Event.decrypted", this._onDecrypted); + client.removeListener("Room.receipt", this.onRoomReceipt); + this.isListeningForReceipts = false; + this.props.mxEvent.removeListener("Event.decrypted", this.onDecrypted); if (this.props.showReactions) { - this.props.mxEvent.removeListener("Event.relationsCreated", this._onReactionsCreated); + this.props.mxEvent.removeListener("Event.relationsCreated", this.onReactionsCreated); } } componentDidUpdate(prevProps, prevState, snapshot) { // If we're not listening for receipts and expect to be, register a listener. - if (!this._isListeningForReceipts && (this._shouldShowSentReceipt || this._shouldShowSendingReceipt)) { - this.context.on("Room.receipt", this._onRoomReceipt); - this._isListeningForReceipts = true; + if (!this.isListeningForReceipts && (this.shouldShowSentReceipt || this.shouldShowSendingReceipt)) { + this.context.on("Room.receipt", this.onRoomReceipt); + this.isListeningForReceipts = true; } } - _onRoomReceipt = (ev, room) => { + private onRoomReceipt = (ev, room) => { // ignore events for other rooms const tileRoom = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId()); if (room !== tileRoom) return; - if (!this._shouldShowSentReceipt && !this._shouldShowSendingReceipt && !this._isListeningForReceipts) { + if (!this.shouldShowSentReceipt && !this.shouldShowSendingReceipt && !this.isListeningForReceipts) { return; } @@ -474,36 +473,36 @@ export default class EventTile extends React.Component { // the getters we use here to determine what needs rendering. this.forceUpdate(() => { // Per elsewhere in this file, we can remove the listener once we will have no further purpose for it. - if (!this._shouldShowSentReceipt && !this._shouldShowSendingReceipt) { - this.context.removeListener("Room.receipt", this._onRoomReceipt); - this._isListeningForReceipts = false; + if (!this.shouldShowSentReceipt && !this.shouldShowSendingReceipt) { + this.context.removeListener("Room.receipt", this.onRoomReceipt); + this.isListeningForReceipts = false; } }); }; /** called when the event is decrypted after we show it. */ - _onDecrypted = () => { + private onDecrypted = () => { // we need to re-verify the sending device. - // (we call onHeightChanged in _verifyEvent to handle the case where decryption + // (we call onHeightChanged in verifyEvent to handle the case where decryption // has caused a change in size of the event tile) - this._verifyEvent(this.props.mxEvent); + this.verifyEvent(this.props.mxEvent); this.forceUpdate(); }; - onDeviceVerificationChanged = (userId, device) => { + private onDeviceVerificationChanged = (userId, device) => { if (userId === this.props.mxEvent.getSender()) { - this._verifyEvent(this.props.mxEvent); + this.verifyEvent(this.props.mxEvent); } }; - onUserVerificationChanged = (userId, _trustStatus) => { + private onUserVerificationChanged = (userId, _trustStatus) => { if (userId === this.props.mxEvent.getSender()) { - this._verifyEvent(this.props.mxEvent); + this.verifyEvent(this.props.mxEvent); } }; - async _verifyEvent(mxEvent) { + private async verifyEvent(mxEvent) { if (!mxEvent.isEncrypted()) { return; } @@ -557,7 +556,7 @@ export default class EventTile extends React.Component { }, this.props.onHeightChanged); // Decryption may have caused a change in size } - _propsEqual(objA, objB) { + private propsEqual(objA, objB) { const keysA = Object.keys(objA); const keysB = Object.keys(objB); @@ -624,7 +623,7 @@ export default class EventTile extends React.Component { }; getReadAvatars() { - if (this._shouldShowSentReceipt || this._shouldShowSendingReceipt) { + if (this.shouldShowSentReceipt || this.shouldShowSendingReceipt) { return ; } @@ -671,7 +670,7 @@ export default class EventTile extends React.Component { leftOffset={left} hidden={hidden} readReceiptInfo={readReceiptInfo} checkUnmounting={this.props.checkUnmounting} - suppressAnimation={this._suppressReadReceiptAnimation} + suppressAnimation={this.suppressReadReceiptAnimation} onClick={this.toggleAllReadAvatars} timestamp={receipt.ts} showTwelveHour={this.props.isTwelveHour} @@ -728,7 +727,7 @@ export default class EventTile extends React.Component { }); }; - _renderE2EPadlock() { + private renderE2EPadlock() { const ev = this.props.mxEvent; // event could not be decrypted @@ -777,9 +776,9 @@ export default class EventTile extends React.Component { }); }; - getTile = () => this._tile.current; + getTile = () => this.tile.current; - getReplyThread = () => this._replyThread.current; + getReplyThread = () => this.replyThread.current; getReactions = () => { if ( @@ -799,11 +798,11 @@ export default class EventTile extends React.Component { return this.props.getRelationsForEvent(eventId, "m.annotation", "m.reaction"); }; - _onReactionsCreated = (relationType, eventType) => { + private onReactionsCreated = (relationType, eventType) => { if (relationType !== "m.annotation" || eventType !== "m.reaction") { return; } - this.props.mxEvent.removeListener("Event.relationsCreated", this._onReactionsCreated); + this.props.mxEvent.removeListener("Event.relationsCreated", this.onReactionsCreated); this.setState({ reactions: this.getReactions(), }); @@ -1017,8 +1016,8 @@ export default class EventTile extends React.Component { const useIRCLayout = this.props.layout == Layout.IRC; const groupTimestamp = !useIRCLayout ? linkedTimestamp : null; const ircTimestamp = useIRCLayout ? linkedTimestamp : null; - const groupPadlock = !useIRCLayout && !isBubbleMessage && this._renderE2EPadlock(); - const ircPadlock = useIRCLayout && !isBubbleMessage && this._renderE2EPadlock(); + const groupPadlock = !useIRCLayout && !isBubbleMessage && this.renderE2EPadlock(); + const ircPadlock = useIRCLayout && !isBubbleMessage && this.renderE2EPadlock(); let msgOption; if (this.props.showReadReceipts) { @@ -1049,7 +1048,7 @@ export default class EventTile extends React.Component {
- { return (
- { this.props.mxEvent, this.props.onHeightChanged, this.props.permalinkCreator, - this._replyThread, + this.replyThread, ); } return ( @@ -1108,7 +1107,7 @@ export default class EventTile extends React.Component { { groupTimestamp } { groupPadlock } { thread } - { this.props.mxEvent, this.props.onHeightChanged, this.props.permalinkCreator, - this._replyThread, + this.replyThread, this.props.layout, ); @@ -1139,7 +1138,7 @@ export default class EventTile extends React.Component { { groupTimestamp } { groupPadlock } { thread } - { - private _uploadInput = React.createRef(); - private _dispatcherRef: string; + private uploadInput = React.createRef(); + private dispatcherRef: string; constructor(props) { super(props); - this._dispatcherRef = dis.register(this.onAction); + this.dispatcherRef = dis.register(this.onAction); } componentWillUnmount() { - dis.unregister(this._dispatcherRef); + dis.unregister(this.dispatcherRef); } private onAction = payload => { @@ -132,7 +132,7 @@ class UploadButton extends React.Component { dis.dispatch({action: 'require_registration'}); return; } - this._uploadInput.current.click(); + this.uploadInput.current.click(); } private onUploadFileInputChange = (ev) => { @@ -165,7 +165,7 @@ class UploadButton extends React.Component { title={_t('Upload file')} > { constructor(props) { super(props); - VoiceRecordingStore.instance.on(UPDATE_EVENT, this._onVoiceStoreUpdate); + VoiceRecordingStore.instance.on(UPDATE_EVENT, this.onVoiceStoreUpdate); this.state = { tombstone: this.getRoomTombstone(), @@ -249,7 +249,7 @@ export default class MessageComposer extends React.Component { if (MatrixClientPeg.get()) { MatrixClientPeg.get().removeListener("RoomState.events", this.onRoomStateEvents); } - VoiceRecordingStore.instance.off(UPDATE_EVENT, this._onVoiceStoreUpdate); + VoiceRecordingStore.instance.off(UPDATE_EVENT, this.onVoiceStoreUpdate); dis.unregister(this.dispatcherRef); } @@ -331,7 +331,7 @@ export default class MessageComposer extends React.Component { }); } - _onVoiceStoreUpdate = () => { + private onVoiceStoreUpdate = () => { const recording = VoiceRecordingStore.instance.activeRecording; this.setState({haveRecording: !!recording}); if (recording) { diff --git a/src/components/views/settings/EventIndexPanel.tsx b/src/components/views/settings/EventIndexPanel.tsx index c97b436854..fa84063ee8 100644 --- a/src/components/views/settings/EventIndexPanel.tsx +++ b/src/components/views/settings/EventIndexPanel.tsx @@ -109,7 +109,7 @@ export default class EventIndexPanel extends React.Component<{}, IState> { }); } - _onManage = async () => { + private onManage = async () => { Modal.createTrackedDialogAsync('Message search', 'Message search', // @ts-ignore: TS doesn't seem to like the type of this now that it // has also been converted to TS as well, but I can't figure out why... @@ -120,7 +120,7 @@ export default class EventIndexPanel extends React.Component<{}, IState> { ); } - _onEnable = async () => { + private onEnable = async () => { this.setState({ enabling: true, }); @@ -132,13 +132,13 @@ export default class EventIndexPanel extends React.Component<{}, IState> { await this.updateState(); } - _confirmEventStoreReset = () => { + private confirmEventStoreReset = () => { const { close } = Modal.createDialog(SeshatResetDialog, { onFinished: async (success) => { if (success) { await SettingsStore.setValue('enableEventIndexing', null, SettingLevel.DEVICE, false); await EventIndexPeg.deleteEventIndex(); - await this._onEnable(); + await this.onEnable(); close(); } }, @@ -165,7 +165,7 @@ export default class EventIndexPanel extends React.Component<{}, IState> { }, )}
- + {_t("Manage")}
@@ -180,7 +180,7 @@ export default class EventIndexPanel extends React.Component<{}, IState> { )}
+ onClick={this.onEnable}> {_t("Enable")} {this.state.enabling ? :
} @@ -242,7 +242,7 @@ export default class EventIndexPanel extends React.Component<{}, IState> { {EventIndexPeg.error.message}

- + {_t("Reset")}

diff --git a/src/components/views/settings/SetIdServer.tsx b/src/components/views/settings/SetIdServer.tsx index a3dbcc7830..70a4c46f69 100644 --- a/src/components/views/settings/SetIdServer.tsx +++ b/src/components/views/settings/SetIdServer.tsx @@ -107,7 +107,7 @@ export default class SetIdServer extends React.Component { dis.unregister(this.dispatcherRef); } - onAction = (payload) => { + private onAction = (payload) => { // We react to changes in the ID server in the event the user is staring at this form // when changing their identity server on another device. if (payload.action !== "id_server_changed") return; @@ -117,13 +117,13 @@ export default class SetIdServer extends React.Component { }); }; - _onIdentityServerChanged = (ev) => { + private onIdentityServerChanged = (ev) => { const u = ev.target.value; this.setState({idServer: u}); }; - _getTooltip = () => { + private getTooltip = () => { if (this.state.checking) { const InlineSpinner = sdk.getComponent('views.elements.InlineSpinner'); return
@@ -137,11 +137,11 @@ export default class SetIdServer extends React.Component { } }; - _idServerChangeEnabled = () => { + private idServerChangeEnabled = () => { return !!this.state.idServer && !this.state.busy; }; - _saveIdServer = (fullUrl) => { + private saveIdServer = (fullUrl) => { // Account data change will update localstorage, client, etc through dispatcher MatrixClientPeg.get().setAccountData("m.identity_server", { base_url: fullUrl, @@ -154,7 +154,7 @@ export default class SetIdServer extends React.Component { }); }; - _checkIdServer = async (e) => { + private checkIdServer = async (e) => { e.preventDefault(); const { idServer, currentClientIdServer } = this.state; @@ -177,14 +177,14 @@ export default class SetIdServer extends React.Component { // Double check that the identity server even has terms of service. const hasTerms = await doesIdentityServerHaveTerms(fullUrl); if (!hasTerms) { - const [confirmed] = await this._showNoTermsWarning(fullUrl); + const [confirmed] = await this.showNoTermsWarning(fullUrl); save = confirmed; } // Show a general warning, possibly with details about any bound // 3PIDs that would be left behind. if (save && currentClientIdServer && fullUrl !== currentClientIdServer) { - const [confirmed] = await this._showServerChangeWarning({ + const [confirmed] = await this.showServerChangeWarning({ title: _t("Change identity server"), unboundMessage: _t( "Disconnect from the identity server and " + @@ -200,7 +200,7 @@ export default class SetIdServer extends React.Component { } if (save) { - this._saveIdServer(fullUrl); + this.saveIdServer(fullUrl); } } catch (e) { console.error(e); @@ -215,7 +215,7 @@ export default class SetIdServer extends React.Component { }); }; - _showNoTermsWarning(fullUrl) { + private showNoTermsWarning(fullUrl) { const QuestionDialog = sdk.getComponent("views.dialogs.QuestionDialog"); const { finished } = Modal.createTrackedDialog('No Terms Warning', '', QuestionDialog, { title: _t("Identity server has no terms of service"), @@ -234,10 +234,10 @@ export default class SetIdServer extends React.Component { return finished; } - _onDisconnectClicked = async () => { + private onDisconnectClicked = async () => { this.setState({disconnectBusy: true}); try { - const [confirmed] = await this._showServerChangeWarning({ + const [confirmed] = await this.showServerChangeWarning({ title: _t("Disconnect identity server"), unboundMessage: _t( "Disconnect from the identity server ?", {}, @@ -246,14 +246,14 @@ export default class SetIdServer extends React.Component { button: _t("Disconnect"), }); if (confirmed) { - this._disconnectIdServer(); + this.disconnectIdServer(); } } finally { this.setState({disconnectBusy: false}); } }; - async _showServerChangeWarning({ title, unboundMessage, button }) { + private async showServerChangeWarning({ title, unboundMessage, button }) { const { currentClientIdServer } = this.state; let threepids = []; @@ -329,7 +329,7 @@ export default class SetIdServer extends React.Component { return finished; } - _disconnectIdServer = () => { + private disconnectIdServer = () => { // Account data change will update localstorage, client, etc through dispatcher MatrixClientPeg.get().setAccountData("m.identity_server", { base_url: null, // clear @@ -402,14 +402,14 @@ export default class SetIdServer extends React.Component { } discoSection =
{discoBodyText} - + {discoButtonContent}
; } return ( -
+ {sectionTitle} @@ -422,15 +422,15 @@ export default class SetIdServer extends React.Component { autoComplete="off" placeholder={this.state.defaultIdServer} value={this.state.idServer} - onChange={this._onIdentityServerChanged} - tooltipContent={this._getTooltip()} + onChange={this.onIdentityServerChanged} + tooltipContent={this.getTooltip()} tooltipClassName="mx_SetIdServer_tooltip" disabled={this.state.busy} forceValidity={this.state.error ? false : null} /> {_t("Change")} {discoSection} diff --git a/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx index f5fd537918..a945b22d1f 100644 --- a/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx @@ -71,7 +71,7 @@ interface IBannedUserProps { } export class BannedUser extends React.Component { - _onUnbanClick = (e) => { + private onUnbanClick = (e) => { MatrixClientPeg.get().unban(this.props.member.roomId, this.props.member.userId).catch((err) => { const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); console.error("Failed to unban: " + err); @@ -89,7 +89,7 @@ export class BannedUser extends React.Component { unbanButton = ( { _t('Unban') } @@ -116,22 +116,22 @@ interface IProps { @replaceableComponent("views.settings.tabs.room.RolesRoomSettingsTab") export default class RolesRoomSettingsTab extends React.Component { componentDidMount(): void { - MatrixClientPeg.get().on("RoomState.members", this._onRoomMembership); + MatrixClientPeg.get().on("RoomState.members", this.onRoomMembership); } componentWillUnmount(): void { const client = MatrixClientPeg.get(); if (client) { - client.removeListener("RoomState.members", this._onRoomMembership); + client.removeListener("RoomState.members", this.onRoomMembership); } } - _onRoomMembership = (event, state, member) => { + private onRoomMembership = (event, state, member) => { if (state.roomId !== this.props.roomId) return; this.forceUpdate(); }; - _populateDefaultPlEvents(eventsSection, stateLevel, eventsLevel) { + private populateDefaultPlEvents(eventsSection, stateLevel, eventsLevel) { for (const desiredEvent of Object.keys(plEventsToShow)) { if (!(desiredEvent in eventsSection)) { eventsSection[desiredEvent] = (plEventsToShow[desiredEvent].isState ? stateLevel : eventsLevel); @@ -139,7 +139,7 @@ export default class RolesRoomSettingsTab extends React.Component { } } - _onPowerLevelsChanged = (value, powerLevelKey) => { + private onPowerLevelsChanged = (value, powerLevelKey) => { const client = MatrixClientPeg.get(); const room = client.getRoom(this.props.roomId); const plEvent = room.currentState.getStateEvents('m.room.power_levels', ''); @@ -184,7 +184,7 @@ export default class RolesRoomSettingsTab extends React.Component { }); }; - _onUserPowerLevelChanged = (value, powerLevelKey) => { + private onUserPowerLevelChanged = (value, powerLevelKey) => { const client = MatrixClientPeg.get(); const room = client.getRoom(this.props.roomId); const plEvent = room.currentState.getStateEvents('m.room.power_levels', ''); @@ -268,7 +268,7 @@ export default class RolesRoomSettingsTab extends React.Component { currentUserLevel = defaultUserLevel; } - this._populateDefaultPlEvents( + this.populateDefaultPlEvents( eventsLevels, parseIntWithDefault(plContent.state_default, powerLevelDescriptors.state_default.defaultValue), parseIntWithDefault(plContent.events_default, powerLevelDescriptors.events_default.defaultValue), @@ -290,7 +290,7 @@ export default class RolesRoomSettingsTab extends React.Component { label={user} key={user} powerLevelKey={user} // Will be sent as the second parameter to `onChange` - onChange={this._onUserPowerLevelChanged} + onChange={this.onUserPowerLevelChanged} />, ); } else if (userLevels[user] < defaultUserLevel) { // muted @@ -301,7 +301,7 @@ export default class RolesRoomSettingsTab extends React.Component { label={user} key={user} powerLevelKey={user} // Will be sent as the second parameter to `onChange` - onChange={this._onUserPowerLevelChanged} + onChange={this.onUserPowerLevelChanged} />, ); } @@ -376,7 +376,7 @@ export default class RolesRoomSettingsTab extends React.Component { usersDefault={defaultUserLevel} disabled={!canChangeLevels || currentUserLevel < value} powerLevelKey={key} // Will be sent as the second parameter to `onChange` - onChange={this._onPowerLevelsChanged} + onChange={this.onPowerLevelsChanged} />
; }); @@ -401,7 +401,7 @@ export default class RolesRoomSettingsTab extends React.Component { usersDefault={defaultUserLevel} disabled={!canChangeLevels || currentUserLevel < eventsLevels[eventType]} powerLevelKey={"event_levels_" + eventType} - onChange={this._onPowerLevelsChanged} + onChange={this.onPowerLevelsChanged} />
); diff --git a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx index a8cd920eb2..07776a5a54 100644 --- a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx @@ -59,42 +59,42 @@ export default class SecurityRoomSettingsTab extends React.Component { // eslint-disable-line camelcase - MatrixClientPeg.get().on("RoomState.events", this._onStateEvent); + MatrixClientPeg.get().on("RoomState.events", this.onStateEvent); const room = MatrixClientPeg.get().getRoom(this.props.roomId); const state = room.currentState; - const joinRule: JoinRule = this._pullContentPropertyFromEvent( + const joinRule: JoinRule = this.pullContentPropertyFromEvent( state.getStateEvents("m.room.join_rules", ""), 'join_rule', 'invite', ); - const guestAccess: GuestAccess = this._pullContentPropertyFromEvent( + const guestAccess: GuestAccess = this.pullContentPropertyFromEvent( state.getStateEvents("m.room.guest_access", ""), 'guest_access', 'forbidden', ); - const history: History = this._pullContentPropertyFromEvent( + const history: History = this.pullContentPropertyFromEvent( state.getStateEvents("m.room.history_visibility", ""), 'history_visibility', 'shared', ); const encrypted = MatrixClientPeg.get().isRoomEncrypted(this.props.roomId); this.setState({joinRule, guestAccess, history, encrypted}); - const hasAliases = await this._hasAliases(); + const hasAliases = await this.hasAliases(); this.setState({hasAliases}); } - _pullContentPropertyFromEvent(event, key, defaultValue) { + private pullContentPropertyFromEvent(event, key, defaultValue) { if (!event || !event.getContent()) return defaultValue; return event.getContent()[key] || defaultValue; } componentWillUnmount(): void { - MatrixClientPeg.get().removeListener("RoomState.events", this._onStateEvent); + MatrixClientPeg.get().removeListener("RoomState.events", this.onStateEvent); } - _onStateEvent = (e) => { + private onStateEvent = (e) => { const refreshWhenTypes = [ 'm.room.join_rules', 'm.room.guest_access', @@ -104,7 +104,7 @@ export default class SecurityRoomSettingsTab extends React.Component { + private onEncryptionChange = (e) => { Modal.createTrackedDialog('Enable encryption', '', QuestionDialog, { title: _t('Enable encryption?'), description: _t( @@ -137,7 +137,7 @@ export default class SecurityRoomSettingsTab extends React.Component { + private fixGuestAccess = (e) => { e.preventDefault(); e.stopPropagation(); @@ -159,7 +159,7 @@ export default class SecurityRoomSettingsTab extends React.Component { + private onRoomAccessRadioToggle = (roomAccess) => { // join_rule // INVITE | PUBLIC // ----------------------+---------------- @@ -205,7 +205,7 @@ export default class SecurityRoomSettingsTab extends React.Component { + private onHistoryRadioToggle = (history) => { const beforeHistory = this.state.history; this.setState({history: history}); MatrixClientPeg.get().sendStateEvent(this.props.roomId, "m.room.history_visibility", { @@ -216,11 +216,11 @@ export default class SecurityRoomSettingsTab extends React.Component { + private updateBlacklistDevicesFlag = (checked) => { MatrixClientPeg.get().getRoom(this.props.roomId).setBlacklistUnverifiedDevices(checked); }; - async _hasAliases() { + private async hasAliases() { const cli = MatrixClientPeg.get(); if (await cli.doesServerSupportUnstableFeature("org.matrix.msc2432")) { const response = await cli.unstableGetLocalAliases(this.props.roomId); @@ -234,7 +234,7 @@ export default class SecurityRoomSettingsTab extends React.Component {_t("Guests cannot join this room even if explicitly invited.")}  - {_t("Click here to fix")} + {_t("Click here to fix")}
); @@ -275,7 +275,7 @@ export default class SecurityRoomSettingsTab extends React.Component; } @@ -366,7 +366,7 @@ export default class SecurityRoomSettingsTab extends React.Component {_t("Who can read history?")}
- {this._renderHistory()} + {this.renderHistory()}
); if (!SettingsStore.getValue(UIFeature.RoomHistorySettings)) { @@ -383,7 +383,7 @@ export default class SecurityRoomSettingsTab extends React.Component {_t("Once enabled, encryption cannot be disabled.")}
- @@ -392,7 +392,7 @@ export default class SecurityRoomSettingsTab extends React.Component{_t("Who can access this room?")}
- {this._renderRoomAccess()} + {this.renderRoomAccess()}
{historySection} diff --git a/src/components/views/settings/tabs/user/HelpUserSettingsTab.tsx b/src/components/views/settings/tabs/user/HelpUserSettingsTab.tsx index b620088096..a009ead064 100644 --- a/src/components/views/settings/tabs/user/HelpUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/HelpUserSettingsTab.tsx @@ -56,7 +56,7 @@ export default class HelpUserSettingsTab extends React.Component }); } - _onClearCacheAndReload = (e) => { + private onClearCacheAndReload = (e) => { if (!PlatformPeg.get()) return; // Dev note: please keep this log line, it's useful when troubleshooting a MatrixClient suddenly @@ -68,7 +68,7 @@ export default class HelpUserSettingsTab extends React.Component }); }; - _onBugReport = (e) => { + private onBugReport = (e) => { const BugReportDialog = sdk.getComponent("dialogs.BugReportDialog"); if (!BugReportDialog) { return; @@ -76,7 +76,7 @@ export default class HelpUserSettingsTab extends React.Component Modal.createTrackedDialog('Bug Report Dialog', '', BugReportDialog, {}); }; - _onStartBotChat = (e) => { + private onStartBotChat = (e) => { this.props.closeSettingsFn(); createRoom({ dmUserId: SdkConfig.get().welcomeUserId, @@ -84,7 +84,7 @@ export default class HelpUserSettingsTab extends React.Component }); }; - _showSpoiler = (event) => { + private showSpoiler = (event) => { const target = event.target; target.innerHTML = target.getAttribute('data-spoiler'); @@ -96,7 +96,7 @@ export default class HelpUserSettingsTab extends React.Component selection.addRange(range); }; - _renderLegal() { + private renderLegal() { const tocLinks = SdkConfig.get().terms_and_conditions_links; if (!tocLinks) return null; @@ -117,7 +117,7 @@ export default class HelpUserSettingsTab extends React.Component ); } - _renderCredits() { + private renderCredits() { // Note: This is not translated because it is legal text. // Also,   is ugly but necessary. return ( @@ -191,7 +191,7 @@ export default class HelpUserSettingsTab extends React.Component }, )}
- + {_t("Chat with %(brand)s Bot", { brand })}
@@ -223,7 +223,7 @@ export default class HelpUserSettingsTab extends React.Component "other users. They do not contain messages.", )}
- + {_t("Submit debug logs")}
@@ -262,21 +262,21 @@ export default class HelpUserSettingsTab extends React.Component {updateButton} - {this._renderLegal()} - {this._renderCredits()} + {this.renderLegal()} + {this.renderCredits()}
{_t("Advanced")}
{_t("Homeserver is")} {MatrixClientPeg.get().getHomeserverUrl()}
{_t("Identity Server is")} {MatrixClientPeg.get().getIdentityServerUrl()}
{_t("Access Token:") + ' '} - <{ _t("click to reveal") }>
- + {_t("Clear cache and reload")}
diff --git a/src/components/views/settings/tabs/user/MjolnirUserSettingsTab.tsx b/src/components/views/settings/tabs/user/MjolnirUserSettingsTab.tsx index a265016d1a..6997defea9 100644 --- a/src/components/views/settings/tabs/user/MjolnirUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/MjolnirUserSettingsTab.tsx @@ -43,15 +43,15 @@ export default class MjolnirUserSettingsTab extends React.Component<{}, IState> }; } - _onPersonalRuleChanged = (e) => { + private onPersonalRuleChanged = (e) => { this.setState({newPersonalRule: e.target.value}); }; - _onNewListChanged = (e) => { + private onNewListChanged = (e) => { this.setState({newList: e.target.value}); }; - _onAddPersonalRule = async (e) => { + private onAddPersonalRule = async (e) => { e.preventDefault(); e.stopPropagation(); @@ -78,7 +78,7 @@ export default class MjolnirUserSettingsTab extends React.Component<{}, IState> } }; - _onSubscribeList = async (e) => { + private onSubscribeList = async (e) => { e.preventDefault(); e.stopPropagation(); @@ -100,7 +100,7 @@ export default class MjolnirUserSettingsTab extends React.Component<{}, IState> } }; - async _removePersonalRule(rule: ListRule) { + private async removePersonalRule(rule: ListRule) { this.setState({busy: true}); try { const list = Mjolnir.sharedInstance().getPersonalList(); @@ -118,7 +118,7 @@ export default class MjolnirUserSettingsTab extends React.Component<{}, IState> } } - async _unsubscribeFromList(list: BanList) { + private async unsubscribeFromList(list: BanList) { this.setState({busy: true}); try { await Mjolnir.sharedInstance().unsubscribeFromList(list.roomId); @@ -136,7 +136,7 @@ export default class MjolnirUserSettingsTab extends React.Component<{}, IState> } } - _viewListRules(list: BanList) { + private viewListRules(list: BanList) { const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); const room = MatrixClientPeg.get().getRoom(list.roomId); @@ -167,7 +167,7 @@ export default class MjolnirUserSettingsTab extends React.Component<{}, IState> }); } - _renderPersonalBanListRules() { + private renderPersonalBanListRules() { const AccessibleButton = sdk.getComponent('elements.AccessibleButton'); const list = Mjolnir.sharedInstance().getPersonalList(); @@ -180,7 +180,7 @@ export default class MjolnirUserSettingsTab extends React.Component<{}, IState>
  • this._removePersonalRule(rule)} + onClick={() => this.removePersonalRule(rule)} disabled={this.state.busy} > {_t("Remove")} @@ -198,7 +198,7 @@ export default class MjolnirUserSettingsTab extends React.Component<{}, IState> ); } - _renderSubscribedBanLists() { + private renderSubscribedBanLists() { const AccessibleButton = sdk.getComponent('elements.AccessibleButton'); const personalList = Mjolnir.sharedInstance().getPersonalList(); @@ -215,14 +215,14 @@ export default class MjolnirUserSettingsTab extends React.Component<{}, IState>
  • this._unsubscribeFromList(list)} + onClick={() => this.unsubscribeFromList(list)} disabled={this.state.busy} > {_t("Unsubscribe")}   this._viewListRules(list)} + onClick={() => this.viewListRules(list)} disabled={this.state.busy} > {_t("View rules")} @@ -277,21 +277,21 @@ export default class MjolnirUserSettingsTab extends React.Component<{}, IState> )}
  • - {this._renderPersonalBanListRules()} + {this.renderPersonalBanListRules()}
    -
    + {_t("Ignore")} @@ -309,20 +309,20 @@ export default class MjolnirUserSettingsTab extends React.Component<{}, IState> )}
    - {this._renderSubscribedBanLists()} + {this.renderSubscribedBanLists()}
    - + {_t("Subscribe")} diff --git a/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx b/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx index 3e8c5f929c..138bf40b80 100644 --- a/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx @@ -142,38 +142,38 @@ export default class PreferencesUserSettingsTab extends React.Component<{}, ISta }); } - _onAutoLaunchChange = (checked) => { + private onAutoLaunchChange = (checked) => { PlatformPeg.get().setAutoLaunchEnabled(checked).then(() => this.setState({autoLaunch: checked})); }; - _onWarnBeforeExitChange = (checked) => { + private onWarnBeforeExitChange = (checked) => { PlatformPeg.get().setWarnBeforeExit(checked).then(() => this.setState({warnBeforeExit: checked})); } - _onAlwaysShowMenuBarChange = (checked) => { + private onAlwaysShowMenuBarChange = (checked) => { PlatformPeg.get().setAutoHideMenuBarEnabled(!checked).then(() => this.setState({alwaysShowMenuBar: checked})); }; - _onMinimizeToTrayChange = (checked) => { + private onMinimizeToTrayChange = (checked) => { PlatformPeg.get().setMinimizeToTrayEnabled(checked).then(() => this.setState({minimizeToTray: checked})); }; - _onAutocompleteDelayChange = (e) => { + private onAutocompleteDelayChange = (e) => { this.setState({autocompleteDelay: e.target.value}); SettingsStore.setValue("autocompleteDelay", null, SettingLevel.DEVICE, e.target.value); }; - _onReadMarkerInViewThresholdMs = (e) => { + private onReadMarkerInViewThresholdMs = (e) => { this.setState({readMarkerInViewThresholdMs: e.target.value}); SettingsStore.setValue("readMarkerInViewThresholdMs", null, SettingLevel.DEVICE, e.target.value); }; - _onReadMarkerOutOfViewThresholdMs = (e) => { + private onReadMarkerOutOfViewThresholdMs = (e) => { this.setState({readMarkerOutOfViewThresholdMs: e.target.value}); SettingsStore.setValue("readMarkerOutOfViewThresholdMs", null, SettingLevel.DEVICE, e.target.value); }; - _renderGroup(settingIds) { + private renderGroup(settingIds) { const SettingsFlag = sdk.getComponent("views.elements.SettingsFlag"); return settingIds.filter(SettingsStore.isEnabled).map(i => { return ; @@ -185,7 +185,7 @@ export default class PreferencesUserSettingsTab extends React.Component<{}, ISta if (this.state.autoLaunchSupported) { autoLaunchOption = ; } @@ -193,7 +193,7 @@ export default class PreferencesUserSettingsTab extends React.Component<{}, ISta if (this.state.warnBeforeExitSupported) { warnBeforeExitOption = ; } @@ -201,7 +201,7 @@ export default class PreferencesUserSettingsTab extends React.Component<{}, ISta if (this.state.alwaysShowMenuBarSupported) { autoHideMenuOption = ; } @@ -209,7 +209,7 @@ export default class PreferencesUserSettingsTab extends React.Component<{}, ISta if (this.state.minimizeToTraySupported) { minimizeToTrayOption = ; } @@ -219,22 +219,22 @@ export default class PreferencesUserSettingsTab extends React.Component<{}, ISta
    {_t("Room list")} - {this._renderGroup(PreferencesUserSettingsTab.ROOM_LIST_SETTINGS)} + {this.renderGroup(PreferencesUserSettingsTab.ROOM_LIST_SETTINGS)}
    {_t("Composer")} - {this._renderGroup(PreferencesUserSettingsTab.COMPOSER_SETTINGS)} + {this.renderGroup(PreferencesUserSettingsTab.COMPOSER_SETTINGS)}
    {_t("Timeline")} - {this._renderGroup(PreferencesUserSettingsTab.TIMELINE_SETTINGS)} + {this.renderGroup(PreferencesUserSettingsTab.TIMELINE_SETTINGS)}
    {_t("General")} - {this._renderGroup(PreferencesUserSettingsTab.GENERAL_SETTINGS)} + {this.renderGroup(PreferencesUserSettingsTab.GENERAL_SETTINGS)} {minimizeToTrayOption} {autoHideMenuOption} {autoLaunchOption} @@ -243,17 +243,17 @@ export default class PreferencesUserSettingsTab extends React.Component<{}, ISta label={_t('Autocomplete delay (ms)')} type='number' value={this.state.autocompleteDelay} - onChange={this._onAutocompleteDelayChange} /> + onChange={this.onAutocompleteDelayChange} /> + onChange={this.onReadMarkerInViewThresholdMs} /> + onChange={this.onReadMarkerOutOfViewThresholdMs} />
    ); diff --git a/src/stores/TypingStore.ts b/src/stores/TypingStore.ts index 8b96105a7d..d5177a33a0 100644 --- a/src/stores/TypingStore.ts +++ b/src/stores/TypingStore.ts @@ -25,7 +25,7 @@ const TYPING_SERVER_TIMEOUT = 30000; * Tracks typing state for users. */ export default class TypingStore { - private _typingStates: { + private typingStates: { [roomId: string]: { isTyping: boolean, userTimer: Timer, @@ -49,7 +49,7 @@ export default class TypingStore { * MatrixClientPeg client changes. */ reset() { - this._typingStates = { + this.typingStates = { // "roomId": { // isTyping: bool, // Whether the user is typing or not // userTimer: Timer, // Local timeout for "user has stopped typing" @@ -67,14 +67,14 @@ export default class TypingStore { if (!SettingsStore.getValue('sendTypingNotifications')) return; if (SettingsStore.getValue('lowBandwidth')) return; - let currentTyping = this._typingStates[roomId]; + let currentTyping = this.typingStates[roomId]; if ((!isTyping && !currentTyping) || (currentTyping && currentTyping.isTyping === isTyping)) { // No change in state, so don't do anything. We'll let the timer run its course. return; } if (!currentTyping) { - currentTyping = this._typingStates[roomId] = { + currentTyping = this.typingStates[roomId] = { isTyping: isTyping, serverTimer: new Timer(TYPING_SERVER_TIMEOUT), userTimer: new Timer(TYPING_USER_TIMEOUT), @@ -86,7 +86,7 @@ export default class TypingStore { if (isTyping) { if (!currentTyping.serverTimer.isRunning()) { currentTyping.serverTimer.restart().finished().then(() => { - const currentTyping = this._typingStates[roomId]; + const currentTyping = this.typingStates[roomId]; if (currentTyping) currentTyping.isTyping = false; // The server will (should) time us out on typing, so we don't diff --git a/src/stores/WidgetEchoStore.ts b/src/stores/WidgetEchoStore.ts index e312cecac5..e752f3db20 100644 --- a/src/stores/WidgetEchoStore.ts +++ b/src/stores/WidgetEchoStore.ts @@ -23,7 +23,7 @@ import {WidgetType} from "../widgets/WidgetType"; * proxying through state from the js-sdk. */ class WidgetEchoStore extends EventEmitter { - private _roomWidgetEcho: { + private roomWidgetEcho: { [roomId: string]: { [widgetId: string]: IWidget, }, @@ -32,7 +32,7 @@ class WidgetEchoStore extends EventEmitter { constructor() { super(); - this._roomWidgetEcho = { + this.roomWidgetEcho = { // Map as below. Object is the content of the widget state event, // so for widgets that have been deleted locally, the object is empty. // roomId: { @@ -55,7 +55,7 @@ class WidgetEchoStore extends EventEmitter { getEchoedRoomWidgets(roomId, currentRoomWidgets) { const echoedWidgets = []; - const roomEchoState = Object.assign({}, this._roomWidgetEcho[roomId]); + const roomEchoState = Object.assign({}, this.roomWidgetEcho[roomId]); for (const w of currentRoomWidgets) { const widgetId = w.getStateKey(); @@ -72,7 +72,7 @@ class WidgetEchoStore extends EventEmitter { } roomHasPendingWidgetsOfType(roomId, currentRoomWidgets, type?: WidgetType) { - const roomEchoState = Object.assign({}, this._roomWidgetEcho[roomId]); + const roomEchoState = Object.assign({}, this.roomWidgetEcho[roomId]); // any widget IDs that are already in the room are not pending, so // echoes for them don't count as pending. @@ -96,15 +96,15 @@ class WidgetEchoStore extends EventEmitter { } setRoomWidgetEcho(roomId: string, widgetId: string, state: IWidget) { - if (this._roomWidgetEcho[roomId] === undefined) this._roomWidgetEcho[roomId] = {}; + if (this.roomWidgetEcho[roomId] === undefined) this.roomWidgetEcho[roomId] = {}; - this._roomWidgetEcho[roomId][widgetId] = state; + this.roomWidgetEcho[roomId][widgetId] = state; this.emit('update', roomId, widgetId); } removeRoomWidgetEcho(roomId, widgetId) { - delete this._roomWidgetEcho[roomId][widgetId]; - if (Object.keys(this._roomWidgetEcho[roomId]).length === 0) delete this._roomWidgetEcho[roomId]; + delete this.roomWidgetEcho[roomId][widgetId]; + if (Object.keys(this.roomWidgetEcho[roomId]).length === 0) delete this.roomWidgetEcho[roomId]; this.emit('update', roomId, widgetId); } } diff --git a/src/utils/Timer.ts b/src/utils/Timer.ts index 4d0532087e..3e370413e5 100644 --- a/src/utils/Timer.ts +++ b/src/utils/Timer.ts @@ -26,51 +26,51 @@ Once a timer is finished or aborted, it can't be started again a new one through `clone()` or `cloneIfRun()`. */ export default class Timer { - private _timeout: number; - private _timerHandle: NodeJS.Timeout; - private _startTs: number; - private _promise: Promise; - private _resolve: () => void; - private _reject: (Error) => void; + private timeout: number; + private timerHandle: NodeJS.Timeout; + private startTs: number; + private promise: Promise; + private resolve: () => void; + private reject: (Error) => void; constructor(timeout) { - this._timeout = timeout; - this._onTimeout = this._onTimeout.bind(this); - this._setNotStarted(); + this.timeout = timeout; + this.onTimeout = this.onTimeout.bind(this); + this.setNotStarted(); } - _setNotStarted() { - this._timerHandle = null; - this._startTs = null; - this._promise = new Promise((resolve, reject) => { - this._resolve = resolve; - this._reject = reject; + private setNotStarted() { + this.timerHandle = null; + this.startTs = null; + this.promise = new Promise((resolve, reject) => { + this.resolve = resolve; + this.reject = reject; }).finally(() => { - this._timerHandle = null; + this.timerHandle = null; }); } - _onTimeout() { + private onTimeout() { const now = Date.now(); - const elapsed = now - this._startTs; - if (elapsed >= this._timeout) { - this._resolve(); - this._setNotStarted(); + const elapsed = now - this.startTs; + if (elapsed >= this.timeout) { + this.resolve(); + this.setNotStarted(); } else { - const delta = this._timeout - elapsed; - this._timerHandle = setTimeout(this._onTimeout, delta); + const delta = this.timeout - elapsed; + this.timerHandle = setTimeout(this.onTimeout, delta); } } changeTimeout(timeout) { - if (timeout === this._timeout) { + if (timeout === this.timeout) { return; } - const isSmallerTimeout = timeout < this._timeout; - this._timeout = timeout; + const isSmallerTimeout = timeout < this.timeout; + this.timeout = timeout; if (this.isRunning() && isSmallerTimeout) { - clearTimeout(this._timerHandle); - this._onTimeout(); + clearTimeout(this.timerHandle); + this.onTimeout(); } } @@ -80,8 +80,8 @@ export default class Timer { */ start() { if (!this.isRunning()) { - this._startTs = Date.now(); - this._timerHandle = setTimeout(this._onTimeout, this._timeout); + this.startTs = Date.now(); + this.timerHandle = setTimeout(this.onTimeout, this.timeout); } return this; } @@ -96,7 +96,7 @@ export default class Timer { // can be called in fast succession, // instead just take note and compare // when the already running timeout expires - this._startTs = Date.now(); + this.startTs = Date.now(); return this; } else { return this.start(); @@ -110,9 +110,9 @@ export default class Timer { */ abort() { if (this.isRunning()) { - clearTimeout(this._timerHandle); - this._reject(new Error("Timer was aborted.")); - this._setNotStarted(); + clearTimeout(this.timerHandle); + this.reject(new Error("Timer was aborted.")); + this.setNotStarted(); } return this; } @@ -123,10 +123,10 @@ export default class Timer { *@return {Promise} */ finished() { - return this._promise; + return this.promise; } isRunning() { - return this._timerHandle !== null; + return this.timerHandle !== null; } } diff --git a/src/utils/permalinks/ElementPermalinkConstructor.ts b/src/utils/permalinks/ElementPermalinkConstructor.ts index 6702217c8e..cd7f2b9d2c 100644 --- a/src/utils/permalinks/ElementPermalinkConstructor.ts +++ b/src/utils/permalinks/ElementPermalinkConstructor.ts @@ -20,31 +20,31 @@ import PermalinkConstructor, {PermalinkParts} from "./PermalinkConstructor"; * Generates permalinks that self-reference the running webapp */ export default class ElementPermalinkConstructor extends PermalinkConstructor { - private _elementUrl: string; + private elementUrl: string; constructor(elementUrl: string) { super(); - this._elementUrl = elementUrl; + this.elementUrl = elementUrl; - if (!this._elementUrl.startsWith("http:") && !this._elementUrl.startsWith("https:")) { + if (!this.elementUrl.startsWith("http:") && !this.elementUrl.startsWith("https:")) { throw new Error("Element prefix URL does not appear to be an HTTP(S) URL"); } } forEvent(roomId: string, eventId: string, serverCandidates: string[]): string { - return `${this._elementUrl}/#/room/${roomId}/${eventId}${this.encodeServerCandidates(serverCandidates)}`; + return `${this.elementUrl}/#/room/${roomId}/${eventId}${this.encodeServerCandidates(serverCandidates)}`; } forRoom(roomIdOrAlias: string, serverCandidates?: string[]): string { - return `${this._elementUrl}/#/room/${roomIdOrAlias}${this.encodeServerCandidates(serverCandidates)}`; + return `${this.elementUrl}/#/room/${roomIdOrAlias}${this.encodeServerCandidates(serverCandidates)}`; } forUser(userId: string): string { - return `${this._elementUrl}/#/user/${userId}`; + return `${this.elementUrl}/#/user/${userId}`; } forGroup(groupId: string): string { - return `${this._elementUrl}/#/group/${groupId}`; + return `${this.elementUrl}/#/group/${groupId}`; } forEntity(entityId: string): string { @@ -58,7 +58,7 @@ export default class ElementPermalinkConstructor extends PermalinkConstructor { } isPermalinkHost(testHost: string): boolean { - const parsedUrl = new URL(this._elementUrl); + const parsedUrl = new URL(this.elementUrl); return testHost === (parsedUrl.host || parsedUrl.hostname); // one of the hosts should match } @@ -71,11 +71,11 @@ export default class ElementPermalinkConstructor extends PermalinkConstructor { // https://github.com/turt2live/matrix-js-bot-sdk/blob/7c4665c9a25c2c8e0fe4e509f2616505b5b66a1c/src/Permalinks.ts#L33-L61 // Adapted for Element's URL format parsePermalink(fullUrl: string): PermalinkParts { - if (!fullUrl || !fullUrl.startsWith(this._elementUrl)) { + if (!fullUrl || !fullUrl.startsWith(this.elementUrl)) { throw new Error("Does not appear to be a permalink"); } - const parts = fullUrl.substring(`${this._elementUrl}/#/`.length); + const parts = fullUrl.substring(`${this.elementUrl}/#/`.length); return ElementPermalinkConstructor.parseAppRoute(parts); } diff --git a/src/utils/permalinks/Permalinks.ts b/src/utils/permalinks/Permalinks.ts index f5eeca86ee..cb463d6781 100644 --- a/src/utils/permalinks/Permalinks.ts +++ b/src/utils/permalinks/Permalinks.ts @@ -74,29 +74,29 @@ const MAX_SERVER_CANDIDATES = 3; // the list and magically have the link work. export class RoomPermalinkCreator { - private _room: Room; - private _roomId: string; - private _highestPlUserId: string; - private _populationMap: { [serverName: string]: number }; - private _bannedHostsRegexps: RegExp[]; - private _allowedHostsRegexps: RegExp[]; + private room: Room; + private roomId: string; + private highestPlUserId: string; + private populationMap: { [serverName: string]: number }; + private bannedHostsRegexps: RegExp[]; + private allowedHostsRegexps: RegExp[]; private _serverCandidates: string[]; - private _started: boolean; + private started: boolean; // We support being given a roomId as a fallback in the event the `room` object // doesn't exist or is not healthy for us to rely on. For example, loading a // permalink to a room which the MatrixClient doesn't know about. constructor(room: Room, roomId: string = null) { - this._room = room; - this._roomId = room ? room.roomId : roomId; - this._highestPlUserId = null; - this._populationMap = null; - this._bannedHostsRegexps = null; - this._allowedHostsRegexps = null; + this.room = room; + this.roomId = room ? room.roomId : roomId; + this.highestPlUserId = null; + this.populationMap = null; + this.bannedHostsRegexps = null; + this.allowedHostsRegexps = null; this._serverCandidates = null; - this._started = false; + this.started = false; - if (!this._roomId) { + if (!this.roomId) { throw new Error("Failed to resolve a roomId for the permalink creator to use"); } @@ -105,7 +105,7 @@ export class RoomPermalinkCreator { } load() { - if (!this._room || !this._room.currentState) { + if (!this.room || !this.room.currentState) { // Under rare and unknown circumstances it is possible to have a room with no // currentState, at least potentially at the early stages of joining a room. // To avoid breaking everything, we'll just warn rather than throw as well as @@ -113,23 +113,23 @@ export class RoomPermalinkCreator { console.warn("Tried to load a permalink creator with no room state"); return; } - this._updateAllowedServers(); - this._updateHighestPlUser(); - this._updatePopulationMap(); - this._updateServerCandidates(); + this.updateAllowedServers(); + this.updateHighestPlUser(); + this.updatePopulationMap(); + this.updateServerCandidates(); } start() { this.load(); - this._room.on("RoomMember.membership", this.onMembership); - this._room.on("RoomState.events", this.onRoomState); - this._started = true; + this.room.on("RoomMember.membership", this.onMembership); + this.room.on("RoomState.events", this.onRoomState); + this.started = true; } stop() { - this._room.removeListener("RoomMember.membership", this.onMembership); - this._room.removeListener("RoomState.events", this.onRoomState); - this._started = false; + this.room.removeListener("RoomMember.membership", this.onMembership); + this.room.removeListener("RoomState.events", this.onRoomState); + this.started = false; } get serverCandidates() { @@ -137,44 +137,44 @@ export class RoomPermalinkCreator { } isStarted() { - return this._started; + return this.started; } forEvent(eventId) { - return getPermalinkConstructor().forEvent(this._roomId, eventId, this._serverCandidates); + return getPermalinkConstructor().forEvent(this.roomId, eventId, this._serverCandidates); } forShareableRoom() { - if (this._room) { + if (this.room) { // Prefer to use canonical alias for permalink if possible - const alias = this._room.getCanonicalAlias(); + const alias = this.room.getCanonicalAlias(); if (alias) { return getPermalinkConstructor().forRoom(alias, this._serverCandidates); } } - return getPermalinkConstructor().forRoom(this._roomId, this._serverCandidates); + return getPermalinkConstructor().forRoom(this.roomId, this._serverCandidates); } forRoom() { - return getPermalinkConstructor().forRoom(this._roomId, this._serverCandidates); + return getPermalinkConstructor().forRoom(this.roomId, this._serverCandidates); } - onRoomState(event) { + private onRoomState(event) { switch (event.getType()) { case "m.room.server_acl": - this._updateAllowedServers(); - this._updateHighestPlUser(); - this._updatePopulationMap(); - this._updateServerCandidates(); + this.updateAllowedServers(); + this.updateHighestPlUser(); + this.updatePopulationMap(); + this.updateServerCandidates(); return; case "m.room.power_levels": - this._updateHighestPlUser(); - this._updateServerCandidates(); + this.updateHighestPlUser(); + this.updateServerCandidates(); return; } } - onMembership(evt, member, oldMembership) { + private onMembership(evt, member, oldMembership) { const userId = member.userId; const membership = member.membership; const serverName = getServerName(userId); @@ -182,17 +182,17 @@ export class RoomPermalinkCreator { const hasLeft = oldMembership === "join" && membership !== "join"; if (hasLeft) { - this._populationMap[serverName]--; + this.populationMap[serverName]--; } else if (hasJoined) { - this._populationMap[serverName]++; + this.populationMap[serverName]++; } - this._updateHighestPlUser(); - this._updateServerCandidates(); + this.updateHighestPlUser(); + this.updateServerCandidates(); } - _updateHighestPlUser() { - const plEvent = this._room.currentState.getStateEvents("m.room.power_levels", ""); + private updateHighestPlUser() { + const plEvent = this.room.currentState.getStateEvents("m.room.power_levels", ""); if (plEvent) { const content = plEvent.getContent(); if (content) { @@ -200,14 +200,14 @@ export class RoomPermalinkCreator { if (users) { const entries = Object.entries(users); const allowedEntries = entries.filter(([userId]) => { - const member = this._room.getMember(userId); + const member = this.room.getMember(userId); if (!member || member.membership !== "join") { return false; } const serverName = getServerName(userId); return !isHostnameIpAddress(serverName) && - !isHostInRegex(serverName, this._bannedHostsRegexps) && - isHostInRegex(serverName, this._allowedHostsRegexps); + !isHostInRegex(serverName, this.bannedHostsRegexps) && + isHostInRegex(serverName, this.allowedHostsRegexps); }); const maxEntry = allowedEntries.reduce((max, entry) => { return (entry[1] > max[1]) ? entry : max; @@ -215,20 +215,20 @@ export class RoomPermalinkCreator { const [userId, powerLevel] = maxEntry; // object wasn't empty, and max entry wasn't a demotion from the default if (userId !== null && powerLevel >= 50) { - this._highestPlUserId = userId; + this.highestPlUserId = userId; return; } } } } - this._highestPlUserId = null; + this.highestPlUserId = null; } - _updateAllowedServers() { + private updateAllowedServers() { const bannedHostsRegexps = []; let allowedHostsRegexps = [new RegExp(".*")]; // default allow everyone - if (this._room.currentState) { - const aclEvent = this._room.currentState.getStateEvents("m.room.server_acl", ""); + if (this.room.currentState) { + const aclEvent = this.room.currentState.getStateEvents("m.room.server_acl", ""); if (aclEvent && aclEvent.getContent()) { const getRegex = (hostname) => new RegExp("^" + utils.globToRegexp(hostname, false) + "$"); @@ -240,35 +240,35 @@ export class RoomPermalinkCreator { allowed.forEach(h => allowedHostsRegexps.push(getRegex(h))); } } - this._bannedHostsRegexps = bannedHostsRegexps; - this._allowedHostsRegexps = allowedHostsRegexps; + this.bannedHostsRegexps = bannedHostsRegexps; + this.allowedHostsRegexps = allowedHostsRegexps; } - _updatePopulationMap() { + private updatePopulationMap() { const populationMap: { [server: string]: number } = {}; - for (const member of this._room.getJoinedMembers()) { + for (const member of this.room.getJoinedMembers()) { const serverName = getServerName(member.userId); if (!populationMap[serverName]) { populationMap[serverName] = 0; } populationMap[serverName]++; } - this._populationMap = populationMap; + this.populationMap = populationMap; } - _updateServerCandidates() { + private updateServerCandidates() { let candidates = []; - if (this._highestPlUserId) { - candidates.push(getServerName(this._highestPlUserId)); + if (this.highestPlUserId) { + candidates.push(getServerName(this.highestPlUserId)); } - const serversByPopulation = Object.keys(this._populationMap) - .sort((a, b) => this._populationMap[b] - this._populationMap[a]) + const serversByPopulation = Object.keys(this.populationMap) + .sort((a, b) => this.populationMap[b] - this.populationMap[a]) .filter(a => { return !candidates.includes(a) && !isHostnameIpAddress(a) && - !isHostInRegex(a, this._bannedHostsRegexps) && - isHostInRegex(a, this._allowedHostsRegexps); + !isHostInRegex(a, this.bannedHostsRegexps) && + isHostInRegex(a, this.allowedHostsRegexps); }); const remainingServers = serversByPopulation.slice(0, MAX_SERVER_CANDIDATES - candidates.length); From 3b39007a5d7edbdd637a8d823580c92cd9678768 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 26 Apr 2021 14:06:25 +0100 Subject: [PATCH 07/33] Move initialisers to field --- src/indexing/EventIndexPeg.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/indexing/EventIndexPeg.ts b/src/indexing/EventIndexPeg.ts index 050a8c6217..4356d882d5 100644 --- a/src/indexing/EventIndexPeg.ts +++ b/src/indexing/EventIndexPeg.ts @@ -28,16 +28,10 @@ import {SettingLevel} from "../settings/SettingLevel"; const INDEX_VERSION = 1; export class EventIndexPeg { - public index: EventIndex; - public error: Error; + public index: EventIndex = null; + public error: Error = null; - private _supportIsInstalled: boolean; - - constructor() { - this.index = null; - this.error = null; - this._supportIsInstalled = false; - } + private _supportIsInstalled = false; /** * Initialize the EventIndexPeg and if event indexing is enabled initialize From 69fbfdc552a1026797f792e370487dd7cb1df8e3 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 26 Apr 2021 14:07:45 +0100 Subject: [PATCH 08/33] Fix interface syntax --- .../views/settings/tabs/user/PreferencesUserSettingsTab.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx b/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx index 138bf40b80..7e2da2b53b 100644 --- a/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx @@ -34,9 +34,9 @@ interface IState { alwaysShowMenuBar: boolean; minimizeToTraySupported: boolean; minimizeToTray: boolean; - autocompleteDelay: string, - readMarkerInViewThresholdMs: string, - readMarkerOutOfViewThresholdMs: string, + autocompleteDelay: string; + readMarkerInViewThresholdMs: string; + readMarkerOutOfViewThresholdMs: string; } @replaceableComponent("views.settings.tabs.user.PreferencesUserSettingsTab") From a3a756fdb26eaf42855454879aab37daa466bb17 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 26 Apr 2021 14:08:45 +0100 Subject: [PATCH 09/33] Rename history visibility type --- .../views/settings/tabs/room/SecurityRoomSettingsTab.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx index 07776a5a54..3814a8c1b7 100644 --- a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx @@ -29,7 +29,7 @@ import { replaceableComponent } from "../../../../../utils/replaceableComponent" type JoinRule = "public" | "knock" | "invite" | "private"; type GuestAccess = "can_join" | "forbidden"; -type History = "invited" | "joined" | "shared" | "world_readable"; +type HistoryVisibility = "invited" | "joined" | "shared" | "world_readable"; interface IProps { roomId: string; @@ -38,7 +38,7 @@ interface IProps { interface IState { joinRule: JoinRule; guestAccess: GuestAccess; - history: History; + history: HistoryVisibility; hasAliases: boolean; encrypted: boolean; } @@ -74,7 +74,7 @@ export default class SecurityRoomSettingsTab extends React.Component Date: Mon, 26 Apr 2021 14:54:36 +0100 Subject: [PATCH 10/33] Use private parameter properties --- src/ScalarAuthClient.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ScalarAuthClient.ts b/src/ScalarAuthClient.ts index c59136263d..c18265be55 100644 --- a/src/ScalarAuthClient.ts +++ b/src/ScalarAuthClient.ts @@ -30,13 +30,11 @@ const imApiVersion = "1.1"; // TODO: Generify the name of this class and all components within - it's not just for Scalar. export default class ScalarAuthClient { - private apiUrl: string; - private uiUrl: string; private scalarToken: string; private termsInteractionCallback: TermsInteractionCallback; private isDefaultManager: boolean; - constructor(apiUrl, uiUrl) { + constructor(private apiUrl: string, private uiUrl: string) { this.apiUrl = apiUrl; this.uiUrl = uiUrl; this.scalarToken = null; From 1b615eebc1859917d9f97b798f001d56aab764a1 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 26 Apr 2021 14:56:43 +0100 Subject: [PATCH 11/33] Fix optional props --- .../views/settings/tabs/room/RolesRoomSettingsTab.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx index a945b22d1f..acf98edc18 100644 --- a/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx @@ -64,10 +64,10 @@ function parseIntWithDefault(val, def) { } interface IBannedUserProps { - canUnban: boolean; + canUnban?: boolean; member: RoomMember; by: string; - reason: string; + reason?: string; } export class BannedUser extends React.Component { From 8537f0a5a154960ea48a4123453a37e48c49d5a6 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 26 Apr 2021 14:59:26 +0100 Subject: [PATCH 12/33] Remove unneeded lint tweak --- src/@types/common.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/@types/common.ts b/src/@types/common.ts index e5503a0b68..b887bd4090 100644 --- a/src/@types/common.ts +++ b/src/@types/common.ts @@ -17,7 +17,6 @@ limitations under the License. import { JSXElementConstructor } from "react"; // Based on https://stackoverflow.com/a/53229857/3532235 -// eslint-disable-next-line @typescript-eslint/type-annotation-spacing export type Without = {[P in Exclude] ? : never}; export type XOR = (T | U) extends object ? (Without & U) | (Without & T) : T | U; export type Writeable = { -readonly [P in keyof T]: T[P] }; From 889289d46446715d94d4de3f320f36c1069520eb Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 26 Apr 2021 15:01:05 +0100 Subject: [PATCH 13/33] Tweak Timer constructor --- src/utils/Timer.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/utils/Timer.ts b/src/utils/Timer.ts index 3e370413e5..26170491d8 100644 --- a/src/utils/Timer.ts +++ b/src/utils/Timer.ts @@ -26,16 +26,14 @@ Once a timer is finished or aborted, it can't be started again a new one through `clone()` or `cloneIfRun()`. */ export default class Timer { - private timeout: number; private timerHandle: NodeJS.Timeout; private startTs: number; private promise: Promise; private resolve: () => void; private reject: (Error) => void; - constructor(timeout) { + constructor(private timeout: number) { this.timeout = timeout; - this.onTimeout = this.onTimeout.bind(this); this.setNotStarted(); } @@ -50,7 +48,7 @@ export default class Timer { }); } - private onTimeout() { + private onTimeout = () => { const now = Date.now(); const elapsed = now - this.startTs; if (elapsed >= this.timeout) { From eb9bf9c83f2dd03eaaeee1a7c9df7b2202ab1654 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 26 Apr 2021 15:03:17 +0100 Subject: [PATCH 14/33] Tweak Terms constructor --- src/Terms.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Terms.ts b/src/Terms.ts index 382e2d9782..31eeb6b29a 100644 --- a/src/Terms.ts +++ b/src/Terms.ts @@ -27,16 +27,12 @@ export class TermsNotSignedError extends Error {} * require agreement from the user before the user can use that service. */ export class Service { - public serviceType: string; - public baseUrl: string; - public accessToken: string; - /** * @param {MatrixClient.SERVICE_TYPES} serviceType The type of service * @param {string} baseUrl The Base URL of the service (ie. before '/_matrix') * @param {string} accessToken The user's access token for the service */ - constructor(serviceType, baseUrl, accessToken) { + constructor(public serviceType: string, public baseUrl: string, public accessToken: string) { this.serviceType = serviceType; this.baseUrl = baseUrl; this.accessToken = accessToken; From 01cfd9361e58f98f815eb4a7471975c6d5a845e7 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 26 Apr 2021 15:06:10 +0100 Subject: [PATCH 15/33] Fix ManageEventIndexDialog props syntax --- .../views/dialogs/eventindex/ManageEventIndexDialog.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx b/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx index 8864e043aa..78945a96f5 100644 --- a/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx +++ b/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx @@ -26,7 +26,7 @@ import EventIndexPeg from "../../../../indexing/EventIndexPeg"; import {SettingLevel} from "../../../../settings/SettingLevel"; interface IProps { - onFinished: (boolean) => {}, + onFinished: (boolean) => void; } interface IState { From bf43144f6e1b43fa60cf3e9a364ecb466392bf6f Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 26 Apr 2021 15:21:49 +0100 Subject: [PATCH 16/33] Add ActionPayload type --- src/components/views/rooms/MessageComposer.tsx | 5 +++-- src/components/views/settings/SetIdServer.tsx | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/views/rooms/MessageComposer.tsx b/src/components/views/rooms/MessageComposer.tsx index 62df0e7d72..ab7c358a2c 100644 --- a/src/components/views/rooms/MessageComposer.tsx +++ b/src/components/views/rooms/MessageComposer.tsx @@ -22,6 +22,7 @@ import {MatrixEvent} from "matrix-js-sdk/src/models/event"; import {Room} from "matrix-js-sdk/src/models/room"; import {RoomMember} from "matrix-js-sdk/src/models/room-member"; import dis from '../../../dispatcher/dispatcher'; +import { ActionPayload } from "../../../dispatcher/payloads"; import Stickerpicker from './Stickerpicker'; import { makeRoomPermalink, RoomPermalinkCreator } from '../../../utils/permalinks/Permalinks'; import ContentMessages from '../../../ContentMessages'; @@ -121,7 +122,7 @@ class UploadButton extends React.Component { dis.unregister(this.dispatcherRef); } - private onAction = payload => { + private onAction = (payload: ActionPayload) => { if (payload.action === "upload_file") { this.onUploadClick(); } @@ -217,7 +218,7 @@ export default class MessageComposer extends React.Component { this.waitForOwnMember(); } - private onAction = (payload) => { + private onAction = (payload: ActionPayload) => { if (payload.action === 'reply_to_event') { // add a timeout for the reply preview to be rendered, so // that the ScrollPanel listening to the resizeNotifier can diff --git a/src/components/views/settings/SetIdServer.tsx b/src/components/views/settings/SetIdServer.tsx index 70a4c46f69..05d1f83387 100644 --- a/src/components/views/settings/SetIdServer.tsx +++ b/src/components/views/settings/SetIdServer.tsx @@ -27,6 +27,7 @@ import {abbreviateUrl, unabbreviateUrl} from "../../../utils/UrlUtils"; import { getDefaultIdentityServerUrl, doesIdentityServerHaveTerms } from '../../../utils/IdentityServerUtils'; import {timeout} from "../../../utils/promise"; import {replaceableComponent} from "../../../utils/replaceableComponent"; +import { ActionPayload } from '../../../dispatcher/payloads'; // We'll wait up to this long when checking for 3PID bindings on the IS. const REACHABILITY_TIMEOUT = 10000; // ms @@ -107,7 +108,7 @@ export default class SetIdServer extends React.Component { dis.unregister(this.dispatcherRef); } - private onAction = (payload) => { + private onAction = (payload: ActionPayload) => { // We react to changes in the ID server in the event the user is staring at this form // when changing their identity server on another device. if (payload.action !== "id_server_changed") return; From 809454e66accc3229c48105486a8182e55df2cc8 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 26 Apr 2021 15:23:55 +0100 Subject: [PATCH 17/33] Use new managed prop for emoji composer menu --- src/components/views/rooms/MessageComposer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/rooms/MessageComposer.tsx b/src/components/views/rooms/MessageComposer.tsx index ab7c358a2c..ebc8d3711c 100644 --- a/src/components/views/rooms/MessageComposer.tsx +++ b/src/components/views/rooms/MessageComposer.tsx @@ -74,7 +74,7 @@ const EmojiButton = ({addEmoji}) => { if (menuDisplayed) { const buttonRect = button.current.getBoundingClientRect(); const EmojiPicker = sdk.getComponent('emojipicker.EmojiPicker'); - contextMenu = + contextMenu = ; } From 4b66082b0f30f7a93af7a8eb9bddefee4e7b590a Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 26 Apr 2021 15:27:30 +0100 Subject: [PATCH 18/33] Add change event type --- src/components/views/rooms/MessageComposer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/rooms/MessageComposer.tsx b/src/components/views/rooms/MessageComposer.tsx index ebc8d3711c..d126a7b161 100644 --- a/src/components/views/rooms/MessageComposer.tsx +++ b/src/components/views/rooms/MessageComposer.tsx @@ -136,7 +136,7 @@ class UploadButton extends React.Component { this.uploadInput.current.click(); } - private onUploadFileInputChange = (ev) => { + private onUploadFileInputChange = (ev: React.ChangeEvent) => { if (ev.target.files.length === 0) return; // take a copy so we can safely reset the value of the form control From 82caac16c892f6f595b5b406224b869eadb92779 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 26 Apr 2021 15:30:34 +0100 Subject: [PATCH 19/33] Add types for StorageManager functions --- src/utils/StorageManager.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/StorageManager.ts b/src/utils/StorageManager.ts index 07a731cd71..883c032771 100644 --- a/src/utils/StorageManager.ts +++ b/src/utils/StorageManager.ts @@ -32,15 +32,15 @@ try { const SYNC_STORE_NAME = "riot-web-sync"; const CRYPTO_STORE_NAME = "matrix-js-sdk:crypto"; -function log(msg) { +function log(msg: string) { console.log(`StorageManager: ${msg}`); } -function error(msg, ...args) { +function error(msg: string, ...args: string[]) { console.error(`StorageManager: ${msg}`, ...args); } -function track(action) { +function track(action: string) { Analytics.trackEvent("StorageManager", action); } From 25e4feeb388eefe8f44ed9d1311703a7711d7698 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 26 Apr 2021 15:38:43 +0100 Subject: [PATCH 20/33] Add more types in WidgetEchoStore --- src/stores/WidgetEchoStore.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/stores/WidgetEchoStore.ts b/src/stores/WidgetEchoStore.ts index e752f3db20..09120d6108 100644 --- a/src/stores/WidgetEchoStore.ts +++ b/src/stores/WidgetEchoStore.ts @@ -16,6 +16,7 @@ limitations under the License. import EventEmitter from 'events'; import { IWidget } from 'matrix-widget-api'; +import MatrixEvent from "matrix-js-sdk/src/models/event"; import {WidgetType} from "../widgets/WidgetType"; /** @@ -36,7 +37,7 @@ class WidgetEchoStore extends EventEmitter { // Map as below. Object is the content of the widget state event, // so for widgets that have been deleted locally, the object is empty. // roomId: { - // widgetId: [object] + // widgetId: IWidget // } }; } @@ -48,11 +49,11 @@ class WidgetEchoStore extends EventEmitter { * and we don't really need the actual widget events anyway since we just want to * show a spinner / prevent widgets being added twice. * - * @param {Room} roomId The ID of the room to get widgets for + * @param {string} roomId The ID of the room to get widgets for * @param {MatrixEvent[]} currentRoomWidgets Current widgets for the room * @returns {MatrixEvent[]} List of widgets in the room, minus any pending removal */ - getEchoedRoomWidgets(roomId, currentRoomWidgets) { + getEchoedRoomWidgets(roomId: string, currentRoomWidgets: MatrixEvent[]): MatrixEvent[] { const echoedWidgets = []; const roomEchoState = Object.assign({}, this.roomWidgetEcho[roomId]); @@ -71,7 +72,7 @@ class WidgetEchoStore extends EventEmitter { return echoedWidgets; } - roomHasPendingWidgetsOfType(roomId, currentRoomWidgets, type?: WidgetType) { + roomHasPendingWidgetsOfType(roomId: string, currentRoomWidgets: MatrixEvent[], type?: WidgetType): boolean { const roomEchoState = Object.assign({}, this.roomWidgetEcho[roomId]); // any widget IDs that are already in the room are not pending, so @@ -91,7 +92,7 @@ class WidgetEchoStore extends EventEmitter { } } - roomHasPendingWidgets(roomId, currentRoomWidgets) { + roomHasPendingWidgets(roomId: string, currentRoomWidgets: MatrixEvent[]): boolean { return this.roomHasPendingWidgetsOfType(roomId, currentRoomWidgets); } @@ -102,7 +103,7 @@ class WidgetEchoStore extends EventEmitter { this.emit('update', roomId, widgetId); } - removeRoomWidgetEcho(roomId, widgetId) { + removeRoomWidgetEcho(roomId: string, widgetId: string) { delete this.roomWidgetEcho[roomId][widgetId]; if (Object.keys(this.roomWidgetEcho[roomId]).length === 0) delete this.roomWidgetEcho[roomId]; this.emit('update', roomId, widgetId); From ba4e58513d1bb6a7c21041bab837c1d29d1894af Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 26 Apr 2021 15:41:19 +0100 Subject: [PATCH 21/33] Fix ScalarAuthClient test --- test/ScalarAuthClient-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ScalarAuthClient-test.js b/test/ScalarAuthClient-test.js index 83f357811a..3435f70932 100644 --- a/test/ScalarAuthClient-test.js +++ b/test/ScalarAuthClient-test.js @@ -29,7 +29,7 @@ describe('ScalarAuthClient', function() { it('should request a new token if the old one fails', async function() { const sac = new ScalarAuthClient(); - sac._getAccountName = jest.fn((arg) => { + sac.getAccountName = jest.fn((arg) => { switch (arg) { case "brokentoken": return Promise.reject({ From 8659c98c448eb2633aa6e896d4c779c95593e1c2 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 26 Apr 2021 15:55:04 +0100 Subject: [PATCH 22/33] Add tile shape string type --- src/components/views/rooms/EventTile.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/rooms/EventTile.tsx b/src/components/views/rooms/EventTile.tsx index 33bc4951a8..7de8578ae9 100644 --- a/src/components/views/rooms/EventTile.tsx +++ b/src/components/views/rooms/EventTile.tsx @@ -245,7 +245,7 @@ interface IProps { // It could also be done by subclassing EventTile, but that'd be quite // boiilerplatey. So just make the necessary render decisions conditional // for now. - tileShape?: string; + tileShape?: 'notif' | 'file_grid' | 'reply' | 'reply_preview'; // show twelve hour timestamps isTwelveHour?: boolean; From d497d62db36d00d46bcaf76c91bf6868ced9c632 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 26 Apr 2021 16:14:21 +0100 Subject: [PATCH 23/33] Use enums in SecurityRoomSettingsTab --- .../tabs/room/SecurityRoomSettingsTab.tsx | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx index 3814a8c1b7..cd40761150 100644 --- a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx @@ -27,9 +27,24 @@ import SettingsStore from "../../../../../settings/SettingsStore"; import {UIFeature} from "../../../../../settings/UIFeature"; import { replaceableComponent } from "../../../../../utils/replaceableComponent"; -type JoinRule = "public" | "knock" | "invite" | "private"; -type GuestAccess = "can_join" | "forbidden"; -type HistoryVisibility = "invited" | "joined" | "shared" | "world_readable"; +enum JoinRule { + Public = "public", + Knock = "knock", + Invite = "invite", + Private = "private", +} + +enum GuestAccess { + CanJoin = "can_join", + Forbidden = "forbidden", +} + +enum HistoryVisibility { + Invited = "invited", + Joined = "joined", + Shared = "shared", + WorldReadable = "world_readable", +} interface IProps { roomId: string; @@ -49,9 +64,9 @@ export default class SecurityRoomSettingsTab extends React.Component Date: Mon, 26 Apr 2021 16:16:43 +0100 Subject: [PATCH 24/33] Tweak interface syntax --- src/components/views/rooms/EventTile.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/views/rooms/EventTile.tsx b/src/components/views/rooms/EventTile.tsx index 67eaa40611..19c5a7acaa 100644 --- a/src/components/views/rooms/EventTile.tsx +++ b/src/components/views/rooms/EventTile.tsx @@ -222,20 +222,20 @@ interface IProps { isSelectedEvent?: boolean; // callback called when dynamic content in events are loaded - onHeightChanged?: () => void, + onHeightChanged?: () => void; // a list of read-receipts we should show. Each object has a 'roomMember' and 'ts'. - readReceipts?: IReadReceiptProps[], + readReceipts?: IReadReceiptProps[]; // opaque readreceipt info for each userId; used by ReadReceiptMarker // to manage its animations. Should be an empty object when the room // first loads - readReceiptMap?: any, + readReceiptMap?: any; // A function which is used to check if the parent panel is being // unmounted, to avoid unnecessary work. Should return true if we // are being unmounted. - checkUnmounting?: () => boolean, + checkUnmounting?: () => boolean; // the status of this event - ie, mxEvent.status. Denormalised to here so // that we can tell when it changes. @@ -253,13 +253,13 @@ interface IProps { isTwelveHour?: boolean; // helper function to access relations for this event - getRelationsForEvent?: (eventId: string, relationType: string, eventType: string) => Relations, + getRelationsForEvent?: (eventId: string, relationType: string, eventType: string) => Relations; // whether to show reactions for this event showReactions?: boolean; // which layout to use - layout: Layout, + layout: Layout; // whether or not to show flair at all enableFlair?: boolean; From 26bb7c08c253c059636e441eb28b0cf072fab056 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 26 Apr 2021 16:20:16 +0100 Subject: [PATCH 25/33] Add join rule comment --- .../views/settings/tabs/room/SecurityRoomSettingsTab.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx index cd40761150..3beb329dc1 100644 --- a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx @@ -27,6 +27,7 @@ import SettingsStore from "../../../../../settings/SettingsStore"; import {UIFeature} from "../../../../../settings/UIFeature"; import { replaceableComponent } from "../../../../../utils/replaceableComponent"; +// Knock and private are reserved keywords which are not yet implemented. enum JoinRule { Public = "public", Knock = "knock", From 417f662ea783a143ebcfca3ac79199d1b3d3137f Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 26 Apr 2021 17:12:31 +0100 Subject: [PATCH 26/33] Remove redundant parameter initialisers --- src/ScalarAuthClient.ts | 2 -- src/Terms.ts | 3 --- src/utils/Timer.ts | 1 - 3 files changed, 6 deletions(-) diff --git a/src/ScalarAuthClient.ts b/src/ScalarAuthClient.ts index c18265be55..c8695eb80f 100644 --- a/src/ScalarAuthClient.ts +++ b/src/ScalarAuthClient.ts @@ -35,8 +35,6 @@ export default class ScalarAuthClient { private isDefaultManager: boolean; constructor(private apiUrl: string, private uiUrl: string) { - this.apiUrl = apiUrl; - this.uiUrl = uiUrl; this.scalarToken = null; // `undefined` to allow `startTermsFlow` to fallback to a default // callback if this is unset. diff --git a/src/Terms.ts b/src/Terms.ts index 31eeb6b29a..1bdff36cbc 100644 --- a/src/Terms.ts +++ b/src/Terms.ts @@ -33,9 +33,6 @@ export class Service { * @param {string} accessToken The user's access token for the service */ constructor(public serviceType: string, public baseUrl: string, public accessToken: string) { - this.serviceType = serviceType; - this.baseUrl = baseUrl; - this.accessToken = accessToken; } } diff --git a/src/utils/Timer.ts b/src/utils/Timer.ts index 26170491d8..0b846e02ab 100644 --- a/src/utils/Timer.ts +++ b/src/utils/Timer.ts @@ -33,7 +33,6 @@ export default class Timer { private reject: (Error) => void; constructor(private timeout: number) { - this.timeout = timeout; this.setNotStarted(); } From 5107ce7f4087b2b4f0325b8538589d576ab123a6 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Tue, 27 Apr 2021 11:22:17 +0100 Subject: [PATCH 27/33] Add types to ScalarAuthClient --- src/ScalarAuthClient.ts | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/ScalarAuthClient.ts b/src/ScalarAuthClient.ts index c8695eb80f..a09c3494a8 100644 --- a/src/ScalarAuthClient.ts +++ b/src/ScalarAuthClient.ts @@ -23,6 +23,7 @@ import request from "browser-request"; import SdkConfig from "./SdkConfig"; import {WidgetType} from "./widgets/WidgetType"; import {SERVICE_TYPES} from "matrix-js-sdk/src/service-types"; +import { Room } from "matrix-js-sdk/src/models/room"; // The version of the integration manager API we're intending to work with const imApiVersion = "1.1"; @@ -57,7 +58,7 @@ export default class ScalarAuthClient { } } - private readTokenFromStore() { + private readTokenFromStore(): string { let token = window.localStorage.getItem("mx_scalar_token_at_" + this.apiUrl); if (!token && this.isDefaultManager) { token = window.localStorage.getItem("mx_scalar_token"); @@ -65,7 +66,7 @@ export default class ScalarAuthClient { return token; } - private readToken() { + private readToken(): string { if (this.scalarToken) return this.scalarToken; return this.readTokenFromStore(); } @@ -74,18 +75,18 @@ export default class ScalarAuthClient { this.termsInteractionCallback = callback; } - connect() { + connect(): Promise { return this.getScalarToken().then((tok) => { this.scalarToken = tok; }); } - hasCredentials() { + hasCredentials(): boolean { return this.scalarToken != null; // undef or null } // Returns a promise that resolves to a scalar_token string - getScalarToken() { + getScalarToken(): Promise { const token = this.readToken(); if (!token) { @@ -101,7 +102,7 @@ export default class ScalarAuthClient { } } - private getAccountName(token) { + private getAccountName(token: string): Promise { const url = this.apiUrl + "/account"; return new Promise(function(resolve, reject) { @@ -126,7 +127,7 @@ export default class ScalarAuthClient { }); } - private checkToken(token) { + private checkToken(token: string): Promise { return this.getAccountName(token).then(userId => { const me = MatrixClientPeg.get().getUserId(); if (userId !== me) { @@ -166,7 +167,7 @@ export default class ScalarAuthClient { }); } - registerForToken() { + registerForToken(): Promise { // Get openid bearer token from the HS as the first part of our dance return MatrixClientPeg.get().getOpenIdToken().then((tokenObject) => { // Now we can send that to scalar and exchange it for a scalar token @@ -181,7 +182,7 @@ export default class ScalarAuthClient { }); } - exchangeForScalarToken(openidTokenObject) { + exchangeForScalarToken(openidTokenObject: any): Promise { const scalarRestUrl = this.apiUrl; return new Promise(function(resolve, reject) { @@ -205,7 +206,7 @@ export default class ScalarAuthClient { }); } - getScalarPageTitle(url) { + getScalarPageTitle(url: string): Promise { let scalarPageLookupUrl = this.apiUrl + '/widgets/title_lookup'; scalarPageLookupUrl = this.getStarterLink(scalarPageLookupUrl); scalarPageLookupUrl += '&curl=' + encodeURIComponent(url); @@ -241,7 +242,7 @@ export default class ScalarAuthClient { * @param {string} widgetId The widget ID to disable assets for * @return {Promise} Resolves on completion */ - disableWidgetAssets(widgetType: WidgetType, widgetId) { + disableWidgetAssets(widgetType: WidgetType, widgetId: string): Promise { let url = this.apiUrl + '/widgets/set_assets_state'; url = this.getStarterLink(url); return new Promise((resolve, reject) => { @@ -268,7 +269,7 @@ export default class ScalarAuthClient { }); } - getScalarInterfaceUrlForRoom(room, screen, id) { + getScalarInterfaceUrlForRoom(room: Room, screen: string, id: string): string { const roomId = room.roomId; const roomName = room.name; let url = this.uiUrl; @@ -285,7 +286,7 @@ export default class ScalarAuthClient { return url; } - getStarterLink(starterLinkUrl) { + getStarterLink(starterLinkUrl: string): string { return starterLinkUrl + "?scalar_token=" + encodeURIComponent(this.scalarToken); } } From 2be8f0c9c78ea7a1247f9a4e79b7eb296421033f Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Tue, 27 Apr 2021 11:26:37 +0100 Subject: [PATCH 28/33] Fix onFinished type --- .../views/dialogs/eventindex/ManageEventIndexDialog.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx b/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx index 78945a96f5..0710c513da 100644 --- a/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx +++ b/src/async-components/views/dialogs/eventindex/ManageEventIndexDialog.tsx @@ -26,7 +26,7 @@ import EventIndexPeg from "../../../../indexing/EventIndexPeg"; import {SettingLevel} from "../../../../settings/SettingLevel"; interface IProps { - onFinished: (boolean) => void; + onFinished: (confirmed: boolean) => void; } interface IState { From 2ebd25659052a1fc7c8207e4ba846cd00ab9906c Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Tue, 27 Apr 2021 11:42:11 +0100 Subject: [PATCH 29/33] Add types to RolesRoomSettingsTab --- .../settings/tabs/room/RolesRoomSettingsTab.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx index acf98edc18..4fa521f598 100644 --- a/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/RolesRoomSettingsTab.tsx @@ -23,6 +23,8 @@ import Modal from "../../../../../Modal"; import {replaceableComponent} from "../../../../../utils/replaceableComponent"; import {EventType} from "matrix-js-sdk/src/@types/event"; import { RoomMember } from "matrix-js-sdk/src/models/room-member"; +import { MatrixEvent } from "matrix-js-sdk/src/models/event"; +import { RoomState } from "matrix-js-sdk/src/models/room-state"; const plEventsToLabels = { // These will be translated for us later. @@ -115,23 +117,23 @@ interface IProps { @replaceableComponent("views.settings.tabs.room.RolesRoomSettingsTab") export default class RolesRoomSettingsTab extends React.Component { - componentDidMount(): void { + componentDidMount() { MatrixClientPeg.get().on("RoomState.members", this.onRoomMembership); } - componentWillUnmount(): void { + componentWillUnmount() { const client = MatrixClientPeg.get(); if (client) { client.removeListener("RoomState.members", this.onRoomMembership); } } - private onRoomMembership = (event, state, member) => { + private onRoomMembership = (event: MatrixEvent, state: RoomState, member: RoomMember) => { if (state.roomId !== this.props.roomId) return; this.forceUpdate(); }; - private populateDefaultPlEvents(eventsSection, stateLevel, eventsLevel) { + private populateDefaultPlEvents(eventsSection: Record, stateLevel: number, eventsLevel: number) { for (const desiredEvent of Object.keys(plEventsToShow)) { if (!(desiredEvent in eventsSection)) { eventsSection[desiredEvent] = (plEventsToShow[desiredEvent].isState ? stateLevel : eventsLevel); @@ -139,7 +141,7 @@ export default class RolesRoomSettingsTab extends React.Component { } } - private onPowerLevelsChanged = (value, powerLevelKey) => { + private onPowerLevelsChanged = (inputValue: string, powerLevelKey: string) => { const client = MatrixClientPeg.get(); const room = client.getRoom(this.props.roomId); const plEvent = room.currentState.getStateEvents('m.room.power_levels', ''); @@ -150,7 +152,7 @@ export default class RolesRoomSettingsTab extends React.Component { const eventsLevelPrefix = "event_levels_"; - value = parseInt(value); + const value = parseInt(inputValue); if (powerLevelKey.startsWith(eventsLevelPrefix)) { // deep copy "events" object, Object.assign itself won't deep copy @@ -184,7 +186,7 @@ export default class RolesRoomSettingsTab extends React.Component { }); }; - private onUserPowerLevelChanged = (value, powerLevelKey) => { + private onUserPowerLevelChanged = (value: string, powerLevelKey: string) => { const client = MatrixClientPeg.get(); const room = client.getRoom(this.props.roomId); const plEvent = room.currentState.getStateEvents('m.room.power_levels', ''); From 4e7240ebc9bef608e1de8f94875409b179029319 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Tue, 27 Apr 2021 11:56:45 +0100 Subject: [PATCH 30/33] Add types to SecurityRoomSettingsTab --- .../tabs/room/SecurityRoomSettingsTab.tsx | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx index 3beb329dc1..02bbcfb751 100644 --- a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx @@ -15,6 +15,7 @@ limitations under the License. */ import React from 'react'; +import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import {_t} from "../../../../../languageHandler"; import {MatrixClientPeg} from "../../../../../MatrixClientPeg"; import * as sdk from "../../../../.."; @@ -74,7 +75,7 @@ export default class SecurityRoomSettingsTab extends React.Component { // eslint-disable-line camelcase + async UNSAFE_componentWillMount() { // eslint-disable-line camelcase MatrixClientPeg.get().on("RoomState.events", this.onStateEvent); const room = MatrixClientPeg.get().getRoom(this.props.roomId); @@ -83,17 +84,17 @@ export default class SecurityRoomSettingsTab extends React.Component(event: MatrixEvent, key: string, defaultValue: T): T { if (!event || !event.getContent()) return defaultValue; return event.getContent()[key] || defaultValue; } - componentWillUnmount(): void { + componentWillUnmount() { MatrixClientPeg.get().removeListener("RoomState.events", this.onStateEvent); } - private onStateEvent = (e) => { + private onStateEvent = (e: MatrixEvent) => { const refreshWhenTypes = [ 'm.room.join_rules', 'm.room.guest_access', @@ -120,7 +121,7 @@ export default class SecurityRoomSettingsTab extends React.Component { + private onEncryptionChange = (e: React.ChangeEvent) => { Modal.createTrackedDialog('Enable encryption', '', QuestionDialog, { title: _t('Enable encryption?'), description: _t( @@ -153,7 +154,7 @@ export default class SecurityRoomSettingsTab extends React.Component { + private fixGuestAccess = (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); @@ -175,7 +176,7 @@ export default class SecurityRoomSettingsTab extends React.Component { + private onRoomAccessRadioToggle = (roomAccess: string) => { // join_rule // INVITE | PUBLIC // ----------------------+---------------- @@ -221,7 +222,7 @@ export default class SecurityRoomSettingsTab extends React.Component { + private onHistoryRadioToggle = (history: HistoryVisibility) => { const beforeHistory = this.state.history; this.setState({history: history}); MatrixClientPeg.get().sendStateEvent(this.props.roomId, "m.room.history_visibility", { @@ -232,11 +233,11 @@ export default class SecurityRoomSettingsTab extends React.Component { + private updateBlacklistDevicesFlag = (checked: boolean) => { MatrixClientPeg.get().getRoom(this.props.roomId).setBlacklistUnverifiedDevices(checked); }; - private async hasAliases() { + private async hasAliases(): Promise { const cli = MatrixClientPeg.get(); if (await cli.doesServerSupportUnstableFeature("org.matrix.msc2432")) { const response = await cli.unstableGetLocalAliases(this.props.roomId); @@ -335,22 +336,22 @@ export default class SecurityRoomSettingsTab extends React.Component Date: Tue, 27 Apr 2021 12:00:36 +0100 Subject: [PATCH 31/33] Add types to PreferencesUserSettingsTab --- .../tabs/user/PreferencesUserSettingsTab.tsx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx b/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx index 7e2da2b53b..f02c5c9ce0 100644 --- a/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx +++ b/src/components/views/settings/tabs/user/PreferencesUserSettingsTab.tsx @@ -103,7 +103,7 @@ export default class PreferencesUserSettingsTab extends React.Component<{}, ISta }; } - async componentDidMount(): Promise { + async componentDidMount() { const platform = PlatformPeg.get(); const autoLaunchSupported = await platform.supportsAutoLaunch(); @@ -142,38 +142,38 @@ export default class PreferencesUserSettingsTab extends React.Component<{}, ISta }); } - private onAutoLaunchChange = (checked) => { + private onAutoLaunchChange = (checked: boolean) => { PlatformPeg.get().setAutoLaunchEnabled(checked).then(() => this.setState({autoLaunch: checked})); }; - private onWarnBeforeExitChange = (checked) => { + private onWarnBeforeExitChange = (checked: boolean) => { PlatformPeg.get().setWarnBeforeExit(checked).then(() => this.setState({warnBeforeExit: checked})); } - private onAlwaysShowMenuBarChange = (checked) => { + private onAlwaysShowMenuBarChange = (checked: boolean) => { PlatformPeg.get().setAutoHideMenuBarEnabled(!checked).then(() => this.setState({alwaysShowMenuBar: checked})); }; - private onMinimizeToTrayChange = (checked) => { + private onMinimizeToTrayChange = (checked: boolean) => { PlatformPeg.get().setMinimizeToTrayEnabled(checked).then(() => this.setState({minimizeToTray: checked})); }; - private onAutocompleteDelayChange = (e) => { + private onAutocompleteDelayChange = (e: React.ChangeEvent) => { this.setState({autocompleteDelay: e.target.value}); SettingsStore.setValue("autocompleteDelay", null, SettingLevel.DEVICE, e.target.value); }; - private onReadMarkerInViewThresholdMs = (e) => { + private onReadMarkerInViewThresholdMs = (e: React.ChangeEvent) => { this.setState({readMarkerInViewThresholdMs: e.target.value}); SettingsStore.setValue("readMarkerInViewThresholdMs", null, SettingLevel.DEVICE, e.target.value); }; - private onReadMarkerOutOfViewThresholdMs = (e) => { + private onReadMarkerOutOfViewThresholdMs = (e: React.ChangeEvent) => { this.setState({readMarkerOutOfViewThresholdMs: e.target.value}); SettingsStore.setValue("readMarkerOutOfViewThresholdMs", null, SettingLevel.DEVICE, e.target.value); }; - private renderGroup(settingIds) { + private renderGroup(settingIds: string[]): React.ReactNodeArray { const SettingsFlag = sdk.getComponent("views.elements.SettingsFlag"); return settingIds.filter(SettingsStore.isEnabled).map(i => { return ; From bca45a1ad42a391696298fa1652d952a38fdb3a5 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Tue, 27 Apr 2021 12:02:20 +0100 Subject: [PATCH 32/33] Add types to Timer --- src/utils/Timer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/Timer.ts b/src/utils/Timer.ts index 0b846e02ab..9760631d09 100644 --- a/src/utils/Timer.ts +++ b/src/utils/Timer.ts @@ -59,7 +59,7 @@ export default class Timer { } } - changeTimeout(timeout) { + changeTimeout(timeout: number) { if (timeout === this.timeout) { return; } From b8203043be45f4c55cc3039c3f9c475e2dc7600c Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Tue, 27 Apr 2021 12:11:23 +0100 Subject: [PATCH 33/33] Add types to Permalinks --- src/utils/permalinks/Permalinks.ts | 36 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/utils/permalinks/Permalinks.ts b/src/utils/permalinks/Permalinks.ts index cb463d6781..2ef955c358 100644 --- a/src/utils/permalinks/Permalinks.ts +++ b/src/utils/permalinks/Permalinks.ts @@ -17,6 +17,9 @@ limitations under the License. import isIp from "is-ip"; import * as utils from "matrix-js-sdk/src/utils"; import {Room} from "matrix-js-sdk/src/models/room"; +import {EventType} from "matrix-js-sdk/src/@types/event"; +import { MatrixEvent } from "matrix-js-sdk/src/models/event"; +import { RoomMember } from "matrix-js-sdk/src/models/room-member"; import {MatrixClientPeg} from "../../MatrixClientPeg"; import SpecPermalinkConstructor, {baseUrl as matrixtoBaseUrl} from "./SpecPermalinkConstructor"; @@ -99,9 +102,6 @@ export class RoomPermalinkCreator { if (!this.roomId) { throw new Error("Failed to resolve a roomId for the permalink creator to use"); } - - this.onMembership = this.onMembership.bind(this); - this.onRoomState = this.onRoomState.bind(this); } load() { @@ -140,11 +140,11 @@ export class RoomPermalinkCreator { return this.started; } - forEvent(eventId) { + forEvent(eventId: string): string { return getPermalinkConstructor().forEvent(this.roomId, eventId, this._serverCandidates); } - forShareableRoom() { + forShareableRoom(): string { if (this.room) { // Prefer to use canonical alias for permalink if possible const alias = this.room.getCanonicalAlias(); @@ -155,26 +155,26 @@ export class RoomPermalinkCreator { return getPermalinkConstructor().forRoom(this.roomId, this._serverCandidates); } - forRoom() { + forRoom(): string { return getPermalinkConstructor().forRoom(this.roomId, this._serverCandidates); } - private onRoomState(event) { + private onRoomState = (event: MatrixEvent) => { switch (event.getType()) { - case "m.room.server_acl": + case EventType.RoomServerAcl: this.updateAllowedServers(); this.updateHighestPlUser(); this.updatePopulationMap(); this.updateServerCandidates(); return; - case "m.room.power_levels": + case EventType.RoomPowerLevels: this.updateHighestPlUser(); this.updateServerCandidates(); return; } } - private onMembership(evt, member, oldMembership) { + private onMembership = (evt: MatrixEvent, member: RoomMember, oldMembership: string) => { const userId = member.userId; const membership = member.membership; const serverName = getServerName(userId); @@ -282,11 +282,11 @@ export function makeGenericPermalink(entityId: string): string { return getPermalinkConstructor().forEntity(entityId); } -export function makeUserPermalink(userId) { +export function makeUserPermalink(userId: string): string { return getPermalinkConstructor().forUser(userId); } -export function makeRoomPermalink(roomId) { +export function makeRoomPermalink(roomId: string): string { if (!roomId) { throw new Error("can't permalink a falsey roomId"); } @@ -305,7 +305,7 @@ export function makeRoomPermalink(roomId) { return permalinkCreator.forRoom(); } -export function makeGroupPermalink(groupId) { +export function makeGroupPermalink(groupId: string): string { return getPermalinkConstructor().forGroup(groupId); } @@ -437,24 +437,24 @@ export function parseAppLocalLink(localLink: string): PermalinkParts { return null; } -function getServerName(userId) { +function getServerName(userId: string): string { return userId.split(":").splice(1).join(":"); } -function getHostnameFromMatrixDomain(domain) { +function getHostnameFromMatrixDomain(domain: string): string { if (!domain) return null; return new URL(`https://${domain}`).hostname; } -function isHostInRegex(hostname, regexps) { +function isHostInRegex(hostname: string, regexps: RegExp[]) { hostname = getHostnameFromMatrixDomain(hostname); if (!hostname) return true; // assumed - if (regexps.length > 0 && !regexps[0].test) throw new Error(regexps[0]); + if (regexps.length > 0 && !regexps[0].test) throw new Error(regexps[0].toString()); return regexps.filter(h => h.test(hostname)).length > 0; } -function isHostnameIpAddress(hostname) { +function isHostnameIpAddress(hostname: string): boolean { hostname = getHostnameFromMatrixDomain(hostname); if (!hostname) return false;