mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Merge pull request #3737 from omnivore-app/fix/newsletter-rules
append newsletter labels to avoid labels attached by rules being replaced
This commit is contained in:
commit
e2b38d3e91
5 changed files with 36 additions and 17 deletions
|
|
@ -171,7 +171,7 @@ export const recommendResolver = authorized<
|
|||
member.user.id,
|
||||
item.id,
|
||||
{
|
||||
group: { id: group.id },
|
||||
group: { id: group.id, name: group.name },
|
||||
note: input.note,
|
||||
recommender: { id: uid },
|
||||
createdAt: new Date(),
|
||||
|
|
@ -278,11 +278,11 @@ export const recommendHighlightsResolver = authorized<
|
|||
member.user.id,
|
||||
item.id,
|
||||
{
|
||||
id: group.id,
|
||||
note: input.note,
|
||||
recommender: { id: uid },
|
||||
createdAt: new Date(),
|
||||
libraryItem: { id: item.id },
|
||||
group: { id: group.id, name: group.name },
|
||||
},
|
||||
auth,
|
||||
input.highlightIds
|
||||
|
|
|
|||
|
|
@ -259,7 +259,7 @@ export const createLabelAndRuleForGroup = async (
|
|||
},
|
||||
],
|
||||
// add a condition to check if the page is created
|
||||
filter: `event:created recommendedBy:"${groupName}"`,
|
||||
filter: `recommendedBy:"${groupName}"`,
|
||||
})
|
||||
|
||||
await Promise.all([addLabelPromise, sendNotificationPromise])
|
||||
|
|
|
|||
|
|
@ -879,6 +879,7 @@ export const updateLibraryItem = async (
|
|||
...updatedLibraryItem,
|
||||
originalContent: undefined,
|
||||
readableContent: undefined,
|
||||
feedContent: undefined,
|
||||
},
|
||||
userId,
|
||||
id
|
||||
|
|
@ -893,6 +894,7 @@ export const updateLibraryItem = async (
|
|||
...libraryItem,
|
||||
originalContent: undefined,
|
||||
readableContent: undefined,
|
||||
feedContent: undefined,
|
||||
},
|
||||
userId,
|
||||
id
|
||||
|
|
@ -1061,6 +1063,7 @@ export const createOrUpdateLibraryItem = async (
|
|||
...newLibraryItem,
|
||||
originalContent: undefined,
|
||||
readableContent: undefined,
|
||||
feedContent: undefined,
|
||||
},
|
||||
userId,
|
||||
newLibraryItem.id
|
||||
|
|
@ -1430,7 +1433,9 @@ export const filterItemEvents = (
|
|||
return labelsToTest.some((label) => {
|
||||
const hasWildcard = label.includes('*')
|
||||
if (hasWildcard) {
|
||||
return labels?.some((l) => l.match(new RegExp(label, 'i')))
|
||||
return labels?.some(
|
||||
(l) => l.match(new RegExp(label.replace('*', '.*'), 'i')) // match wildcard
|
||||
)
|
||||
}
|
||||
|
||||
return labels?.some((l) => l.toLowerCase() === label)
|
||||
|
|
@ -1523,16 +1528,17 @@ export const filterItemEvents = (
|
|||
return event.id && ids.includes(event.id.toString())
|
||||
}
|
||||
case 'recommendedby': {
|
||||
if (lowercasedValue === '*') {
|
||||
// select all if * is provided
|
||||
return event.recommenderNames && event.recommenderNames.length > 0
|
||||
if (!event.recommenderNames) {
|
||||
return false
|
||||
}
|
||||
|
||||
return (
|
||||
event.recommenderNames &&
|
||||
(event.recommenderNames as string[]).some(
|
||||
(name) => name.toLowerCase() === lowercasedValue
|
||||
)
|
||||
if (lowercasedValue === '*') {
|
||||
// select all if * is provided
|
||||
return event.recommenderNames.length > 0
|
||||
}
|
||||
|
||||
return (event.recommenderNames as string[]).some(
|
||||
(name) => name.toLowerCase() === lowercasedValue
|
||||
)
|
||||
}
|
||||
case 'no':
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import {
|
|||
createOrUpdateLibraryItem,
|
||||
CreateOrUpdateLibraryItemArgs,
|
||||
findLibraryItemByUrl,
|
||||
updateLibraryItem,
|
||||
} from './library_item'
|
||||
|
||||
export const addRecommendation = async (
|
||||
|
|
@ -41,7 +42,7 @@ export const addRecommendation = async (
|
|||
uploadFile: item.uploadFile,
|
||||
wordCount: item.wordCount,
|
||||
publishedAt: item.publishedAt,
|
||||
recommenderNames: item.recommenderNames,
|
||||
recommenderNames: [recommendation.group?.name],
|
||||
}
|
||||
|
||||
recommendedItem = await createOrUpdateLibraryItem(newItem, userId)
|
||||
|
|
@ -66,6 +67,15 @@ export const addRecommendation = async (
|
|||
if (highlights) {
|
||||
await createHighlights(highlights, userId)
|
||||
}
|
||||
} else {
|
||||
// update the item
|
||||
await updateLibraryItem(
|
||||
recommendedItem.id,
|
||||
{
|
||||
recommenderNames: [recommendation.group?.name],
|
||||
},
|
||||
userId
|
||||
)
|
||||
}
|
||||
|
||||
await createRecommendation(
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue