Conform more code to strict null checking (#10153)
* Conform more code to strict null checking * Conform more code to strict null checking * Iterate * Iterate
This commit is contained in:
parent
a4ff959aa1
commit
145a5a8a8d
89 changed files with 520 additions and 551 deletions
|
@ -35,7 +35,7 @@ import { _t, _td, Tags, TranslatedString } from "../languageHandler";
|
|||
*/
|
||||
export function messageForResourceLimitError(
|
||||
limitType: string,
|
||||
adminContact: string,
|
||||
adminContact: string | undefined,
|
||||
strings: Record<string, string>,
|
||||
extraTranslations?: Tags,
|
||||
): TranslatedString {
|
||||
|
@ -57,7 +57,7 @@ export function messageForResourceLimitError(
|
|||
if (errString.includes("<a>")) {
|
||||
return _t(errString, {}, Object.assign({ a: linkSub }, extraTranslations));
|
||||
} else {
|
||||
return _t(errString, {}, extraTranslations);
|
||||
return _t(errString, {}, extraTranslations!);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ export function presentableTextForFile(
|
|||
shortened = false,
|
||||
): string {
|
||||
let text = fallbackText;
|
||||
if (content.body?.length > 0) {
|
||||
if (content.body?.length) {
|
||||
// The content body should be the name of the file including a
|
||||
// file extension.
|
||||
text = content.body;
|
||||
|
|
|
@ -69,7 +69,7 @@ async function isColrFontSupported(): Promise<boolean> {
|
|||
|
||||
try {
|
||||
const canvas = document.createElement("canvas");
|
||||
const context = canvas.getContext("2d");
|
||||
const context = canvas.getContext("2d")!;
|
||||
const img = new Image();
|
||||
// eslint-disable-next-line
|
||||
const fontCOLR =
|
||||
|
|
|
@ -26,8 +26,8 @@ import { useEventEmitterState } from "../../hooks/useEventEmitter";
|
|||
export const useLiveBeacons = (roomId: Room["roomId"], matrixClient: MatrixClient): Beacon[] => {
|
||||
const room = matrixClient.getRoom(roomId);
|
||||
|
||||
const liveBeacons = useEventEmitterState(room.currentState, RoomStateEvent.BeaconLiveness, () =>
|
||||
room.currentState?.liveBeaconIds.map((beaconIdentifier) => room.currentState.beacons.get(beaconIdentifier)),
|
||||
const liveBeacons = useEventEmitterState(room?.currentState, RoomStateEvent.BeaconLiveness, () =>
|
||||
room?.currentState?.liveBeaconIds.map((beaconIdentifier) => room.currentState.beacons.get(beaconIdentifier)),
|
||||
);
|
||||
|
||||
return liveBeacons;
|
||||
|
|
|
@ -102,7 +102,7 @@ export abstract class Member {
|
|||
* Gets the MXC URL of this Member's avatar. For users this should be their profile's
|
||||
* avatar MXC URL or null if none set. For 3PIDs this should always be null.
|
||||
*/
|
||||
public abstract getMxcAvatarUrl(): string;
|
||||
public abstract getMxcAvatarUrl(): string | null;
|
||||
}
|
||||
|
||||
export class DirectoryMember extends Member {
|
||||
|
@ -127,8 +127,8 @@ export class DirectoryMember extends Member {
|
|||
return this._userId;
|
||||
}
|
||||
|
||||
public getMxcAvatarUrl(): string {
|
||||
return this.avatarUrl;
|
||||
public getMxcAvatarUrl(): string | null {
|
||||
return this.avatarUrl ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ export class ThreepidMember extends Member {
|
|||
return this.id;
|
||||
}
|
||||
|
||||
public getMxcAvatarUrl(): string {
|
||||
public getMxcAvatarUrl(): string | null {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -276,14 +276,14 @@ export default abstract class Exporter {
|
|||
protected isReply(event: MatrixEvent): boolean {
|
||||
const isEncrypted = event.isEncrypted();
|
||||
// If encrypted, in_reply_to lies in event.event.content
|
||||
const content = isEncrypted ? event.event.content : event.getContent();
|
||||
const content = isEncrypted ? event.event.content! : event.getContent();
|
||||
const relatesTo = content["m.relates_to"];
|
||||
return !!(relatesTo && relatesTo["m.in_reply_to"]);
|
||||
}
|
||||
|
||||
protected isAttachment(mxEv: MatrixEvent): boolean {
|
||||
const attachmentTypes = ["m.sticker", "m.image", "m.file", "m.video", "m.audio"];
|
||||
return mxEv.getType() === attachmentTypes[0] || attachmentTypes.includes(mxEv.getContent().msgtype);
|
||||
return mxEv.getType() === attachmentTypes[0] || attachmentTypes.includes(mxEv.getContent().msgtype!);
|
||||
}
|
||||
|
||||
public abstract export(): Promise<void>;
|
||||
|
|
|
@ -217,10 +217,10 @@ export default class HTMLExporter extends Exporter {
|
|||
</html>`;
|
||||
}
|
||||
|
||||
protected getAvatarURL(event: MatrixEvent): string | undefined {
|
||||
protected getAvatarURL(event: MatrixEvent): string | null {
|
||||
const member = event.sender;
|
||||
const avatarUrl = member?.getMxcAvatarUrl();
|
||||
return avatarUrl ? mediaFromMxc(avatarUrl).getThumbnailOfSourceHttp(30, 30, "crop") : undefined;
|
||||
return avatarUrl ? mediaFromMxc(avatarUrl).getThumbnailOfSourceHttp(30, 30, "crop") : null;
|
||||
}
|
||||
|
||||
protected async saveAvatarIfNeeded(event: MatrixEvent): Promise<void> {
|
||||
|
@ -386,7 +386,7 @@ export default class HTMLExporter extends Exporter {
|
|||
|
||||
protected async createHTML(events: MatrixEvent[], start: number): Promise<string> {
|
||||
let content = "";
|
||||
let prevEvent = null;
|
||||
let prevEvent: MatrixEvent | null = null;
|
||||
for (let i = start; i < Math.min(start + 1000, events.length); i++) {
|
||||
const event = events[i];
|
||||
this.updateProgress(
|
||||
|
|
|
@ -47,7 +47,7 @@ export default class JSONExporter extends Exporter {
|
|||
const creator = this.room.currentState.getStateEvents(EventType.RoomCreate, "")?.getSender();
|
||||
const creatorName = this.room?.getMember(creator)?.rawDisplayName || creator;
|
||||
const topic = this.room.currentState.getStateEvents(EventType.RoomTopic, "")?.getContent()?.topic || "";
|
||||
const exporter = this.client.getUserId();
|
||||
const exporter = this.client.getUserId()!;
|
||||
const exporterName = this.room?.getMember(exporter)?.rawDisplayName || exporter;
|
||||
const jsonObject = {
|
||||
room_name: this.room.name,
|
||||
|
|
|
@ -45,7 +45,7 @@ async function getRulesFromCssFile(path: string): Promise<CSSStyleSheet> {
|
|||
// the style will only be parsed once it is added to a document
|
||||
doc.body.appendChild(styleElement);
|
||||
|
||||
return styleElement.sheet;
|
||||
return styleElement.sheet!;
|
||||
}
|
||||
|
||||
// naively culls unused css rules based on which classes are present in the html,
|
||||
|
|
|
@ -19,6 +19,8 @@ import { IEncryptedFile } from "../customisations/models/IMediaEventContent";
|
|||
|
||||
type ThumbnailableElement = HTMLImageElement | HTMLVideoElement;
|
||||
|
||||
export const BLURHASH_FIELD = "xyz.amorgan.blurhash"; // MSC2448
|
||||
|
||||
interface IThumbnail {
|
||||
info: {
|
||||
thumbnail_info?: {
|
||||
|
@ -29,15 +31,13 @@ interface IThumbnail {
|
|||
};
|
||||
w: number;
|
||||
h: number;
|
||||
[BLURHASH_FIELD]: string;
|
||||
[BLURHASH_FIELD]?: string;
|
||||
thumbnail_url?: string;
|
||||
thumbnail_file?: IEncryptedFile;
|
||||
};
|
||||
thumbnail: Blob;
|
||||
}
|
||||
|
||||
export const BLURHASH_FIELD = "xyz.amorgan.blurhash"; // MSC2448
|
||||
|
||||
const MAX_WIDTH = 800;
|
||||
const MAX_HEIGHT = 600;
|
||||
|
||||
|
@ -88,7 +88,7 @@ export async function createThumbnail(
|
|||
canvas = document.createElement("canvas");
|
||||
canvas.width = targetWidth;
|
||||
canvas.height = targetHeight;
|
||||
context = canvas.getContext("2d");
|
||||
context = canvas.getContext("2d")!;
|
||||
}
|
||||
|
||||
context.drawImage(element, 0, 0, targetWidth, targetHeight);
|
||||
|
@ -97,7 +97,9 @@ export async function createThumbnail(
|
|||
if (window.OffscreenCanvas && canvas instanceof OffscreenCanvas) {
|
||||
thumbnailPromise = canvas.convertToBlob({ type: mimeType });
|
||||
} else {
|
||||
thumbnailPromise = new Promise<Blob>((resolve) => (canvas as HTMLCanvasElement).toBlob(resolve, mimeType));
|
||||
thumbnailPromise = new Promise<Blob>((resolve) =>
|
||||
(canvas as HTMLCanvasElement).toBlob(resolve as BlobCallback, mimeType),
|
||||
);
|
||||
}
|
||||
|
||||
const imageData = context.getImageData(0, 0, targetWidth, targetHeight);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue