Skip to content

Commit d404e06

Browse files
authored
Conform more of the codebase to strictNullChecks (matrix-org#11135)
1 parent a87362a commit d404e06

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

src/AddThreepid.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@ See the License for the specific language governing permissions and
1616
limitations under the License.
1717
*/
1818

19-
import { IAuthData, IRequestMsisdnTokenResponse, IRequestTokenResponse, MatrixClient } from "matrix-js-sdk/src/matrix";
19+
import {
20+
IAddThreePidOnlyBody,
21+
IAuthData,
22+
IRequestMsisdnTokenResponse,
23+
IRequestTokenResponse,
24+
MatrixClient,
25+
} from "matrix-js-sdk/src/matrix";
2026
import { MatrixError, HTTPError } from "matrix-js-sdk/src/matrix";
2127

2228
import Modal from "./Modal";
2329
import { _t, UserFriendlyError } from "./languageHandler";
2430
import IdentityAuthClient from "./IdentityAuthClient";
2531
import { SSOAuthEntry } from "./components/views/auth/InteractiveAuthEntryComponents";
26-
import InteractiveAuthDialog from "./components/views/dialogs/InteractiveAuthDialog";
32+
import InteractiveAuthDialog, { InteractiveAuthDialogProps } from "./components/views/dialogs/InteractiveAuthDialog";
2733

2834
function getIdServerDomain(matrixClient: MatrixClient): string {
2935
const idBaseUrl = matrixClient.getIdentityServerUrl(true);
@@ -239,7 +245,7 @@ export default class AddThreepid {
239245
[SSOAuthEntry.LOGIN_TYPE]: dialogAesthetics,
240246
[SSOAuthEntry.UNSTABLE_LOGIN_TYPE]: dialogAesthetics,
241247
},
242-
});
248+
} as InteractiveAuthDialogProps<IAddThreePidOnlyBody>);
243249
return finished;
244250
}
245251
}
@@ -270,11 +276,11 @@ export default class AddThreepid {
270276
* @param {{type: string, session?: string}} auth UI auth object
271277
* @return {Promise<Object>} Response from /3pid/add call (in current spec, an empty object)
272278
*/
273-
private makeAddThreepidOnlyRequest = (auth?: { type: string; session?: string }): Promise<{}> => {
279+
private makeAddThreepidOnlyRequest = (auth?: IAddThreePidOnlyBody["auth"] | null): Promise<{}> => {
274280
return this.matrixClient.addThreePidOnly({
275281
sid: this.sessionId,
276282
client_secret: this.clientSecret,
277-
auth,
283+
auth: auth ?? undefined,
278284
});
279285
};
280286

@@ -360,7 +366,7 @@ export default class AddThreepid {
360366
[SSOAuthEntry.LOGIN_TYPE]: dialogAesthetics,
361367
[SSOAuthEntry.UNSTABLE_LOGIN_TYPE]: dialogAesthetics,
362368
},
363-
});
369+
} as InteractiveAuthDialogProps<IAddThreePidOnlyBody>);
364370
return finished;
365371
}
366372
}

