Use mapped types around account data events (#28752)
* Use mapped types around account data events --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
committed by
GitHub
parent
baaed75c4b
commit
be181d2c79
@@ -20,7 +20,7 @@ export function setToDefaultIdentityServer(matrixClient: MatrixClient): void {
|
||||
const url = getDefaultIdentityServerUrl();
|
||||
// Account data change will update localstorage, client, etc through dispatcher
|
||||
matrixClient.setAccountData("m.identity_server", {
|
||||
base_url: url,
|
||||
base_url: url ?? null,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
32
src/utils/WidgetUtils-types.ts
Normal file
32
src/utils/WidgetUtils-types.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
Copyright 2024 New Vector Ltd.
|
||||
Copyright 2017-2020 The Matrix.org Foundation C.I.C.
|
||||
Copyright 2019 Travis Ralston
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { IWidget } from "matrix-widget-api";
|
||||
|
||||
export interface IApp extends IWidget {
|
||||
"roomId": string;
|
||||
"eventId"?: string; // not present on virtual widgets
|
||||
// eslint-disable-next-line camelcase
|
||||
"avatar_url"?: string; // MSC2765 https://github.com/matrix-org/matrix-doc/pull/2765
|
||||
// Whether the widget was created from `widget_build_url` and thus is a call widget of some kind
|
||||
"io.element.managed_hybrid"?: boolean;
|
||||
}
|
||||
|
||||
export interface IWidgetEvent {
|
||||
id: string;
|
||||
type: string;
|
||||
sender: string;
|
||||
// eslint-disable-next-line camelcase
|
||||
state_key: string;
|
||||
content: IApp;
|
||||
}
|
||||
|
||||
export interface UserWidget extends Omit<IWidgetEvent, "content"> {
|
||||
content: IWidget & Partial<IApp>;
|
||||
}
|
||||
@@ -29,23 +29,13 @@ import WidgetStore, { IApp, isAppWidget } from "../stores/WidgetStore";
|
||||
import { parseUrl } from "./UrlUtils";
|
||||
import { useEventEmitter } from "../hooks/useEventEmitter";
|
||||
import { WidgetLayoutStore } from "../stores/widgets/WidgetLayoutStore";
|
||||
import { IWidgetEvent, UserWidget } from "./WidgetUtils-types";
|
||||
|
||||
// How long we wait for the state event echo to come back from the server
|
||||
// before waitFor[Room/User]Widget rejects its promise
|
||||
const WIDGET_WAIT_TIME = 20000;
|
||||
|
||||
export interface IWidgetEvent {
|
||||
id: string;
|
||||
type: string;
|
||||
sender: string;
|
||||
// eslint-disable-next-line camelcase
|
||||
state_key: string;
|
||||
content: IApp;
|
||||
}
|
||||
|
||||
export interface UserWidget extends Omit<IWidgetEvent, "content"> {
|
||||
content: IWidget & Partial<IApp>;
|
||||
}
|
||||
export type { IWidgetEvent, UserWidget };
|
||||
|
||||
export default class WidgetUtils {
|
||||
/**
|
||||
|
||||
@@ -6,17 +6,14 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import { AccountDataEvents, MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import BasePlatform from "../../BasePlatform";
|
||||
import { IConfigOptions } from "../../IConfigOptions";
|
||||
import { DeepReadonly } from "../../@types/common";
|
||||
import { DeviceClientInformation } from "./types";
|
||||
|
||||
export type DeviceClientInformation = {
|
||||
name?: string;
|
||||
version?: string;
|
||||
url?: string;
|
||||
};
|
||||
export type { DeviceClientInformation };
|
||||
|
||||
const formatUrl = (): string | undefined => {
|
||||
// don't record url for electron clients
|
||||
@@ -34,7 +31,8 @@ const formatUrl = (): string | undefined => {
|
||||
};
|
||||
|
||||
const clientInformationEventPrefix = "io.element.matrix_client_information.";
|
||||
export const getClientInformationEventType = (deviceId: string): string => `${clientInformationEventPrefix}${deviceId}`;
|
||||
export const getClientInformationEventType = (deviceId: string): `${typeof clientInformationEventPrefix}${string}` =>
|
||||
`${clientInformationEventPrefix}${deviceId}`;
|
||||
|
||||
/**
|
||||
* Record extra client information for the current device
|
||||
@@ -70,7 +68,7 @@ export const pruneClientInformation = (validDeviceIds: string[], matrixClient: M
|
||||
}
|
||||
const [, deviceId] = event.getType().split(clientInformationEventPrefix);
|
||||
if (deviceId && !validDeviceIds.includes(deviceId)) {
|
||||
matrixClient.deleteAccountData(event.getType());
|
||||
matrixClient.deleteAccountData(event.getType() as keyof AccountDataEvents);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
13
src/utils/device/types.ts
Normal file
13
src/utils/device/types.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
Copyright 2024 New Vector Ltd.
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
export type DeviceClientInformation = {
|
||||
name?: string;
|
||||
version?: string;
|
||||
url?: string;
|
||||
};
|
||||
@@ -40,7 +40,9 @@ export const deviceNotificationSettingsKeys = [
|
||||
"audioNotificationsEnabled",
|
||||
];
|
||||
|
||||
export function getLocalNotificationAccountDataEventType(deviceId: string | null): string {
|
||||
export function getLocalNotificationAccountDataEventType(
|
||||
deviceId: string | null,
|
||||
): `${typeof LOCAL_NOTIFICATION_SETTINGS_PREFIX.name}.${string}` {
|
||||
return `${LOCAL_NOTIFICATION_SETTINGS_PREFIX.name}.${deviceId}`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user