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

Commit

Permalink
Device manager - use deleteAccountData to prune device manager client…
Browse files Browse the repository at this point in the history
… information events (#9734)
  • Loading branch information
Kerry committed Dec 14, 2022
1 parent 85d43ff commit aeb9f43
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/utils/device/clientInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ export const removeClientInformation = async (matrixClient: MatrixClient): Promi
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);
}
};

Expand Down
6 changes: 3 additions & 3 deletions test/DeviceListener-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -188,17 +189,16 @@ describe("DeviceListener", () => {
mockClient!.getAccountData.mockReturnValue(clientInfoEvent);
await createAndStart();

expect(mockClient!.setAccountData).toHaveBeenCalledWith(
expect(mockClient!.deleteAccountData).toHaveBeenCalledWith(
`io.element.matrix_client_information.${deviceId}`,
{},
);
});

it("does not try to remove client info event that are already empty", async () => {
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 () => {
Expand Down

0 comments on commit aeb9f43

Please sign in to comment.