@@ -136,6 +136,7 @@ import {
136
136
UpdateDelayedEventAction ,
137
137
} from "./@types/requests.ts" ;
138
138
import {
139
+ AccountDataEvents ,
139
140
EventType ,
140
141
LOCAL_NOTIFICATION_SETTINGS_PREFIX ,
141
142
MSC3912_RELATION_BASED_REDACTIONS_PROP ,
@@ -232,6 +233,7 @@ import {
232
233
import { DeviceInfoMap } from "./crypto/DeviceList.ts" ;
233
234
import {
234
235
AddSecretStorageKeyOpts ,
236
+ SecretStorageKey ,
235
237
SecretStorageKeyDescription ,
236
238
ServerSideSecretStorage ,
237
239
ServerSideSecretStorageImpl ,
@@ -3070,7 +3072,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
3070
3072
*
3071
3073
* @deprecated Use {@link MatrixClient#secretStorage} and {@link SecretStorage.ServerSideSecretStorage#isStored}.
3072
3074
*/
3073
- public isSecretStored ( name : string ) : Promise < Record < string , SecretStorageKeyDescription > | null > {
3075
+ public isSecretStored ( name : SecretStorageKey ) : Promise < Record < string , SecretStorageKeyDescription > | null > {
3074
3076
return this . secretStorage . isStored ( name ) ;
3075
3077
}
3076
3078
@@ -4236,7 +4238,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
4236
4238
* @returns Promise which resolves: an empty object
4237
4239
* @returns Rejects: with an error response.
4238
4240
*/
4239
- public setAccountData ( eventType : EventType | string , content : IContent ) : Promise < { } > {
4241
+ public setAccountData < K extends keyof AccountDataEvents > (
4242
+ eventType : K ,
4243
+ content : AccountDataEvents [ K ] | Record < string , never > ,
4244
+ ) : Promise < { } > {
4240
4245
const path = utils . encodeUri ( "/user/$userId/account_data/$type" , {
4241
4246
$userId : this . credentials . userId ! ,
4242
4247
$type : eventType ,
@@ -4251,7 +4256,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
4251
4256
* @param eventType - The event type
4252
4257
* @returns The contents of the given account data event
4253
4258
*/
4254
- public getAccountData ( eventType : string ) : MatrixEvent | undefined {
4259
+ public getAccountData < K extends keyof AccountDataEvents > ( eventType : K ) : MatrixEvent | undefined {
4255
4260
return this . store . getAccountData ( eventType ) ;
4256
4261
}
4257
4262
@@ -4263,15 +4268,17 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
4263
4268
* @returns Promise which resolves: The contents of the given account data event.
4264
4269
* @returns Rejects: with an error response.
4265
4270
*/
4266
- public async getAccountDataFromServer < T extends { [ k : string ] : any } > ( eventType : string ) : Promise < T | null > {
4271
+ public async getAccountDataFromServer < K extends keyof AccountDataEvents > (
4272
+ eventType : K ,
4273
+ ) : Promise < AccountDataEvents [ K ] | null > {
4267
4274
if ( this . isInitialSyncComplete ( ) ) {
4268
4275
const event = this . store . getAccountData ( eventType ) ;
4269
4276
if ( ! event ) {
4270
4277
return null ;
4271
4278
}
4272
4279
// The network version below returns just the content, so this branch
4273
4280
// does the same to match.
4274
- return event . getContent < T > ( ) ;
4281
+ return event . getContent < AccountDataEvents [ K ] > ( ) ;
4275
4282
}
4276
4283
const path = utils . encodeUri ( "/user/$userId/account_data/$type" , {
4277
4284
$userId : this . credentials . userId ! ,
@@ -4287,7 +4294,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
4287
4294
}
4288
4295
}
4289
4296
4290
- public async deleteAccountData ( eventType : string ) : Promise < void > {
4297
+ public async deleteAccountData ( eventType : keyof AccountDataEvents ) : Promise < void > {
4291
4298
const msc3391DeleteAccountDataServerSupport = this . canSupport . get ( Feature . AccountDataDeletion ) ;
4292
4299
// if deletion is not supported overwrite with empty content
4293
4300
if ( msc3391DeleteAccountDataServerSupport === ServerSupport . Unsupported ) {
@@ -4310,7 +4317,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
4310
4317
* @returns The array of users that are ignored (empty if none)
4311
4318
*/
4312
4319
public getIgnoredUsers ( ) : string [ ] {
4313
- const event = this . getAccountData ( "m.ignored_user_list" ) ;
4320
+ const event = this . getAccountData ( EventType . IgnoredUserList ) ;
4314
4321
if ( ! event ?. getContent ( ) [ "ignored_users" ] ) return [ ] ;
4315
4322
return Object . keys ( event . getContent ( ) [ "ignored_users" ] ) ;
4316
4323
}
@@ -4326,7 +4333,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
4326
4333
userIds . forEach ( ( u ) => {
4327
4334
content . ignored_users [ u ] = { } ;
4328
4335
} ) ;
4329
- return this . setAccountData ( "m.ignored_user_list" , content ) ;
4336
+ return this . setAccountData ( EventType . IgnoredUserList , content ) ;
4330
4337
}
4331
4338
4332
4339
/**
@@ -9264,7 +9271,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
9264
9271
deviceId : string ,
9265
9272
notificationSettings : LocalNotificationSettings ,
9266
9273
) : Promise < { } > {
9267
- const key = `${ LOCAL_NOTIFICATION_SETTINGS_PREFIX . name } .${ deviceId } ` ;
9274
+ const key = `${ LOCAL_NOTIFICATION_SETTINGS_PREFIX . name } .${ deviceId } ` as const ;
9268
9275
return this . setAccountData ( key , notificationSettings ) ;
9269
9276
}
9270
9277
0 commit comments