fix(ai-chat): incorporate unreadOnly setting in timeline summary logic

This commit is contained in:
DIYgod 2025-10-20 11:42:10 +08:00
parent add77bf597
commit 2d3f271e78
No known key found for this signature in database
2 changed files with 29 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import { nanoid } from "nanoid"
import { useEffect, useMemo, useRef } from "react"
import { useAISettingValue } from "~/atoms/settings/ai"
import { useGeneralSettingKey } from "~/atoms/settings/general"
import { ROUTE_FEED_IN_FOLDER, ROUTE_FEED_PENDING } from "~/constants"
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
@ -52,20 +53,24 @@ const buildTimelineSummaryChatId = ({
view,
feedId,
timelineId,
unreadOnly,
seed,
}: {
view: number
feedId: string
timelineId?: string | null
unreadOnly: boolean
seed: string
}) => {
const normalizedTimelineId = timelineId ?? "all"
const unreadSegment = unreadOnly ? "unread" : "all"
const prefix = AI_CHAT_SPECIAL_ID_PREFIX.TIMELINE_SUMMARY
return `${prefix}${view}:${feedId}:${normalizedTimelineId}:${seed}`
return `${prefix}${view}:${feedId}:${normalizedTimelineId}:${unreadSegment}:${seed}`
}
export const useAutoTimelineSummaryShortcut = () => {
const aiSettings = useAISettingValue()
const unreadOnly = useGeneralSettingKey("unreadOnly")
const { view, feedId, entryId, timelineId } = useRouteParamsSelector((params) => ({
view: params.view,
@ -108,9 +113,13 @@ export const useAutoTimelineSummaryShortcut = () => {
const contextKey = useMemo(() => {
if (!isAllTimeline) return null
const keyParts = [`timeline:${timelineId ?? "all"}`, `feed:${normalizedFeedId}`]
const keyParts = [
`timeline:${timelineId ?? "all"}`,
`feed:${normalizedFeedId}`,
`unread:${unreadOnly ? "1" : "0"}`,
]
return keyParts.join("|")
}, [isAllTimeline, timelineId, normalizedFeedId])
}, [isAllTimeline, timelineId, normalizedFeedId, unreadOnly])
useEffect(() => {
if (previousContextKeyRef.current !== contextKey) {
@ -157,8 +166,16 @@ export const useAutoTimelineSummaryShortcut = () => {
})
}
if (unreadOnly) {
blocks.push({
id: BlockSliceAction.SPECIAL_TYPES.unreadOnly,
type: "unreadOnly",
value: "true",
})
}
return blocks
}, [isAllTimeline, normalizedFeedId])
}, [isAllTimeline, normalizedFeedId, unreadOnly])
useEffect(() => {
if (!contextKey || !defaultShortcut) {
@ -198,6 +215,7 @@ export const useAutoTimelineSummaryShortcut = () => {
view,
feedId: normalizedFeedId,
timelineId: timelineId ?? null,
unreadOnly,
})
const now = Date.now()
@ -216,6 +234,7 @@ export const useAutoTimelineSummaryShortcut = () => {
view,
feedId: normalizedFeedId,
timelineId: timelineId ?? null,
unreadOnly,
seed: nanoid(6),
})
@ -254,6 +273,7 @@ export const useAutoTimelineSummaryShortcut = () => {
defaultShortcut,
normalizedFeedId,
timelineId,
unreadOnly,
view,
timelineSummaryManualOverride,
])

View File

@ -316,11 +316,14 @@ class AIPersistServiceStatic {
view: number
feedId: string
timelineId?: string | null
unreadOnly: boolean
}) {
const timelineSegment = criteria.timelineId ?? "all"
const unreadSegment = criteria.unreadOnly ? "unread" : "all"
const prefix = `${AI_CHAT_SPECIAL_ID_PREFIX.TIMELINE_SUMMARY}${criteria.view}:${criteria.feedId}:${timelineSegment}:${unreadSegment}:`
return db.query.aiChatTable
.findFirst({
where: (table) =>
sql`${table.chatId} LIKE ${`${AI_CHAT_SPECIAL_ID_PREFIX.TIMELINE_SUMMARY}${criteria.view}:${criteria.feedId}:${criteria.timelineId ?? "all"}:%`}`,
where: (table) => sql`${table.chatId} LIKE ${`${prefix}%`}`,
orderBy: (table, { desc }) => desc(table.updatedAt),
columns: {
chatId: true,