Device manager - display client information in device details (PSG-682) (#9315)

* record device client inforamtion events on app start

* matrix-client-information -> matrix_client_information

* fix types

* remove another unused export

* add docs link

* display device client information in device details

* update snapshots

* integration-ish test client information in metadata

* tests

* fix tests

* export helper

* DeviceClientInformation type
This commit is contained in:
Kerry 2022-10-04 15:12:23 +02:00 committed by GitHub
parent c7a3209b84
commit 16c3efead5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 210 additions and 109 deletions

View file

@ -19,6 +19,12 @@ import { MatrixClient } from "matrix-js-sdk/src/client";
import BasePlatform from "../../BasePlatform";
import { IConfigOptions } from "../../IConfigOptions";
export type DeviceClientInformation = {
name?: string;
version?: string;
url?: string;
};
const formatUrl = (): string | undefined => {
// don't record url for electron clients
if (window.electron) {
@ -34,7 +40,7 @@ const formatUrl = (): string | undefined => {
].join("");
};
const getClientInformationEventType = (deviceId: string): string =>
export const getClientInformationEventType = (deviceId: string): string =>
`io.element.matrix_client_information.${deviceId}`;
/**
@ -58,3 +64,23 @@ export const recordClientInformation = async (
url,
});
};
const sanitizeContentString = (value: unknown): string | undefined =>
value && typeof value === 'string' ? value : undefined;
export const getDeviceClientInformation = (matrixClient: MatrixClient, deviceId: string): DeviceClientInformation => {
const event = matrixClient.getAccountData(getClientInformationEventType(deviceId));
if (!event) {
return {};
}
const { name, version, url } = event.getContent();
return {
name: sanitizeContentString(name),
version: sanitizeContentString(version),
url: sanitizeContentString(url),
};
};