merge labels and highlights when saving a duplicate item
This commit is contained in:
@ -58,6 +58,34 @@ export const findOrCreateLabels = async (
|
||||
)
|
||||
}
|
||||
|
||||
export const createAndAddLabelsToLibraryItem = async (
|
||||
libraryItemId: string,
|
||||
userId: string,
|
||||
labels?: CreateLabelInput[] | null,
|
||||
rssFeedUrl?: string | null,
|
||||
source?: LabelSource,
|
||||
pubsub?: PubsubClient
|
||||
) => {
|
||||
if (rssFeedUrl) {
|
||||
// add rss label to labels
|
||||
labels = (labels || []).concat({ name: 'RSS' })
|
||||
source = 'system'
|
||||
}
|
||||
|
||||
// save labels in item
|
||||
if (labels && labels.length > 0) {
|
||||
const newLabels = await findOrCreateLabels(labels, userId)
|
||||
|
||||
await addLabelsToLibraryItem(
|
||||
newLabels,
|
||||
libraryItemId,
|
||||
userId,
|
||||
source,
|
||||
pubsub
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export const createAndSaveLabelsInLibraryItem = async (
|
||||
libraryItemId: string,
|
||||
userId: string,
|
||||
|
||||
@ -24,7 +24,7 @@ import { parsePreparedContent } from '../utils/parser'
|
||||
import { contentReaderForLibraryItem } from '../utils/uploads'
|
||||
import { createPageSaveRequest } from './create_page_save_request'
|
||||
import { createHighlight } from './highlights'
|
||||
import { createAndSaveLabelsInLibraryItem } from './labels'
|
||||
import { createAndAddLabelsToLibraryItem } from './labels'
|
||||
import { createOrUpdateLibraryItem } from './library_item'
|
||||
|
||||
// where we can use APIs to fetch their underlying content.
|
||||
@ -132,7 +132,8 @@ export const savePage = async (
|
||||
)
|
||||
clientRequestId = newItem.id
|
||||
|
||||
await createAndSaveLabelsInLibraryItem(
|
||||
// merge labels
|
||||
await createAndAddLabelsToLibraryItem(
|
||||
clientRequestId,
|
||||
user.id,
|
||||
input.labels,
|
||||
@ -157,6 +158,7 @@ export const savePage = async (
|
||||
libraryItem: { id: clientRequestId },
|
||||
}
|
||||
|
||||
// merge highlights
|
||||
try {
|
||||
await createHighlight(highlight, clientRequestId, user.id)
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user