Conform more code to `strictNullChecks` and `noImplicitAny` (#11156)

pull/28788/head^2
Michael Telatynski 2023-06-28 14:05:36 +01:00 committed by GitHub
parent 46eb34a55d
commit 6836a5fa7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 36 additions and 19 deletions

View File

@ -686,14 +686,22 @@ async function persistCredentials(credentials: IMatrixClientCreds): Promise<void
// if we couldn't save to indexedDB, fall back to localStorage. We
// store the access token unencrypted since localStorage only saves
// strings.
localStorage.setItem("mx_access_token", credentials.accessToken);
if (!!credentials.accessToken) {
localStorage.setItem("mx_access_token", credentials.accessToken);
} else {
localStorage.removeItem("mx_access_token");
}
}
localStorage.setItem("mx_has_pickle_key", String(true));
} else {
try {
await StorageManager.idbSave("account", "mx_access_token", credentials.accessToken);
} catch (e) {
localStorage.setItem("mx_access_token", credentials.accessToken);
if (!!credentials.accessToken) {
localStorage.setItem("mx_access_token", credentials.accessToken);
} else {
localStorage.removeItem("mx_access_token");
}
}
if (localStorage.getItem("mx_has_pickle_key") === "true") {
logger.error("Expected a pickle key, but none provided. Encryption may not work.");

View File

@ -1597,14 +1597,15 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
};
private injectSticker(url: string, info: object, text: string, threadId: string | null): void {
if (!this.context.client) return;
const roomId = this.getRoomId();
if (!this.context.client || !roomId) return;
if (this.context.client.isGuest()) {
dis.dispatch({ action: "require_registration" });
return;
}
ContentMessages.sharedInstance()
.sendStickerContentToRoom(url, this.getRoomId(), threadId, info, text, this.context.client)
.sendStickerContentToRoom(url, roomId, threadId, info, text, this.context.client)
.then(undefined, (error) => {
if (error.name === "UnknownDeviceError") {
// Let the staus bar handle this
@ -1636,7 +1637,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
private onSearchUpdate = (inProgress: boolean, searchResults: ISearchResults | null): void => {
this.setState({
search: {
...this.state.search,
...this.state.search!,
count: searchResults?.count,
inProgress,
},
@ -1658,10 +1659,12 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
};
private onRejectButtonClicked = (): void => {
const roomId = this.getRoomId();
if (!roomId) return;
this.setState({
rejecting: true,
});
this.context.client?.leave(this.getRoomId()).then(
this.context.client?.leave(roomId).then(
() => {
dis.dispatch({ action: Action.ViewHomePage });
this.setState({
@ -1896,14 +1899,17 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
});
}
private onFileDrop = (dataTransfer: DataTransfer): Promise<void> =>
ContentMessages.sharedInstance().sendContentListToRoom(
private onFileDrop = async (dataTransfer: DataTransfer): Promise<void> => {
const roomId = this.getRoomId();
if (!roomId || !this.context.client) return;
await ContentMessages.sharedInstance().sendContentListToRoom(
Array.from(dataTransfer.files),
this.getRoomId(),
null,
roomId,
undefined,
this.context.client,
TimelineRenderingType.Room,
);
};
private onMeasurement = (narrow: boolean): void => {
this.setState({ narrow });

View File

@ -830,6 +830,7 @@ export default class ScrollPanel extends React.Component<IProps> {
}
private topFromBottom(node: HTMLElement): number {
if (!this.itemlist.current) return -1;
// current capped height - distance from top = distance from bottom of container to top of tracked element
return this.itemlist.current.clientHeight - node.offsetTop;
}

View File

@ -166,7 +166,7 @@ describe("SpaceHierarchy", () => {
observe: () => null,
unobserve: () => null,
disconnect: () => null,
});
} as ResizeObserver);
window.IntersectionObserver = mockIntersectionObserver;
});

View File

@ -70,7 +70,7 @@ const mkTimeline = (room: Room, events: MatrixEvent[]): [EventTimeline, EventTim
room: room as Room,
getLiveTimeline: () => timeline,
getTimelineForEvent: () => timeline,
getPendingEvents: () => [],
getPendingEvents: () => [] as MatrixEvent[],
} as unknown as EventTimelineSet;
const timeline = new EventTimeline(timelineSet);
events.forEach((event) => timeline.addEvent(event, { toStartOfTimeline: false }));

View File

@ -185,7 +185,7 @@ function renderComponent(props: Partial<ComponentProps<typeof VerificationPanel>
const defaultProps = {
layout: "",
member: {} as User,
onClose: () => undefined,
onClose: () => {},
isRoomEncrypted: false,
inDialog: false,
phase: props.request.phase,

View File

@ -17,7 +17,7 @@ limitations under the License.
import React from "react";
import { render, screen, fireEvent, act } from "@testing-library/react";
import { mocked } from "jest-mock";
import { MatrixClient } from "matrix-js-sdk/src/matrix";
import { MatrixClient, Room } from "matrix-js-sdk/src/matrix";
import UnwrappedSpacePanel from "../../../../src/components/views/spaces/SpacePanel";
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
@ -28,6 +28,7 @@ import { mkStubRoom, wrapInSdkContext } from "../../../test-utils";
import { SdkContextClass } from "../../../../src/contexts/SDKContext";
import SpaceStore from "../../../../src/stores/spaces/SpaceStore";
import DMRoomMap from "../../../../src/utils/DMRoomMap";
import { SpaceNotificationState } from "../../../../src/stores/notifications/SpaceNotificationState";
// DND test utilities based on
// https://github.com/colinrobertbrooks/react-beautiful-dnd-test-utils/issues/18#issuecomment-1373388693
@ -98,8 +99,8 @@ jest.mock("../../../../src/stores/spaces/SpaceStore", () => {
enabledMetaSpaces: MetaSpace[] = [];
spacePanelSpaces: string[] = [];
activeSpace: SpaceKey = "!space1";
getChildSpaces = () => [];
getNotificationState = () => null;
getChildSpaces = () => [] as Room[];
getNotificationState = () => null as SpaceNotificationState | null;
setActiveSpace = jest.fn();
moveRootSpace = jest.fn();
}

View File

@ -214,7 +214,7 @@ describe("AutoDiscoveryUtils", () => {
registrationEndpoint: "https://test.com/registration",
tokenEndpoint: "https://test.com/token",
};
const discoveryResult = {
const discoveryResult: ClientConfig = {
...validIsConfig,
...validHsConfig,
[M_AUTHENTICATION.stable!]: {

View File

@ -18,6 +18,7 @@ import fetchMockJest from "fetch-mock-jest";
import { OidcError } from "matrix-js-sdk/src/oidc/error";
import { getOidcClientId } from "../../../src/utils/oidc/registerClient";
import { ValidatedDelegatedAuthConfig } from "../../../src/utils/ValidatedServerConfig";
describe("getOidcClientId()", () => {
const issuer = "https://auth.com/";
@ -49,7 +50,7 @@ describe("getOidcClientId()", () => {
});
it("should throw when no static clientId is configured and no registration endpoint", async () => {
const authConfigWithoutRegistration = {
const authConfigWithoutRegistration: ValidatedDelegatedAuthConfig = {
...delegatedAuthConfig,
issuer: "https://issuerWithoutStaticClientId.org/",
registrationEndpoint: undefined,
@ -62,7 +63,7 @@ describe("getOidcClientId()", () => {
});
it("should handle when staticOidcClients object is falsy", async () => {
const authConfigWithoutRegistration = {
const authConfigWithoutRegistration: ValidatedDelegatedAuthConfig = {
...delegatedAuthConfig,
registrationEndpoint: undefined,
};