feat: readHistories option for reads post
This commit is contained in:
@@ -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),
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -5174,6 +5174,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
|
||||
json: {
|
||||
entryIds: string[];
|
||||
isInbox?: boolean | undefined;
|
||||
readHistories?: string[] | undefined;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
|
||||
Reference in New Issue
Block a user