Conform more of the codebase to strictNullChecks (#11135)

pull/28217/head
Michael Telatynski 2023-06-28 11:02:15 +01:00 committed by GitHub
parent a87362a048
commit d404e0656a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 18 deletions

View File

@ -16,14 +16,20 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { IAuthData, IRequestMsisdnTokenResponse, IRequestTokenResponse, MatrixClient } from "matrix-js-sdk/src/matrix";
import {
IAddThreePidOnlyBody,
IAuthData,
IRequestMsisdnTokenResponse,
IRequestTokenResponse,
MatrixClient,
} from "matrix-js-sdk/src/matrix";
import { MatrixError, HTTPError } from "matrix-js-sdk/src/matrix";
import Modal from "./Modal";
import { _t, UserFriendlyError } from "./languageHandler";
import IdentityAuthClient from "./IdentityAuthClient";
import { SSOAuthEntry } from "./components/views/auth/InteractiveAuthEntryComponents";
import InteractiveAuthDialog from "./components/views/dialogs/InteractiveAuthDialog";
import InteractiveAuthDialog, { InteractiveAuthDialogProps } from "./components/views/dialogs/InteractiveAuthDialog";
function getIdServerDomain(matrixClient: MatrixClient): string {
const idBaseUrl = matrixClient.getIdentityServerUrl(true);
@ -239,7 +245,7 @@ export default class AddThreepid {
[SSOAuthEntry.LOGIN_TYPE]: dialogAesthetics,
[SSOAuthEntry.UNSTABLE_LOGIN_TYPE]: dialogAesthetics,
},
});
} as InteractiveAuthDialogProps<IAddThreePidOnlyBody>);
return finished;
}
}
@ -270,11 +276,11 @@ export default class AddThreepid {
* @param {{type: string, session?: string}} auth UI auth object
* @return {Promise<Object>} Response from /3pid/add call (in current spec, an empty object)
*/
private makeAddThreepidOnlyRequest = (auth?: { type: string; session?: string }): Promise<{}> => {
private makeAddThreepidOnlyRequest = (auth?: IAddThreePidOnlyBody["auth"] | null): Promise<{}> => {
return this.matrixClient.addThreePidOnly({
sid: this.sessionId,
client_secret: this.clientSecret,
auth,
auth: auth ?? undefined,
});
};
@ -360,7 +366,7 @@ export default class AddThreepid {
[SSOAuthEntry.LOGIN_TYPE]: dialogAesthetics,
[SSOAuthEntry.UNSTABLE_LOGIN_TYPE]: dialogAesthetics,
},
});
} as InteractiveAuthDialogProps<IAddThreePidOnlyBody>);
return finished;
}
}

View File

@ -90,7 +90,7 @@ export default class RightPanelStore extends ReadyWatchingStore {
* during room changes.
*/
public get isOpen(): boolean {
return this.byRoom[this.viewedRoomId]?.isOpen ?? false;
return this.byRoom[this.viewedRoomId ?? ""]?.isOpen ?? false;
}
public isOpenForRoom(roomId: string): boolean {
@ -98,7 +98,7 @@ export default class RightPanelStore extends ReadyWatchingStore {
}
public get roomPhaseHistory(): Array<IRightPanelCard> {
return this.byRoom[this.viewedRoomId]?.history ?? [];
return this.byRoom[this.viewedRoomId ?? ""]?.history ?? [];
}
/**
@ -133,7 +133,7 @@ export default class RightPanelStore extends ReadyWatchingStore {
// Setters
public setCard(card: IRightPanelCard, allowClose = true, roomId?: string): void {
const rId = roomId ?? this.viewedRoomId;
const rId = roomId ?? this.viewedRoomId ?? "";
// This function behaves as following:
// Update state: if the same phase is send but with a state
// 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 {
public setCards(cards: IRightPanelCard[], allowClose = true, roomId: string | null = null): void {
// This function sets the history of the right panel and shows the right panel if not already visible.
const rId = roomId ?? this.viewedRoomId;
const rId = roomId ?? this.viewedRoomId ?? "";
const history = cards.map((c) => ({ phase: c.phase, state: c.state ?? {} }));
this.byRoom[rId] = { history, isOpen: true };
this.show(rId);
@ -172,7 +172,7 @@ export default class RightPanelStore extends ReadyWatchingStore {
// Appends a card to the history and shows the right panel if not already visible
public pushCard(card: IRightPanelCard, allowClose = true, roomId: string | null = null): void {
const rId = roomId ?? this.viewedRoomId;
const rId = roomId ?? this.viewedRoomId ?? "";
const redirect = this.getVerificationRedirect(card);
const targetPhase = redirect?.phase ?? card.phase;
const pState = redirect?.state ?? card.state ?? {};
@ -198,7 +198,7 @@ export default class RightPanelStore extends ReadyWatchingStore {
}
public popCard(roomId: string | null = null): IRightPanelCard | undefined {
const rId = roomId ?? this.viewedRoomId;
const rId = roomId ?? this.viewedRoomId ?? "";
if (!this.byRoom[rId]) return;
const removedCard = this.byRoom[rId].history.pop();
@ -207,7 +207,7 @@ export default class RightPanelStore extends ReadyWatchingStore {
}
public togglePanel(roomId: string | null): void {
const rId = roomId ?? this.viewedRoomId;
const rId = roomId ?? this.viewedRoomId ?? "";
if (!this.byRoom[rId]) return;
this.byRoom[rId].isOpen = !this.byRoom[rId].isOpen;
@ -215,13 +215,13 @@ export default class RightPanelStore extends ReadyWatchingStore {
}
public show(roomId: string | null): void {
if (!this.isOpenForRoom(roomId ?? this.viewedRoomId)) {
if (!this.isOpenForRoom(roomId ?? this.viewedRoomId ?? "")) {
this.togglePanel(roomId);
}
}
public hide(roomId: string | null): void {
if (this.isOpenForRoom(roomId ?? this.viewedRoomId)) {
if (this.isOpenForRoom(roomId ?? this.viewedRoomId ?? "")) {
this.togglePanel(roomId);
}
}
@ -360,7 +360,7 @@ export default class RightPanelStore extends ReadyWatchingStore {
// when we're switching to a room, clear out any stale MemberInfo cards
// in order to fix https://github.com/vector-im/element-web/issues/21487
if (this.currentCard?.phase !== RightPanelPhases.EncryptionPanel) {
const panel = this.byRoom[this.viewedRoomId];
const panel = this.byRoom[this.viewedRoomId ?? ""];
if (panel?.history) {
panel.history = panel.history.filter(
(card: IRightPanelCard) =>
@ -380,13 +380,16 @@ export default class RightPanelStore extends ReadyWatchingStore {
// If the right panel stays open mode is used, and the panel was either
// closed or never shown for that room, then force it open and display
// the room member list.
if (SettingsStore.getValue("feature_right_panel_default_open") && !this.byRoom[this.viewedRoomId]?.isOpen) {
if (
SettingsStore.getValue("feature_right_panel_default_open") &&
!this.byRoom[this.viewedRoomId ?? ""]?.isOpen
) {
const history = [{ phase: RightPanelPhases.RoomMemberList }];
const room = this.viewedRoomId ? this.mxClient?.getRoom(this.viewedRoomId) : undefined;
if (!room?.isSpaceRoom()) {
history.unshift({ phase: RightPanelPhases.RoomSummary });
}
this.byRoom[this.viewedRoomId] = {
this.byRoom[this.viewedRoomId ?? ""] = {
isOpen: true,
history,
};