Update to matrix-js-sdk changes (#31871)

* Update to matrix-js-sdk changes

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Delint

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Simplify

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

---------

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2026-02-11 16:14:06 +00:00 committed by GitHub
parent df11e1ff2b
commit e1ec93d4bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 58 additions and 17 deletions

View File

@ -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;

View File

@ -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<number>(content);
const timestamp = M_TIMESTAMP.findIn<number>(content as ILocationContent);
const geoUri = locationEventGeoUri(event);
return {
type,

View File

@ -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<IEditorProps> = ({ mxEvent, on
const fields = useMemo(() => [eventTypeField(mxEvent?.getType())], [mxEvent]);
const onSend = async ([eventType]: string[], content?: IContent): Promise<void> => {
const onSend = async ([eventType]: Array<keyof RoomAccountDataEvents>, content?: IContent): Promise<void> => {
await cli.setRoomAccountData(context.room.roomId, eventType, content || {});
};

View File

@ -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[] };
}
}

View File

@ -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.

View File

@ -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<string, any>;
"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<K extends keyof RoomAccountDataEvents, F extends keyof RoomAccountDataEvents[K]>(
roomId: string,
eventType: string,
field: string | null,
value: any,
eventType: K,
field: F | null,
value: RoomAccountDataEvents[K][F],
): Promise<void> {
let content: ReturnType<RoomAccountSettingsHandler["getSettings"]>;
@ -101,7 +115,7 @@ export default class RoomAccountSettingsHandler extends MatrixClientBackedSettin
const deferred = Promise.withResolvers<void>();
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<Record<F, RoomAccountDataEvents[K][F]>>()[field] !== value) return;
this.client.off(RoomEvent.AccountData, handler);
deferred.resolve();
};

View File

@ -1406,7 +1406,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<EmptyObject> {
return sortBy(spaces, [this.getSpaceTagOrdering, "roomId"]);
}
private async setRootSpaceOrder(space: Room, order?: string): Promise<void> {
private async setRootSpaceOrder(space: Room, order: string): Promise<void> {
this.spaceOrderLocalEchoMap.set(space.roomId, order);
try {
await this.matrixClient?.setRoomAccountData(space.roomId, EventType.SpaceOrder, { order });

View File

@ -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<LocationEvent>();
const loc = M_LOCATION.findIn(content);
return loc?.uri ?? content["geo_uri"];
};

View File

@ -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 });
}
}

View File

@ -54,7 +54,7 @@ export const reorderLexicographically = (
fromIndex: number,
toIndex: number,
maxLen = 50,
): IEntry[] => {
): Required<IEntry>[] => {
// sanity check inputs
if (fromIndex < 0 || toIndex < 0 || fromIndex > orders.length || toIndex > orders.length || fromIndex === toIndex) {
return [];