Skip to content

Commit 9095197

Browse files
committed
fix(mobile): notification for inbox
1 parent 4bde427 commit 9095197

5 files changed

Lines changed: 19 additions & 11 deletions

File tree

apps/mobile/src/hooks/useMessaging.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useHasNotificationActions } from "@follow/store/action/hooks"
2+
import { ROUTE_FEED_IN_INBOX } from "@follow/store/constants/app"
23
import { useWhoami } from "@follow/store/user/hooks"
34
import { getApp } from "@react-native-firebase/app"
45
import type { FirebaseMessagingTypes } from "@react-native-firebase/messaging"
@@ -48,6 +49,7 @@ export function useMessaging() {
4849
function navigateToEntry(message: FirebaseMessagingTypes.RemoteMessage) {
4950
if (
5051
!message.data ||
52+
message.data.type !== "new-entry" ||
5153
typeof message.data.view !== "string" ||
5254
typeof message.data.entryId !== "string"
5355
) {
@@ -57,6 +59,7 @@ export function useMessaging() {
5759
navigation.pushControllerView(EntryDetailScreen, {
5860
entryId: message.data.entryId,
5961
view: Number.parseInt(message.data.view),
62+
isInbox: String(message.data.feedId).startsWith(ROUTE_FEED_IN_INBOX),
6063
})
6164
}
6265

apps/mobile/src/screens/(stack)/entries/[entryId]/EntryDetailScreen.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ export const EntryDetailScreen: NavigationControllerView<{
3737
entryId: string
3838
entryIds?: string[]
3939
view: FeedViewType
40-
}> = ({ entryId, entryIds, view: viewType }) => {
41-
useAutoMarkAsRead(entryId)
40+
isInbox?: boolean
41+
}> = ({ entryId, entryIds, view: viewType, isInbox }) => {
42+
usePrefetchEntryDetail(entryId, isInbox)
4243
const entry = useEntry(entryId, (state) => ({
4344
title: state.title,
4445
url: state.url,
4546
summary: state.settings?.summary,
4647
translation: state.settings?.translation,
4748
readability: state.settings?.readability,
4849
}))
50+
useAutoMarkAsRead(entryId, !!entry)
4951
const insets = useSafeAreaInsets()
5052
const ctxValue = useMemo(
5153
() => ({

packages/internal/store/src/entry/hooks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ export const useEntriesQuery = (
120120
}, [entriesIds, query])
121121
}
122122

123-
export const usePrefetchEntryDetail = (entryId: string) => {
123+
export const usePrefetchEntryDetail = (entryId: string, isInbox?: boolean) => {
124124
return useQuery({
125125
queryKey: ["entry", entryId],
126-
queryFn: () => entrySyncServices.fetchEntryDetail(entryId),
126+
queryFn: () => entrySyncServices.fetchEntryDetail(entryId, isInbox),
127127
})
128128
}
129129

packages/internal/store/src/entry/store.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,11 +543,12 @@ class EntrySyncServices {
543543
return res
544544
}
545545

546-
async fetchEntryDetail(entryId: EntryId) {
546+
async fetchEntryDetail(entryId: EntryId, isInbox?: boolean) {
547547
const currentEntry = getEntry(entryId)
548-
const res = currentEntry?.inboxHandle
549-
? await apiClient().entries.inbox.$get({ query: { id: entryId } })
550-
: await apiClient().entries.$get({ query: { id: entryId } })
548+
const res =
549+
currentEntry?.inboxHandle || isInbox
550+
? await apiClient().entries.inbox.$get({ query: { id: entryId } })
551+
: await apiClient().entries.$get({ query: { id: entryId } })
551552
const entry = honoMorph.toEntry(res.data)
552553
if (!currentEntry && entry) {
553554
await entryActions.upsertMany([entry])

packages/internal/store/src/unread/hooks.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ export const useSyncUnreadWhenUnMatch = (entryIds: string[]) => {
4242
}, [entryIds.toString()])
4343
}
4444

45-
export const useAutoMarkAsRead = (entryId: string) => {
45+
export const useAutoMarkAsRead = (entryId: string, enabled: boolean) => {
4646
const { mutate } = useMutation({
4747
mutationFn: (entryId: string) => unreadSyncService.markEntryAsRead(entryId),
4848
})
4949
useEffect(() => {
50-
mutate(entryId)
51-
}, [entryId, mutate])
50+
if (enabled) {
51+
mutate(entryId)
52+
}
53+
}, [enabled, entryId, mutate])
5254
}
5355

5456
export const useUnreadById = (id: string) => {

0 commit comments

Comments
 (0)