From 6ce2c2270fbe611fc7ac8f532f68a45cf5f86cff Mon Sep 17 00:00:00 2001 From: DIYgod Date: Sat, 12 Oct 2024 00:32:39 +0800 Subject: [PATCH] feat: readHistories option for reads post --- apps/renderer/src/store/entry/helper.ts | 16 ++++++++++------ apps/renderer/src/store/entry/store.ts | 8 +++++++- packages/shared/src/hono.ts | 1 + 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/apps/renderer/src/store/entry/helper.ts b/apps/renderer/src/store/entry/helper.ts index a211cfb62..81618116d 100644 --- a/apps/renderer/src/store/entry/helper.ts +++ b/apps/renderer/src/store/entry/helper.ts @@ -7,9 +7,6 @@ import { useSubscriptionStore } from "../subscription" import { useEntryStore } from "./store" import type { EntryFilter } from "./types" -type EntryId = string -type FeedId = string - export const getFilteredFeedIds = (feedIds: string[], filter?: EntryFilter) => { const state = useEntryStore.getState() const ids = [] as string[] @@ -33,11 +30,18 @@ export const getFilteredFeedIds = (feedIds: string[], filter?: EntryFilter) => { } const unread = create({ - fetcher: async (ids: ([FeedId, EntryId, boolean] | [FeedId, EntryId])[]) => { + fetcher: async ( + ids: { + entryId: string + isInbox: boolean + isPrivate?: boolean + }[], + ) => { await apiClient.reads.$post({ json: { - entryIds: ids.map((i) => i[1]), - isInbox: ids[0][2], + entryIds: ids.map((i) => i.entryId), + isInbox: ids[0].isInbox, + readHistories: ids.filter((i) => !i.isPrivate).map((i) => i.entryId), }, }) diff --git a/apps/renderer/src/store/entry/store.ts b/apps/renderer/src/store/entry/store.ts index 52fe53e40..b290137cd 100644 --- a/apps/renderer/src/store/entry/store.ts +++ b/apps/renderer/src/store/entry/store.ts @@ -11,6 +11,7 @@ import { EntryService } from "~/services" import { feedActions } from "../feed" import { imageActions } from "../image" import { inboxActions } from "../inbox" +import { getSubscriptionByFeedId } from "../subscription" import { feedUnreadActions } from "../unread" import { createZustandStore, doMutationAndTransaction } from "../utils/helper" import { internal_batchMarkRead } from "./helper" @@ -349,6 +350,7 @@ class EntryActions { async markRead({ feedId, entryId, read }: { feedId: string; entryId: string; read: boolean }) { const entry = get().flatMapEntries[entryId] const isInbox = entry?.entries && "inboxHandle" in entry.entries + const subscription = getSubscriptionByFeedId(feedId) if (read && entry?.read) { return @@ -364,7 +366,11 @@ class EntryActions { // Send api request async () => { if (read) { - await internal_batchMarkRead([feedId, entryId, isInbox]) + await internal_batchMarkRead({ + entryId, + isInbox, + isPrivate: subscription?.isPrivate, + }) } else { await apiClient.reads.$delete({ json: { diff --git a/packages/shared/src/hono.ts b/packages/shared/src/hono.ts index 9184f21f3..aa6922d00 100644 --- a/packages/shared/src/hono.ts +++ b/packages/shared/src/hono.ts @@ -5174,6 +5174,7 @@ declare const _routes: hono_hono_base.HonoBase