Conform more code to strictNullChecks
(#10383
* Update matrix-widget-api * Conform more code to `strictNullChecks` * Iterate
This commit is contained in:
parent
aae9dfbb7d
commit
9c816bb720
18 changed files with 112 additions and 93 deletions
|
@ -189,8 +189,11 @@ export default class DMRoomMap {
|
|||
if (!this.roomToUser) return {}; // No rooms means no map.
|
||||
return Object.keys(this.roomToUser)
|
||||
.map((r) => ({ userId: this.getUserIdForRoomId(r), room: this.matrixClient.getRoom(r) }))
|
||||
.filter((r) => r.userId && r.room && r.room.getInvitedAndJoinedMemberCount() === 2)
|
||||
.reduce((obj, r) => (obj[r.userId] = r.room) && obj, {} as Record<string, Room>);
|
||||
.filter((r) => r.userId && r.room?.getInvitedAndJoinedMemberCount() === 2)
|
||||
.reduce((obj, r) => {
|
||||
obj[r.userId] = r.room;
|
||||
return obj;
|
||||
}, {} as Record<string, Room>);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -141,8 +141,8 @@ export default class MultiInviter {
|
|||
return this.completionStates[addr];
|
||||
}
|
||||
|
||||
public getErrorText(addr: string): string {
|
||||
return this.errors[addr] ? this.errors[addr].errorText : null;
|
||||
public getErrorText(addr: string): string | null {
|
||||
return this.errors[addr]?.errorText ?? null;
|
||||
}
|
||||
|
||||
private async inviteToRoom(roomId: string, addr: string, ignoreProfile = false): Promise<{}> {
|
||||
|
|
|
@ -37,7 +37,7 @@ export function abbreviateUrl(u: string): string {
|
|||
return u;
|
||||
}
|
||||
|
||||
export function unabbreviateUrl(u: string): string {
|
||||
export function unabbreviateUrl(u?: string): string {
|
||||
if (!u) return "";
|
||||
|
||||
let longUrl = u;
|
||||
|
|
|
@ -450,7 +450,7 @@ export default class WidgetUtils {
|
|||
oobRoomName?: string,
|
||||
): Promise<void> {
|
||||
const domain = Jitsi.getInstance().preferredDomain;
|
||||
const auth = await Jitsi.getInstance().getJitsiAuth();
|
||||
const auth = (await Jitsi.getInstance().getJitsiAuth()) ?? undefined;
|
||||
const widgetId = randomString(24); // Must be globally unique
|
||||
|
||||
let confId;
|
||||
|
|
|
@ -29,14 +29,11 @@ import { findDMForUser } from "./findDMForUser";
|
|||
*/
|
||||
export function findDMRoom(client: MatrixClient, targets: Member[]): Room | null {
|
||||
const targetIds = targets.map((t) => t.userId);
|
||||
let existingRoom: Room | undefined;
|
||||
let existingRoom: Room | null;
|
||||
if (targetIds.length === 1) {
|
||||
existingRoom = findDMForUser(client, targetIds[0]);
|
||||
existingRoom = findDMForUser(client, targetIds[0]) ?? null;
|
||||
} else {
|
||||
existingRoom = DMRoomMap.shared().getDMRoomForIdentifiers(targetIds);
|
||||
}
|
||||
if (existingRoom) {
|
||||
return existingRoom;
|
||||
}
|
||||
return null;
|
||||
return existingRoom;
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ export default abstract class Exporter {
|
|||
let limit: number;
|
||||
switch (this.exportType) {
|
||||
case ExportType.LastNMessages:
|
||||
limit = this.exportOptions.numberOfMessages;
|
||||
limit = this.exportOptions.numberOfMessages!;
|
||||
break;
|
||||
case ExportType.Timeline:
|
||||
limit = 40;
|
||||
|
@ -221,11 +221,11 @@ export default abstract class Exporter {
|
|||
return events;
|
||||
}
|
||||
|
||||
protected async getMediaBlob(event: MatrixEvent): Promise<Blob> {
|
||||
let blob: Blob;
|
||||
protected async getMediaBlob(event: MatrixEvent): Promise<Blob | undefined> {
|
||||
let blob: Blob | undefined;
|
||||
try {
|
||||
const isEncrypted = event.isEncrypted();
|
||||
const content: IMediaEventContent = event.getContent();
|
||||
const content = event.getContent<IMediaEventContent>();
|
||||
const shouldDecrypt = isEncrypted && content.hasOwnProperty("file") && event.getType() !== "m.sticker";
|
||||
if (shouldDecrypt) {
|
||||
blob = await decryptFile(content.file);
|
||||
|
|
|
@ -45,7 +45,7 @@ export default class JSONExporter extends Exporter {
|
|||
protected createJSONString(): string {
|
||||
const exportDate = formatFullDateNoDayNoTime(new Date());
|
||||
const creator = this.room.currentState.getStateEvents(EventType.RoomCreate, "")?.getSender();
|
||||
const creatorName = this.room?.getMember(creator)?.rawDisplayName || creator;
|
||||
const creatorName = (creator && this.room?.getMember(creator)?.rawDisplayName) || creator;
|
||||
const topic = this.room.currentState.getStateEvents(EventType.RoomTopic, "")?.getContent()?.topic || "";
|
||||
const exporter = this.client.getUserId()!;
|
||||
const exporterName = this.room?.getMember(exporter)?.rawDisplayName || exporter;
|
||||
|
|
|
@ -19,6 +19,7 @@ import React, { ReactNode } from "react";
|
|||
import { EventStatus } from "matrix-js-sdk/src/models/event-status";
|
||||
import { MatrixEventEvent } from "matrix-js-sdk/src/models/event";
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { MatrixError } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import Modal, { IHandle } from "../Modal";
|
||||
import Spinner from "../components/views/elements/Spinner";
|
||||
|
@ -87,7 +88,7 @@ export async function leaveRoomBehaviour(roomId: string, retry = true, spinner =
|
|||
),
|
||||
);
|
||||
|
||||
let results: { [roomId: string]: Error & { errcode?: string; message: string; data?: Record<string, any> } } = {};
|
||||
let results: { [roomId: string]: Error | MatrixError | null } = {};
|
||||
if (!leavingAllVersions) {
|
||||
try {
|
||||
await cli.leave(roomId);
|
||||
|
@ -104,7 +105,9 @@ export async function leaveRoomBehaviour(roomId: string, retry = true, spinner =
|
|||
}
|
||||
|
||||
if (retry) {
|
||||
const limitExceededError = Object.values(results).find((e) => e?.errcode === "M_LIMIT_EXCEEDED");
|
||||
const limitExceededError = Object.values(results).find(
|
||||
(e) => (e as MatrixError)?.errcode === "M_LIMIT_EXCEEDED",
|
||||
) as MatrixError;
|
||||
if (limitExceededError) {
|
||||
await sleep(limitExceededError.data.retry_after_ms ?? 100);
|
||||
return leaveRoomBehaviour(roomId, false, false);
|
||||
|
@ -117,9 +120,9 @@ export async function leaveRoomBehaviour(roomId: string, retry = true, spinner =
|
|||
if (errors.length > 0) {
|
||||
const messages: ReactNode[] = [];
|
||||
for (const roomErr of errors) {
|
||||
const err = roomErr[1]; // [0] is the roomId
|
||||
const err = roomErr[1] as MatrixError; // [0] is the roomId
|
||||
let message = _t("Unexpected server error trying to leave the room");
|
||||
if (err.errcode && err.message) {
|
||||
if (err?.errcode && err.message) {
|
||||
if (err.errcode === "M_CANNOT_LEAVE_SERVER_NOTICE_ROOM") {
|
||||
Modal.createDialog(ErrorDialog, {
|
||||
title: _t("Can't leave Server Notices room"),
|
||||
|
@ -130,7 +133,7 @@ export async function leaveRoomBehaviour(roomId: string, retry = true, spinner =
|
|||
});
|
||||
return;
|
||||
}
|
||||
message = results[roomId].message;
|
||||
message = results[roomId]!.message;
|
||||
}
|
||||
messages.push(message, React.createElement("BR")); // createElement to avoid using a tsx file in utils
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ export const makeMapSiteLink = (coords: GeolocationCoordinates): string => {
|
|||
);
|
||||
};
|
||||
|
||||
export const createMapSiteLinkFromEvent = (event: MatrixEvent): string => {
|
||||
export const createMapSiteLinkFromEvent = (event: MatrixEvent): string | null => {
|
||||
const content = event.getContent();
|
||||
const mLocation = content[M_LOCATION.name];
|
||||
if (mLocation !== undefined) {
|
||||
|
|
|
@ -192,7 +192,7 @@ export class RoomPermalinkCreator {
|
|||
isHostInRegex(domain, this.allowedHostsRegexps)
|
||||
);
|
||||
});
|
||||
const maxEntry = allowedEntries.reduce(
|
||||
const maxEntry = allowedEntries.reduce<[string | null, number]>(
|
||||
(max, entry) => {
|
||||
return entry[1] > max[1] ? entry : max;
|
||||
},
|
||||
|
@ -329,7 +329,7 @@ export function tryTransformEntityToPermalink(entity: string): string | null {
|
|||
if (permalinkParts.roomIdOrAlias) {
|
||||
const eventIdPart = permalinkParts.eventId ? `/${permalinkParts.eventId}` : "";
|
||||
let pl = matrixtoBaseUrl + `/#/${permalinkParts.roomIdOrAlias}${eventIdPart}`;
|
||||
if (permalinkParts.viaServers.length > 0) {
|
||||
if (permalinkParts.viaServers?.length) {
|
||||
pl += new MatrixToPermalinkConstructor().encodeServerCandidates(permalinkParts.viaServers);
|
||||
}
|
||||
return pl;
|
||||
|
@ -376,7 +376,7 @@ export function tryTransformPermalinkToLocalHref(permalink: string): string {
|
|||
if (permalinkParts.roomIdOrAlias) {
|
||||
const eventIdPart = permalinkParts.eventId ? `/${permalinkParts.eventId}` : "";
|
||||
permalink = `#/room/${permalinkParts.roomIdOrAlias}${eventIdPart}`;
|
||||
if (permalinkParts.viaServers.length > 0) {
|
||||
if (permalinkParts.viaServers?.length) {
|
||||
permalink += new MatrixToPermalinkConstructor().encodeServerCandidates(permalinkParts.viaServers);
|
||||
}
|
||||
} else if (permalinkParts.userId) {
|
||||
|
@ -475,7 +475,7 @@ function isHostnameIpAddress(hostname: string): boolean {
|
|||
return isIp(hostname);
|
||||
}
|
||||
|
||||
export const calculateRoomVia = (room: Room): string[] => {
|
||||
export const calculateRoomVia = (room: Room): string[] | undefined => {
|
||||
const permalinkCreator = new RoomPermalinkCreator(room);
|
||||
permalinkCreator.load();
|
||||
return permalinkCreator.serverCandidates;
|
||||
|
|
|
@ -84,7 +84,7 @@ export const showCreateNewRoom = async (space: Room, type?: RoomType): Promise<b
|
|||
if (shouldCreate) {
|
||||
await createRoom(opts);
|
||||
}
|
||||
return shouldCreate;
|
||||
return !!shouldCreate;
|
||||
};
|
||||
|
||||
export const shouldShowSpaceInvite = (space: Room): boolean =>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue