From 252443f1e46cf5f83bc411a6f83163f22a602589 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Thu, 1 Feb 2024 16:45:08 +0800 Subject: [PATCH] fix: update reading progress in cache when mark as read action was triggered in a rule --- packages/api/src/jobs/trigger_rule.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/api/src/jobs/trigger_rule.ts b/packages/api/src/jobs/trigger_rule.ts index 72d902a90..efd3063fd 100644 --- a/packages/api/src/jobs/trigger_rule.ts +++ b/packages/api/src/jobs/trigger_rule.ts @@ -1,3 +1,4 @@ +import { ReadingProgressDataSource } from '../datasources/reading_progress_data_source' import { LibraryItem, LibraryItemState } from '../entity/library_item' import { Rule, RuleAction, RuleActionType, RuleEventType } from '../entity/rule' import { addLabelsToLibraryItem } from '../services/labels' @@ -21,10 +22,10 @@ interface RuleActionObj { action: RuleAction libraryItem: LibraryItem } +type RuleActionFunc = (obj: RuleActionObj) => Promise export const TRIGGER_RULE_JOB_NAME = 'trigger-rule' - -type RuleActionFunc = (obj: RuleActionObj) => Promise +const readingProgressDataSource = new ReadingProgressDataSource() const addLabels = async (obj: RuleActionObj) => { const labelIds = obj.action.params @@ -48,16 +49,14 @@ const archivePage = async (obj: RuleActionObj) => { } const markPageAsRead = async (obj: RuleActionObj) => { - return updateLibraryItem( + return readingProgressDataSource.updateReadingProgress( + obj.userId, obj.libraryItem.id, { + readingProgressPercent: 100, readingProgressTopPercent: 100, - readingProgressBottomPercent: 100, - readAt: new Date(), - }, - obj.userId, - undefined, - true + readingProgressAnchorIndex: undefined, + } ) }