Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
blackforestboi committed Nov 12, 2021
2 parents 0691f60 + 8931626 commit bc2acd5
Show file tree
Hide file tree
Showing 53 changed files with 1,317 additions and 441 deletions.
121 changes: 121 additions & 0 deletions img/bookmarking-providers.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "worldbrain-extension",
"version": "3.0.6",
"version": "3.0.7",
"homepage": "https://worldbrain.io",
"repository": "https://github.com/WorldBrain/Memex",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/annotations/annotation-save-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export async function createAnnotation({
})
}

await contentSharingBG.setAnnotationPrivacyLevel({
await annotationsBG.setAnnotationPrivacyLevel({
annotation: annotationUrl,
privacyLevel: shareOptsToPrivacyLvl(shareOpts),
})
Expand Down Expand Up @@ -134,7 +134,7 @@ export async function updateAnnotation({
shareToLists: true,
skipPrivacyLevelUpdate: true,
}),
contentSharingBG.setAnnotationPrivacyLevel({
annotationsBG.setAnnotationPrivacyLevel({
annotation: annotationData.localId,
privacyLevel: shareOptsToPrivacyLvl(shareOpts),
}),
Expand Down
2 changes: 1 addition & 1 deletion src/annotations/annotations-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const createAnnotationsCache = (
)

const annotationUrls = annotations.map((a) => a.url)
const privacyLevels = await bgModules.contentSharing.findAnnotationPrivacyLevels(
const privacyLevels = await bgModules.annotations.findAnnotationPrivacyLevels(
{
annotationUrls,
},
Expand Down
17 changes: 9 additions & 8 deletions src/annotations/background/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import {
} from '@worldbrain/memex-storage/lib/lists/constants'
import { AnnotationPrivacyLevels } from '@worldbrain/memex-common/lib/annotations/types'

const contentSharing = (setup: BackgroundIntegrationTestSetup) =>
setup.backgroundModules.contentSharing
const directLinking = (setup: BackgroundIntegrationTestSetup) =>
setup.backgroundModules.directLinking
const customLists = (setup: BackgroundIntegrationTestSetup) =>
Expand Down Expand Up @@ -55,14 +53,17 @@ const createAnnotationStep = (args?: {
DATA.ANNOT_1,
)
if (args?.protectAnnotation) {
await contentSharing(setup).setAnnotationPrivacyLevel({
annotation: annotUrl,
privacyLevel: AnnotationPrivacyLevels.PROTECTED,
})
await directLinking(setup).setAnnotationPrivacyLevel(
{ tab: DATA.TEST_TAB_1 },
{
annotation: annotUrl,
privacyLevel: AnnotationPrivacyLevels.PROTECTED,
},
)
}
annotPrivacyLevel = await contentSharing(
annotPrivacyLevel = await directLinking(
setup,
).storage.findAnnotationPrivacyLevel({ annotation: annotUrl })
).annotationStorage.findAnnotationPrivacyLevel({ annotation: annotUrl })
},
expectedStorageChanges: {
annotations: (): StorageCollectionDiff => ({
Expand Down
39 changes: 34 additions & 5 deletions src/annotations/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
AnnotationSender,
AnnotListEntry,
} from 'src/annotations/types'
import { AnnotationPrivacyLevels } from '@worldbrain/memex-common/lib/annotations/types'
import { AnnotationInterface, CreateAnnotationParams } from './types'
import { InPageUIContentScriptRemoteInterface } from 'src/in-page-ui/content_script/types'
import { InPageUIRibbonAction } from 'src/in-page-ui/shared-state/types'
Expand All @@ -38,7 +39,6 @@ import { Analytics } from 'src/analytics/types'
import { getUrl } from 'src/util/uri-utils'
import { ServerStorageModules } from 'src/storage/types'
import { GetUsersPublicDetailsResult } from '@worldbrain/memex-common/lib/user-management/types'
import type ContentSharingBackground from 'src/content-sharing/background'

interface TabArg {
tab: Tabs.Tab
Expand All @@ -59,7 +59,6 @@ export default class DirectLinkingBackground {
browserAPIs: Pick<Browser, 'tabs' | 'storage' | 'webRequest'>
storageManager: Storex
pages: PageIndexingBackground
contentSharingBG: ContentSharingBackground
socialBg: SocialBG
normalizeUrl?: URLNormalizer
analytics: Analytics
Expand Down Expand Up @@ -94,6 +93,11 @@ export default class DirectLinkingBackground {
getAllAnnotationsByUrl: this.getAllAnnotationsByUrl.bind(this),
listAnnotationsByPageUrl: this.listAnnotationsByPageUrl.bind(this),
createAnnotation: this.createAnnotation.bind(this),
findAnnotationPrivacyLevels: this.findAnnotationPrivacyLevels.bind(
this,
),
setAnnotationPrivacyLevel: this.setAnnotationPrivacyLevel,
deleteAnnotationPrivacyLevel: this.deleteAnnotationPrivacyLevel,
editAnnotation: this.editAnnotation.bind(this),
editAnnotationTags: this.editAnnotationTags.bind(this),
updateAnnotationTags: this.updateAnnotationTags.bind(this),
Expand Down Expand Up @@ -428,6 +432,34 @@ export default class DirectLinkingBackground {
return annotationUrl
}

async findAnnotationPrivacyLevels(_, params: { annotationUrls: string[] }) {
const storedLevels = await this.annotationStorage.getPrivacyLevelsByAnnotation(
{ annotations: params.annotationUrls },
)

const privacyLevels = {}
for (const annotationUrl of params.annotationUrls) {
privacyLevels[annotationUrl] =
storedLevels[annotationUrl]?.privacyLevel ??
AnnotationPrivacyLevels.PRIVATE
}
return privacyLevels
}

setAnnotationPrivacyLevel = async (
_,
params: { annotation: string; privacyLevel: AnnotationPrivacyLevels },
) => {
await this.annotationStorage.setAnnotationPrivacyLevel(params)
}

deleteAnnotationPrivacyLevel = async (
_,
params: { annotation: string },
) => {
await this.annotationStorage.deleteAnnotationPrivacyLevel(params)
}

async insertAnnotToList(_, params: AnnotListEntry) {
return this.annotationStorage.insertAnnotToList(params)
}
Expand Down Expand Up @@ -537,9 +569,6 @@ export default class DirectLinkingBackground {
await this.annotationStorage.deleteTagsByUrl({ url: pk })
}

await this.options.contentSharingBG.deleteAnnotationShareData({
annotationUrl: pk,
})
await this.annotationStorage.deleteAnnotation(pk)
}

Expand Down
45 changes: 20 additions & 25 deletions src/annotations/background/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { AnnotationPrivacyLevels } from '@worldbrain/memex-common/lib/annotation
async function insertTestData({
storageManager,
backgroundModules: {
contentSharing: { storage: contentSharingStorage },
directLinking: { annotationStorage },
customLists,
},
Expand Down Expand Up @@ -38,7 +37,7 @@ async function insertTestData({
url: annot.url,
} as any)

await contentSharingStorage.setAnnotationPrivacyLevel({
await annotationStorage.setAnnotationPrivacyLevel({
annotation: annot.url,
privacyLevel: AnnotationPrivacyLevels.PROTECTED,
})
Expand Down Expand Up @@ -73,7 +72,6 @@ async function setupTest() {
return {
annotationStorage:
setup.backgroundModules.directLinking.annotationStorage,
contentSharingStorage: setup.backgroundModules.contentSharing.storage,
}
}

Expand All @@ -96,11 +94,11 @@ describe('Annotations storage', () => {
})

test('fetch privacy level for an annotation', async () => {
const { contentSharingStorage } = await setupTest()
const { annotationStorage } = await setupTest()

const url = DATA.annotation.url
expect(
await contentSharingStorage.findAnnotationPrivacyLevel({
await annotationStorage.findAnnotationPrivacyLevel({
annotation: url,
}),
).toEqual(
Expand Down Expand Up @@ -172,10 +170,10 @@ describe('Annotations storage', () => {
})

test('update annotation privacy level', async () => {
const { contentSharingStorage } = await setupTest()
const { annotationStorage } = await setupTest()

const url = DATA.annotation.url
const origPrivacyLevel = await contentSharingStorage.findAnnotationPrivacyLevel(
const origPrivacyLevel = await annotationStorage.findAnnotationPrivacyLevel(
{ annotation: url },
)
expect(origPrivacyLevel).toEqual(
Expand All @@ -186,26 +184,26 @@ describe('Annotations storage', () => {
}),
)

await contentSharingStorage.deleteAnnotationPrivacyLevel({
await annotationStorage.deleteAnnotationPrivacyLevel({
annotation: url,
})

expect(
await contentSharingStorage.findAnnotationPrivacyLevel({
await annotationStorage.findAnnotationPrivacyLevel({
annotation: url,
}),
).toEqual(null)

const updatedWhen = new Date()

await contentSharingStorage.setAnnotationPrivacyLevel({
await annotationStorage.setAnnotationPrivacyLevel({
annotation: url,
privacyLevel: AnnotationPrivacyLevels.PRIVATE,
updatedWhen,
})

expect(
await contentSharingStorage.findAnnotationPrivacyLevel({
await annotationStorage.findAnnotationPrivacyLevel({
annotation: url,
}),
).toEqual(
Expand All @@ -216,14 +214,14 @@ describe('Annotations storage', () => {
}),
)

await contentSharingStorage.setAnnotationPrivacyLevel({
await annotationStorage.setAnnotationPrivacyLevel({
annotation: url,
privacyLevel: AnnotationPrivacyLevels.SHARED,
updatedWhen,
})

expect(
await contentSharingStorage.findAnnotationPrivacyLevel({
await annotationStorage.findAnnotationPrivacyLevel({
annotation: url,
}),
).toEqual(
Expand All @@ -234,14 +232,14 @@ describe('Annotations storage', () => {
}),
)

await contentSharingStorage.setAnnotationPrivacyLevel({
await annotationStorage.setAnnotationPrivacyLevel({
annotation: url,
privacyLevel: AnnotationPrivacyLevels.SHARED_PROTECTED,
updatedWhen,
})

expect(
await contentSharingStorage.findAnnotationPrivacyLevel({
await annotationStorage.findAnnotationPrivacyLevel({
annotation: url,
}),
).toEqual(
Expand Down Expand Up @@ -274,14 +272,11 @@ describe('Annotations storage', () => {
})

test('delete annotation should result in delete of any privacy level', async () => {
const {
annotationStorage,
contentSharingStorage,
} = await setupTest()
const { annotationStorage } = await setupTest()

const url = DATA.directLink.url
expect(
await contentSharingStorage.findAnnotationPrivacyLevel({
await annotationStorage.findAnnotationPrivacyLevel({
annotation: url,
}),
).toEqual(
Expand All @@ -294,7 +289,7 @@ describe('Annotations storage', () => {

await annotationStorage.deleteAnnotation(url)
expect(
await contentSharingStorage.findAnnotationPrivacyLevel({
await annotationStorage.findAnnotationPrivacyLevel({
annotation: url,
}),
).toEqual(null)
Expand Down Expand Up @@ -385,11 +380,11 @@ describe('Annotations storage', () => {
})

test('delete annotation privacy level', async () => {
const { contentSharingStorage } = await setupTest()
const { annotationStorage } = await setupTest()

const url = DATA.directLink.url
expect(
await contentSharingStorage.findAnnotationPrivacyLevel({
await annotationStorage.findAnnotationPrivacyLevel({
annotation: url,
}),
).toEqual(
Expand All @@ -400,12 +395,12 @@ describe('Annotations storage', () => {
}),
)

await contentSharingStorage.deleteAnnotationPrivacyLevel({
await annotationStorage.deleteAnnotationPrivacyLevel({
annotation: url,
})

expect(
await contentSharingStorage.findAnnotationPrivacyLevel({
await annotationStorage.findAnnotationPrivacyLevel({
annotation: url,
}),
).toEqual(null)
Expand Down
Loading

0 comments on commit bc2acd5

Please sign in to comment.