Files
standardnotes-app-web/packages/services/src/Domain/AsymmetricMessage/UseCase/ProcessAcceptedVaultInvite.ts
Karol Sójko 5bca53736b chore: display shared vault file usage (#2399)
* chore: display shared vault file usage

* fix: specs

* fix: reshape filtering result

* fix: resolving invalid server items

* fix: get revisions specs

* fix: processing issue

* fix: tests

---------

Co-authored-by: Mo <mo@standardnotes.com>
2023-08-11 08:59:16 +02:00

63 lines
2.1 KiB
TypeScript

import { SyncServiceInterface } from '../../Sync/SyncServiceInterface'
import {
KeySystemRootKeyInterface,
AsymmetricMessageSharedVaultInvite,
KeySystemRootKeyContent,
FillItemContent,
FillItemContentSpecialized,
VaultListingContentSpecialized,
KeySystemRootKeyStorageMode,
} from '@standardnotes/models'
import { MutatorClientInterface } from '../../Mutator/MutatorClientInterface'
import { ContentType } from '@standardnotes/domain-core'
import { CreateOrEditContact } from '../../Contacts/UseCase/CreateOrEditContact'
export class ProcessAcceptedVaultInvite {
constructor(
private mutator: MutatorClientInterface,
private sync: SyncServiceInterface,
private _createOrEditContact: CreateOrEditContact,
) {}
async execute(
message: AsymmetricMessageSharedVaultInvite,
sharedVaultUuid: string,
ownerUuid: string,
): Promise<void> {
const { rootKey: rootKeyContent, trustedContacts, metadata } = message.data
const content: VaultListingContentSpecialized = {
systemIdentifier: rootKeyContent.systemIdentifier,
rootKeyParams: rootKeyContent.keyParams,
keyStorageMode: KeySystemRootKeyStorageMode.Synced,
name: metadata.name,
description: metadata.description,
iconString: metadata.iconString,
sharing: {
sharedVaultUuid: sharedVaultUuid,
ownerUserUuid: ownerUuid,
fileBytesUsed: metadata.fileBytesUsed,
},
}
await this.mutator.createItem<KeySystemRootKeyInterface>(
ContentType.TYPES.KeySystemRootKey,
FillItemContent<KeySystemRootKeyContent>(rootKeyContent),
true,
)
await this.mutator.createItem(ContentType.TYPES.VaultListing, FillItemContentSpecialized(content), true)
for (const contact of trustedContacts) {
await this._createOrEditContact.execute({
name: contact.name,
contactUuid: contact.contactUuid,
publicKey: contact.publicKeySet.encryption,
signingPublicKey: contact.publicKeySet.signing,
})
}
void this.sync.sync({ sourceDescription: 'Not awaiting due to this event handler running from sync response' })
}
}