diff --git a/src/components/chats/UnapprovedMemeCount.tsx b/src/components/chats/UnapprovedMemeCount.tsx index 86ef07b01..19954a46f 100644 --- a/src/components/chats/UnapprovedMemeCount.tsx +++ b/src/components/chats/UnapprovedMemeCount.tsx @@ -1,8 +1,16 @@ import { getUnapprovedMemesCountQuery } from '@/services/datahub/posts/query' -export default function UnapprovedMemeCount({ address }: { address: string }) { - const { data: count, isLoading } = - getUnapprovedMemesCountQuery.useQuery(address) +export default function UnapprovedMemeCount({ + address, + chatId, +}: { + address: string + chatId: string +}) { + const { data: count, isLoading } = getUnapprovedMemesCountQuery.useQuery({ + address, + chatId, + }) if (isLoading) return null return ( diff --git a/src/components/extensions/common/CommonChatItem.tsx b/src/components/extensions/common/CommonChatItem.tsx index 44fd9b201..a89580806 100644 --- a/src/components/extensions/common/CommonChatItem.tsx +++ b/src/components/extensions/common/CommonChatItem.tsx @@ -219,7 +219,7 @@ export default function CommonChatItem({ className={cx('text-sm font-medium text-text-secondary')} /> {showApproveButton && inView && ( - + )} {/* */} {othersMessage.checkMark === 'top' && diff --git a/src/services/datahub/generated-query.ts b/src/services/datahub/generated-query.ts index bfa7f63f0..2f3347afd 100644 --- a/src/services/datahub/generated-query.ts +++ b/src/services/datahub/generated-query.ts @@ -2853,6 +2853,7 @@ export type GetLastPostedMemeQuery = { export type GetUnapprovedMemesCountQueryVariables = Exact<{ address: Scalars['String']['input'] + postId: Scalars['String']['input'] }> export type GetUnapprovedMemesCountQuery = { @@ -3624,10 +3625,14 @@ export const GetLastPostedMeme = gql` } ` export const GetUnapprovedMemesCount = gql` - query GetUnapprovedMemesCount($address: String!) { + query GetUnapprovedMemesCount($address: String!, $postId: String!) { posts( args: { - filter: { createdByAccountAddress: $address, approvedInRootPost: true } + filter: { + createdByAccountAddress: $address + approvedInRootPost: false + rootPostId: $postId + } } ) { total diff --git a/src/services/datahub/posts/query.ts b/src/services/datahub/posts/query.ts index dcce16060..9375b4065 100644 --- a/src/services/datahub/posts/query.ts +++ b/src/services/datahub/posts/query.ts @@ -537,10 +537,14 @@ export const getTimeLeftUntilCanPostQuery = createQuery({ }) const GET_UNAPPROVED_MEMES_COUNT = gql` - query GetUnapprovedMemesCount($address: String!) { + query GetUnapprovedMemesCount($address: String!, $postId: String!) { posts( args: { - filter: { createdByAccountAddress: $address, approvedInRootPost: false } + filter: { + createdByAccountAddress: $address + approvedInRootPost: false + rootPostId: $postId + } } ) { total @@ -549,17 +553,17 @@ const GET_UNAPPROVED_MEMES_COUNT = gql` ` export const getUnapprovedMemesCountQuery = createQuery({ key: 'unapprovedMemesCount', - fetcher: async (address: string) => { + fetcher: async ({ address, chatId }: { chatId: string; address: string }) => { const res = await datahubQueryRequest< GetUnapprovedMemesCountQuery, GetUnapprovedMemesCountQueryVariables >({ document: GET_UNAPPROVED_MEMES_COUNT, - variables: { address }, + variables: { address, postId: chatId }, }) return res.posts.total ?? 0 }, - defaultConfigGenerator: (address) => ({ - enabled: !!address, + defaultConfigGenerator: (params) => ({ + enabled: !!params?.address && !!params.chatId, }), }) diff --git a/src/services/datahub/posts/subscription.tsx b/src/services/datahub/posts/subscription.tsx index c2cebb817..d177bfcd0 100644 --- a/src/services/datahub/posts/subscription.tsx +++ b/src/services/datahub/posts/subscription.tsx @@ -180,7 +180,11 @@ async function processMessage( const newPost = getPostQuery.getQueryData(queryClient, newestId) const myAddress = getMyMainAddress() - const isCurrentOwner = newPost?.struct.ownerId === myAddress + + const rootPostId = entity.rootPost?.persistentId + const ownerId = newPost?.struct.ownerId + const isCurrentOwner = ownerId === myAddress + if (isCreationEvent) { const tokenomics = await getTokenomicsMetadataQuery.fetchQuery( queryClient, @@ -204,22 +208,22 @@ async function processMessage( // to not wait for another query to run the other synchronous actions below processUnapprovedMeme(newPost) async function processUnapprovedMeme(newPost: PostData) { - if (newPost.struct.ownerId) { + if (ownerId) { const cachedCount = getUnapprovedMemesCountQuery.getQueryData( queryClient, - newPost.struct.ownerId + { address: ownerId, chatId: rootPostId ?? '' } ) if (typeof cachedCount === 'number') { getUnapprovedMemesCountQuery.setQueryData( queryClient, - newPost.struct.ownerId, + { address: ownerId, chatId: rootPostId ?? '' }, (count) => (count ?? 0) + 1 ) } else if (isCurrentOwner) { - await getUnapprovedMemesCountQuery.fetchQuery( - queryClient, - myAddress - ) + await getUnapprovedMemesCountQuery.fetchQuery(queryClient, { + address: ownerId, + chatId: rootPostId ?? '', + }) } } if (isCurrentOwner) { @@ -229,7 +233,7 @@ async function processMessage( const count = getUnapprovedMemesCountQuery.getQueryData( queryClient, - myAddress + { address: myAddress, chatId: rootPostId ?? '' } ) const remaining = Math.max(MIN_MEME_FOR_REVIEW - (count ?? 0), 0) const title = @@ -256,7 +260,6 @@ async function processMessage( } } - const rootPostId = entity.rootPost?.persistentId if (!rootPostId) return if (isCreationEvent && !entity.approvedInRootPost && isCurrentOwner) {