fix: inbox unread count not up to date, close #3137
This commit is contained in:
@@ -582,6 +582,8 @@ class EntryActions {
|
||||
const { inboxId } = entry
|
||||
const fullInboxId = `inbox-${inboxId}`
|
||||
|
||||
feedUnreadActions.incrementByFeedId(inboxId, -1)
|
||||
|
||||
set((state) => {
|
||||
const nextFlatMapEntries = { ...state.flatMapEntries }
|
||||
|
||||
@@ -618,6 +620,9 @@ class EntryActions {
|
||||
})
|
||||
|
||||
tx.rollback((entry, ctx) => {
|
||||
const { inboxId } = entry
|
||||
feedUnreadActions.incrementByFeedId(inboxId, 1)
|
||||
|
||||
set((state) => ({
|
||||
...state,
|
||||
entries: {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { FeedViewType } from "@follow/constants"
|
||||
|
||||
import { setFeedUnreadDirty } from "~/atoms/feed"
|
||||
import { INBOX_PREFIX_ID } from "~/constants"
|
||||
import { apiClient } from "~/lib/api-fetch"
|
||||
import { FeedUnreadService } from "~/services"
|
||||
|
||||
@@ -74,17 +75,25 @@ class FeedUnreadActions {
|
||||
* @returns previous value
|
||||
*/
|
||||
incrementByFeedId(feedId: string, inc: number) {
|
||||
const finalFeedId = feedId.startsWith(INBOX_PREFIX_ID)
|
||||
? feedId.slice(INBOX_PREFIX_ID.length)
|
||||
: feedId
|
||||
|
||||
const state = get()
|
||||
const cur = state.data[feedId]
|
||||
const cur = state.data[finalFeedId]
|
||||
const nextValue = Math.max(0, (cur || 0) + inc)
|
||||
|
||||
this.internal_setValue([[feedId, nextValue]])
|
||||
setFeedUnreadDirty(feedId)
|
||||
this.internal_setValue([[finalFeedId, nextValue]])
|
||||
setFeedUnreadDirty(finalFeedId)
|
||||
return cur
|
||||
}
|
||||
|
||||
updateByFeedId(feedId: string, unread: number) {
|
||||
this.internal_setValue([[feedId, unread]])
|
||||
const finalFeedId = feedId.startsWith(INBOX_PREFIX_ID)
|
||||
? feedId.slice(INBOX_PREFIX_ID.length)
|
||||
: feedId
|
||||
|
||||
this.internal_setValue([[finalFeedId, unread]])
|
||||
}
|
||||
|
||||
subscribeUnreadCount(fn: (count: number) => void, immediately?: boolean) {
|
||||
|
||||
Reference in New Issue
Block a user