Conform more of the codebase to strictNullChecks (#10738)

This commit is contained in:
Michael Telatynski 2023-05-09 18:24:40 +01:00 committed by GitHub
parent 5e8488c283
commit 52017f62e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 105 additions and 84 deletions

View file

@ -71,7 +71,7 @@ class FilePanel extends React.Component<IProps, IState> {
removed: boolean,
data: IRoomTimelineData,
): void => {
if (room?.roomId !== this.props?.roomId) return;
if (room?.roomId !== this.props.roomId) return;
if (toStartOfTimeline || !data || !data.liveEvent || ev.isRedacted()) return;
const client = MatrixClientPeg.get();

View file

@ -164,7 +164,7 @@ interface IProps {
onNewScreen: (screen: string, replaceLast: boolean) => void;
enableGuest?: boolean;
// the queryParams extracted from the [real] query-string of the URI
realQueryParams?: QueryDict;
realQueryParams: QueryDict;
// the initial queryParams extracted from the hash-fragment of the URI
startingFragmentQueryParams?: QueryDict;
// called when we have completed a token login

View file

@ -97,7 +97,7 @@ export default class RightPanel extends React.Component<IProps, IState> {
return {
cardState: currentCard?.state,
phase: currentCard?.phase,
phase: currentCard?.phase ?? undefined,
};
}
@ -111,7 +111,7 @@ export default class RightPanel extends React.Component<IProps, IState> {
this.delayedUpdate();
} else if (
this.state.phase === RightPanelPhases.RoomMemberInfo &&
member.userId === this.state.cardState.member?.userId
member.userId === this.state.cardState?.member?.userId
) {
// refresh the member info (e.g. new power level)
this.delayedUpdate();
@ -156,7 +156,7 @@ export default class RightPanel extends React.Component<IProps, IState> {
const cardState = this.props.overwriteCard?.state ?? this.state.cardState;
switch (phase) {
case RightPanelPhases.RoomMemberList:
if (roomId) {
if (!!roomId) {
card = (
<MemberList
roomId={roomId}
@ -199,7 +199,9 @@ export default class RightPanel extends React.Component<IProps, IState> {
}
case RightPanelPhases.Room3pidMemberInfo:
case RightPanelPhases.Space3pidMemberInfo:
card = <ThirdPartyMemberInfo event={cardState?.memberInfoEvent} key={roomId} />;
if (!!cardState?.memberInfoEvent) {
card = <ThirdPartyMemberInfo event={cardState.memberInfoEvent} key={roomId} />;
}
break;
case RightPanelPhases.NotificationPanel:
@ -207,7 +209,7 @@ export default class RightPanel extends React.Component<IProps, IState> {
break;
case RightPanelPhases.PinnedMessages:
if (this.props.room && SettingsStore.getValue("feature_pinning")) {
if (!!this.props.room && SettingsStore.getValue("feature_pinning")) {
card = (
<PinnedMessagesCard
room={this.props.room}
@ -218,7 +220,7 @@ export default class RightPanel extends React.Component<IProps, IState> {
}
break;
case RightPanelPhases.Timeline:
if (this.props.room) {
if (!!this.props.room) {
card = (
<TimelineCard
classNames="mx_ThreadPanel mx_TimelineCard"
@ -233,20 +235,24 @@ export default class RightPanel extends React.Component<IProps, IState> {
}
break;
case RightPanelPhases.FilePanel:
card = <FilePanel roomId={roomId} resizeNotifier={this.props.resizeNotifier} onClose={this.onClose} />;
if (!!roomId) {
card = (
<FilePanel roomId={roomId} resizeNotifier={this.props.resizeNotifier} onClose={this.onClose} />
);
}
break;
case RightPanelPhases.ThreadView:
if (this.props.room) {
if (!!this.props.room && !!cardState?.threadHeadEvent) {
card = (
<ThreadView
room={this.props.room}
resizeNotifier={this.props.resizeNotifier}
onClose={this.onClose}
mxEvent={cardState?.threadHeadEvent}
initialEvent={cardState?.initialEvent}
isInitialEventHighlighted={cardState?.isInitialEventHighlighted}
initialEventScrollIntoView={cardState?.initialEventScrollIntoView}
mxEvent={cardState.threadHeadEvent}
initialEvent={cardState.initialEvent}
isInitialEventHighlighted={cardState.isInitialEventHighlighted}
initialEventScrollIntoView={cardState.initialEventScrollIntoView}
permalinkCreator={this.props.permalinkCreator}
e2eStatus={this.props.e2eStatus}
/>
@ -255,18 +261,20 @@ export default class RightPanel extends React.Component<IProps, IState> {
break;
case RightPanelPhases.ThreadPanel:
card = (
<ThreadPanel
roomId={roomId}
resizeNotifier={this.props.resizeNotifier}
onClose={this.onClose}
permalinkCreator={this.props.permalinkCreator}
/>
);
if (!!roomId) {
card = (
<ThreadPanel
roomId={roomId}
resizeNotifier={this.props.resizeNotifier}
onClose={this.onClose}
permalinkCreator={this.props.permalinkCreator}
/>
);
}
break;
case RightPanelPhases.RoomSummary:
if (this.props.room) {
if (!!this.props.room) {
card = (
<RoomSummaryCard
room={this.props.room}
@ -279,8 +287,8 @@ export default class RightPanel extends React.Component<IProps, IState> {
break;
case RightPanelPhases.Widget:
if (this.props.room) {
card = <WidgetCard room={this.props.room} widgetId={cardState?.widgetId} onClose={this.onClose} />;
if (!!this.props.room && !!cardState?.widgetId) {
card = <WidgetCard room={this.props.room} widgetId={cardState.widgetId} onClose={this.onClose} />;
}
break;
}

View file

@ -626,7 +626,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
wasContextSwitch: this.context.roomViewStore.getWasContextSwitch(),
mainSplitContentType: room ? this.getMainSplitContentType(room) : undefined,
initialEventId: undefined, // default to clearing this, will get set later in the method if needed
showRightPanel: this.context.rightPanelStore.isOpenForRoom(roomId),
showRightPanel: roomId ? this.context.rightPanelStore.isOpenForRoom(roomId) : false,
activeCall: roomId ? CallStore.instance.getActiveCall(roomId) : null,
};
@ -662,7 +662,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
newState.initialEventPixelOffset = undefined;
const thread = initialEvent?.getThread();
if (thread && !initialEvent?.isThreadRoot) {
if (thread?.rootEvent && !initialEvent?.isThreadRoot) {
dis.dispatch<ShowThreadPayload>({
action: Action.ShowThread,
rootEvent: thread.rootEvent,
@ -675,7 +675,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
newState.isInitialEventHighlighted = this.context.roomViewStore.isInitialEventHighlighted();
newState.initialEventScrollIntoView = this.context.roomViewStore.initialEventScrollIntoView();
if (thread && initialEvent?.isThreadRoot) {
if (thread?.rootEvent && initialEvent?.isThreadRoot) {
dis.dispatch<ShowThreadPayload>({
action: Action.ShowThread,
rootEvent: thread.rootEvent,
@ -1016,7 +1016,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
private onRightPanelStoreUpdate = (): void => {
this.setState({
showRightPanel: this.context.rightPanelStore.isOpenForRoom(this.state.roomId),
showRightPanel: this.state.roomId ? this.context.rightPanelStore.isOpenForRoom(this.state.roomId) : false,
});
};
@ -1087,7 +1087,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
case "picture_snapshot":
ContentMessages.sharedInstance().sendContentListToRoom(
[payload.file],
this.state.room.roomId,
this.getRoomId(),
undefined,
this.context.client,
);
@ -1496,6 +1496,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
);
private checkDesktopNotifications(): void {
if (!this.state.room) return;
const memberCount = this.state.room.getJoinedMemberCount() + this.state.room.getInvitedMemberCount();
// if they are not alone prompt the user about notifications so they don't miss replies
if (memberCount > 1 && Notifier.shouldShowPrompt()) {
@ -1518,7 +1519,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
// open the room inviter
dis.dispatch({
action: "view_invite",
roomId: this.state.room.roomId,
roomId: this.getRoomId(),
});
};
@ -1588,7 +1589,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
debuglog("Removing scroll_into_view flag from initial event");
dis.dispatch<ViewRoomPayload>({
action: Action.ViewRoom,
room_id: this.state.room.roomId,
room_id: this.getRoomId(),
event_id: this.state.initialEventId,
highlighted: this.state.isInitialEventHighlighted,
scroll_into_view: false,
@ -1606,7 +1607,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
}
ContentMessages.sharedInstance()
.sendStickerContentToRoom(url, this.state.room.roomId, threadId, info, text, this.context.client)
.sendStickerContentToRoom(url, this.getRoomId(), threadId, info, text, this.context.client)
.then(undefined, (error) => {
if (error.name === "UnknownDeviceError") {
// Let the staus bar handle this
@ -1616,7 +1617,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
}
private onSearch = (term: string, scope: SearchScope): void => {
const roomId = scope === SearchScope.Room ? this.state.room.roomId : undefined;
const roomId = scope === SearchScope.Room ? this.getRoomId() : undefined;
debuglog("sending search request");
const abortController = new AbortController();
const promise = eventSearch(term, roomId, abortController.signal);
@ -1655,7 +1656,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
private onForgetClick = (): void => {
dis.dispatch({
action: "forget_room",
room_id: this.state.room.roomId,
room_id: this.getRoomId(),
});
};
@ -1663,7 +1664,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
this.setState({
rejecting: true,
});
this.context.client?.leave(this.state.roomId).then(
this.context.client?.leave(this.getRoomId()).then(
() => {
dis.dispatch({ action: Action.ViewHomePage });
this.setState({
@ -1757,7 +1758,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
// jumping to the bottom
dis.dispatch<ViewRoomPayload>({
action: Action.ViewRoom,
room_id: this.state.room.roomId,
room_id: this.getRoomId(),
metricsTrigger: undefined, // room doesn't change
});
} else {
@ -1903,7 +1904,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
private onFileDrop = (dataTransfer: DataTransfer): Promise<void> =>
ContentMessages.sharedInstance().sendContentListToRoom(
Array.from(dataTransfer.files),
this.state.room?.roomId ?? this.state.roomId,
this.getRoomId(),
null,
this.context.client,
TimelineRenderingType.Room,
@ -1921,7 +1922,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
return this.getPermalinkCreatorForRoom(this.state.room);
}
private renderLocalRoomCreateLoader(localRoom: LocalRoom): ReactElement {
private renderLocalRoomCreateLoader(localRoom: LocalRoom): ReactNode {
if (!this.state.room || !this.context?.client) return null;
const names = this.state.room.getDefaultRoomName(this.context.client.getSafeUserId());
return (
<RoomContext.Provider value={this.state}>
@ -1930,7 +1932,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
);
}
private renderLocalRoomView(localRoom: LocalRoom): ReactElement {
private renderLocalRoomView(localRoom: LocalRoom): ReactNode {
return (
<RoomContext.Provider value={this.state}>
<LocalRoomView
@ -1944,7 +1946,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
);
}
private renderWaitingForThirdPartyRoomView(inviteEvent: MatrixEvent): ReactElement {
private renderWaitingForThirdPartyRoomView(inviteEvent: MatrixEvent): ReactNode {
return (
<RoomContext.Provider value={this.state}>
<WaitingForThirdPartyRoomView
@ -1956,7 +1958,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
);
}
public render(): React.ReactNode {
public render(): ReactNode {
if (!this.context.client) return null;
if (this.state.room instanceof LocalRoom) {

View file

@ -1023,7 +1023,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
shouldSendRR &&
// Only send a RR if the last read event is ahead in the timeline relative to
// the current RR event.
lastReadEventIndex > currentRREventIndex &&
lastReadEventIndex! > currentRREventIndex! &&
// Only send a RR if the last RR set != the one we would send
this.lastRRSentEventId !== lastReadEvent?.getId();
@ -1307,7 +1307,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
const pos = this.getReadMarkerPosition();
const ret =
this.state.readMarkerEventId !== null && // 1.
(pos < 0 || pos === null); // 3., 4.
(pos === null || pos < 0); // 3., 4.
return ret;
};
@ -1351,7 +1351,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
"TimelinePanel scrolling to eventId " +
eventId +
" at position " +
offsetBase * 100 +
offsetBase! * 100 +
"% + " +
pixelOffset,
);

View file

@ -64,7 +64,7 @@ interface IOptionsButtonProps {
// TODO: Types
getTile: () => any | null;
getReplyChain: () => ReplyChain | null;
permalinkCreator: RoomPermalinkCreator;
permalinkCreator?: RoomPermalinkCreator;
onFocusChange: (menuDisplayed: boolean) => void;
getRelationsForEvent?: GetRelationsForEvent;
}
@ -208,10 +208,11 @@ const ReplyInThreadButton: React.FC<IReplyInThreadButton> = ({ mxEvent }) => {
e.preventDefault();
e.stopPropagation();
if (mxEvent.getThread() && !mxEvent.isThreadRoot) {
const thread = mxEvent.getThread();
if (thread?.rootEvent && !mxEvent.isThreadRoot) {
defaultDispatcher.dispatch<ShowThreadPayload>({
action: Action.ShowThread,
rootEvent: mxEvent.getThread()!.rootEvent,
rootEvent: thread.rootEvent,
initialEvent: mxEvent,
scroll_into_view: true,
highlighted: true,

View file

@ -576,6 +576,12 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
const encryptionInfo = MatrixClientPeg.get().getEventEncryptionInfo(mxEvent);
const senderId = mxEvent.getSender();
if (!senderId) {
// something definitely wrong is going on here
this.setState({ verified: E2EState.Warning });
return;
}
const userTrust = MatrixClientPeg.get().checkUserTrust(senderId);
if (encryptionInfo.mismatchedSender) {

View file

@ -55,7 +55,7 @@ const SpacePublicShare: React.FC<IProps> = ({ space, onFinished }) => {
{_t("Share invite link")}
<span>{copiedText}</span>
</AccessibleButton>
{space.canInvite(MatrixClientPeg.get()?.getUserId()) && shouldShowComponent(UIComponent.InviteUsers) ? (
{space.canInvite(MatrixClientPeg.get()?.getSafeUserId()) && shouldShowComponent(UIComponent.InviteUsers) ? (
<AccessibleButton
className="mx_SpacePublicShare_inviteButton"
onClick={() => {