Merge pull request #4063 from omnivore-app/fix/mark-item-as-seen
Hide move/archived/deleted items from home feed
This commit is contained in:
@ -876,6 +876,7 @@ export const moveToFolderResolver = authorized<
|
||||
{
|
||||
folder,
|
||||
savedAt,
|
||||
seenAt: new Date(),
|
||||
},
|
||||
uid,
|
||||
pubsub
|
||||
@ -969,10 +970,10 @@ export const emptyTrashResolver = authorized<
|
||||
})
|
||||
|
||||
await batchDelete({
|
||||
state: LibraryItemState.Deleted,
|
||||
user: {
|
||||
id: uid,
|
||||
},
|
||||
state: LibraryItemState.Deleted,
|
||||
})
|
||||
|
||||
return {
|
||||
|
||||
@ -657,7 +657,9 @@ export const functionResolvers = {
|
||||
.map((item) => item.id)
|
||||
const libraryItems = (
|
||||
await ctx.dataLoaders.libraryItems.loadMany(libraryItemIds)
|
||||
).filter((libraryItem) => !isError(libraryItem)) as Array<LibraryItem>
|
||||
).filter(
|
||||
(libraryItem) => !!libraryItem && !isError(libraryItem)
|
||||
) as Array<LibraryItem>
|
||||
|
||||
const publicItemIds = section.items
|
||||
.filter((item) => item.type === 'public_item')
|
||||
|
||||
@ -79,6 +79,7 @@ export const setLinkArchivedResolver = authorized<
|
||||
{
|
||||
state,
|
||||
archivedAt,
|
||||
seenAt: new Date(),
|
||||
},
|
||||
uid
|
||||
)
|
||||
|
||||
@ -5,6 +5,8 @@ import {
|
||||
DeepPartial,
|
||||
EntityManager,
|
||||
FindOptionsWhere,
|
||||
In,
|
||||
IsNull,
|
||||
ObjectLiteral,
|
||||
} from 'typeorm'
|
||||
import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity'
|
||||
@ -133,26 +135,34 @@ export enum SortBy {
|
||||
const readingProgressDataSource = new ReadingProgressDataSource()
|
||||
|
||||
export const batchGetLibraryItems = async (ids: readonly string[]) => {
|
||||
const items = await findLibraryItemsByIds(ids as string[], undefined, {
|
||||
select: [
|
||||
'id',
|
||||
'title',
|
||||
'author',
|
||||
'thumbnail',
|
||||
'wordCount',
|
||||
'savedAt',
|
||||
'originalUrl',
|
||||
'directionality',
|
||||
'description',
|
||||
'subscription',
|
||||
'siteName',
|
||||
'siteIcon',
|
||||
'archivedAt',
|
||||
'deletedAt',
|
||||
'slug',
|
||||
'previewContent',
|
||||
],
|
||||
})
|
||||
const selectColumns: Array<keyof LibraryItem> = [
|
||||
'id',
|
||||
'title',
|
||||
'author',
|
||||
'thumbnail',
|
||||
'wordCount',
|
||||
'savedAt',
|
||||
'originalUrl',
|
||||
'directionality',
|
||||
'description',
|
||||
'subscription',
|
||||
'siteName',
|
||||
'siteIcon',
|
||||
'archivedAt',
|
||||
'deletedAt',
|
||||
'slug',
|
||||
'previewContent',
|
||||
]
|
||||
const items = await authTrx(async (tx) =>
|
||||
tx.getRepository(LibraryItem).find({
|
||||
select: selectColumns,
|
||||
where: {
|
||||
id: In(ids as string[]),
|
||||
state: LibraryItemState.Succeeded,
|
||||
seenAt: IsNull(),
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
return ids.map((id) => items.find((item) => item.id === id) || undefined)
|
||||
}
|
||||
@ -891,6 +901,7 @@ export const softDeleteLibraryItem = async (
|
||||
await itemRepo.update(id, {
|
||||
state: LibraryItemState.Deleted,
|
||||
deletedAt: new Date(),
|
||||
seenAt: new Date(),
|
||||
})
|
||||
|
||||
return itemRepo.findOneByOrFail({ id })
|
||||
@ -1381,30 +1392,6 @@ export const batchDelete = async (criteria: FindOptionsWhere<LibraryItem>) => {
|
||||
return authTrx(async (t) => t.query(sql))
|
||||
}
|
||||
|
||||
export const batchDeleteAllTrash = async () => {
|
||||
const sql = `
|
||||
DO $$
|
||||
DECLARE
|
||||
user_record RECORD;
|
||||
user_cursor CURSOR FOR SELECT id FROM omnivore.user WHERE status = 'ACTIVE'; -- Adjust the condition as needed
|
||||
BEGIN
|
||||
OPEN user_cursor;
|
||||
|
||||
LOOP
|
||||
FETCH NEXT FROM user_cursor INTO user_record;
|
||||
EXIT WHEN NOT FOUND;
|
||||
|
||||
DELETE FROM omnivore.library_item WHERE user_id = user_record.id AND state = 'DELETED' AND deleted_at < '2023-01-01';
|
||||
|
||||
RETURN NEXT;
|
||||
END LOOP;
|
||||
|
||||
CLOSE user_cursor;
|
||||
END $$;`
|
||||
|
||||
return authTrx(async (t) => t.query(sql))
|
||||
}
|
||||
|
||||
export const findLibraryItemIdsByLabelId = async (
|
||||
labelId: string,
|
||||
userId: string
|
||||
|
||||
Reference in New Issue
Block a user