diff --git a/src/components/activity/AccountActivity.tsx b/src/components/activity/AccountActivity.tsx
index 70b9b77b1..b4a784e69 100644
--- a/src/components/activity/AccountActivity.tsx
+++ b/src/components/activity/AccountActivity.tsx
@@ -19,7 +19,7 @@ import { useIsMySpace } from '../spaces/helpers'
import { CreatePostButton } from '../spaces/helpers/CreatePostButton'
import { FollowerCanPostAlert } from '../spaces/permissions/FollowerCanPostAlert'
import { useSubsocialApi } from '../substrate'
-import { Loading } from '../utils'
+import { getCreatorChatIdFromProfile, Loading } from '../utils'
import { createLoadMorePosts, FeedActivities } from './FeedActivities'
import { OnchainAccountActivity } from './OnchainAccountActivity'
import { SpaceActivities } from './SpaceActivities'
@@ -147,7 +147,7 @@ const OffchainAccountActivity = ({
const space = useSelectSpace(spaceId)
- const chatId = (space?.content?.chats as any[])?.[0]?.id as string | undefined
+ const chatId = getCreatorChatIdFromProfile(space)
useFetchPosts(chatId ? [chatId] : [])
diff --git a/src/components/chat/ChatButton.tsx b/src/components/chat/ChatButton.tsx
index 7f9dc9a62..fb4a43119 100644
--- a/src/components/chat/ChatButton.tsx
+++ b/src/components/chat/ChatButton.tsx
@@ -1,5 +1,5 @@
-import { isEmptyArray } from '@subsocial/utils'
import { useFetchPosts, useSelectPost, useSelectSpace } from 'src/rtk/app/hooks'
+import { getCreatorChatIdFromProfile } from '../utils'
import CreateChatModalButton from './CreateChatModal'
import UnhideChatButton from './UnhideChatButton'
@@ -12,20 +12,19 @@ const ChatButton = ({ spaceId }: ChatButtonProps) => {
const spaceContent = space?.content
- const chats = spaceContent?.chats
- const chat = chats?.[0]
+ const chatId = getCreatorChatIdFromProfile(space)
- useFetchPosts(chat ? [chat?.id] : [])
+ useFetchPosts(chatId ? [chatId] : [])
- const post = useSelectPost(chat?.id)
+ const chat = useSelectPost(chatId)
- const isPostHidden = !!post?.post.struct.hidden
- const isRemovedPost = !post?.post.struct.spaceId
+ const isPostHidden = !!chat?.post.struct.hidden
+ const isRemovedPost = !chat?.post.struct.spaceId
- if (chat && post && spaceContent && !isEmptyArray(chats) && !isPostHidden) return null
+ if (chatId && chat && spaceContent && !isPostHidden) return null
return isPostHidden && !isRemovedPost ? (
-
+
) : (
)
diff --git a/src/components/profiles/address-views/ProfilePreview.tsx b/src/components/profiles/address-views/ProfilePreview.tsx
index 5f2ab1046..d402f5820 100644
--- a/src/components/profiles/address-views/ProfilePreview.tsx
+++ b/src/components/profiles/address-views/ProfilePreview.tsx
@@ -2,6 +2,7 @@ import { Button, Col, Row } from 'antd'
import clsx from 'clsx'
import dynamic from 'next/dynamic'
import React, { FC } from 'react'
+import { getCreatorChatIdFromProfile } from 'src/components/utils'
import { Pluralize } from 'src/components/utils/Plularize'
import { LARGE_AVATAR_SIZE } from 'src/config/Size.config'
import {
@@ -91,11 +92,11 @@ export const ProfilePreviewPopup: FC = props => {
const sendEvent = useSendEvent()
const profile = useSelectProfile(address.toString())
- const chat = profile?.content?.chats?.[0]
+ const chatId = getCreatorChatIdFromProfile(profile)
- useFetchPosts(chat ? [chat.id] : [])
+ useFetchPosts(chatId ? [chatId] : [])
- const post = useSelectPost(chat?.id)
+ const post = useSelectPost(chatId)
const onOpenChatClick = () => {
if (!post) return