1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-24 08:09:59 +02:00

Move private helper methods to bottom

This commit is contained in:
Thomas Rittson 2024-10-24 11:59:07 +10:00
parent 7f0236acfd
commit ea23acc988
No known key found for this signature in database
GPG Key ID: CDDDA03861C35E27

View File

@ -101,32 +101,6 @@ export class DefaultCollectionvNextService implements CollectionvNextService {
return userId$.pipe(switchMap((userId) => this.decryptedCollectionState(userId).state$)); return userId$.pipe(switchMap((userId) => this.decryptedCollectionState(userId).state$));
} }
/**
* @returns a SingleUserState for encrypted collection data.
*/
private encryptedCollectionState(userId: UserId) {
return this.stateProvider.getUser(userId, ENCRYPTED_COLLECTION_DATA_KEY);
}
/**
* @returns a SingleUserState for decrypted collection data.
*/
private decryptedCollectionState(userId: UserId): DerivedState<CollectionView[]> {
const encryptedCollectionsWithKeys = this.encryptedCollectionState(userId).combinedState$.pipe(
switchMap(([userId, collectionData]) =>
combineLatest([of(collectionData), this.cryptoService.orgKeys$(userId)]),
),
);
return this.stateProvider.getDerived(
encryptedCollectionsWithKeys,
DECRYPTED_COLLECTION_DATA_KEY,
{
collectionService: this,
},
);
}
async encrypt(model: CollectionView): Promise<Collection> { async encrypt(model: CollectionView): Promise<Collection> {
if (model.organizationId == null) { if (model.organizationId == null) {
throw new Error("Collection has no organization id."); throw new Error("Collection has no organization id.");
@ -250,4 +224,30 @@ export class DefaultCollectionvNextService implements CollectionvNextService {
return collections; return collections;
}); });
} }
/**
* @returns a SingleUserState for encrypted collection data.
*/
private encryptedCollectionState(userId: UserId) {
return this.stateProvider.getUser(userId, ENCRYPTED_COLLECTION_DATA_KEY);
}
/**
* @returns a SingleUserState for decrypted collection data.
*/
private decryptedCollectionState(userId: UserId): DerivedState<CollectionView[]> {
const encryptedCollectionsWithKeys = this.encryptedCollectionState(userId).combinedState$.pipe(
switchMap(([userId, collectionData]) =>
combineLatest([of(collectionData), this.cryptoService.orgKeys$(userId)]),
),
);
return this.stateProvider.getDerived(
encryptedCollectionsWithKeys,
DECRYPTED_COLLECTION_DATA_KEY,
{
collectionService: this,
},
);
}
} }