-
-
Couldn't load subscription status.
- Fork 648
Use mapped types for account data content #4590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
50b9b67
b5d1cbd
276fbe0
ae935eb
d28bf64
a1635c5
49a43fc
cf0ee8b
0e5012d
f72f5b0
7040e75
e4f9ddf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,6 +136,7 @@ import { | |
| UpdateDelayedEventAction, | ||
| } from "./@types/requests.ts"; | ||
| import { | ||
| AccountDataEvents, | ||
| EventType, | ||
| LOCAL_NOTIFICATION_SETTINGS_PREFIX, | ||
| MSC3912_RELATION_BASED_REDACTIONS_PROP, | ||
|
|
@@ -232,6 +233,7 @@ import { | |
| import { DeviceInfoMap } from "./crypto/DeviceList.ts"; | ||
| import { | ||
| AddSecretStorageKeyOpts, | ||
| SecretStorageKey, | ||
| SecretStorageKeyDescription, | ||
| ServerSideSecretStorage, | ||
| ServerSideSecretStorageImpl, | ||
|
|
@@ -3070,7 +3072,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa | |
| * | ||
| * @deprecated Use {@link MatrixClient#secretStorage} and {@link SecretStorage.ServerSideSecretStorage#isStored}. | ||
| */ | ||
| public isSecretStored(name: string): Promise<Record<string, SecretStorageKeyDescription> | null> { | ||
| public isSecretStored(name: SecretStorageKey): Promise<Record<string, SecretStorageKeyDescription> | null> { | ||
| return this.secretStorage.isStored(name); | ||
| } | ||
|
|
||
|
|
@@ -4236,7 +4238,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa | |
| * @returns Promise which resolves: an empty object | ||
| * @returns Rejects: with an error response. | ||
| */ | ||
| public setAccountData(eventType: EventType | string, content: IContent): Promise<{}> { | ||
| public setAccountData<K extends keyof AccountDataEvents>( | ||
t3chguy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| eventType: K, | ||
| content: AccountDataEvents[K] | Record<string, never>, | ||
| ): Promise<{}> { | ||
| const path = utils.encodeUri("/user/$userId/account_data/$type", { | ||
| $userId: this.credentials.userId!, | ||
| $type: eventType, | ||
|
|
@@ -4251,7 +4256,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa | |
| * @param eventType - The event type | ||
| * @returns The contents of the given account data event | ||
| */ | ||
| public getAccountData(eventType: string): MatrixEvent | undefined { | ||
| public getAccountData<K extends keyof AccountDataEvents>(eventType: K): MatrixEvent | undefined { | ||
|
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. Extending this PR to cover fetching account data is fine, but it's a significant scope creep. Adding it in the middle of a review cycle doesn't make a reviewer's job any easier. It'd be good just to make another PR next time. |
||
| return this.store.getAccountData(eventType); | ||
| } | ||
|
|
||
|
|
@@ -4263,15 +4268,17 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa | |
| * @returns Promise which resolves: The contents of the given account data event. | ||
| * @returns Rejects: with an error response. | ||
| */ | ||
| public async getAccountDataFromServer<T extends { [k: string]: any }>(eventType: string): Promise<T | null> { | ||
| public async getAccountDataFromServer<K extends keyof AccountDataEvents>( | ||
| eventType: K, | ||
| ): Promise<AccountDataEvents[K] | null> { | ||
| if (this.isInitialSyncComplete()) { | ||
| const event = this.store.getAccountData(eventType); | ||
| if (!event) { | ||
| return null; | ||
| } | ||
| // The network version below returns just the content, so this branch | ||
| // does the same to match. | ||
| return event.getContent<T>(); | ||
| return event.getContent<AccountDataEvents[K]>(); | ||
| } | ||
| const path = utils.encodeUri("/user/$userId/account_data/$type", { | ||
| $userId: this.credentials.userId!, | ||
|
|
@@ -4287,7 +4294,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa | |
| } | ||
| } | ||
|
|
||
| public async deleteAccountData(eventType: string): Promise<void> { | ||
| public async deleteAccountData(eventType: keyof AccountDataEvents): Promise<void> { | ||
| const msc3391DeleteAccountDataServerSupport = this.canSupport.get(Feature.AccountDataDeletion); | ||
| // if deletion is not supported overwrite with empty content | ||
| if (msc3391DeleteAccountDataServerSupport === ServerSupport.Unsupported) { | ||
|
|
@@ -4310,7 +4317,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa | |
| * @returns The array of users that are ignored (empty if none) | ||
| */ | ||
| public getIgnoredUsers(): string[] { | ||
| const event = this.getAccountData("m.ignored_user_list"); | ||
| const event = this.getAccountData(EventType.IgnoredUserList); | ||
| if (!event?.getContent()["ignored_users"]) return []; | ||
| return Object.keys(event.getContent()["ignored_users"]); | ||
| } | ||
|
|
@@ -4326,7 +4333,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa | |
| userIds.forEach((u) => { | ||
| content.ignored_users[u] = {}; | ||
| }); | ||
| return this.setAccountData("m.ignored_user_list", content); | ||
| return this.setAccountData(EventType.IgnoredUserList, content); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -9264,7 +9271,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa | |
| deviceId: string, | ||
| notificationSettings: LocalNotificationSettings, | ||
| ): Promise<{}> { | ||
| const key = `${LOCAL_NOTIFICATION_SETTINGS_PREFIX.name}.${deviceId}`; | ||
| const key = `${LOCAL_NOTIFICATION_SETTINGS_PREFIX.name}.${deviceId}` as const; | ||
| return this.setAccountData(key, notificationSettings); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.