Conform more code to strict null checking (#10167)
* Conform more code to strict null checking * Delint * Iterate PR based on feedback
This commit is contained in:
parent
f7bea2cae5
commit
4574c665ea
103 changed files with 517 additions and 495 deletions
|
@ -19,6 +19,7 @@ import { logger } from "matrix-js-sdk/src/logger";
|
|||
|
||||
import SdkConfig from "../SdkConfig";
|
||||
import { MatrixClientPeg } from "../MatrixClientPeg";
|
||||
import { Policies } from "../Terms";
|
||||
|
||||
export function getDefaultIdentityServerUrl(): string {
|
||||
return SdkConfig.get("validated_server_config").isUrl;
|
||||
|
@ -33,7 +34,7 @@ export function setToDefaultIdentityServer(): void {
|
|||
}
|
||||
|
||||
export async function doesIdentityServerHaveTerms(fullUrl: string): Promise<boolean> {
|
||||
let terms;
|
||||
let terms: { policies?: Policies } | null;
|
||||
try {
|
||||
terms = await MatrixClientPeg.get().getTerms(SERVICE_TYPES.IS, fullUrl);
|
||||
} catch (e) {
|
||||
|
@ -45,7 +46,7 @@ export async function doesIdentityServerHaveTerms(fullUrl: string): Promise<bool
|
|||
}
|
||||
}
|
||||
|
||||
return terms && terms["policies"] && Object.keys(terms["policies"]).length > 0;
|
||||
return !!terms?.["policies"] && Object.keys(terms["policies"]).length > 0;
|
||||
}
|
||||
|
||||
export function doesAccountDataHaveIdentityServer(): boolean {
|
||||
|
|
|
@ -28,12 +28,12 @@ import { IDestroyable } from "./IDestroyable";
|
|||
|
||||
export class MediaEventHelper implements IDestroyable {
|
||||
// Either an HTTP or Object URL (when encrypted) to the media.
|
||||
public readonly sourceUrl: LazyValue<string>;
|
||||
public readonly thumbnailUrl: LazyValue<string>;
|
||||
public readonly sourceUrl: LazyValue<string | null>;
|
||||
public readonly thumbnailUrl: LazyValue<string | null>;
|
||||
|
||||
// Either the raw or decrypted (when encrypted) contents of the file.
|
||||
public readonly sourceBlob: LazyValue<Blob>;
|
||||
public readonly thumbnailBlob: LazyValue<Blob>;
|
||||
public readonly thumbnailBlob: LazyValue<Blob | null>;
|
||||
|
||||
public readonly media: Media;
|
||||
|
||||
|
@ -56,12 +56,12 @@ export class MediaEventHelper implements IDestroyable {
|
|||
|
||||
public destroy(): void {
|
||||
if (this.media.isEncrypted) {
|
||||
if (this.sourceUrl.present) URL.revokeObjectURL(this.sourceUrl.cachedValue);
|
||||
if (this.thumbnailUrl.present) URL.revokeObjectURL(this.thumbnailUrl.cachedValue);
|
||||
if (this.sourceUrl.cachedValue) URL.revokeObjectURL(this.sourceUrl.cachedValue);
|
||||
if (this.thumbnailUrl.cachedValue) URL.revokeObjectURL(this.thumbnailUrl.cachedValue);
|
||||
}
|
||||
}
|
||||
|
||||
private prepareSourceUrl = async (): Promise<string> => {
|
||||
private prepareSourceUrl = async (): Promise<string | null> => {
|
||||
if (this.media.isEncrypted) {
|
||||
const blob = await this.sourceBlob.value;
|
||||
return URL.createObjectURL(blob);
|
||||
|
@ -70,7 +70,7 @@ export class MediaEventHelper implements IDestroyable {
|
|||
}
|
||||
};
|
||||
|
||||
private prepareThumbnailUrl = async (): Promise<string> => {
|
||||
private prepareThumbnailUrl = async (): Promise<string | null> => {
|
||||
if (this.media.isEncrypted) {
|
||||
const blob = await this.thumbnailBlob.value;
|
||||
if (blob === null) return null;
|
||||
|
@ -83,12 +83,12 @@ export class MediaEventHelper implements IDestroyable {
|
|||
private fetchSource = (): Promise<Blob> => {
|
||||
if (this.media.isEncrypted) {
|
||||
const content = this.event.getContent<IMediaEventContent>();
|
||||
return decryptFile(content.file, content.info);
|
||||
return decryptFile(content.file!, content.info);
|
||||
}
|
||||
return this.media.downloadSource().then((r) => r.blob());
|
||||
};
|
||||
|
||||
private fetchThumbnail = (): Promise<Blob> => {
|
||||
private fetchThumbnail = (): Promise<Blob | null> => {
|
||||
if (!this.media.hasThumbnail) return Promise.resolve(null);
|
||||
|
||||
if (this.media.isEncrypted) {
|
||||
|
@ -113,7 +113,7 @@ export class MediaEventHelper implements IDestroyable {
|
|||
|
||||
const content = event.getContent();
|
||||
const mediaMsgTypes: string[] = [MsgType.Video, MsgType.Audio, MsgType.Image, MsgType.File];
|
||||
if (mediaMsgTypes.includes(content.msgtype)) return true;
|
||||
if (mediaMsgTypes.includes(content.msgtype!)) return true;
|
||||
if (typeof content.url === "string") return true;
|
||||
|
||||
// Finally, it's probably not media
|
||||
|
|
|
@ -96,7 +96,7 @@ export default class WidgetUtils {
|
|||
* @param {[type]} testUrlString URL to check
|
||||
* @return {Boolean} True if specified URL is a scalar URL
|
||||
*/
|
||||
public static isScalarUrl(testUrlString: string): boolean {
|
||||
public static isScalarUrl(testUrlString?: string): boolean {
|
||||
if (!testUrlString) {
|
||||
logger.error("Scalar URL check failed. No URL specified");
|
||||
return false;
|
||||
|
@ -554,7 +554,7 @@ export default class WidgetUtils {
|
|||
// noinspection JSIgnoredPromiseFromCall
|
||||
IntegrationManagers.sharedInstance()
|
||||
.getPrimaryManager()
|
||||
.open(room, "type_" + app.type, app.id);
|
||||
?.open(room, "type_" + app.type, app.id);
|
||||
}
|
||||
|
||||
public static isManagedByManager(app: IApp): boolean {
|
||||
|
@ -563,7 +563,7 @@ export default class WidgetUtils {
|
|||
if (managers.hasManager()) {
|
||||
// TODO: Pick the right manager for the widget
|
||||
const defaultManager = managers.getPrimaryManager();
|
||||
return WidgetUtils.isScalarUrl(defaultManager.apiUrl);
|
||||
return WidgetUtils.isScalarUrl(defaultManager?.apiUrl);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -29,7 +29,7 @@ export const useBeacon = (beaconInfoEvent: MatrixEvent): Beacon | undefined => {
|
|||
const beaconIdentifier = getBeaconInfoIdentifier(beaconInfoEvent);
|
||||
|
||||
const room = matrixClient.getRoom(roomId);
|
||||
const beaconInstance = room.currentState.beacons.get(beaconIdentifier);
|
||||
const beaconInstance = room?.currentState.beacons.get(beaconIdentifier);
|
||||
|
||||
// TODO could this be less stupid?
|
||||
|
||||
|
|
|
@ -173,7 +173,7 @@ export class ThreepidMember extends Member {
|
|||
|
||||
export interface IDMUserTileProps {
|
||||
member: Member;
|
||||
onRemove(member: Member): void;
|
||||
onRemove?(member: Member): void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -92,7 +92,7 @@ export async function createDmLocalRoom(client: MatrixClient, targets: Member[])
|
|||
type: EventType.RoomMember,
|
||||
content: {
|
||||
displayname: target.name,
|
||||
avatar_url: target.getMxcAvatarUrl(),
|
||||
avatar_url: target.getMxcAvatarUrl() ?? undefined,
|
||||
membership: "invite",
|
||||
isDirect: true,
|
||||
},
|
||||
|
@ -107,7 +107,7 @@ export async function createDmLocalRoom(client: MatrixClient, targets: Member[])
|
|||
type: EventType.RoomMember,
|
||||
content: {
|
||||
displayname: target.name,
|
||||
avatar_url: target.getMxcAvatarUrl(),
|
||||
avatar_url: target.getMxcAvatarUrl() ?? undefined,
|
||||
membership: "join",
|
||||
},
|
||||
state_key: target.userId,
|
||||
|
|
|
@ -37,7 +37,7 @@ import { bulkSpaceBehaviour } from "./space";
|
|||
import { SdkContextClass } from "../contexts/SDKContext";
|
||||
|
||||
export async function leaveRoomBehaviour(roomId: string, retry = true, spinner = true): Promise<void> {
|
||||
let spinnerModal: IHandle<any>;
|
||||
let spinnerModal: IHandle<any> | undefined;
|
||||
if (spinner) {
|
||||
spinnerModal = Modal.createDialog(Spinner, undefined, "mx_Dialog_spinner");
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ export async function leaveRoomBehaviour(roomId: string, retry = true, spinner =
|
|||
room
|
||||
.getPendingEvents()
|
||||
.filter((ev) => {
|
||||
return [EventStatus.QUEUED, EventStatus.ENCRYPTING, EventStatus.SENDING].includes(ev.status);
|
||||
return [EventStatus.QUEUED, EventStatus.ENCRYPTING, EventStatus.SENDING].includes(ev.status!);
|
||||
})
|
||||
.map(
|
||||
(ev) =>
|
||||
|
|
|
@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
export const parseGeoUri = (uri: string): GeolocationCoordinates => {
|
||||
function parse(s: string): number {
|
||||
export const parseGeoUri = (uri: string): GeolocationCoordinates | undefined => {
|
||||
function parse(s: string): number | undefined {
|
||||
const ret = parseFloat(s);
|
||||
if (Number.isNaN(ret)) {
|
||||
return undefined;
|
||||
|
@ -28,7 +28,7 @@ export const parseGeoUri = (uri: string): GeolocationCoordinates => {
|
|||
if (!m) return;
|
||||
const parts = m[1].split(";");
|
||||
const coords = parts[0].split(",");
|
||||
let uncertainty: number;
|
||||
let uncertainty: number | undefined;
|
||||
for (const param of parts.slice(1)) {
|
||||
const m = param.match(/u=(.*)/);
|
||||
if (m) uncertainty = parse(m[1]);
|
||||
|
|
|
@ -23,5 +23,5 @@ export function isLoggedIn(): boolean {
|
|||
// store to hold this state.
|
||||
// See also https://github.com/vector-im/element-web/issues/15034.
|
||||
const app = window.matrixChat;
|
||||
return app && (app as MatrixChat).state.view === Views.LOGGED_IN;
|
||||
return (app as MatrixChat)?.state.view === Views.LOGGED_IN;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ import { parsePermalink } from "./permalinks/Permalinks";
|
|||
* The initial caller should pass in an empty array to seed the accumulator.
|
||||
*/
|
||||
export function pillifyLinks(nodes: ArrayLike<Element>, mxEvent: MatrixEvent, pills: Element[]): void {
|
||||
const room = MatrixClientPeg.get().getRoom(mxEvent.getRoomId());
|
||||
const room = MatrixClientPeg.get().getRoom(mxEvent.getRoomId()) ?? undefined;
|
||||
const shouldShowPillAvatar = SettingsStore.getValue("Pill.shouldShowPillAvatar");
|
||||
let node = nodes[0];
|
||||
while (node) {
|
||||
|
@ -49,7 +49,7 @@ export function pillifyLinks(nodes: ArrayLike<Element>, mxEvent: MatrixEvent, pi
|
|||
node = node.nextSibling as Element;
|
||||
continue;
|
||||
} else if (node.tagName === "A" && node.getAttribute("href")) {
|
||||
const href = node.getAttribute("href");
|
||||
const href = node.getAttribute("href")!;
|
||||
const parts = parsePermalink(href);
|
||||
// If the link is a (localised) matrix.to link, replace it with a pill
|
||||
// We don't want to pill event permalinks, so those are ignored.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue