Drill into notifications/util
(cherry picked from commit 84b535ed54f4fe93debcd198809bb184519c3507)
This commit is contained in:
@@ -27,6 +27,7 @@ import {
|
|||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useMutedThreads} from '#/state/muted-threads'
|
import {useMutedThreads} from '#/state/muted-threads'
|
||||||
|
import {getAgent} from '#/state/session'
|
||||||
import {STALE} from '..'
|
import {STALE} from '..'
|
||||||
import {useModerationOpts} from '../preferences'
|
import {useModerationOpts} from '../preferences'
|
||||||
import {embedViewRecordToPostView, getEmbeddedPost} from '../util'
|
import {embedViewRecordToPostView, getEmbeddedPost} from '../util'
|
||||||
@@ -71,6 +72,7 @@ export function useNotificationFeedQuery(opts?: {enabled?: boolean}) {
|
|||||||
if (!page) {
|
if (!page) {
|
||||||
page = (
|
page = (
|
||||||
await fetchPage({
|
await fetchPage({
|
||||||
|
agent: getAgent(),
|
||||||
limit: PAGE_SIZE,
|
limit: PAGE_SIZE,
|
||||||
cursor: pageParam,
|
cursor: pageParam,
|
||||||
queryClient,
|
queryClient,
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
|||||||
|
|
||||||
// count
|
// count
|
||||||
const {page, indexedAt: lastIndexed} = await fetchPage({
|
const {page, indexedAt: lastIndexed} = await fetchPage({
|
||||||
|
agent: getAgent(),
|
||||||
cursor: undefined,
|
cursor: undefined,
|
||||||
limit: 40,
|
limit: 40,
|
||||||
queryClient,
|
queryClient,
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
import {
|
import {
|
||||||
AppBskyNotificationListNotifications,
|
AppBskyEmbedRecord,
|
||||||
ModerationOpts,
|
|
||||||
moderateNotification,
|
|
||||||
AppBskyFeedDefs,
|
AppBskyFeedDefs,
|
||||||
|
AppBskyFeedLike,
|
||||||
AppBskyFeedPost,
|
AppBskyFeedPost,
|
||||||
AppBskyFeedRepost,
|
AppBskyFeedRepost,
|
||||||
AppBskyFeedLike,
|
AppBskyNotificationListNotifications,
|
||||||
AppBskyEmbedRecord,
|
BskyAgent,
|
||||||
|
moderateNotification,
|
||||||
|
ModerationOpts,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import chunk from 'lodash.chunk'
|
|
||||||
import {QueryClient} from '@tanstack/react-query'
|
import {QueryClient} from '@tanstack/react-query'
|
||||||
import {getAgent} from '../../session'
|
import chunk from 'lodash.chunk'
|
||||||
|
|
||||||
import {precacheProfile} from '../profile'
|
import {precacheProfile} from '../profile'
|
||||||
import {NotificationType, FeedNotification, FeedPage} from './types'
|
import {FeedNotification, FeedPage, NotificationType} from './types'
|
||||||
|
|
||||||
const GROUPABLE_REASONS = ['like', 'repost', 'follow']
|
const GROUPABLE_REASONS = ['like', 'repost', 'follow']
|
||||||
const MS_1HR = 1e3 * 60 * 60
|
const MS_1HR = 1e3 * 60 * 60
|
||||||
@@ -22,6 +23,7 @@ const MS_2DAY = MS_1HR * 48
|
|||||||
// =
|
// =
|
||||||
|
|
||||||
export async function fetchPage({
|
export async function fetchPage({
|
||||||
|
agent,
|
||||||
cursor,
|
cursor,
|
||||||
limit,
|
limit,
|
||||||
queryClient,
|
queryClient,
|
||||||
@@ -29,6 +31,7 @@ export async function fetchPage({
|
|||||||
threadMutes,
|
threadMutes,
|
||||||
fetchAdditionalData,
|
fetchAdditionalData,
|
||||||
}: {
|
}: {
|
||||||
|
agent: BskyAgent
|
||||||
cursor: string | undefined
|
cursor: string | undefined
|
||||||
limit: number
|
limit: number
|
||||||
queryClient: QueryClient
|
queryClient: QueryClient
|
||||||
@@ -36,7 +39,7 @@ export async function fetchPage({
|
|||||||
threadMutes: string[]
|
threadMutes: string[]
|
||||||
fetchAdditionalData: boolean
|
fetchAdditionalData: boolean
|
||||||
}): Promise<{page: FeedPage; indexedAt: string | undefined}> {
|
}): Promise<{page: FeedPage; indexedAt: string | undefined}> {
|
||||||
const res = await getAgent().listNotifications({
|
const res = await agent.listNotifications({
|
||||||
limit,
|
limit,
|
||||||
cursor,
|
cursor,
|
||||||
})
|
})
|
||||||
@@ -53,7 +56,7 @@ export async function fetchPage({
|
|||||||
// we fetch subjects of notifications (usually posts) now instead of lazily
|
// we fetch subjects of notifications (usually posts) now instead of lazily
|
||||||
// in the UI to avoid relayouts
|
// in the UI to avoid relayouts
|
||||||
if (fetchAdditionalData) {
|
if (fetchAdditionalData) {
|
||||||
const subjects = await fetchSubjects(notifsGrouped)
|
const subjects = await fetchSubjects(agent, notifsGrouped)
|
||||||
for (const notif of notifsGrouped) {
|
for (const notif of notifsGrouped) {
|
||||||
if (notif.subjectUri) {
|
if (notif.subjectUri) {
|
||||||
notif.subject = subjects.get(notif.subjectUri)
|
notif.subject = subjects.get(notif.subjectUri)
|
||||||
@@ -137,6 +140,7 @@ export function groupNotifications(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function fetchSubjects(
|
async function fetchSubjects(
|
||||||
|
agent: BskyAgent,
|
||||||
groupedNotifs: FeedNotification[],
|
groupedNotifs: FeedNotification[],
|
||||||
): Promise<Map<string, AppBskyFeedDefs.PostView>> {
|
): Promise<Map<string, AppBskyFeedDefs.PostView>> {
|
||||||
const uris = new Set<string>()
|
const uris = new Set<string>()
|
||||||
@@ -148,9 +152,7 @@ async function fetchSubjects(
|
|||||||
const uriChunks = chunk(Array.from(uris), 25)
|
const uriChunks = chunk(Array.from(uris), 25)
|
||||||
const postsChunks = await Promise.all(
|
const postsChunks = await Promise.all(
|
||||||
uriChunks.map(uris =>
|
uriChunks.map(uris =>
|
||||||
getAgent()
|
agent.app.bsky.feed.getPosts({uris}).then(res => res.data.posts),
|
||||||
.app.bsky.feed.getPosts({uris})
|
|
||||||
.then(res => res.data.posts),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
const map = new Map<string, AppBskyFeedDefs.PostView>()
|
const map = new Map<string, AppBskyFeedDefs.PostView>()
|
||||||
|
|||||||
Reference in New Issue
Block a user