You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-12-04 05:02:41 +03:00
Support MSC3391: Account data deletion (#2967)
* add deleteAccountData endpoint * check server support and test * test current state of memorystore * interpret account data events with empty content as deleted * add handling for (future) stable version of endpoint * add getSafeUserId * user getSafeUserId in deleteAccountData * better jsdoc for throws documentation
This commit is contained in:
@@ -1672,6 +1672,20 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user-id of the logged-in user
|
||||
*
|
||||
* @returns MXID for the logged-in user
|
||||
* @throws Error if not logged in
|
||||
*/
|
||||
public getSafeUserId(): string {
|
||||
const userId = this.getUserId();
|
||||
if (!userId) {
|
||||
throw new Error("Expected logged in user but found none.");
|
||||
}
|
||||
return userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the domain for this client's MXID
|
||||
* @returns Domain of this MXID
|
||||
@@ -3766,6 +3780,24 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
}
|
||||
}
|
||||
|
||||
public async deleteAccountData(eventType: string): Promise<void> {
|
||||
const msc3391DeleteAccountDataServerSupport = this.canSupport.get(Feature.AccountDataDeletion);
|
||||
// if deletion is not supported overwrite with empty content
|
||||
if (msc3391DeleteAccountDataServerSupport === ServerSupport.Unsupported) {
|
||||
await this.setAccountData(eventType, {});
|
||||
return;
|
||||
}
|
||||
const path = utils.encodeUri("/user/$userId/account_data/$type", {
|
||||
$userId: this.getSafeUserId(),
|
||||
$type: eventType,
|
||||
});
|
||||
const options =
|
||||
msc3391DeleteAccountDataServerSupport === ServerSupport.Unstable
|
||||
? { prefix: "/_matrix/client/unstable/org.matrix.msc3391" }
|
||||
: undefined;
|
||||
return await this.http.authedRequest(Method.Delete, path, undefined, undefined, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the users that are ignored by this client
|
||||
* @returns The array of users that are ignored (empty if none)
|
||||
|
||||
Reference in New Issue
Block a user