1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 17:23:37 +00:00

move attachment sharing logic to service

This commit is contained in:
Kyle Spearrin
2018-10-23 22:10:08 -04:00
parent 43c0cbce45
commit 4165a78277
3 changed files with 49 additions and 54 deletions

View File

@@ -65,23 +65,14 @@ export class ShareComponent implements OnInit {
const cipherDomain = await this.cipherService.get(this.cipherId);
const cipherView = await cipherDomain.decrypt();
const attachmentPromises: Array<Promise<any>> = [];
if (cipherView.attachments != null) {
for (const attachment of cipherView.attachments) {
const promise = this.cipherService.shareAttachmentWithServer(attachment, cipherView.id,
this.organizationId);
attachmentPromises.push(promise);
}
}
const checkedCollectionIds = this.collections.filter((c) => (c as any).checked).map((c) => c.id);
try {
this.formPromise = Promise.all(attachmentPromises).then(async () => {
await this.cipherService.shareWithServer(cipherView, this.organizationId, checkedCollectionIds);
this.onSharedCipher.emit();
this.platformUtilsService.eventTrack('Shared Cipher');
this.platformUtilsService.showToast('success', null, this.i18nService.t('sharedItem'));
});
this.formPromise = this.cipherService.shareWithServer(cipherView, this.organizationId,
checkedCollectionIds).then(async () => {
this.onSharedCipher.emit();
this.platformUtilsService.eventTrack('Shared Cipher');
this.platformUtilsService.showToast('success', null, this.i18nService.t('sharedItem'));
});
await this.formPromise;
} catch { }
}