src/stores/right-panel/RightPanelStore.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ export default class RightPanelStore extends ReadyWatchingStore {
9090
* during room changes.
9191
*/
9292
public get isOpen(): boolean {
93-
return this.byRoom[this.viewedRoomId]?.isOpen ?? false;
93+
return this.byRoom[this.viewedRoomId ?? ""]?.isOpen ?? false;
9494
}
9595

9696
public isOpenForRoom(roomId: string): boolean {
9797
return this.byRoom[roomId]?.isOpen ?? false;
9898
}
9999

100100
public get roomPhaseHistory(): Array<IRightPanelCard> {
101-
return this.byRoom[this.viewedRoomId]?.history ?? [];
101+
return this.byRoom[this.viewedRoomId ?? ""]?.history ?? [];
102102
}
103103

104104
/**
@@ -133,7 +133,7 @@ export default class RightPanelStore extends ReadyWatchingStore {
133133

134134
// Setters
135135
public setCard(card: IRightPanelCard, allowClose = true, roomId?: string): void {
136-
const rId = roomId ?? this.viewedRoomId;
136+
const rId = roomId ?? this.viewedRoomId ?? "";
137137
// This function behaves as following:
138138
// Update state: if the same phase is send but with a state
139139
// Set right panel and erase history: if a "different to the current" phase is send (with or without a state)
@@ -163,7 +163,7 @@ export default class RightPanelStore extends ReadyWatchingStore {
163163

164164
public setCards(cards: IRightPanelCard[], allowClose = true, roomId: string | null = null): void {
165165
// This function sets the history of the right panel and shows the right panel if not already visible.
166-
const rId = roomId ?? this.viewedRoomId;
166+
const rId = roomId ?? this.viewedRoomId ?? "";
167167
const history = cards.map((c) => ({ phase: c.phase, state: c.state ?? {} }));
168168
this.byRoom[rId] = { history, isOpen: true };
169169
this.show(rId);
@@ -172,7 +172,7 @@ export default class RightPanelStore extends ReadyWatchingStore {
172172

173173
// Appends a card to the history and shows the right panel if not already visible
174174
public pushCard(card: IRightPanelCard, allowClose = true, roomId: string | null = null): void {
175-
const rId = roomId ?? this.viewedRoomId;
175+
const rId = roomId ?? this.viewedRoomId ?? "";
176176
const redirect = this.getVerificationRedirect(card);
177177
const targetPhase = redirect?.phase ?? card.phase;
178178
const pState = redirect?.state ?? card.state ?? {};
@@ -198,7 +198,7 @@ export default class RightPanelStore extends ReadyWatchingStore {
198198
}
199199

200200
public popCard(roomId: string | null = null): IRightPanelCard | undefined {
201-
const rId = roomId ?? this.viewedRoomId;
201+
const rId = roomId ?? this.viewedRoomId ?? "";
202202
if (!this.byRoom[rId]) return;
203203

204204
const removedCard = this.byRoom[rId].history.pop();
@@ -207,21 +207,21 @@ export default class RightPanelStore extends ReadyWatchingStore {
207207
}
208208

209209
public togglePanel(roomId: string | null): void {
210-
const rId = roomId ?? this.viewedRoomId;
210+
const rId = roomId ?? this.viewedRoomId ?? "";
211211
if (!this.byRoom[rId]) return;
212212

213213
this.byRoom[rId].isOpen = !this.byRoom[rId].isOpen;
214214
this.emitAndUpdateSettings();
215215
}
216216

217217
public show(roomId: string | null): void {
218-
if (!this.isOpenForRoom(roomId ?? this.viewedRoomId)) {
218+
if (!this.isOpenForRoom(roomId ?? this.viewedRoomId ?? "")) {
219219
this.togglePanel(roomId);
220220
}
221221
}
222222

223223
public hide(roomId: string | null): void {
224-
if (this.isOpenForRoom(roomId ?? this.viewedRoomId)) {
224+
if (this.isOpenForRoom(roomId ?? this.viewedRoomId ?? "")) {
225225
this.togglePanel(roomId);
226226
}
227227
}
@@ -360,7 +360,7 @@ export default class RightPanelStore extends ReadyWatchingStore {
360360
// when we're switching to a room, clear out any stale MemberInfo cards
361361
// in order to fix https://github.com/vector-im/element-web/issues/21487
362362
if (this.currentCard?.phase !== RightPanelPhases.EncryptionPanel) {
363-
const panel = this.byRoom[this.viewedRoomId];
363+
const panel = this.byRoom[this.viewedRoomId ?? ""];
364364
if (panel?.history) {
365365
panel.history = panel.history.filter(
366366
(card: IRightPanelCard) =>
@@ -380,13 +380,16 @@ export default class RightPanelStore extends ReadyWatchingStore {
380380
// If the right panel stays open mode is used, and the panel was either
381381
// closed or never shown for that room, then force it open and display
382382
// the room member list.
383-
if (SettingsStore.getValue("feature_right_panel_default_open") && !this.byRoom[this.viewedRoomId]?.isOpen) {
383+
if (
384+
SettingsStore.getValue("feature_right_panel_default_open") &&
385+
!this.byRoom[this.viewedRoomId ?? ""]?.isOpen
386+
) {
384387
const history = [{ phase: RightPanelPhases.RoomMemberList }];
385388
const room = this.viewedRoomId ? this.mxClient?.getRoom(this.viewedRoomId) : undefined;
386389
if (!room?.isSpaceRoom()) {
387390
history.unshift({ phase: RightPanelPhases.RoomSummary });
388391
}
389-
this.byRoom[this.viewedRoomId] = {
392+
this.byRoom[this.viewedRoomId ?? ""] = {
390393
isOpen: true,
391394
history,
392395
};

0 commit comments

Comments
 (0)