From 7c6d3a041bc894a66c2dd327db4a5a82aaa45f40 Mon Sep 17 00:00:00 2001 From: Bonn Date: Fri, 9 Feb 2024 15:30:33 +0700 Subject: [PATCH] fix: useChannel instead of channel from livecollection (#139) # Conflicts: # src/chat/components/ChatItem/index.tsx --- src/chat/components/ChatItem/index.tsx | 14 +++++++++++--- src/chat/components/RecentChat/index.tsx | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/chat/components/ChatItem/index.tsx b/src/chat/components/ChatItem/index.tsx index e93e97e35..c0ee6f68b 100644 --- a/src/chat/components/ChatItem/index.tsx +++ b/src/chat/components/ChatItem/index.tsx @@ -6,6 +6,8 @@ import useChatInfo from '~/chat/hooks/useChatInfo'; import { ChatItemLeft, Title, Avatar, ChatItemContainer, UnreadCount } from './styles'; import { useCustomComponent } from '~/core/providers/CustomComponentsProvider'; +import useChannelSubscription from '~/social/hooks/useChannelSubscription'; +import useChannel from '~/chat/hooks/useChannel'; function getNormalizedUnreadCount(channelUnreadCount: number) { // Within this range the unread counter will show an actuall number @@ -24,16 +26,22 @@ function getNormalizedUnreadCount(channelUnreadCount: number) { } interface ChatItemProps { - channel?: Amity.Channel; + channelId: string; isSelected: boolean; onSelect: ({ channelId, type }: { channelId: string; type: string }) => void; } -const ChatItem = ({ channel, isSelected, onSelect }: ChatItemProps) => { - const { chatName, chatAvatar } = useChatInfo({ channel: channel || null }); +const ChatItem = ({ channelId, isSelected, onSelect }: ChatItemProps) => { + const channel = useChannel(channelId); + const { chatName, chatAvatar } = useChatInfo({ channel }); const normalizedUnreadCount = getNormalizedUnreadCount(channel?.unreadCount || 0); + useChannelSubscription({ + channelId: channel?.channelId, + shouldSubscribe: () => !!channel?.channelId, + }); + return ( ( { onChannelSelect?.(data);