diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 50ca8d622..7bad5c817 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -138,6 +138,7 @@ module.exports = { tryExtensions: [".ts"], }, ], + "no-extra-boolean-cast": "error", }, }, { diff --git a/spec/integ/matrix-client-methods.spec.ts b/spec/integ/matrix-client-methods.spec.ts index b5347e3b5..d5ec9677b 100644 --- a/spec/integ/matrix-client-methods.spec.ts +++ b/spec/integ/matrix-client-methods.spec.ts @@ -1915,6 +1915,28 @@ describe("MatrixClient", function () { return prom; }); }); + + describe("getDomain", () => { + it("should return null if no userId is set", () => { + const client = new MatrixClient({ baseUrl: "http://localhost" }); + expect(client.getDomain()).toBeNull(); + }); + + it("should return the domain of the userId", () => { + expect(client.getDomain()).toBe("localhost"); + }); + }); + + describe("getUserIdLocalpart", () => { + it("should return null if no userId is set", () => { + const client = new MatrixClient({ baseUrl: "http://localhost" }); + expect(client.getUserIdLocalpart()).toBeNull(); + }); + + it("should return the localpart of the userId", () => { + expect(client.getUserIdLocalpart()).toBe("alice"); + }); + }); }); function withThreadId(event: MatrixEvent, newThreadId: string): MatrixEvent { diff --git a/spec/test-utils/webrtc.ts b/spec/test-utils/webrtc.ts index fbc6d93be..924d024ca 100644 --- a/spec/test-utils/webrtc.ts +++ b/spec/test-utils/webrtc.ts @@ -481,6 +481,9 @@ export class MockCallMatrixClient extends TypedEventEmitter { - client = new MatrixClient({ baseUrl: "base_url" }); + client = new MatrixClient({ baseUrl: "base_url", userId: "my_user_id" }); jest.spyOn(client, "sendStateEvent").mockResolvedValue({} as any); }); diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index 0b51c2b22..5a280f0e2 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -65,6 +65,6 @@ declare global { interface Navigator { // We check for the webkit-prefixed getUserMedia to detect if we're // on webkit: we should check if we still need to do this - webkitGetUserMedia: DummyInterfaceWeShouldntBeUsingThis; + webkitGetUserMedia?: DummyInterfaceWeShouldntBeUsingThis; } } diff --git a/src/autodiscovery.ts b/src/autodiscovery.ts index b321dcddc..d9243e4da 100644 --- a/src/autodiscovery.ts +++ b/src/autodiscovery.ts @@ -130,7 +130,7 @@ export class AutoDiscovery { * configuration, which may include error states. Rejects on unexpected * failure, not when verification fails. */ - public static async fromDiscoveryConfig(wellknown: IClientWellKnown): Promise { + public static async fromDiscoveryConfig(wellknown?: IClientWellKnown): Promise { // Step 1 is to get the config, which is provided to us here. // We default to an error state to make the first few checks easier to diff --git a/src/client.ts b/src/client.ts index 5ef823a29..478e2784e 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1832,10 +1832,7 @@ export class MatrixClient extends TypedEventEmitter { diff --git a/src/crypto/store/localStorage-crypto-store.ts b/src/crypto/store/localStorage-crypto-store.ts index d24e648d6..818a83140 100644 --- a/src/crypto/store/localStorage-crypto-store.ts +++ b/src/crypto/store/localStorage-crypto-store.ts @@ -162,7 +162,7 @@ export class LocalStorageCryptoStore extends MemoryCryptoStore implements Crypto func: (session: ISessionInfo) => void, ): void { const sessions = this._getEndToEndSessions(deviceKey); - func(sessions[sessionId] || {}); + func(sessions[sessionId] ?? {}); } public getEndToEndSessions( @@ -170,7 +170,7 @@ export class LocalStorageCryptoStore extends MemoryCryptoStore implements Crypto txn: unknown, func: (sessions: { [sessionId: string]: ISessionInfo }) => void, ): void { - func(this._getEndToEndSessions(deviceKey) || {}); + func(this._getEndToEndSessions(deviceKey) ?? {}); } public getAllEndToEndSessions(txn: unknown, func: (session: ISessionInfo) => void): void { diff --git a/src/models/event.ts b/src/models/event.ts index 5ce7e9fb9..bdb75f5ea 100644 --- a/src/models/event.ts +++ b/src/models/event.ts @@ -559,9 +559,9 @@ export class MatrixEvent extends TypedEventEmitter { const list = this.lists.get(key); if (!list || !resp) { @@ -934,7 +934,7 @@ export class SlidingSync extends TypedEventEmitter = new Set(); if (!doNotUpdateList) { for (const [key, list] of Object.entries(resp.lists)) { - list.ops = list.ops || []; + list.ops = list.ops ?? []; if (list.ops.length > 0) { listKeysWithUpdates.add(key); } diff --git a/src/store/indexeddb.ts b/src/store/indexeddb.ts index dfed00df2..8705f4a5c 100644 --- a/src/store/indexeddb.ts +++ b/src/store/indexeddb.ts @@ -42,7 +42,7 @@ const WRITE_DELAY_MS = 1000 * 60 * 5; // once every 5 minutes interface IOpts extends IBaseOpts { /** The Indexed DB interface e.g. `window.indexedDB` */ - indexedDB: IDBFactory; + indexedDB?: IDBFactory; /** Optional database name. The same name must be used to open the same database. */ dbName?: string; /** Optional factory to spin up a Worker to execute the IDB transactions within. */ diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index c2b24cadb..c1203e247 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -3016,9 +3016,9 @@ export function supportsMatrixCall(): boolean { // is that the browser throwing a SecurityError will brick the client creation process. try { const supported = Boolean( - window.RTCPeerConnection || - window.RTCSessionDescription || - window.RTCIceCandidate || + window.RTCPeerConnection ?? + window.RTCSessionDescription ?? + window.RTCIceCandidate ?? navigator.mediaDevices, ); if (!supported) { diff --git a/src/webrtc/groupCall.ts b/src/webrtc/groupCall.ts index 6f0266d4a..0d2538538 100644 --- a/src/webrtc/groupCall.ts +++ b/src/webrtc/groupCall.ts @@ -1445,7 +1445,7 @@ export class GroupCall extends TypedEventEmitter< * Recalculates and updates the participant map to match the room state. */ private updateParticipants(): void { - const localMember = this.room.getMember(this.client.getUserId()!)!; + const localMember = this.room.getMember(this.client.getSafeUserId()); if (!localMember) { // The client hasn't fetched enough of the room state to get our own member // event. This probably shouldn't happen, but sanity check & exit for now. diff --git a/src/webrtc/stats/callFeedStatsReporter.ts b/src/webrtc/stats/callFeedStatsReporter.ts index d219f7172..e78438acb 100644 --- a/src/webrtc/stats/callFeedStatsReporter.ts +++ b/src/webrtc/stats/callFeedStatsReporter.ts @@ -49,8 +49,8 @@ export class CallFeedStatsReporter { return { id: track.id, kind: track.kind, - settingDeviceId: settingDeviceId ? settingDeviceId : "unknown", - constrainDeviceId: constrainDeviceId ? constrainDeviceId : "unknown", + settingDeviceId: settingDeviceId ?? "unknown", + constrainDeviceId: constrainDeviceId ?? "unknown", muted: track.muted, enabled: track.enabled, readyState: track.readyState, @@ -63,9 +63,6 @@ export class CallFeedStatsReporter { callFeeds: CallFeed[], prefix = "unknown", ): CallFeedReport { - if (!report.callFeeds) { - report.callFeeds = []; - } callFeeds.forEach((feed) => { const audioTracks = feed.stream.getAudioTracks(); const videoTracks = feed.stream.getVideoTracks(); diff --git a/src/webrtc/stats/media/mediaTrackHandler.ts b/src/webrtc/stats/media/mediaTrackHandler.ts index 31f1264b3..8d2108c0b 100644 --- a/src/webrtc/stats/media/mediaTrackHandler.ts +++ b/src/webrtc/stats/media/mediaTrackHandler.ts @@ -49,18 +49,12 @@ export class MediaTrackHandler { public getLocalTrackIdByMid(mid: string): string | undefined { const transceiver = this.pc.getTransceivers().find((t) => t.mid === mid); - if (transceiver !== undefined && !!transceiver.sender && !!transceiver.sender.track) { - return transceiver.sender.track.id; - } - return undefined; + return transceiver?.sender?.track?.id; } public getRemoteTrackIdByMid(mid: string): string | undefined { const transceiver = this.pc.getTransceivers().find((t) => t.mid === mid); - if (transceiver !== undefined && !!transceiver.receiver && !!transceiver.receiver.track) { - return transceiver.receiver.track.id; - } - return undefined; + return transceiver?.receiver?.track?.id; } public getActiveSimulcastStreams(): number {