mirror of
https://github.com/vector-im/element-web.git
synced 2026-03-02 20:12:04 +01:00
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:
parent
df11e1ff2b
commit
e1ec93d4bf
@ -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;
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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 || {});
|
||||
};
|
||||
|
||||
|
||||
@ -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[] };
|
||||
}
|
||||
}
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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();
|
||||
};
|
||||
|
||||
@ -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 });
|
||||
|
||||
@ -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"];
|
||||
};
|
||||
|
||||
@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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 [];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user