Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit aeb9f43

Browse files
author
Kerry
authored
Device manager - use deleteAccountData to prune device manager client information events (#9734)
1 parent 85d43ff commit aeb9f43

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/utils/device/clientInformation.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ export const removeClientInformation = async (matrixClient: MatrixClient): Promi
7575
const type = getClientInformationEventType(deviceId);
7676
const clientInformation = getDeviceClientInformation(matrixClient, deviceId);
7777

78-
// if a non-empty client info event exists, overwrite to remove the content
78+
// if a non-empty client info event exists, remove it
7979
if (clientInformation.name || clientInformation.version || clientInformation.url) {
80-
await matrixClient.setAccountData(type, {});
80+
await matrixClient.deleteAccountData(type);
8181
}
8282
};
8383

test/DeviceListener-test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ describe("DeviceListener", () => {
9696
getDeviceId: jest.fn().mockReturnValue(deviceId),
9797
setAccountData: jest.fn(),
9898
getAccountData: jest.fn(),
99+
deleteAccountData: jest.fn(),
99100
checkDeviceTrust: jest.fn().mockReturnValue(new DeviceTrustLevel(false, false, false, false)),
100101
});
101102
jest.spyOn(MatrixClientPeg, "get").mockReturnValue(mockClient);
@@ -188,17 +189,16 @@ describe("DeviceListener", () => {
188189
mockClient!.getAccountData.mockReturnValue(clientInfoEvent);
189190
await createAndStart();
190191

191-
expect(mockClient!.setAccountData).toHaveBeenCalledWith(
192+
expect(mockClient!.deleteAccountData).toHaveBeenCalledWith(
192193
`io.element.matrix_client_information.${deviceId}`,
193-
{},
194194
);
195195
});
196196

197197
it("does not try to remove client info event that are already empty", async () => {
198198
mockClient!.getAccountData.mockReturnValue(emptyClientInfoEvent);
199199
await createAndStart();
200200

201-
expect(mockClient!.setAccountData).not.toHaveBeenCalled();
201+
expect(mockClient!.deleteAccountData).not.toHaveBeenCalled();
202202
});
203203

204204
it("does not save client information on logged in action", async () => {

0 commit comments

Comments
 (0)