From 4cb5cfa8d4d96ac7054d1803a1cc1625b8561014 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Mon, 6 Jan 2025 16:01:07 -0600 Subject: [PATCH] Expand AnyProfileView to include chat profile view, update post shadow to reflect this --- src/state/cache/profile-shadow.ts | 11 ++++++----- src/types/atproto/profile.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/state/cache/profile-shadow.ts b/src/state/cache/profile-shadow.ts index e55cd48538..b085ee922a 100644 --- a/src/state/cache/profile-shadow.ts +++ b/src/state/cache/profile-shadow.ts @@ -1,9 +1,9 @@ import {useEffect, useMemo, useState} from 'react' -import {AppBskyActorDefs} from '@atproto/api' import {QueryClient} from '@tanstack/react-query' import EventEmitter from 'eventemitter3' import {batchedUpdates} from '#/lib/batchedUpdates' +import * as atp from '#/types/atproto' import {findAllProfilesInQueryData as findAllProfilesInActorSearchQueryData} from '../queries/actor-search' import {findAllProfilesInQueryData as findAllProfilesInKnownFollowersQueryData} from '../queries/known-followers' 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 findAllProfilesInSuggestedFollowsQueryData} from '../queries/suggested-follows' import {castAsShadow, Shadow} from './types' + export type {Shadow} from './types' export interface ProfileShadow { @@ -29,13 +30,13 @@ export interface ProfileShadow { } const shadows: WeakMap< - AppBskyActorDefs.ProfileView, + atp.profile.AnyProfileView, Partial > = new WeakMap() const emitter = new EventEmitter() export function useProfileShadow< - TProfileView extends Omit, + TProfileView extends atp.profile.AnyProfileView, >(profile: TProfileView): Shadow { const [shadow, setShadow] = useState(() => shadows.get(profile)) const [prevPost, setPrevPost] = useState(profile) @@ -77,7 +78,7 @@ export function updateProfileShadow( }) } -function mergeShadow( +function mergeShadow( profile: TProfileView, shadow: Partial, ): Shadow { @@ -99,7 +100,7 @@ function mergeShadow( function* findProfilesInCache( queryClient: QueryClient, did: string, -): Generator { +): Generator { yield* findAllProfilesInListMembersQueryData(queryClient, did) yield* findAllProfilesInMyBlockedAccountsQueryData(queryClient, did) yield* findAllProfilesInMyMutedAccountsQueryData(queryClient, did) diff --git a/src/types/atproto/profile.ts b/src/types/atproto/profile.ts index 884f10295d..fd3a0c0816 100644 --- a/src/types/atproto/profile.ts +++ b/src/types/atproto/profile.ts @@ -1,4 +1,4 @@ -import {AppBskyActorDefs} from '@atproto/api' +import {AppBskyActorDefs, ChatBskyActorDefs} from '@atproto/api' export { /** @@ -25,6 +25,7 @@ export type AnyProfileView = | AppBskyActorDefs.ProfileViewBasic | AppBskyActorDefs.ProfileView | AppBskyActorDefs.ProfileViewDetailed + | ChatBskyActorDefs.ProfileViewBasic /** * Maps any profile view type to `ProfileViewBasic`. @@ -41,7 +42,10 @@ export function anyToBasic( associated: view.associated, viewer: view.viewer, labels: view.labels, - createdAt: view.createdAt, + // @ts-expect-error `createdAt` doesn't exist on chat view + createdAt: ChatBskyActorDefs.isProfileViewBasic(view) + ? undefined + : view.createdAt, } }