Expand AnyProfileView to include chat profile view, update post shadow to reflect this
This commit is contained in:
Vendored
+6
-5
@@ -1,9 +1,9 @@
|
|||||||
import {useEffect, useMemo, useState} from 'react'
|
import {useEffect, useMemo, useState} from 'react'
|
||||||
import {AppBskyActorDefs} from '@atproto/api'
|
|
||||||
import {QueryClient} from '@tanstack/react-query'
|
import {QueryClient} from '@tanstack/react-query'
|
||||||
import EventEmitter from 'eventemitter3'
|
import EventEmitter from 'eventemitter3'
|
||||||
|
|
||||||
import {batchedUpdates} from '#/lib/batchedUpdates'
|
import {batchedUpdates} from '#/lib/batchedUpdates'
|
||||||
|
import * as atp from '#/types/atproto'
|
||||||
import {findAllProfilesInQueryData as findAllProfilesInActorSearchQueryData} from '../queries/actor-search'
|
import {findAllProfilesInQueryData as findAllProfilesInActorSearchQueryData} from '../queries/actor-search'
|
||||||
import {findAllProfilesInQueryData as findAllProfilesInKnownFollowersQueryData} from '../queries/known-followers'
|
import {findAllProfilesInQueryData as findAllProfilesInKnownFollowersQueryData} from '../queries/known-followers'
|
||||||
import {findAllProfilesInQueryData as findAllProfilesInListMembersQueryData} from '../queries/list-members'
|
import {findAllProfilesInQueryData as findAllProfilesInListMembersQueryData} from '../queries/list-members'
|
||||||
@@ -20,6 +20,7 @@ import {findAllProfilesInQueryData as findAllProfilesInProfileFollowersQueryData
|
|||||||
import {findAllProfilesInQueryData as findAllProfilesInProfileFollowsQueryData} from '../queries/profile-follows'
|
import {findAllProfilesInQueryData as findAllProfilesInProfileFollowsQueryData} from '../queries/profile-follows'
|
||||||
import {findAllProfilesInQueryData as findAllProfilesInSuggestedFollowsQueryData} from '../queries/suggested-follows'
|
import {findAllProfilesInQueryData as findAllProfilesInSuggestedFollowsQueryData} from '../queries/suggested-follows'
|
||||||
import {castAsShadow, Shadow} from './types'
|
import {castAsShadow, Shadow} from './types'
|
||||||
|
|
||||||
export type {Shadow} from './types'
|
export type {Shadow} from './types'
|
||||||
|
|
||||||
export interface ProfileShadow {
|
export interface ProfileShadow {
|
||||||
@@ -29,13 +30,13 @@ export interface ProfileShadow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const shadows: WeakMap<
|
const shadows: WeakMap<
|
||||||
AppBskyActorDefs.ProfileView,
|
atp.profile.AnyProfileView,
|
||||||
Partial<ProfileShadow>
|
Partial<ProfileShadow>
|
||||||
> = new WeakMap()
|
> = new WeakMap()
|
||||||
const emitter = new EventEmitter()
|
const emitter = new EventEmitter()
|
||||||
|
|
||||||
export function useProfileShadow<
|
export function useProfileShadow<
|
||||||
TProfileView extends Omit<AppBskyActorDefs.ProfileView, '$type'>,
|
TProfileView extends atp.profile.AnyProfileView,
|
||||||
>(profile: TProfileView): Shadow<TProfileView> {
|
>(profile: TProfileView): Shadow<TProfileView> {
|
||||||
const [shadow, setShadow] = useState(() => shadows.get(profile))
|
const [shadow, setShadow] = useState(() => shadows.get(profile))
|
||||||
const [prevPost, setPrevPost] = useState(profile)
|
const [prevPost, setPrevPost] = useState(profile)
|
||||||
@@ -77,7 +78,7 @@ export function updateProfileShadow(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function mergeShadow<TProfileView extends AppBskyActorDefs.ProfileView>(
|
function mergeShadow<TProfileView extends atp.profile.AnyProfileView>(
|
||||||
profile: TProfileView,
|
profile: TProfileView,
|
||||||
shadow: Partial<ProfileShadow>,
|
shadow: Partial<ProfileShadow>,
|
||||||
): Shadow<TProfileView> {
|
): Shadow<TProfileView> {
|
||||||
@@ -99,7 +100,7 @@ function mergeShadow<TProfileView extends AppBskyActorDefs.ProfileView>(
|
|||||||
function* findProfilesInCache(
|
function* findProfilesInCache(
|
||||||
queryClient: QueryClient,
|
queryClient: QueryClient,
|
||||||
did: string,
|
did: string,
|
||||||
): Generator<AppBskyActorDefs.ProfileView, void> {
|
): Generator<atp.profile.AnyProfileView, void> {
|
||||||
yield* findAllProfilesInListMembersQueryData(queryClient, did)
|
yield* findAllProfilesInListMembersQueryData(queryClient, did)
|
||||||
yield* findAllProfilesInMyBlockedAccountsQueryData(queryClient, did)
|
yield* findAllProfilesInMyBlockedAccountsQueryData(queryClient, did)
|
||||||
yield* findAllProfilesInMyMutedAccountsQueryData(queryClient, did)
|
yield* findAllProfilesInMyMutedAccountsQueryData(queryClient, did)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {AppBskyActorDefs} from '@atproto/api'
|
import {AppBskyActorDefs, ChatBskyActorDefs} from '@atproto/api'
|
||||||
|
|
||||||
export {
|
export {
|
||||||
/**
|
/**
|
||||||
@@ -25,6 +25,7 @@ export type AnyProfileView =
|
|||||||
| AppBskyActorDefs.ProfileViewBasic
|
| AppBskyActorDefs.ProfileViewBasic
|
||||||
| AppBskyActorDefs.ProfileView
|
| AppBskyActorDefs.ProfileView
|
||||||
| AppBskyActorDefs.ProfileViewDetailed
|
| AppBskyActorDefs.ProfileViewDetailed
|
||||||
|
| ChatBskyActorDefs.ProfileViewBasic
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps any profile view type to `ProfileViewBasic`.
|
* Maps any profile view type to `ProfileViewBasic`.
|
||||||
@@ -41,7 +42,10 @@ export function anyToBasic(
|
|||||||
associated: view.associated,
|
associated: view.associated,
|
||||||
viewer: view.viewer,
|
viewer: view.viewer,
|
||||||
labels: view.labels,
|
labels: view.labels,
|
||||||
createdAt: view.createdAt,
|
// @ts-expect-error `createdAt` doesn't exist on chat view
|
||||||
|
createdAt: ChatBskyActorDefs.isProfileViewBasic(view)
|
||||||
|
? undefined
|
||||||
|
: view.createdAt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user