diff --git a/src/components/channels/channelListItem.tsx b/src/components/channels/channelListItem.tsx index e7699c1a..4d5b9808 100644 --- a/src/components/channels/channelListItem.tsx +++ b/src/components/channels/channelListItem.tsx @@ -1,12 +1,11 @@ -import { DEFAULT_AVATAR } from '@stores/constants'; - import { useChannelMetadata } from '@utils/hooks/useChannelMetadata'; import { usePageContext } from '@utils/hooks/usePageContext'; +import Skeleton from 'react-loading-skeleton'; import { twMerge } from 'tailwind-merge'; export const ChannelListItem = ({ data }: { data: any }) => { - const channel: any = useChannelMetadata(data.event_id); + const channel: any = useChannelMetadata(data.event_id, data.pubkey); const pageContext = usePageContext(); const searchParams: any = pageContext.urlParsed.search; @@ -14,17 +13,17 @@ export const ChannelListItem = ({ data }: { data: any }) => { return (
- {data.event_id} + } alt={data.event_id} className="h-5 w-5 rounded object-contain" />
-
{channel?.name}
+
{channel?.name || }
); diff --git a/src/components/channels/channelProfile.tsx b/src/components/channels/channelProfile.tsx index 3d3f0590..3eec8a4c 100644 --- a/src/components/channels/channelProfile.tsx +++ b/src/components/channels/channelProfile.tsx @@ -4,8 +4,8 @@ import { Copy } from 'iconoir-react'; import { nip19 } from 'nostr-tools'; import Skeleton from 'react-loading-skeleton'; -export const ChannelProfile = ({ id }: { id: string }) => { - const metadata = useChannelMetadata(id); +export const ChannelProfile = ({ id, pubkey }: { id: string; pubkey: string }) => { + const metadata = useChannelMetadata(id, pubkey); const noteID = nip19.noteEncode(id); const copyNoteID = async () => { diff --git a/src/pages/channel/index.page.tsx b/src/pages/channel/index.page.tsx index 9454859b..9535a7d5 100644 --- a/src/pages/channel/index.page.tsx +++ b/src/pages/channel/index.page.tsx @@ -23,6 +23,7 @@ export function Page() { const searchParams: any = pageContext.urlParsed.search; const id = searchParams.id; + const channelPubkey = searchParams.pubkey; const pool: any = useContext(RelayContext); const activeAccount: any = useContext(AccountContext); @@ -82,7 +83,7 @@ export function Page() {
- +
diff --git a/src/utils/hooks/useChannelMetadata.tsx b/src/utils/hooks/useChannelMetadata.tsx index 36cd7835..420937e5 100644 --- a/src/utils/hooks/useChannelMetadata.tsx +++ b/src/utils/hooks/useChannelMetadata.tsx @@ -7,7 +7,7 @@ import { getChannel } from '@utils/storage'; import { useCallback, useContext, useEffect, useState } from 'react'; -export const useChannelMetadata = (id: string) => { +export const useChannelMetadata = (id: string, channelPubkey: string) => { const pool: any = useContext(RelayContext); const [metadata, setMetadata] = useState(null); @@ -24,18 +24,22 @@ export const useChannelMetadata = (id: string) => { }, ], DEFAULT_RELAYS, - (event: { kind: number; content: string }) => { + (event: { kind: number; pubkey: string; content: string }) => { switch (event.kind) { case 41: - const json = JSON.parse(event.content); - // update state - setMetadata(json); - // update metadata in database - updateChannelMetadata(id, event.content); + if (event.pubkey === channelPubkey) { + const json = JSON.parse(event.content); + // update state + setMetadata(json); + // update metadata in database + updateChannelMetadata(id, event.content); + } break; case 40: - // update state - setMetadata(JSON.parse(event.content)); + if (event.pubkey === channelPubkey) { + // update state + setMetadata(JSON.parse(event.content)); + } default: break; } @@ -51,7 +55,7 @@ export const useChannelMetadata = (id: string) => { return () => { unsubscribe(); }; - }, [id, pool]); + }, [channelPubkey, id, pool]); const getChannelFromDB = useCallback(async () => { return await getChannel(id); @@ -62,7 +66,6 @@ export const useChannelMetadata = (id: string) => { if (!ignore) { getChannelFromDB().then((res) => { - console.log(res); if (res) { setMetadata(JSON.parse(res.metadata)); } else {