This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 833
Device manager - prune client information events after remote sign out #9874
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
18e7338
prune client infromation events from old devices
160527e
test client data pruning
fbe08e7
remove debug
1403b81
strict
a2f52d2
Update src/components/views/settings/devices/useOwnDevices.ts
6d95c85
Merge branch 'develop' into psg-1075/dm-account-data-cleanup
77dd30a
improvements from review
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,8 +40,8 @@ const formatUrl = (): string | undefined => { | |
].join(""); | ||
}; | ||
|
||
export const getClientInformationEventType = (deviceId: string): string => | ||
`io.element.matrix_client_information.${deviceId}`; | ||
const clientInformationEventPrefix = "io.element.matrix_client_information."; | ||
export const getClientInformationEventType = (deviceId: string): string => `${clientInformationEventPrefix}${deviceId}`; | ||
|
||
/** | ||
* Record extra client information for the current device | ||
|
@@ -52,7 +52,7 @@ export const recordClientInformation = async ( | |
sdkConfig: IConfigOptions, | ||
platform: BasePlatform, | ||
): Promise<void> => { | ||
const deviceId = matrixClient.getDeviceId(); | ||
const deviceId = matrixClient.getDeviceId()!; | ||
const { brand } = sdkConfig; | ||
const version = await platform.getAppVersion(); | ||
const type = getClientInformationEventType(deviceId); | ||
|
@@ -66,12 +66,29 @@ export const recordClientInformation = async ( | |
}; | ||
|
||
/** | ||
* Remove extra client information | ||
* @todo(kerrya) revisit after MSC3391: account data deletion is done | ||
* (PSBE-12) | ||
* Remove client information events for devices that no longer exist | ||
* @param validDeviceIds - ids of current devices, | ||
* client information for devices NOT in this list will be removed | ||
*/ | ||
export const pruneClientInformation = async (validDeviceIds: string[], matrixClient: MatrixClient): Promise<void> => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can find neither an |
||
const orphanClientInformationEvents = Object.values(matrixClient.store.accountData).filter((event) => { | ||
if (event.getType().startsWith(clientInformationEventPrefix)) { | ||
const [, deviceId] = event.getType().split(clientInformationEventPrefix); | ||
return deviceId && !validDeviceIds.includes(deviceId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about calling |
||
} | ||
return false; | ||
}); | ||
|
||
orphanClientInformationEvents.forEach((event) => { | ||
matrixClient.deleteAccountData(event.getType()); | ||
}); | ||
}; | ||
|
||
/** | ||
* Remove extra client information for current device | ||
*/ | ||
export const removeClientInformation = async (matrixClient: MatrixClient): Promise<void> => { | ||
const deviceId = matrixClient.getDeviceId(); | ||
const deviceId = matrixClient.getDeviceId()!; | ||
const type = getClientInformationEventType(deviceId); | ||
const clientInformation = getDeviceClientInformation(matrixClient, deviceId); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We maybe need
getSafeDeviceId()
🙃