Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
karolsojko committed Aug 9, 2023
1 parent ed6d265 commit fc8b80d
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 21 deletions.
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"dependencies": {
"@standardnotes/common": "^1.50.0",
"@standardnotes/domain-core": "^1.24.0",
"@standardnotes/domain-core": "^1.25.0",
"@standardnotes/models": "workspace:*",
"@standardnotes/responses": "workspace:*",
"@standardnotes/utils": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@electron/remote": "^2.0.9",
"@standardnotes/domain-core": "^1.24.0",
"@standardnotes/domain-core": "^1.25.0",
"@standardnotes/electron-clear-data": "1.1.1",
"@standardnotes/web": "workspace:*",
"axios": "^1.1.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/encryption/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"dependencies": {
"@standardnotes/common": "^1.50.0",
"@standardnotes/domain-core": "^1.24.0",
"@standardnotes/domain-core": "^1.25.0",
"@standardnotes/models": "workspace:*",
"@standardnotes/responses": "workspace:*",
"@standardnotes/sncrypto-common": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"dependencies": {
"@standardnotes/common": "^1.50.0",
"@standardnotes/domain-core": "^1.24.0",
"@standardnotes/domain-core": "^1.25.0",
"reflect-metadata": "^0.1.13"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/models/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"dependencies": {
"@standardnotes/common": "^1.50.0",
"@standardnotes/domain-core": "^1.24.0",
"@standardnotes/domain-core": "^1.25.0",
"@standardnotes/features": "workspace:*",
"@standardnotes/responses": "workspace:*",
"@standardnotes/sncrypto-common": "workspace:^",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ export function isDeletedTransferPayload(payload: TransferPayload): payload is D
export function isCorruptTransferPayload(payload: TransferPayload): boolean {
const invalidDeletedState = payload.deleted === true && payload.content != undefined

return payload.uuid == undefined || invalidDeletedState || payload.content_type === ContentType.TYPES.Unknown
const contenTypeOrError = ContentType.create(payload.content_type)

return payload.uuid == undefined || invalidDeletedState || contenTypeOrError.isFailed()
}
2 changes: 1 addition & 1 deletion packages/services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"dependencies": {
"@standardnotes/api": "workspace:^",
"@standardnotes/common": "^1.50.0",
"@standardnotes/domain-core": "^1.24.0",
"@standardnotes/domain-core": "^1.25.0",
"@standardnotes/encryption": "workspace:^",
"@standardnotes/features": "workspace:^",
"@standardnotes/files": "workspace:^",
Expand Down
39 changes: 36 additions & 3 deletions packages/services/src/Domain/SharedVaults/SharedVaultService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DiscardItemsLocally } from './../UseCase/DiscardItemsLocally'
import { UserKeyPairChangedEventData } from './../Session/UserKeyPairChangedEventData'
import { ClientDisplayableError } from '@standardnotes/responses'
import { ClientDisplayableError, isErrorResponse } from '@standardnotes/responses'
import {
DecryptedItemInterface,
PayloadEmitSource,
Expand All @@ -10,6 +10,7 @@ import {
KeySystemRootKeyStorageMode,
EmojiString,
IconType,
VaultListingMutator,
} from '@standardnotes/models'
import { SharedVaultServiceInterface } from './SharedVaultServiceInterface'
import { SharedVaultServiceEvent, SharedVaultServiceEventPayload } from './SharedVaultServiceEvent'
Expand All @@ -32,6 +33,8 @@ import { ContentType, NotificationType, Uuid } from '@standardnotes/domain-core'
import { HandleKeyPairChange } from '../Contacts/UseCase/HandleKeyPairChange'
import { FindContact } from '../Contacts/UseCase/FindContact'
import { GetOwnedSharedVaults } from './UseCase/GetOwnedSharedVaults'
import { MutatorClientInterface } from '../Mutator/MutatorClientInterface'
import { SharedVaultServerInterface } from '@standardnotes/api'

export class SharedVaultService
extends AbstractService<SharedVaultServiceEvent, SharedVaultServiceEventPayload>
Expand All @@ -40,6 +43,8 @@ export class SharedVaultService
constructor(
private items: ItemManagerInterface,
private session: SessionsClientInterface,
private mutator: MutatorClientInterface,
private sharedVaultServer: SharedVaultServerInterface,
private _getVault: GetVault,
private _getOwnedSharedVaults: GetOwnedSharedVaults,
private _createSharedVault: CreateSharedVault,
Expand Down Expand Up @@ -88,15 +93,15 @@ export class SharedVaultService
break
}
case NotificationServiceEvent.NotificationReceived:
await this.handleUserEvent(event.payload as NotificationServiceEventPayload)
await this.handleNotification(event.payload as NotificationServiceEventPayload)
break
case SyncEvent.ReceivedRemoteSharedVaults:
void this.notifyEventSync(SharedVaultServiceEvent.SharedVaultStatusChanged)
break
}
}

private async handleUserEvent(event: NotificationServiceEventPayload): Promise<void> {
private async handleNotification(event: NotificationServiceEventPayload): Promise<void> {
switch (event.eventPayload.props.type.value) {
case NotificationType.TYPES.RemovedFromSharedVault: {
const vault = this._getVault.execute<SharedVaultListingInterface>({
Expand All @@ -114,6 +119,34 @@ export class SharedVaultService
}
break
}
case NotificationType.TYPES.SharedVaultFileRemoved:
case NotificationType.TYPES.SharedVaultFileUploaded: {
const vaultOrError = this._getVault.execute<SharedVaultListingInterface>({
sharedVaultUuid: event.eventPayload.props.sharedVaultUuid.value,
})
if (vaultOrError.isFailed()) {
return
}
const vault = vaultOrError.getValue()

const serverResult = await this.sharedVaultServer.getSharedVaults()
if (!isErrorResponse(serverResult)) {
const remoteSharedVault = serverResult.data.sharedVaults.find(
(sharedVault) => sharedVault.uuid === vault.uuid,
)
if (remoteSharedVault) {
await this.mutator.changeItem<VaultListingMutator, VaultListingInterface>(vault, (mutator) => {
mutator.sharing = {
sharedVaultUuid: remoteSharedVault.uuid,
ownerUserUuid: remoteSharedVault.user_uuid,
fileBytesUsed: remoteSharedVault.file_upload_bytes_used,
}
})
}
}

break
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/snjs/lib/Application/Dependencies/Dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,8 @@ export class Dependencies {
return new SharedVaultService(
this.get<ItemManager>(TYPES.ItemManager),
this.get<SessionManager>(TYPES.SessionManager),
this.get<MutatorService>(TYPES.MutatorService),
this.get<SharedVaultServer>(TYPES.SharedVaultServer),
this.get<GetVault>(TYPES.GetVault),
this.get<GetOwnedSharedVaults>(TYPES.GetOwnedSharedVaults),
this.get<CreateSharedVault>(TYPES.CreateSharedVault),
Expand Down
2 changes: 1 addition & 1 deletion packages/snjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@babel/preset-env": "*",
"@standardnotes/api": "workspace:*",
"@standardnotes/common": "^1.50.0",
"@standardnotes/domain-core": "^1.24.0",
"@standardnotes/domain-core": "^1.25.0",
"@standardnotes/domain-events": "^2.108.1",
"@standardnotes/encryption": "workspace:*",
"@standardnotes/features": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"dependencies": {
"@standardnotes/common": "^1.50.0",
"@standardnotes/domain-core": "^1.24.0",
"@standardnotes/domain-core": "^1.25.0",
"@standardnotes/features": "workspace:^",
"@standardnotes/filepicker": "workspace:^",
"@standardnotes/models": "workspace:^",
Expand Down
27 changes: 18 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4140,7 +4140,7 @@ __metadata:
resolution: "@standardnotes/api@workspace:packages/api"
dependencies:
"@standardnotes/common": ^1.50.0
"@standardnotes/domain-core": ^1.24.0
"@standardnotes/domain-core": ^1.25.0
"@standardnotes/models": "workspace:*"
"@standardnotes/responses": "workspace:*"
"@standardnotes/utils": "workspace:*"
Expand Down Expand Up @@ -4290,7 +4290,7 @@ __metadata:
"@babel/core": "*"
"@babel/preset-env": "*"
"@electron/remote": ^2.0.9
"@standardnotes/domain-core": ^1.24.0
"@standardnotes/domain-core": ^1.25.0
"@standardnotes/electron-clear-data": 1.1.1
"@standardnotes/web": "workspace:*"
"@types/fs-extra": ^11.0.1
Expand Down Expand Up @@ -4333,7 +4333,7 @@ __metadata:
languageName: unknown
linkType: soft

"@standardnotes/domain-core@npm:^1.24.0, @standardnotes/domain-core@npm:^1.24.1":
"@standardnotes/domain-core@npm:^1.24.1":
version: 1.24.1
resolution: "@standardnotes/domain-core@npm:1.24.1"
dependencies:
Expand All @@ -4342,6 +4342,15 @@ __metadata:
languageName: node
linkType: hard

"@standardnotes/domain-core@npm:^1.25.0":
version: 1.25.0
resolution: "@standardnotes/domain-core@npm:1.25.0"
dependencies:
uuid: ^9.0.0
checksum: f99196f6209a05a50e84371d3a59cf870937a5589f4ba4caab0f2eb17c2cfa733142b18ca8788016c81ca609d1f5a0461e51bcf159a67d631e249a04a5568244
languageName: node
linkType: hard

"@standardnotes/domain-events@npm:^2.108.1":
version: 2.113.1
resolution: "@standardnotes/domain-events@npm:2.113.1"
Expand Down Expand Up @@ -4385,7 +4394,7 @@ __metadata:
dependencies:
"@standardnotes/common": ^1.50.0
"@standardnotes/config": 2.4.3
"@standardnotes/domain-core": ^1.24.0
"@standardnotes/domain-core": ^1.25.0
"@standardnotes/models": "workspace:*"
"@standardnotes/responses": "workspace:*"
"@standardnotes/sncrypto-common": "workspace:*"
Expand Down Expand Up @@ -4420,7 +4429,7 @@ __metadata:
resolution: "@standardnotes/features@workspace:packages/features"
dependencies:
"@standardnotes/common": ^1.50.0
"@standardnotes/domain-core": ^1.24.0
"@standardnotes/domain-core": ^1.25.0
"@types/jest": ^29.2.3
"@typescript-eslint/eslint-plugin": "*"
eslint: "*"
Expand Down Expand Up @@ -4626,7 +4635,7 @@ __metadata:
resolution: "@standardnotes/models@workspace:packages/models"
dependencies:
"@standardnotes/common": ^1.50.0
"@standardnotes/domain-core": ^1.24.0
"@standardnotes/domain-core": ^1.25.0
"@standardnotes/features": "workspace:*"
"@standardnotes/responses": "workspace:*"
"@standardnotes/sncrypto-common": "workspace:^"
Expand Down Expand Up @@ -4712,7 +4721,7 @@ __metadata:
dependencies:
"@standardnotes/api": "workspace:^"
"@standardnotes/common": ^1.50.0
"@standardnotes/domain-core": ^1.24.0
"@standardnotes/domain-core": ^1.25.0
"@standardnotes/encryption": "workspace:^"
"@standardnotes/features": "workspace:^"
"@standardnotes/files": "workspace:^"
Expand Down Expand Up @@ -4811,7 +4820,7 @@ __metadata:
"@babel/preset-env": "*"
"@standardnotes/api": "workspace:*"
"@standardnotes/common": ^1.50.0
"@standardnotes/domain-core": ^1.24.0
"@standardnotes/domain-core": ^1.25.0
"@standardnotes/domain-events": ^2.108.1
"@standardnotes/encryption": "workspace:*"
"@standardnotes/features": "workspace:*"
Expand Down Expand Up @@ -4936,7 +4945,7 @@ __metadata:
resolution: "@standardnotes/ui-services@workspace:packages/ui-services"
dependencies:
"@standardnotes/common": ^1.50.0
"@standardnotes/domain-core": ^1.24.0
"@standardnotes/domain-core": ^1.25.0
"@standardnotes/features": "workspace:^"
"@standardnotes/filepicker": "workspace:^"
"@standardnotes/models": "workspace:^"
Expand Down

0 comments on commit fc8b80d

Please sign in to comment.