fix rss feeds
This commit is contained in:
@ -24,6 +24,7 @@ import {
|
||||
UpdateSubscriptionErrorCode,
|
||||
UpdateSubscriptionSuccess,
|
||||
} from '../../generated/graphql'
|
||||
import { getRepository } from '../../repository'
|
||||
import { unsubscribe } from '../../services/subscriptions'
|
||||
import { Merge } from '../../util'
|
||||
import { analytics } from '../../utils/analytics'
|
||||
@ -52,45 +53,44 @@ export const subscriptionsResolver = authorized<
|
||||
SubscriptionsSuccessPartial,
|
||||
SubscriptionsError,
|
||||
QuerySubscriptionsArgs
|
||||
>(async (_obj, { sort, type }, { authTrx, uid, log }) => {
|
||||
>(async (_obj, { sort, type }, { uid, log }) => {
|
||||
try {
|
||||
const sortBy =
|
||||
sort?.by === SortBy.UpdatedTime ? 'lastFetchedAt' : 'createdAt'
|
||||
const sortOrder = sort?.order === SortOrder.Ascending ? 'ASC' : 'DESC'
|
||||
|
||||
const subscriptions = await authTrx(async (t) => {
|
||||
const queryBuilder = t
|
||||
.getRepository(Subscription)
|
||||
.createQueryBuilder('subscription')
|
||||
.leftJoinAndSelect('subscription.newsletterEmail', 'newsletterEmail')
|
||||
.where({
|
||||
user: { id: uid },
|
||||
})
|
||||
const queryBuilder = getRepository(Subscription)
|
||||
.createQueryBuilder('subscription')
|
||||
.leftJoinAndSelect('subscription.newsletterEmail', 'newsletterEmail')
|
||||
.where({
|
||||
user: { id: uid },
|
||||
})
|
||||
|
||||
if (type && type == SubscriptionType.Newsletter) {
|
||||
queryBuilder.andWhere({
|
||||
type,
|
||||
status: SubscriptionStatus.Active,
|
||||
})
|
||||
} else if (type && type == SubscriptionType.Rss) {
|
||||
queryBuilder.andWhere({
|
||||
type,
|
||||
})
|
||||
} else {
|
||||
queryBuilder.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where({
|
||||
type: SubscriptionType.Newsletter,
|
||||
status: SubscriptionStatus.Active,
|
||||
}).orWhere({
|
||||
type: SubscriptionType.Rss,
|
||||
})
|
||||
if (type && type == SubscriptionType.Newsletter) {
|
||||
queryBuilder.andWhere({
|
||||
type,
|
||||
status: SubscriptionStatus.Active,
|
||||
})
|
||||
} else if (type && type == SubscriptionType.Rss) {
|
||||
queryBuilder.andWhere({
|
||||
type,
|
||||
})
|
||||
} else {
|
||||
queryBuilder.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where({
|
||||
type: SubscriptionType.Newsletter,
|
||||
status: SubscriptionStatus.Active,
|
||||
}).orWhere({
|
||||
type: SubscriptionType.Rss,
|
||||
})
|
||||
)
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
return queryBuilder.orderBy('subscription.' + sortBy, sortOrder).getMany()
|
||||
})
|
||||
const subscriptions = await queryBuilder
|
||||
.orderBy('subscription.' + sortBy, sortOrder)
|
||||
.getMany()
|
||||
|
||||
return {
|
||||
subscriptions,
|
||||
@ -111,27 +111,24 @@ export const unsubscribeResolver = authorized<
|
||||
UnsubscribeSuccessPartial,
|
||||
UnsubscribeError,
|
||||
MutationUnsubscribeArgs
|
||||
>(async (_, { name, subscriptionId }, { authTrx, uid, log }) => {
|
||||
>(async (_, { name, subscriptionId }, { uid, log }) => {
|
||||
log.info('unsubscribeResolver')
|
||||
|
||||
try {
|
||||
const subscription = await authTrx(async (t) => {
|
||||
const queryBuilder = t
|
||||
.getRepository(Subscription)
|
||||
.createQueryBuilder('subscription')
|
||||
.leftJoinAndSelect('subscription.newsletterEmail', 'newsletterEmail')
|
||||
.where({ user: { id: uid } })
|
||||
const queryBuilder = getRepository(Subscription)
|
||||
.createQueryBuilder('subscription')
|
||||
.leftJoinAndSelect('subscription.newsletterEmail', 'newsletterEmail')
|
||||
.where({ user: { id: uid } })
|
||||
|
||||
if (subscriptionId) {
|
||||
// if subscriptionId is provided, ignore name
|
||||
queryBuilder.andWhere({ id: subscriptionId })
|
||||
} else {
|
||||
// if subscriptionId is not provided, use name for old clients
|
||||
queryBuilder.andWhere({ name })
|
||||
}
|
||||
if (subscriptionId) {
|
||||
// if subscriptionId is provided, ignore name
|
||||
queryBuilder.andWhere({ id: subscriptionId })
|
||||
} else {
|
||||
// if subscriptionId is not provided, use name for old clients
|
||||
queryBuilder.andWhere({ name })
|
||||
}
|
||||
|
||||
return queryBuilder.getOne()
|
||||
})
|
||||
const subscription = await queryBuilder.getOne()
|
||||
|
||||
if (!subscription) {
|
||||
return {
|
||||
@ -139,13 +136,6 @@ export const unsubscribeResolver = authorized<
|
||||
}
|
||||
}
|
||||
|
||||
// if subscription is already unsubscribed, throw error
|
||||
if (subscription.status === SubscriptionStatus.Unsubscribed) {
|
||||
return {
|
||||
errorCodes: [UnsubscribeErrorCode.AlreadyUnsubscribed],
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
subscription.type === SubscriptionType.Newsletter &&
|
||||
!subscription.unsubscribeMailTo &&
|
||||
@ -279,8 +269,6 @@ export const updateSubscriptionResolver = authorized<
|
||||
UpdateSubscriptionError,
|
||||
MutationUpdateSubscriptionArgs
|
||||
>(async (_, { input }, { authTrx, uid, log }) => {
|
||||
log.info('updateSubscriptionResolver')
|
||||
|
||||
try {
|
||||
analytics.track({
|
||||
userId: uid,
|
||||
@ -292,17 +280,10 @@ export const updateSubscriptionResolver = authorized<
|
||||
})
|
||||
|
||||
const updatedSubscription = await authTrx(async (t) => {
|
||||
// find existing subscription
|
||||
const subscription = await t.getRepository(Subscription).findOneBy({
|
||||
id: input.id,
|
||||
user: { id: uid },
|
||||
})
|
||||
if (!subscription) {
|
||||
throw new Error('subscription not found')
|
||||
}
|
||||
const repo = t.getRepository(Subscription)
|
||||
|
||||
// update subscription
|
||||
return t.getRepository(Subscription).save({
|
||||
await t.getRepository(Subscription).save({
|
||||
id: input.id,
|
||||
name: input.name || undefined,
|
||||
description: input.description || undefined,
|
||||
@ -311,6 +292,11 @@ export const updateSubscriptionResolver = authorized<
|
||||
: undefined,
|
||||
status: input.status || undefined,
|
||||
})
|
||||
|
||||
return repo.findOneByOrFail({
|
||||
id: input.id,
|
||||
user: { id: uid },
|
||||
})
|
||||
})
|
||||
|
||||
return {
|
||||
|
||||
@ -16,7 +16,7 @@ import {
|
||||
parsePreparedContent,
|
||||
parseUrlMetadata,
|
||||
} from '../utils/parser'
|
||||
import { addLabelsToLibraryItem, findOrCreateLabels } from './labels'
|
||||
import { findOrCreateLabels, saveLabelsInLibraryItem } from './labels'
|
||||
import {
|
||||
createLibraryItem,
|
||||
findLibraryItemByUrl,
|
||||
@ -130,7 +130,7 @@ export const saveEmail = async (
|
||||
if (newsletterLabel) {
|
||||
// add newsletter label
|
||||
const labels = await findOrCreateLabels([newsletterLabel], input.userId)
|
||||
await addLabelsToLibraryItem(labels, newLibraryItem.id, input.userId)
|
||||
await saveLabelsInLibraryItem(labels, newLibraryItem.id, input.userId)
|
||||
}
|
||||
|
||||
await updateReceivedEmail(input.receivedEmailId, 'article', input.userId)
|
||||
|
||||
@ -27,7 +27,7 @@ import { parsePreparedContent } from '../utils/parser'
|
||||
import { contentReaderForLibraryItem } from '../utils/uploads'
|
||||
import { createPageSaveRequest } from './create_page_save_request'
|
||||
import { createHighlight } from './highlights'
|
||||
import { findOrCreateLabels } from './labels'
|
||||
import { findOrCreateLabels, saveLabelsInLibraryItem } from './labels'
|
||||
import { createLibraryItem, updateLibraryItem } from './library_item'
|
||||
|
||||
// where we can use APIs to fetch their underlying content.
|
||||
@ -112,10 +112,6 @@ export const savePage = async (
|
||||
// save state
|
||||
itemToSave.archivedAt =
|
||||
input.state === ArticleSavingRequestStatus.Archived ? new Date() : null
|
||||
// add labels to page
|
||||
itemToSave.labels = input.labels
|
||||
? await findOrCreateLabels(input.labels, user.id)
|
||||
: undefined
|
||||
|
||||
// check if the page already exists
|
||||
const existingLibraryItem = await authTrx((t) =>
|
||||
@ -135,17 +131,18 @@ export const savePage = async (
|
||||
|
||||
clientRequestId = existingLibraryItem.id
|
||||
slug = existingLibraryItem.slug
|
||||
if (!(await updateLibraryItem(clientRequestId, itemToSave, user.id))) {
|
||||
return {
|
||||
errorCodes: [SaveErrorCode.Unknown],
|
||||
message: 'Failed to update existing page',
|
||||
}
|
||||
}
|
||||
await updateLibraryItem(clientRequestId, itemToSave, user.id)
|
||||
} else {
|
||||
// do not publish a pubsub event if the page is imported
|
||||
const newItem = await createLibraryItem(itemToSave, user.id)
|
||||
clientRequestId = newItem.id
|
||||
}
|
||||
|
||||
// add labels to page
|
||||
if (input.labels) {
|
||||
const labels = await findOrCreateLabels(input.labels, user.id)
|
||||
await saveLabelsInLibraryItem(labels, clientRequestId, user.id)
|
||||
}
|
||||
}
|
||||
|
||||
// we don't want to create thumbnail for imported pages
|
||||
|
||||
@ -91,7 +91,7 @@ const createSavingItemTask = async (
|
||||
source: 'rss-feeder',
|
||||
url: item.link,
|
||||
saveRequestId: '',
|
||||
labels: [{ name: 'RSS', color: '#f26522' }],
|
||||
labels: [{ name: 'RSS' }],
|
||||
rssFeedUrl: feedUrl,
|
||||
savedAt: item.isoDate,
|
||||
publishedAt: item.isoDate,
|
||||
|
||||
Reference in New Issue
Block a user