Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Conform more of the codebase to strictNullChecks #10800

Merged
merged 10 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/LegacyCallHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,9 @@ export default class LegacyCallHandler extends EventEmitter {
}

private onCallStateChanged = (newState: CallState, oldState: CallState | null, call: MatrixCall): void => {
if (!this.matchesCallForThisRoom(call)) return;

const mappedRoomId = this.roomIdForCall(call);
if (!mappedRoomId || !this.matchesCallForThisRoom(call)) return;

this.setCallState(call, newState);
dis.dispatch({
action: "call_state",
Expand Down
2 changes: 1 addition & 1 deletion src/audio/PlaybackClock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class PlaybackClock implements IDestroyable {
private stopped = true;
private lastCheck = 0;
private observable = new SimpleObservable<number[]>();
private timerId: number;
private timerId?: number;
private clipDuration = 0;
private placeholderDuration = 0;

Expand Down
4 changes: 2 additions & 2 deletions src/audio/VoiceMessageRecording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export interface IUpload {
* This class can be used to record a single voice message.
*/
export class VoiceMessageRecording implements IDestroyable {
private lastUpload: IUpload;
private lastUpload?: IUpload;
private buffer = new Uint8Array(0); // use this.audioBuffer to access
private playback: Playback;
private playback?: Playback;

public constructor(private matrixClient: MatrixClient, private voiceRecording: VoiceRecording) {
this.voiceRecording.onDataAvailable = this.onDataAvailable;
Expand Down
5 changes: 3 additions & 2 deletions src/audio/VoiceRecording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export class VoiceRecording extends EventEmitter implements IDestroyable {
return;
}

const secondsLeft = TARGET_MAX_LENGTH - this.recorderSeconds;
const secondsLeft = TARGET_MAX_LENGTH - this.recorderSeconds!;
if (secondsLeft < 0) {
// go over to make sure we definitely capture that last frame
// noinspection JSIgnoredPromiseFromCall - we aren't concerned with it overlapping
Expand All @@ -259,7 +259,8 @@ export class VoiceRecording extends EventEmitter implements IDestroyable {
/**
* {@link https://github.com/chris-rudmin/opus-recorder#instance-fields ref for recorderSeconds}
*/
public get recorderSeconds(): number {
public get recorderSeconds(): number | undefined {
if (!this.recorder) return undefined;
return this.recorder.encodedSamplePosition / 48000;
}

Expand Down
3 changes: 2 additions & 1 deletion src/components/structures/IndicatorScrollbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class IndicatorScrollbar<T extends keyof JSX.IntrinsicElements> e
IState
> {
private autoHideScrollbar = createRef<AutoHideScrollbar<any>>();
private scrollElement: HTMLDivElement;
private scrollElement?: HTMLDivElement;
private likelyTrackpadUser: boolean | null = null;
private checkAgainForTrackpad = 0; // ts in milliseconds to recheck this._likelyTrackpadUser

Expand Down Expand Up @@ -85,6 +85,7 @@ export default class IndicatorScrollbar<T extends keyof JSX.IntrinsicElements> e
}

private checkOverflow = (): void => {
if (!this.scrollElement) return;
const hasTopOverflow = this.scrollElement.scrollTop > 0;
const hasBottomOverflow =
this.scrollElement.scrollHeight > this.scrollElement.scrollTop + this.scrollElement.clientHeight;
Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/LegacyCallEventGrouper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function buildLegacyCallEventGroupers(
export default class LegacyCallEventGrouper extends EventEmitter {
private events: Set<MatrixEvent> = new Set<MatrixEvent>();
private call: MatrixCall | null = null;
public state: CallState | CustomCallState;
public state?: CallState | CustomCallState;

public constructor() {
super();
Expand Down
28 changes: 16 additions & 12 deletions src/components/structures/LoggedInView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ interface IProps {
autoJoin?: boolean;
threepidInvite?: IThreepidInvite;
roomOobData?: IOOBData;
currentRoomId: string;
currentRoomId: string | null;
collapseLhs: boolean;
config: ConfigOptions;
currentUserId: string;
currentUserId: string | null;
justRegistered?: boolean;
roomJustCreatedOpts?: IOpts;
forceTimeline?: boolean; // see props on MatrixChat
Expand Down Expand Up @@ -131,10 +131,10 @@ class LoggedInView extends React.Component<IProps, IState> {
protected readonly _roomView: React.RefObject<RoomViewType>;
protected readonly _resizeContainer: React.RefObject<HTMLDivElement>;
protected readonly resizeHandler: React.RefObject<HTMLDivElement>;
protected layoutWatcherRef: string;
protected compactLayoutWatcherRef: string;
protected backgroundImageWatcherRef: string;
protected resizer: Resizer;
protected layoutWatcherRef?: string;
protected compactLayoutWatcherRef?: string;
protected backgroundImageWatcherRef?: string;
protected resizer?: Resizer;

public constructor(props: IProps) {
super(props);
Expand Down Expand Up @@ -200,10 +200,10 @@ class LoggedInView extends React.Component<IProps, IState> {
this._matrixClient.removeListener(ClientEvent.Sync, this.onSync);
this._matrixClient.removeListener(RoomStateEvent.Events, this.onRoomStateEvents);
OwnProfileStore.instance.off(UPDATE_EVENT, this.refreshBackgroundImage);
SettingsStore.unwatchSetting(this.layoutWatcherRef);
SettingsStore.unwatchSetting(this.compactLayoutWatcherRef);
SettingsStore.unwatchSetting(this.backgroundImageWatcherRef);
this.resizer.detach();
if (this.layoutWatcherRef) SettingsStore.unwatchSetting(this.layoutWatcherRef);
if (this.compactLayoutWatcherRef) SettingsStore.unwatchSetting(this.compactLayoutWatcherRef);
if (this.backgroundImageWatcherRef) SettingsStore.unwatchSetting(this.backgroundImageWatcherRef);
this.resizer?.detach();
}

private onCallState = (): void => {
Expand Down Expand Up @@ -274,7 +274,7 @@ class LoggedInView extends React.Component<IProps, IState> {
if (isNaN(lhsSize)) {
lhsSize = 350;
}
this.resizer.forHandleWithId("lp-resizer")?.resize(lhsSize);
this.resizer?.forHandleWithId("lp-resizer")?.resize(lhsSize);
}

private onAccountData = (event: MatrixEvent): void => {
Expand Down Expand Up @@ -645,7 +645,11 @@ class LoggedInView extends React.Component<IProps, IState> {
break;

case PageTypes.UserView:
pageElement = <UserView userId={this.props.currentUserId} resizeNotifier={this.props.resizeNotifier} />;
if (!!this.props.currentUserId) {
pageElement = (
<UserView userId={this.props.currentUserId} resizeNotifier={this.props.resizeNotifier} />
);
}
break;
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/structures/MatrixChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
private focusComposer: boolean;
private subTitleStatus: string;
private prevWindowWidth: number;
private voiceBroadcastResumer: VoiceBroadcastResumer;
private voiceBroadcastResumer?: VoiceBroadcastResumer;

private readonly loggedInView: React.RefObject<LoggedInViewType>;
private readonly dispatcherRef: string;
Expand Down Expand Up @@ -441,7 +441,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
window.removeEventListener("resize", this.onWindowResized);

this.stores.accountPasswordStore.clearPassword();
if (this.voiceBroadcastResumer) this.voiceBroadcastResumer.destroy();
this.voiceBroadcastResumer?.destroy();
}

private onWindowResized = (): void => {
Expand Down Expand Up @@ -1935,7 +1935,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
private setPageSubtitle(subtitle = ""): void {
if (this.state.currentRoomId) {
const client = MatrixClientPeg.get();
const room = client && client.getRoom(this.state.currentRoomId);
const room = client?.getRoom(this.state.currentRoomId);
if (room) {
subtitle = `${this.subTitleStatus} | ${room.name} ${subtitle}`;
}
Expand Down
10 changes: 5 additions & 5 deletions src/components/structures/ScrollPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export default class ScrollPanel extends React.Component<IProps> {
};
private readonly itemlist = createRef<HTMLOListElement>();
private unmounted = false;
private scrollTimeout: Timer;
private scrollTimeout?: Timer;
// Are we currently trying to backfill?
private isFilling: boolean;
// Is the current fill request caused by a props update?
Expand All @@ -189,8 +189,8 @@ export default class ScrollPanel extends React.Component<IProps> {
// Is that next fill request scheduled because of a props update?
private pendingFillDueToPropsUpdate: boolean;
private scrollState: IScrollState;
private preventShrinkingState: IPreventShrinkingState | null;
private unfillDebouncer: number | null;
private preventShrinkingState: IPreventShrinkingState | null = null;
private unfillDebouncer: number | null = null;
private bottomGrowth: number;
private minListHeight: number;
private heightUpdateInProgress: boolean;
Expand Down Expand Up @@ -234,7 +234,7 @@ export default class ScrollPanel extends React.Component<IProps> {
// skip scroll events caused by resizing
if (this.props.resizeNotifier && this.props.resizeNotifier.isResizing) return;
debuglog("onScroll called past resize gate; scroll node top:", this.getScrollNode().scrollTop);
this.scrollTimeout.restart();
this.scrollTimeout?.restart();
this.saveScrollState();
this.updatePreventShrinking();
this.props.onScroll?.(ev);
Expand Down Expand Up @@ -725,7 +725,7 @@ export default class ScrollPanel extends React.Component<IProps> {
// need a better name that also indicates this will change scrollTop? Rebalance height? Reveal content?
private async updateHeight(): Promise<void> {
// wait until user has stopped scrolling
if (this.scrollTimeout.isRunning()) {
if (this.scrollTimeout?.isRunning()) {
debuglog("updateHeight waiting for scrolling to end ... ");
await this.scrollTimeout.finished();
debuglog("updateHeight actually running now");
Expand Down
6 changes: 3 additions & 3 deletions src/components/structures/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ export default class UserMenu extends React.Component<IProps, IState> {
public static contextType = SDKContext;
public context!: React.ContextType<typeof SDKContext>;

private dispatcherRef: string;
private themeWatcherRef: string;
private readonly dndWatcherRef: string;
private dispatcherRef?: string;
private themeWatcherRef?: string;
private readonly dndWatcherRef?: string;
private buttonRef: React.RefObject<HTMLButtonElement> = createRef();

public constructor(props: IProps, context: React.ContextType<typeof SDKContext>) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/auth/Registration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ interface IState {
export default class Registration extends React.Component<IProps, IState> {
private readonly loginLogic: Login;
// `replaceClient` tracks latest serverConfig to spot when it changes under the async method which fetches flows
private latestServerConfig: ValidatedServerConfig;
private latestServerConfig?: ValidatedServerConfig;

public constructor(props: IProps) {
super(props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,8 @@ export class MsisdnAuthEntry extends React.Component<IMsisdnAuthEntryProps, IMsi
public static LOGIN_TYPE = AuthType.Msisdn;

private submitUrl?: string;
private sid: string;
private msisdn: string;
private sid?: string;
private msisdn?: string;

public constructor(props: IMsisdnAuthEntryProps) {
super(props);
Expand Down Expand Up @@ -615,8 +615,8 @@ export class MsisdnAuthEntry extends React.Component<IMsisdnAuthEntryProps, IMsi
});

try {
let result;
if (this.submitUrl) {
let result: { success: boolean };
if (this.submitUrl && this.sid) {
result = await this.props.matrixClient.submitMsisdnTokenOtherUrl(
this.submitUrl,
this.sid,
Expand Down
6 changes: 5 additions & 1 deletion src/components/views/dialogs/ReportEventDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import React, { ChangeEvent } from "react";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { logger } from "matrix-js-sdk/src/logger";

import { _t } from "../../../languageHandler";
import { _t, UserFriendlyError } from "../../../languageHandler";
import { ensureDMExists } from "../../../createRoom";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
import SdkConfig from "../../../SdkConfig";
Expand Down Expand Up @@ -245,6 +245,10 @@ export default class ReportEventDialog extends React.Component<IProps, IState> {
// Report to moderators through to the dedicated bot,
// as configured in the room's state events.
const dmRoomId = await ensureDMExists(client, this.moderation.moderationBotUserId);
if (!dmRoomId) {
throw new UserFriendlyError("Unable to create room with moderation bot");
}

await client.sendEvent(dmRoomId, ABUSE_EVENT_TYPE, {
event_id: ev.getId(),
room_id: ev.getRoomId(),
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/dialogs/RoomSettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ interface IState {
}

class RoomSettingsDialog extends React.Component<IProps, IState> {
private dispatcherRef: string;
private dispatcherRef?: string;

public constructor(props: IProps) {
super(props);
Expand Down
6 changes: 3 additions & 3 deletions src/components/views/dialogs/RoomUpgradeDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface IState {
}

export default class RoomUpgradeDialog extends React.Component<IProps, IState> {
private targetVersion: string;
private targetVersion?: string;

public state = {
busy: true,
Expand All @@ -53,7 +53,7 @@ export default class RoomUpgradeDialog extends React.Component<IProps, IState> {

private onUpgradeClick = (): void => {
this.setState({ busy: true });
upgradeRoom(this.props.room, this.targetVersion, false, false)
upgradeRoom(this.props.room, this.targetVersion!, false, false)
.then(() => {
this.props.onFinished(true);
})
Expand All @@ -69,7 +69,7 @@ export default class RoomUpgradeDialog extends React.Component<IProps, IState> {
};

public render(): React.ReactNode {
let buttons;
let buttons: JSX.Element;
if (this.state.busy) {
buttons = <Spinner />;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/components/views/dialogs/ServerPickerDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface IState {
export default class ServerPickerDialog extends React.PureComponent<IProps, IState> {
private readonly defaultServer: ValidatedServerConfig;
private readonly fieldRef = createRef<Field>();
private validatedConf: ValidatedServerConfig;
private validatedConf?: ValidatedServerConfig;

public constructor(props: IProps) {
super(props);
Expand Down Expand Up @@ -85,7 +85,7 @@ export default class ServerPickerDialog extends React.PureComponent<IProps, ISta
// find their homeserver without demanding they use "https://matrix.org"
private validate = withValidation<this, { error?: string }>({
deriveData: async ({ value }): Promise<{ error?: string }> => {
let hsUrl = value.trim(); // trim to account for random whitespace
let hsUrl = (value ?? "").trim(); // trim to account for random whitespace

// if the URL has no protocol, try validate it as a serverName via well-known
if (!hsUrl.includes("://")) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/views/dialogs/SetEmailDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface IState {
* On success, `onFinished(true)` is called.
*/
export default class SetEmailDialog extends React.Component<IProps, IState> {
private addThreepid: AddThreepid;
private addThreepid?: AddThreepid;

public constructor(props: IProps) {
super(props);
Expand Down Expand Up @@ -109,7 +109,7 @@ export default class SetEmailDialog extends React.Component<IProps, IState> {
};

private verifyEmailAddress(): void {
this.addThreepid.checkEmailLinkClicked().then(
this.addThreepid?.checkEmailLinkClicked().then(
() => {
this.props.onFinished(true);
},
Expand Down
10 changes: 5 additions & 5 deletions src/components/views/elements/AppTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ export default class AppTile extends React.Component<IProps, IState> {
};

private contextMenuButton = createRef<any>();
private iframe: HTMLIFrameElement; // ref to the iframe (callback style)
private allowedWidgetsWatchRef: string;
private iframe?: HTMLIFrameElement; // ref to the iframe (callback style)
private allowedWidgetsWatchRef?: string;
private persistKey: string;
private sgWidget: StopGapWidget | null;
private dispatcherRef: string;
private dispatcherRef?: string;
private unmounted: boolean;

public constructor(props: IProps) {
Expand Down Expand Up @@ -305,7 +305,7 @@ export default class AppTile extends React.Component<IProps, IState> {
this.context.off(RoomEvent.MyMembership, this.onMyMembership);
}

SettingsStore.unwatchSetting(this.allowedWidgetsWatchRef);
if (this.allowedWidgetsWatchRef) SettingsStore.unwatchSetting(this.allowedWidgetsWatchRef);
OwnProfileStore.instance.removeListener(UPDATE_EVENT, this.onUserReady);
}

Expand Down Expand Up @@ -344,7 +344,7 @@ export default class AppTile extends React.Component<IProps, IState> {

private startMessaging(): void {
try {
this.sgWidget?.startMessaging(this.iframe);
this.sgWidget?.startMessaging(this.iframe!);
} catch (e) {
logger.error("Failed to start widget", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export interface PickerIProps {
type TabId = "screen" | "window";

export default class DesktopCapturerSourcePicker extends React.Component<PickerIProps, PickerIState> {
public interval: number;
public interval?: number;

public constructor(props: PickerIProps) {
super(props);
Expand Down
Loading