diff --git a/external/@worldbrain/memex-common b/external/@worldbrain/memex-common index 3c320ece31..6c6a06bb46 160000 --- a/external/@worldbrain/memex-common +++ b/external/@worldbrain/memex-common @@ -1 +1 @@ -Subproject commit 3c320ece31fc2aa8e48d30abe2dacd28d934d36f +Subproject commit 6c6a06bb4654ead77903d28af37739d42ea5535d diff --git a/src/annotations/annotation-save-logic.ts b/src/annotations/annotation-save-logic.ts index 352f787072..3165e1ff0d 100644 --- a/src/annotations/annotation-save-logic.ts +++ b/src/annotations/annotation-save-logic.ts @@ -129,6 +129,7 @@ export async function createAnnotation({ shareData = await contentSharingBG.shareAnnotation({ annotationUrl, remoteAnnotationId, + excludeFromLists: !shareOpts?.shouldShare ?? true, shareToParentPageLists: shareOpts?.shouldShare ?? false, skipPrivacyLevelUpdate: !!shareOpts?.shouldShare ?? true, }) @@ -144,6 +145,7 @@ export async function createAnnotation({ shareData = await contentSharingBG.shareAnnotation({ annotationUrl, remoteAnnotationId, + excludeFromLists: false, shareToParentPageLists: false, skipPrivacyLevelUpdate: true, }) @@ -234,6 +236,7 @@ export async function updateAnnotation({ remoteAnnotationId, annotationUrl: annotationData.localId, shareToParentPageLists: true, + excludeFromLists: false, }), !shareOpts?.skipPrivacyLevelUpdate && contentSharingBG.setAnnotationPrivacyLevel({ diff --git a/src/content-sharing/background/index.test.ts b/src/content-sharing/background/index.test.ts index 0f98b16092..402d4f24e8 100644 --- a/src/content-sharing/background/index.test.ts +++ b/src/content-sharing/background/index.test.ts @@ -701,18 +701,18 @@ export const INTEGRATION_TESTS = backgroundIntegrationTestSuite( AnnotationPrivacyLevels.SHARED, }, }) - await helper.unshareAnnotations(setup, { - ids: [1], - expectedSharingStates: { - 1: { - sharedListIds: [], - privateListIds: [], - privacyLevel: - AnnotationPrivacyLevels.PRIVATE, - hasLink: true, - }, - }, - }) + // await helper.unshareAnnotations(setup, { + // ids: [1], + // expectedSharingStates: { + // 1: { + // sharedListIds: [], + // privateListIds: [], + // privacyLevel: + // AnnotationPrivacyLevels.PRIVATE, + // hasLink: true, + // }, + // }, + // }) await helper.assertAnnotationPrivacyLevels( setup, [ @@ -774,18 +774,18 @@ export const INTEGRATION_TESTS = backgroundIntegrationTestSuite( AnnotationPrivacyLevels.SHARED_PROTECTED, }, }) - await helper.unshareAnnotations(setup, { - ids: [1], - expectedSharingStates: { - 1: { - sharedListIds: [1, 2], - privateListIds: [], - privacyLevel: - AnnotationPrivacyLevels.SHARED_PROTECTED, - hasLink: true, - }, - }, - }) + // await helper.unshareAnnotations(setup, { + // ids: [1], + // expectedSharingStates: { + // 1: { + // sharedListIds: [1, 2], + // privateListIds: [], + // privacyLevel: + // AnnotationPrivacyLevels.SHARED_PROTECTED, + // hasLink: true, + // }, + // }, + // }) await helper.assertAnnotationPrivacyLevels( setup, [ diff --git a/src/content-sharing/background/index.tests.ts b/src/content-sharing/background/index.tests.ts index 7c6e08598a..28bf4404b2 100644 --- a/src/content-sharing/background/index.tests.ts +++ b/src/content-sharing/background/index.tests.ts @@ -474,26 +474,6 @@ export class SharingTestHelper { ) } - async unshareAnnotations( - setup: BackgroundIntegrationTestSetup, - options: { - ids: number[] - expectedSharingStates: AnnotationSharingStates - }, - ) { - const { - sharingStates, - } = await setup.backgroundModules.contentSharing.unshareAnnotations({ - annotationUrls: options.ids.map( - (id) => this.annotations[id].localId, - ), - }) - this._expectAnnotationSharingStates( - sharingStates, - options.expectedSharingStates, - ) - } - async unshareAnnotation( setup: BackgroundIntegrationTestSetup, options: { id: number; expectedSharingState: AnnotationSharingState }, diff --git a/src/content-sharing/background/index.ts b/src/content-sharing/background/index.ts index 09f71d46b1..3ebd0dffc6 100644 --- a/src/content-sharing/background/index.ts +++ b/src/content-sharing/background/index.ts @@ -3,10 +3,10 @@ import type StorageManager from '@worldbrain/storex' import type { StorageOperationEvent } from '@worldbrain/storex-middleware-change-watcher/lib/types' import type { ContentSharingBackend } from '@worldbrain/memex-common/lib/content-sharing/backend' import { - makeAnnotationPrivacyLevel, getAnnotationPrivacyState, createPageLinkListTitle, getListShareUrl, + makeAnnotationPrivacyLevel, } from '@worldbrain/memex-common/lib/content-sharing/utils' import type { Analytics } from 'src/analytics/types' import { AnnotationPrivacyLevels } from '@worldbrain/memex-common/lib/annotations/types' @@ -261,11 +261,9 @@ export default class ContentSharingBackground { waitForListShareSideEffects: this.waitForListShareSideEffects, deleteListAndAllAssociatedData: this.deleteListAndAllAssociatedData, shareAnnotation: this.shareAnnotation, - shareAnnotations: this.shareAnnotations, executePendingActions: this.executePendingActions.bind(this), shareAnnotationToSomeLists: this.shareAnnotationToSomeLists, unshareAnnotationFromList: this.unshareAnnotationFromList, - unshareAnnotations: this.unshareAnnotations, ensureRemotePageId: this.ensureRemotePageId, getRemoteAnnotationLink: this.getRemoteAnnotationLink, findAnnotationPrivacyLevels: this.findAnnotationPrivacyLevels.bind( @@ -543,9 +541,12 @@ export default class ContentSharingBackground { return this.annotationSharingService.shareAnnotation(options) } - shareAnnotations: ContentSharingInterface['shareAnnotations'] = async ( - options, - ) => { + async shareAnnotations(options: { + annotationUrls: string[] + shareToParentPageLists?: boolean + setBulkShareProtected?: boolean + skipAnalytics?: boolean + }): Promise<{ sharingStates: AnnotationSharingStates }> { const remoteIds = await this.storage.getRemoteAnnotationIds({ localIds: options.annotationUrls, }) @@ -775,50 +776,6 @@ export default class ContentSharingBackground { return { sharingState } } - unshareAnnotations: ContentSharingInterface['unshareAnnotations'] = async ( - options, - ) => { - const annotPrivacyLevels = await this.storage.getPrivacyLevelsByAnnotation( - { annotations: options.annotationUrls }, - ) - const nonProtectedAnnotations = options.annotationUrls.filter( - (annotationUrl) => - ![ - AnnotationPrivacyLevels.PROTECTED, - AnnotationPrivacyLevels.SHARED_PROTECTED, - ].includes(annotPrivacyLevels[annotationUrl]?.privacyLevel), - ) - - const allMetadata = await this.storage.getRemoteAnnotationMetadata({ - localIds: nonProtectedAnnotations, - }) - await this.storage.setAnnotationsExcludedFromLists({ - localIds: Object.values(allMetadata) - .filter((metadata) => !metadata.excludeFromLists) - .map(({ localId }) => localId), - excludeFromLists: true, - }) - - await this.storage.setAnnotationPrivacyLevelBulk({ - annotations: nonProtectedAnnotations, - privacyLevel: options.setBulkShareProtected - ? AnnotationPrivacyLevels.PROTECTED - : AnnotationPrivacyLevels.PRIVATE, - }) - - if (this.options.analyticsBG) { - try { - await trackUnSharedAnnotation(this.options.analyticsBG, { - type: 'bulk', - }) - } catch (error) { - console.error(`Error tracking space create event', ${error}`) - } - } - - return { sharingStates: await this.getAnnotationSharingStates(options) } - } - unshareAnnotation: __DeprecatedContentSharingInterface['unshareAnnotation'] = async ( options, ) => { diff --git a/src/content-sharing/background/types.ts b/src/content-sharing/background/types.ts index 4311c096a5..0c6a746fa7 100644 --- a/src/content-sharing/background/types.ts +++ b/src/content-sharing/background/types.ts @@ -41,16 +41,6 @@ export interface ContentSharingInterface deleteListAndAllAssociatedData(params: { localListId: number }): Promise - shareAnnotations(options: { - annotationUrls: string[] - shareToParentPageLists?: boolean - setBulkShareProtected?: boolean - skipAnalytics?: boolean - }): Promise<{ sharingStates: AnnotationSharingStates }> - unshareAnnotations(options: { - annotationUrls: string[] - setBulkShareProtected?: boolean - }): Promise<{ sharingStates: AnnotationSharingStates }> ensureRemotePageId(normalizedPageUrl: string): Promise getRemoteAnnotationLink(params: { annotationUrl: string diff --git a/src/overview/sharing/AllNotesShareMenu.tsx b/src/overview/sharing/AllNotesShareMenu.tsx index f25ae4a1eb..2cce59a3a9 100644 --- a/src/overview/sharing/AllNotesShareMenu.tsx +++ b/src/overview/sharing/AllNotesShareMenu.tsx @@ -55,49 +55,6 @@ export default class AllNotesShareMenu extends React.Component { this.setState({ link: getPageShareUrl({ remotePageInfoId }) }) } - private shareAllAnnotations = async () => { - try { - const { - sharingStates, - } = await this.props.contentSharingBG.shareAnnotations({ - annotationUrls: this.annotationUrls, - shareToParentPageLists: true, - }) - this.props.postBulkShareHook?.(sharingStates) - } catch (err) {} - } - - private unshareAllAnnotations = async () => { - try { - const { - sharingStates, - } = await this.props.contentSharingBG.unshareAnnotations({ - annotationUrls: this.annotationUrls, - }) - this.props.postBulkShareHook?.(sharingStates) - } catch (err) {} - } - - private handleSetShared = async () => { - await executeReactStateUITask( - this, - 'shareState', - async () => { - await this.shareAllAnnotations() - }, - ) - } - - private handleSetPrivate = async () => { - await executeReactStateUITask( - this, - 'shareState', - async () => { - await this.unshareAllAnnotations() - }, - ) - } - render() { return null // { let sharingState = await contentSharingBG.shareAnnotation({ annotationUrl, - shareToParentPageLists: currentSharingLevel?.privacyLevel === 200, + shareToParentPageLists: + currentSharingLevel?.privacyLevel === + AnnotationPrivacyLevels.SHARED, + excludeFromLists: + currentSharingLevel?.privacyLevel !== + AnnotationPrivacyLevels.SHARED, skipPrivacyLevelUpdate: true, }) @@ -163,6 +169,7 @@ class ShareAnnotationMenu extends PureComponent { await contentSharingBG.shareAnnotation({ annotationUrl, shareToParentPageLists: false, + excludeFromLists: true, skipPrivacyLevelUpdate: true, })