Skip to content

Commit

Permalink
Update approved status after set approved event is received
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Jul 29, 2024
1 parent b0f3ca3 commit b5912c1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
7 changes: 0 additions & 7 deletions src/components/chats/ChatList/ChatItemContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import useIsMessageBlocked from '@/hooks/useIsMessageBlocked'
import usePrevious from '@/hooks/usePrevious'
import { getPostQuery } from '@/services/api/query'
import { useMessageData } from '@/stores/message'
import { useMyMainAddress } from '@/stores/my-account'
import { cx } from '@/utils/class-names'
import { useQueryClient } from '@tanstack/react-query'
import { ComponentProps, forwardRef, useEffect } from 'react'
Expand Down Expand Up @@ -42,16 +41,10 @@ function ChatItemContainer(

const { content } = message
const { body, extensions } = content || {}
const myAddress = useMyMainAddress()

if ((isMessageBlocked && !showBlockedMessage) || (!body && !extensions))
return null

const ownerId = message.struct.ownerId
const senderAddress = ownerId ?? ''

const isMyMessage = myAddress === senderAddress

return (
<div
{...containerProps}
Expand Down
11 changes: 11 additions & 0 deletions src/services/datahub/events/subscription.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Toast from '@/components/Toast'
import { claimTaskErrorStore } from '@/modules/telegram/TasksPage/ClaimTaskTokensModal'
import { getPostQuery } from '@/services/api/query'
import { deleteOptimisticData } from '@/services/subsocial/commentIds/optimistic'
import { getCurrentWallet } from '@/services/subsocial/hooks'
import { getMyMainAddress, useMyMainAddress } from '@/stores/my-account'
Expand Down Expand Up @@ -264,6 +265,16 @@ async function processSubscriptionEvent(
]
}
)
getPostQuery.setQueryData(client, postId, (oldData) => {
if (!oldData) return oldData
return {
...oldData,
struct: {
...oldData.struct,
approvedInRootPost: newStatus,
},
}
})
return
}

Expand Down
1 change: 1 addition & 0 deletions src/services/datahub/posts/subscription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ async function processMessage(
...dataFromEntityId,
struct: {
...dataFromEntityId.struct,
approvedInRootPost: eventData.entity.approvedInRootPost,
approvedInRootPostAtTime: eventData.entity.approvedInRootPostAtTime,
dataType: eventData.entity.dataType,
},
Expand Down

0 comments on commit b5912c1

Please sign in to comment.