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 #11135

Merged
merged 5 commits into from
Jun 28, 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
18 changes: 12 additions & 6 deletions src/AddThreepid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -239,7 +245,7 @@ export default class AddThreepid {
[SSOAuthEntry.LOGIN_TYPE]: dialogAesthetics,
[SSOAuthEntry.UNSTABLE_LOGIN_TYPE]: dialogAesthetics,
},
});
} as InteractiveAuthDialogProps<IAddThreePidOnlyBody>);
return finished;
}
}
Expand Down Expand Up @@ -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,
});
};

Expand Down Expand Up @@ -360,7 +366,7 @@ export default class AddThreepid {
[SSOAuthEntry.LOGIN_TYPE]: dialogAesthetics,
[SSOAuthEntry.UNSTABLE_LOGIN_TYPE]: dialogAesthetics,
},
});
} as InteractiveAuthDialogProps<IAddThreePidOnlyBody>);
return finished;
}
}
Expand Down
27 changes: 15 additions & 12 deletions src/stores/right-panel/RightPanelStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ 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 {
return this.byRoom[roomId]?.isOpen ?? false;
}

public get roomPhaseHistory(): Array<IRightPanelCard> {
return this.byRoom[this.viewedRoomId]?.history ?? [];
return this.byRoom[this.viewedRoomId ?? ""]?.history ?? [];
}

/**
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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 ?? {};
Expand All @@ -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();
Expand All @@ -207,21 +207,21 @@ 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;
this.emitAndUpdateSettings();
}

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);
}
}
Expand Down Expand Up @@ -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) =>
Expand All @@ -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,
};
Expand Down