diff --git a/src/Login.ts b/src/Login.ts index cbaab1cb34..d5992af2ab 100644 --- a/src/Login.ts +++ b/src/Login.ts @@ -15,6 +15,7 @@ import { type ILoginFlow, type LoginRequest, type OidcClientConfig, + type ISSOFlow, } from "matrix-js-sdk/src/matrix"; import { logger } from "matrix-js-sdk/src/logger"; @@ -127,7 +128,7 @@ export default class Login { // If an m.login.sso flow is present which is also flagged as being for MSC3824 OIDC compatibility then we only // return that flow as (per MSC3824) it is the only one that the user should be offered to give the best experience const oidcCompatibilityFlow = flows.find( - (f) => f.type === "m.login.sso" && DELEGATED_OIDC_COMPATIBILITY.findIn(f), + (f) => f.type === "m.login.sso" && DELEGATED_OIDC_COMPATIBILITY.findIn(f as ISSOFlow), ); this.flows = oidcCompatibilityFlow ? [oidcCompatibilityFlow] : flows; return this.flows; diff --git a/src/components/views/dialogs/ForwardDialog.tsx b/src/components/views/dialogs/ForwardDialog.tsx index 19c84bc108..f97ccd61a2 100644 --- a/src/components/views/dialogs/ForwardDialog.tsx +++ b/src/components/views/dialogs/ForwardDialog.tsx @@ -213,7 +213,7 @@ const transformEvent = (event: MatrixEvent, cli: MatrixClient): { type: string; // beacon pulses get transformed into static locations on forward M_BEACON.matches(event.getType()) ) { - const timestamp = M_TIMESTAMP.findIn(content); + const timestamp = M_TIMESTAMP.findIn(content as ILocationContent); const geoUri = locationEventGeoUri(event); return { type, diff --git a/src/components/views/dialogs/devtools/AccountData.tsx b/src/components/views/dialogs/devtools/AccountData.tsx index 6900a7097e..e4e1ffe769 100644 --- a/src/components/views/dialogs/devtools/AccountData.tsx +++ b/src/components/views/dialogs/devtools/AccountData.tsx @@ -8,7 +8,12 @@ Please see LICENSE files in the repository root for full details. */ import React, { useContext, useMemo, useState } from "react"; -import { type AccountDataEvents, type IContent, type MatrixEvent } from "matrix-js-sdk/src/matrix"; +import { + type AccountDataEvents, + type IContent, + type MatrixEvent, + type RoomAccountDataEvents, +} from "matrix-js-sdk/src/matrix"; import BaseTool, { DevtoolsContext, type IDevtoolsProps } from "./BaseTool"; import MatrixClientContext from "../../../../contexts/MatrixClientContext"; @@ -35,7 +40,7 @@ export const RoomAccountDataEventEditor: React.FC = ({ mxEvent, on const fields = useMemo(() => [eventTypeField(mxEvent?.getType())], [mxEvent]); - const onSend = async ([eventType]: string[], content?: IContent): Promise => { + const onSend = async ([eventType]: Array, content?: IContent): Promise => { await cli.setRoomAccountData(context.room.roomId, eventType, content || {}); }; diff --git a/src/components/views/right_panel/types.ts b/src/components/views/right_panel/types.ts index 09965a2a10..da48795aca 100644 --- a/src/components/views/right_panel/types.ts +++ b/src/components/views/right_panel/types.ts @@ -7,3 +7,9 @@ Please see LICENSE files in the repository root for full details. */ export const ReadPinsEventId = "im.vector.room.read_pins"; + +declare module "matrix-js-sdk/src/types" { + interface RoomAccountDataEvents { + [ReadPinsEventId]: { event_ids: string[] }; + } +} diff --git a/src/settings/controllers/MediaPreviewConfigController.ts b/src/settings/controllers/MediaPreviewConfigController.ts index cb8b9b34aa..d349ef33fa 100644 --- a/src/settings/controllers/MediaPreviewConfigController.ts +++ b/src/settings/controllers/MediaPreviewConfigController.ts @@ -16,6 +16,12 @@ import { import { type SettingLevel } from "../SettingLevel.ts"; import MatrixClientBackedController from "./MatrixClientBackedController.ts"; +declare module "matrix-js-sdk/src/types" { + interface RoomAccountDataEvents { + [MEDIA_PREVIEW_ACCOUNT_DATA_TYPE]: MediaPreviewConfig; + } +} + /** * Handles media preview settings provided by MSC4278. * This uses both account-level and room-level account data. diff --git a/src/settings/handlers/RoomAccountSettingsHandler.ts b/src/settings/handlers/RoomAccountSettingsHandler.ts index 6ed09a9801..939c267a15 100644 --- a/src/settings/handlers/RoomAccountSettingsHandler.ts +++ b/src/settings/handlers/RoomAccountSettingsHandler.ts @@ -7,7 +7,13 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com Please see LICENSE files in the repository root for full details. */ -import { type MatrixClient, type MatrixEvent, type Room, RoomEvent } from "matrix-js-sdk/src/matrix"; +import { + type RoomAccountDataEvents, + type MatrixClient, + type MatrixEvent, + type Room, + RoomEvent, +} from "matrix-js-sdk/src/matrix"; import MatrixClientBackedSettingsHandler from "./MatrixClientBackedSettingsHandler"; import { objectClone, objectKeyChanges } from "../../utils/objects"; @@ -18,6 +24,14 @@ import { MEDIA_PREVIEW_ACCOUNT_DATA_TYPE } from "../../@types/media_preview"; const ALLOWED_WIDGETS_EVENT_TYPE = "im.vector.setting.allowed_widgets"; const DEFAULT_SETTINGS_EVENT_TYPE = "im.vector.web.settings"; +declare module "matrix-js-sdk/src/types" { + interface RoomAccountDataEvents { + [ALLOWED_WIDGETS_EVENT_TYPE]: { [eventId: string]: boolean }; + [DEFAULT_SETTINGS_EVENT_TYPE]: Record; + "org.matrix.room.preview_urls": { disable: boolean }; + } +} + /** * Gets and sets settings at the "room-account" level for the current user. */ @@ -81,11 +95,11 @@ export default class RoomAccountSettingsHandler extends MatrixClientBackedSettin } // helper function to send room account data then await it being echoed back - private async setRoomAccountData( + private async setRoomAccountData( roomId: string, - eventType: string, - field: string | null, - value: any, + eventType: K, + field: F | null, + value: RoomAccountDataEvents[K][F], ): Promise { let content: ReturnType; @@ -101,7 +115,7 @@ export default class RoomAccountSettingsHandler extends MatrixClientBackedSettin const deferred = Promise.withResolvers(); const handler = (event: MatrixEvent, room: Room): void => { if (room.roomId !== roomId || event.getType() !== eventType) return; - if (field !== null && event.getContent()[field] !== value) return; + if (field !== null && event.getContent>()[field] !== value) return; this.client.off(RoomEvent.AccountData, handler); deferred.resolve(); }; diff --git a/src/stores/spaces/SpaceStore.ts b/src/stores/spaces/SpaceStore.ts index c0b9a92159..98006ac905 100644 --- a/src/stores/spaces/SpaceStore.ts +++ b/src/stores/spaces/SpaceStore.ts @@ -1406,7 +1406,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient { return sortBy(spaces, [this.getSpaceTagOrdering, "roomId"]); } - private async setRootSpaceOrder(space: Room, order?: string): Promise { + private async setRootSpaceOrder(space: Room, order: string): Promise { this.spaceOrderLocalEchoMap.set(space.roomId, order); try { await this.matrixClient?.setRoomAccountData(space.roomId, EventType.SpaceOrder, { order }); diff --git a/src/utils/location/locationEventGeoUri.ts b/src/utils/location/locationEventGeoUri.ts index 7648120102..f4d206712e 100644 --- a/src/utils/location/locationEventGeoUri.ts +++ b/src/utils/location/locationEventGeoUri.ts @@ -6,7 +6,9 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com Please see LICENSE files in the repository root for full details. */ -import { type MatrixEvent, M_LOCATION } from "matrix-js-sdk/src/matrix"; +import { type MatrixEvent, M_LOCATION, type MLocationEvent } from "matrix-js-sdk/src/matrix"; + +type LocationEvent = { geo_uri: string } & MLocationEvent; /** * Find the geo-URI contained within a location event. @@ -16,7 +18,7 @@ export const locationEventGeoUri = (mxEvent: MatrixEvent): string => { // events until the end of days, or until we figure out mutable // events - so folks can read their old chat history correctly. // https://github.com/matrix-org/matrix-doc/issues/3516 - const content = mxEvent.getContent(); - const loc = M_LOCATION.findIn(content) as { uri?: string }; + const content = mxEvent.getContent(); + const loc = M_LOCATION.findIn(content); return loc?.uri ?? content["geo_uri"]; }; diff --git a/src/utils/notifications.ts b/src/utils/notifications.ts index ebfd7e90f6..9fab246a55 100644 --- a/src/utils/notifications.ts +++ b/src/utils/notifications.ts @@ -15,6 +15,7 @@ import { ReceiptType, type IMarkedUnreadEvent, type EmptyObject, + EventType, } from "matrix-js-sdk/src/matrix"; import { type IndicatorIcon } from "@vector-im/compound-web"; @@ -34,7 +35,13 @@ export const MARKED_UNREAD_TYPE_UNSTABLE = "com.famedly.marked_unread"; /** * Stable identifier for the marked_unread event */ -export const MARKED_UNREAD_TYPE_STABLE = "m.marked_unread"; +export const MARKED_UNREAD_TYPE_STABLE = EventType.MarkedUnread; + +declare module "matrix-js-sdk/src/types" { + interface RoomAccountDataEvents { + [MARKED_UNREAD_TYPE_UNSTABLE]: { [eventId: string]: boolean }; + } +} export const deviceNotificationSettingsKeys: SettingKey[] = [ "notificationsEnabled", @@ -157,7 +164,7 @@ export async function setMarkedUnreadState(room: Room, client: MatrixClient, unr const currentState = getMarkedUnreadState(room); if (Boolean(currentState) !== unread) { - await client.setRoomAccountData(room.roomId, MARKED_UNREAD_TYPE_STABLE, { unread }); + await client.setRoomAccountData(room.roomId, EventType.MarkedUnread, { unread }); } } diff --git a/src/utils/stringOrderField.ts b/src/utils/stringOrderField.ts index b6ba8410e3..e8e3d18cfb 100644 --- a/src/utils/stringOrderField.ts +++ b/src/utils/stringOrderField.ts @@ -54,7 +54,7 @@ export const reorderLexicographically = ( fromIndex: number, toIndex: number, maxLen = 50, -): IEntry[] => { +): Required[] => { // sanity check inputs if (fromIndex < 0 || toIndex < 0 || fromIndex > orders.length || toIndex > orders.length || fromIndex === toIndex) { return [];