1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-08-06 10:22:45 +03:00

Device manager - use deleteAccountData to prune device manager client information events (#9734)

This commit is contained in:
Kerry
2022-12-14 17:59:23 +13:00
committed by GitHub
parent 85d43fffc4
commit aeb9f4373f
2 changed files with 5 additions and 5 deletions

View File

@@ -75,9 +75,9 @@ export const removeClientInformation = async (matrixClient: MatrixClient): Promi
const type = getClientInformationEventType(deviceId); const type = getClientInformationEventType(deviceId);
const clientInformation = getDeviceClientInformation(matrixClient, deviceId); const clientInformation = getDeviceClientInformation(matrixClient, deviceId);
// if a non-empty client info event exists, overwrite to remove the content // if a non-empty client info event exists, remove it
if (clientInformation.name || clientInformation.version || clientInformation.url) { if (clientInformation.name || clientInformation.version || clientInformation.url) {
await matrixClient.setAccountData(type, {}); await matrixClient.deleteAccountData(type);
} }
}; };

View File

@@ -96,6 +96,7 @@ describe("DeviceListener", () => {
getDeviceId: jest.fn().mockReturnValue(deviceId), getDeviceId: jest.fn().mockReturnValue(deviceId),
setAccountData: jest.fn(), setAccountData: jest.fn(),
getAccountData: jest.fn(), getAccountData: jest.fn(),
deleteAccountData: jest.fn(),
checkDeviceTrust: jest.fn().mockReturnValue(new DeviceTrustLevel(false, false, false, false)), checkDeviceTrust: jest.fn().mockReturnValue(new DeviceTrustLevel(false, false, false, false)),
}); });
jest.spyOn(MatrixClientPeg, "get").mockReturnValue(mockClient); jest.spyOn(MatrixClientPeg, "get").mockReturnValue(mockClient);
@@ -188,9 +189,8 @@ describe("DeviceListener", () => {
mockClient!.getAccountData.mockReturnValue(clientInfoEvent); mockClient!.getAccountData.mockReturnValue(clientInfoEvent);
await createAndStart(); await createAndStart();
expect(mockClient!.setAccountData).toHaveBeenCalledWith( expect(mockClient!.deleteAccountData).toHaveBeenCalledWith(
`io.element.matrix_client_information.${deviceId}`, `io.element.matrix_client_information.${deviceId}`,
{},
); );
}); });
@@ -198,7 +198,7 @@ describe("DeviceListener", () => {
mockClient!.getAccountData.mockReturnValue(emptyClientInfoEvent); mockClient!.getAccountData.mockReturnValue(emptyClientInfoEvent);
await createAndStart(); await createAndStart();
expect(mockClient!.setAccountData).not.toHaveBeenCalled(); expect(mockClient!.deleteAccountData).not.toHaveBeenCalled();
}); });
it("does not save client information on logged in action", async () => { it("does not save client information on logged in action", async () => {