Skip to content

Commit

Permalink
Finish checker for approved in root post id
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Jul 8, 2024
1 parent 8d0a33b commit 14828ef
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/@types/subsocial.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ declare module '@subsocial/api/types' {
blockchainSyncFailed?: boolean
dataType?: 'persistent' | 'optimistic' | 'offChain'
parentPostId?: string | null
approvedInRootPost?: boolean
},
PostContent
> & { requestedId?: string }
Expand Down
3 changes: 3 additions & 0 deletions src/components/chats/ChatItem/ChatItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export default function ChatItem({

const canRenderEmbed = useCanRenderEmbed(link ?? '')

if (showApproveButton && message.struct.approvedInRootPost) return null
if (!showApproveButton && !message.struct.approvedInRootPost) return null

if (!body && (!extensions || extensions.length === 0)) return null

const isEmojiOnly = shouldRenderEmojiChatItem(body ?? '')
Expand Down
16 changes: 1 addition & 15 deletions src/components/extensions/common/CommonChatItem.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Button from '@/components/Button'
import LinkText from '@/components/LinkText'
import { ProfilePreviewModalName } from '@/components/ProfilePreviewModalWrapper'
import Toast from '@/components/Toast'
import { useModerateWithSuccessToast } from '@/components/chats/ChatItem/ChatItemMenus'
import ChatRelativeTime from '@/components/chats/ChatItem/ChatRelativeTime'
import MessageStatusIndicator from '@/components/chats/ChatItem/MessageStatusIndicator'
Expand All @@ -18,7 +17,6 @@ import { useMyMainAddress } from '@/stores/my-account'
import { cx } from '@/utils/class-names'
import { getTimeRelativeToNow } from '@/utils/date'
import Linkify from 'linkify-react'
import { toast } from 'sonner'
import { ExtensionChatItemProps } from '../types'

type DerivativesData = {
Expand Down Expand Up @@ -324,19 +322,7 @@ function ApproveButton({
ownerId: string
}) {
const { data: profile } = getProfileQuery.useQuery(ownerId)
const { mutate } = useApproveUser({
onSuccess: () => {
toast.custom((t) => (
<Toast
t={t}
type='default'
title={`You have approved ${
profile?.profileSpace?.content?.name || 'user'
}`}
/>
))
},
})
const { mutate } = useApproveUser()
return (
<Button
variant='greenOutline'
Expand Down
22 changes: 22 additions & 0 deletions src/services/datahub/events/subscription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
SubscribeEventsSubscriptionVariables,
} from '../generated-query'
import { callIdToPostIdMap } from '../posts/mutation'
import { getProfileQuery } from '../profiles/query'
import { getGamificationTasksErrorQuery } from '../tasks/query'
import { datahubSubscription } from '../utils'

Expand Down Expand Up @@ -51,6 +52,7 @@ const SUBSCRIBE_EVENTS = gql`
msg
code
callId
extension
}
}
}
Expand Down Expand Up @@ -205,6 +207,26 @@ async function processSubscriptionEvent(
break
}

if (
eventData.meta.callName ===
SocialCallName.SynthSocialProfileSetActionPermissions
) {
const profile = getProfileQuery.getQueryData(
client,
eventData.meta.extension?.updatedCreatorAddress ?? ''
)
toast.custom((t) => (
<Toast
t={t}
type='default'
title={`You have approved ${
profile?.profileSpace?.content?.name || 'user'
}`}
/>
))
return
}

if (eventData.meta.callName === SocialCallName.SynthGamificationClaimTask) {
claimTaskErrorStore.set(eventData.meta.code)

Expand Down
11 changes: 11 additions & 0 deletions src/services/datahub/generated-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2234,6 +2234,7 @@ export type SubscribeEventsSubscription = {
msg?: string | null
code: ServiceMessageStatusCode
callId?: string | null
extension?: any | null
}
}
}
Expand Down Expand Up @@ -2623,6 +2624,7 @@ export type DatahubPostFragmentFragment = {
createdAtTime?: any | null
title?: string | null
body?: string | null
approvedInRootPost: boolean
createdByAccount: { __typename?: 'Account'; id: string }
space?: { __typename?: 'Space'; id: string } | null
ownedByAccount: { __typename?: 'Account'; id: string }
Expand Down Expand Up @@ -2655,6 +2657,7 @@ export type GetPostsQuery = {
createdAtTime?: any | null
title?: string | null
body?: string | null
approvedInRootPost: boolean
createdByAccount: { __typename?: 'Account'; id: string }
space?: { __typename?: 'Space'; id: string } | null
ownedByAccount: { __typename?: 'Account'; id: string }
Expand Down Expand Up @@ -2688,6 +2691,7 @@ export type GetOptimisticPostsQuery = {
createdAtTime?: any | null
title?: string | null
body?: string | null
approvedInRootPost: boolean
createdByAccount: { __typename?: 'Account'; id: string }
space?: { __typename?: 'Space'; id: string } | null
ownedByAccount: { __typename?: 'Account'; id: string }
Expand Down Expand Up @@ -2720,6 +2724,7 @@ export type GetCommentIdsInPostIdQuery = {
createdAtTime?: any | null
title?: string | null
body?: string | null
approvedInRootPost: boolean
createdByAccount: { __typename?: 'Account'; id: string }
space?: { __typename?: 'Space'; id: string } | null
ownedByAccount: { __typename?: 'Account'; id: string }
Expand Down Expand Up @@ -2784,6 +2789,7 @@ export type GetOwnedPostsQuery = {
createdAtTime?: any | null
title?: string | null
body?: string | null
approvedInRootPost: boolean
createdByAccount: { __typename?: 'Account'; id: string }
space?: { __typename?: 'Space'; id: string } | null
ownedByAccount: { __typename?: 'Account'; id: string }
Expand Down Expand Up @@ -2815,6 +2821,7 @@ export type GetPostsBySpaceIdQuery = {
createdAtTime?: any | null
title?: string | null
body?: string | null
approvedInRootPost: boolean
createdByAccount: { __typename?: 'Account'; id: string }
space?: { __typename?: 'Space'; id: string } | null
ownedByAccount: { __typename?: 'Account'; id: string }
Expand Down Expand Up @@ -2857,6 +2864,7 @@ export type SubscribePostSubscription = {
persistentId?: string | null
optimisticId?: string | null
dataType: DataType
approvedInRootPost: boolean
rootPost?: { __typename?: 'Post'; persistentId?: string | null } | null
}
}
Expand Down Expand Up @@ -2979,6 +2987,7 @@ export const DatahubPostFragment = gql`
}
title
body
approvedInRootPost
ownedByAccount {
id
}
Expand Down Expand Up @@ -3209,6 +3218,7 @@ export const SubscribeEvents = gql`
msg
code
callId
extension
}
}
}
Expand Down Expand Up @@ -3612,6 +3622,7 @@ export const SubscribePost = gql`
persistentId
optimisticId
dataType
approvedInRootPost
rootPost {
persistentId
}
Expand Down
1 change: 1 addition & 0 deletions src/services/datahub/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const mapDatahubPostFragment = (
repliesCount: 0,
sharesCount: 0,
spaceId: '',
approvedInRootPost: post.approvedInRootPost ?? false,
isUpdated: false,
rootPostId: post.rootPost?.persistentId ?? '',
parentPostId: null,
Expand Down
1 change: 1 addition & 0 deletions src/services/datahub/posts/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const DATAHUB_POST_FRAGMENT = gql`
}
title
body
approvedInRootPost
ownedByAccount {
id
}
Expand Down
24 changes: 21 additions & 3 deletions src/services/datahub/posts/subscription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const SUBSCRIBE_POST = gql`
persistentId
optimisticId
dataType
approvedInRootPost
rootPost {
persistentId
}
Expand Down Expand Up @@ -149,20 +150,34 @@ async function processMessage(
getPostQuery.invalidate(queryClient, newestId)
} else {
if (dataFromPersistentId) {
getPostQuery.setQueryData(queryClient, newestId, (oldData) => {
if (!oldData) return oldData
return {
...oldData,
struct: {
...oldData.struct,
approvedInRootPost: eventData.entity.approvedInRootPost,
},
}
})
await getPostQuery.invalidate(queryClient, newestId)
} else {
await getPostQuery.fetchQuery(queryClient, newestId)
}
}

const newPost = getPostQuery.getQueryData(queryClient, newestId)
if (isCreationEvent) {
const newPost = getPostQuery.getQueryData(queryClient, newestId)
const tokenomics = await getTokenomicsMetadataQuery.fetchQuery(
queryClient,
null
)
const myAddress = getMyMainAddress()
if (newPost?.struct.ownerId === myAddress && isCreationEvent) {
if (
newPost?.struct.ownerId === myAddress &&
isCreationEvent &&
newPost.struct.approvedInRootPost
) {
toast.custom((t) => (
<Toast
t={t}
Expand All @@ -178,7 +193,10 @@ async function processMessage(

getPaginatedPostIdsByPostId.setQueryFirstPageData(
queryClient,
{ postId: rootPostId, onlyDisplayUnapprovedMessages: false },
{
postId: rootPostId,
onlyDisplayUnapprovedMessages: !newPost?.struct.approvedInRootPost,
},
(oldData) => {
if (!oldData) return oldData
const oldIdsSet = new Set(oldData)
Expand Down

0 comments on commit 14828ef

Please sign in to comment.