append newsletter labels to avoid labels attached by rules being replaced

This commit is contained in:
Hongbo Wu 2024-03-27 10:37:04 +08:00
parent c791fec421
commit af78b6f4f0

View file

@ -15,7 +15,7 @@ import {
parsePreparedContent,
parseUrlMetadata,
} from '../utils/parser'
import { createAndSaveLabelsInLibraryItem } from './labels'
import { createAndAddLabelsToLibraryItem } from './labels'
import {
createOrUpdateLibraryItem,
findLibraryItemByUrl,
@ -79,6 +79,8 @@ export const saveEmail = async (
return updatedLibraryItem
}
const labels = [{ name: 'Newsletter' }]
// start a transaction to create the library item and update the received email
const newLibraryItem = await createOrUpdateLibraryItem(
{
@ -105,6 +107,7 @@ export const saveEmail = async (
wordCount: wordsCount(content),
subscription: input.author,
folder: input.folder,
labelNames: labels.map((label) => label.name),
},
input.userId
)
@ -120,11 +123,11 @@ export const saveEmail = async (
})
}
// save newsletter label in the item
await createAndSaveLabelsInLibraryItem(
// add newsletter label to the item
await createAndAddLabelsToLibraryItem(
newLibraryItem.id,
input.userId,
[{ name: 'Newsletter' }],
labels,
undefined,
'system'
)