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

Commit 9c816bb

Browse files
authored
Conform more code to strictNullChecks (#10383
* Update matrix-widget-api * Conform more code to `strictNullChecks` * Iterate
1 parent aae9dfb commit 9c816bb

File tree

18 files changed

+112
-93
lines changed

18 files changed

+112
-93
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"matrix-encrypt-attachment": "^1.0.3",
9898
"matrix-events-sdk": "0.0.1",
9999
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#develop",
100-
"matrix-widget-api": "^1.1.1",
100+
"matrix-widget-api": "^1.2.0",
101101
"minimist": "^1.2.5",
102102
"opus-recorder": "^8.0.3",
103103
"pako": "^2.0.3",

src/components/structures/LoggedInView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ class LoggedInView extends React.Component<IProps, IState> {
259259
isItemCollapsed: (domNode) => {
260260
return domNode.classList.contains("mx_LeftPanel_minimized");
261261
},
262-
handler: this.resizeHandler.current,
262+
handler: this.resizeHandler.current ?? undefined,
263263
};
264264
const resizer = new Resizer(this._resizeContainer.current, CollapseDistributor, collapseConfig);
265265
resizer.setClassNames({

src/components/structures/RightPanel.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export default class RightPanel extends React.Component<IProps, IState> {
9090
}
9191

9292
public static getDerivedStateFromProps(props: IProps): Partial<IState> {
93-
let currentCard: IRightPanelCard;
93+
let currentCard: IRightPanelCard | undefined;
9494
if (props.room) {
9595
currentCard = RightPanelStore.instance.currentCardForRoom(props.room.roomId);
9696
}
@@ -111,7 +111,7 @@ export default class RightPanel extends React.Component<IProps, IState> {
111111
this.delayedUpdate();
112112
} else if (
113113
this.state.phase === RightPanelPhases.RoomMemberInfo &&
114-
member.userId === this.state.cardState.member.userId
114+
member.userId === this.state.cardState.member?.userId
115115
) {
116116
// refresh the member info (e.g. new power level)
117117
this.delayedUpdate();
@@ -136,7 +136,7 @@ export default class RightPanel extends React.Component<IProps, IState> {
136136
});
137137
} else if (
138138
this.state.phase === RightPanelPhases.EncryptionPanel &&
139-
this.state.cardState.verificationRequest?.pending
139+
this.state.cardState?.verificationRequest?.pending
140140
) {
141141
// When the user clicks close on the encryption panel cancel the pending request first if any
142142
this.state.cardState.verificationRequest.cancel();
@@ -171,8 +171,8 @@ export default class RightPanel extends React.Component<IProps, IState> {
171171
case RightPanelPhases.SpaceMemberList:
172172
card = (
173173
<MemberList
174-
roomId={cardState.spaceId ? cardState.spaceId : roomId}
175-
key={cardState.spaceId ? cardState.spaceId : roomId}
174+
roomId={cardState?.spaceId ?? roomId}
175+
key={cardState?.spaceId ?? roomId}
176176
onClose={this.onClose}
177177
searchQuery={this.state.searchQuery}
178178
onSearchQueryChanged={this.onSearchQueryChanged}
@@ -183,23 +183,23 @@ export default class RightPanel extends React.Component<IProps, IState> {
183183
case RightPanelPhases.RoomMemberInfo:
184184
case RightPanelPhases.SpaceMemberInfo:
185185
case RightPanelPhases.EncryptionPanel: {
186-
const roomMember = cardState.member instanceof RoomMember ? cardState.member : undefined;
186+
const roomMember = cardState?.member instanceof RoomMember ? cardState.member : undefined;
187187
card = (
188188
<UserInfo
189-
user={cardState.member}
189+
user={cardState?.member}
190190
room={this.context.getRoom(roomMember?.roomId) ?? this.props.room}
191-
key={roomId || cardState.member.userId}
191+
key={roomId ?? cardState?.member?.userId}
192192
onClose={this.onClose}
193193
phase={phase}
194-
verificationRequest={cardState.verificationRequest}
195-
verificationRequestPromise={cardState.verificationRequestPromise}
194+
verificationRequest={cardState?.verificationRequest}
195+
verificationRequestPromise={cardState?.verificationRequestPromise}
196196
/>
197197
);
198198
break;
199199
}
200200
case RightPanelPhases.Room3pidMemberInfo:
201201
case RightPanelPhases.Space3pidMemberInfo:
202-
card = <ThirdPartyMemberInfo event={cardState.memberInfoEvent} key={roomId} />;
202+
card = <ThirdPartyMemberInfo event={cardState?.memberInfoEvent} key={roomId} />;
203203
break;
204204

205205
case RightPanelPhases.NotificationPanel:
@@ -240,10 +240,10 @@ export default class RightPanel extends React.Component<IProps, IState> {
240240
room={this.props.room}
241241
resizeNotifier={this.props.resizeNotifier}
242242
onClose={this.onClose}
243-
mxEvent={cardState.threadHeadEvent}
244-
initialEvent={cardState.initialEvent}
245-
isInitialEventHighlighted={cardState.isInitialEventHighlighted}
246-
initialEventScrollIntoView={cardState.initialEventScrollIntoView}
243+
mxEvent={cardState?.threadHeadEvent}
244+
initialEvent={cardState?.initialEvent}
245+
isInitialEventHighlighted={cardState?.isInitialEventHighlighted}
246+
initialEventScrollIntoView={cardState?.initialEventScrollIntoView}
247247
permalinkCreator={this.props.permalinkCreator}
248248
e2eStatus={this.props.e2eStatus}
249249
/>
@@ -273,7 +273,7 @@ export default class RightPanel extends React.Component<IProps, IState> {
273273
break;
274274

275275
case RightPanelPhases.Widget:
276-
card = <WidgetCard room={this.props.room} widgetId={cardState.widgetId} onClose={this.onClose} />;
276+
card = <WidgetCard room={this.props.room} widgetId={cardState?.widgetId} onClose={this.onClose} />;
277277
break;
278278
}
279279

src/components/structures/RoomView.tsx

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ if (DEBUG) {
132132
}
133133

134134
interface IRoomProps {
135-
threepidInvite: IThreepidInvite;
135+
threepidInvite?: IThreepidInvite;
136136
oobData?: IOOBData;
137137

138138
resizeNotifier: ResizeNotifier;
@@ -606,11 +606,11 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
606606
return;
607607
}
608608

609-
const roomId = this.context.roomViewStore.getRoomId();
610-
const room = this.context.client.getRoom(roomId);
609+
const roomId = this.context.roomViewStore.getRoomId() ?? null;
610+
const room = this.context.client?.getRoom(roomId ?? undefined) ?? undefined;
611611

612612
const newState: Partial<IRoomState> = {
613-
roomId,
613+
roomId: roomId ?? undefined,
614614
roomAlias: this.context.roomViewStore.getRoomAlias(),
615615
roomLoading: this.context.roomViewStore.isRoomLoading(),
616616
roomLoadError: this.context.roomViewStore.getRoomLoadError(),
@@ -624,8 +624,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
624624
showAvatarChanges: SettingsStore.getValue("showAvatarChanges", roomId),
625625
showDisplaynameChanges: SettingsStore.getValue("showDisplaynameChanges", roomId),
626626
wasContextSwitch: this.context.roomViewStore.getWasContextSwitch(),
627-
mainSplitContentType: room === null ? undefined : this.getMainSplitContentType(room),
628-
initialEventId: null, // default to clearing this, will get set later in the method if needed
627+
mainSplitContentType: room ? this.getMainSplitContentType(room) : undefined,
628+
initialEventId: undefined, // default to clearing this, will get set later in the method if needed
629629
showRightPanel: this.context.rightPanelStore.isOpenForRoom(roomId),
630630
activeCall: CallStore.instance.getActiveCall(roomId),
631631
};
@@ -655,12 +655,11 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
655655
// The rest will be lost for now, until the aggregation API on the server
656656
// becomes available to fetch a whole thread
657657
if (!initialEvent) {
658-
initialEvent = await fetchInitialEvent(this.context.client, roomId, initialEventId);
658+
initialEvent = (await fetchInitialEvent(this.context.client, roomId, initialEventId)) ?? undefined;
659659
}
660660

661-
// If we have an initial event, we want to reset the event pixel offset to ensure it ends up
662-
// visible
663-
newState.initialEventPixelOffset = null;
661+
// If we have an initial event, we want to reset the event pixel offset to ensure it ends up visible
662+
newState.initialEventPixelOffset = undefined;
664663

665664
const thread = initialEvent?.getThread();
666665
if (thread && !initialEvent?.isThreadRoot) {
@@ -709,7 +708,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
709708

710709
if (!initial && this.state.shouldPeek && !newState.shouldPeek) {
711710
// Stop peeking because we have joined this room now
712-
this.context.client.stopPeeking();
711+
this.context.client?.stopPeeking();
713712
}
714713

715714
// Temporary logging to diagnose https://github.com/vector-im/element-web/issues/4307
@@ -825,7 +824,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
825824
}
826825
}
827826

828-
private setupRoom(room: Room, roomId: string, joining: boolean, shouldPeek: boolean): void {
827+
private setupRoom(room: Room | undefined, roomId: string | undefined, joining: boolean, shouldPeek: boolean): void {
829828
// if this is an unknown room then we're in one of three states:
830829
// - This is a room we can peek into (search engine) (we can /peek)
831830
// - This is a room we can publicly join or were invited to. (we can /join)
@@ -1504,7 +1503,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
15041503

15051504
private updateDMState(): void {
15061505
const room = this.state.room;
1507-
if (room.getMyMembership() != "join") {
1506+
if (room?.getMyMembership() !== "join") {
15081507
return;
15091508
}
15101509
const dmInviter = room.getDMInviter();
@@ -1564,7 +1563,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
15641563
);
15651564

15661565
private onMessageListScroll = (): void => {
1567-
if (this.messagePanel.isAtEndOfLiveTimeline()) {
1566+
if (this.messagePanel?.isAtEndOfLiveTimeline()) {
15681567
this.setState({
15691568
numUnreadMessages: 0,
15701569
atEndOfLiveTimeline: true,
@@ -1740,7 +1739,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
17401739
this.setState(
17411740
{
17421741
timelineRenderingType: TimelineRenderingType.Room,
1743-
search: null,
1742+
search: undefined,
17441743
},
17451744
resolve,
17461745
);
@@ -1760,20 +1759,20 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
17601759
});
17611760
} else {
17621761
// Otherwise we have to jump manually
1763-
this.messagePanel.jumpToLiveTimeline();
1762+
this.messagePanel?.jumpToLiveTimeline();
17641763
dis.fire(Action.FocusSendMessageComposer);
17651764
}
17661765
};
17671766

17681767
// jump up to wherever our read marker is
17691768
private jumpToReadMarker = (): void => {
1770-
this.messagePanel.jumpToReadMarker();
1769+
this.messagePanel?.jumpToReadMarker();
17711770
};
17721771

17731772
// update the read marker to match the read-receipt
17741773
private forgetReadMarker = (ev: ButtonEvent): void => {
17751774
ev.stopPropagation();
1776-
this.messagePanel.forgetReadMarker();
1775+
this.messagePanel?.forgetReadMarker();
17771776
};
17781777

17791778
// decide whether or not the top 'unread messages' bar should be shown
@@ -1791,7 +1790,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
17911790
// get the current scroll position of the room, so that it can be
17921791
// restored when we switch back to it.
17931792
//
1794-
private getScrollState(): ScrollState {
1793+
private getScrollState(): ScrollState | null {
17951794
const messagePanel = this.messagePanel;
17961795
if (!messagePanel) return null;
17971796

@@ -1845,7 +1844,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
18451844
* We pass it down to the scroll panel.
18461845
*/
18471846
public handleScrollKey = (ev: React.KeyboardEvent | KeyboardEvent): void => {
1848-
let panel: ScrollPanel | TimelinePanel;
1847+
let panel: ScrollPanel | TimelinePanel | undefined;
18491848
if (this.searchResultsPanel.current) {
18501849
panel = this.searchResultsPanel.current;
18511850
} else if (this.messagePanel) {
@@ -1858,7 +1857,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
18581857
/**
18591858
* get any current call for this room
18601859
*/
1861-
private getCallForRoom(): MatrixCall {
1860+
private getCallForRoom(): MatrixCall | null {
18621861
if (!this.state.room) {
18631862
return null;
18641863
}
@@ -1920,7 +1919,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
19201919
}
19211920

19221921
private renderLocalRoomCreateLoader(localRoom: LocalRoom): ReactElement {
1923-
const names = this.state.room.getDefaultRoomName(this.context.client.getUserId());
1922+
const names = this.state.room.getDefaultRoomName(this.context.client.getSafeUserId());
19241923
return (
19251924
<RoomContext.Provider value={this.state}>
19261925
<LocalRoomCreateLoader localRoom={localRoom} names={names} resizeNotifier={this.props.resizeNotifier} />
@@ -1992,7 +1991,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
19921991
</div>
19931992
);
19941993
} else {
1995-
let inviterName = undefined;
1994+
let inviterName: string | undefined;
19961995
if (this.props.oobData) {
19971996
inviterName = this.props.oobData.inviterName;
19981997
}
@@ -2058,12 +2057,12 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
20582057
</ErrorBoundary>
20592058
);
20602059
} else {
2061-
const myUserId = this.context.client.credentials.userId;
2060+
const myUserId = this.context.client.getSafeUserId();
20622061
const myMember = this.state.room.getMember(myUserId);
20632062
const inviteEvent = myMember ? myMember.events.member : null;
20642063
let inviterName = _t("Unknown");
20652064
if (inviteEvent) {
2066-
inviterName = inviteEvent.sender ? inviteEvent.sender.name : inviteEvent.getSender();
2065+
inviterName = inviteEvent.sender?.name ?? inviteEvent.getSender();
20672066
}
20682067

20692068
// We deliberately don't try to peek into invites, even if we have permission to peek
@@ -2140,7 +2139,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
21402139
const showRoomUpgradeBar =
21412140
roomVersionRecommendation &&
21422141
roomVersionRecommendation.needsUpgrade &&
2143-
this.state.room.userMayUpgradeRoom(this.context.client.credentials.userId);
2142+
this.state.room.userMayUpgradeRoom(this.context.client.getSafeUserId());
21442143

21452144
const hiddenHighlightCount = this.getHiddenHighlightCount();
21462145

@@ -2160,7 +2159,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
21602159
} else if (myMembership !== "join") {
21612160
// We do have a room object for this room, but we're not currently in it.
21622161
// We may have a 3rd party invite to it.
2163-
let inviterName = undefined;
2162+
let inviterName: string | undefined;
21642163
if (this.props.oobData) {
21652164
inviterName = this.props.oobData.inviterName;
21662165
}
@@ -2207,6 +2206,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
22072206
space={this.state.room}
22082207
justCreatedOpts={this.props.justCreatedOpts}
22092208
resizeNotifier={this.props.resizeNotifier}
2209+
permalinkCreator={this.permalinkCreator}
22102210
onJoinButtonClicked={this.onJoinButtonClicked}
22112211
onRejectButtonClicked={
22122212
this.props.threepidInvite
@@ -2220,7 +2220,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
22202220
const auxPanel = (
22212221
<AuxPanel
22222222
room={this.state.room}
2223-
userId={this.context.client.credentials.userId}
2223+
userId={this.context.client.getSafeUserId()}
22242224
showApps={this.state.showApps}
22252225
resizeNotifier={this.props.resizeNotifier}
22262226
>
@@ -2330,7 +2330,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
23302330
permalinkCreator={this.permalinkCreator}
23312331
e2eStatus={this.state.e2eStatus}
23322332
/>
2333-
) : null;
2333+
) : undefined;
23342334

23352335
const timelineClasses = classNames("mx_RoomView_timeline", {
23362336
mx_RoomView_timeline_rr_enabled: this.state.showReadReceipts,
@@ -2344,14 +2344,16 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
23442344
const showChatEffects = SettingsStore.getValue("showChatEffects");
23452345

23462346
let mainSplitBody: JSX.Element | undefined;
2347-
let mainSplitContentClassName: string;
2347+
let mainSplitContentClassName: string | undefined;
23482348
// Decide what to show in the main split
23492349
switch (this.state.mainSplitContentType) {
23502350
case MainSplitContentType.Timeline:
23512351
mainSplitContentClassName = "mx_MainSplit_timeline";
23522352
mainSplitBody = (
23532353
<>
2354-
<Measured sensor={this.roomViewBody.current} onMeasurement={this.onMeasurement} />
2354+
{this.roomViewBody.current && (
2355+
<Measured sensor={this.roomViewBody.current} onMeasurement={this.onMeasurement} />
2356+
)}
23552357
{auxPanel}
23562358
<div className={timelineClasses}>
23572359
<FileDropTarget parent={this.roomView.current} onFileDrop={this.onFileDrop} />
@@ -2372,7 +2374,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
23722374
<>
23732375
<AppsDrawer
23742376
room={this.state.room}
2375-
userId={this.context.client.credentials.userId}
2377+
userId={this.context.client.getSafeUserId()}
23762378
resizeNotifier={this.props.resizeNotifier}
23772379
showApps={true}
23782380
/>
@@ -2426,7 +2428,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
24262428
onAppsClick = null;
24272429
onForgetClick = null;
24282430
onSearchClick = null;
2429-
if (this.state.room.canInvite(this.context.client.credentials.userId)) {
2431+
if (this.state.room.canInvite(this.context.client.getSafeUserId())) {
24302432
onInviteClick = this.onInviteClick;
24312433
}
24322434
viewingCall = true;

0 commit comments

Comments
 (0)