From 12063edd7f2bfa24f14cc72dbe33879331a08362 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 12 Dec 2022 16:27:28 +1300 Subject: [PATCH] use deleteAccountData to prune device manager client information events --- src/utils/device/clientInformation.ts | 4 ++-- test/DeviceListener-test.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utils/device/clientInformation.ts b/src/utils/device/clientInformation.ts index 5c9b65b54bc..1f9b755ba8e 100644 --- a/src/utils/device/clientInformation.ts +++ b/src/utils/device/clientInformation.ts @@ -77,9 +77,9 @@ export const removeClientInformation = async ( const type = getClientInformationEventType(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) { - await matrixClient.setAccountData(type, {}); + await matrixClient.deleteAccountData(type); } }; diff --git a/test/DeviceListener-test.ts b/test/DeviceListener-test.ts index 20adbfd45dc..a4ce1d96abf 100644 --- a/test/DeviceListener-test.ts +++ b/test/DeviceListener-test.ts @@ -96,6 +96,7 @@ describe('DeviceListener', () => { getDeviceId: jest.fn().mockReturnValue(deviceId), setAccountData: jest.fn(), getAccountData: jest.fn(), + deleteAccountData: jest.fn(), checkDeviceTrust: jest.fn().mockReturnValue(new DeviceTrustLevel(false, false, false, false)), }); jest.spyOn(MatrixClientPeg, 'get').mockReturnValue(mockClient); @@ -192,9 +193,8 @@ describe('DeviceListener', () => { mockClient!.getAccountData.mockReturnValue(clientInfoEvent); await createAndStart(); - expect(mockClient!.setAccountData).toHaveBeenCalledWith( + expect(mockClient!.deleteAccountData).toHaveBeenCalledWith( `io.element.matrix_client_information.${deviceId}`, - {}, ); }); @@ -202,7 +202,7 @@ describe('DeviceListener', () => { mockClient!.getAccountData.mockReturnValue(emptyClientInfoEvent); await createAndStart(); - expect(mockClient!.setAccountData).not.toHaveBeenCalled(); + expect(mockClient!.deleteAccountData).not.toHaveBeenCalled(); }); it('does not save client information on logged in action', async () => {