import { ChannelBlackList } from "@app/channel/components/blacklist"; import { ChannelMembers } from "@app/channel/components/members"; import { ChannelMessageList } from "@app/channel/components/messageList"; import { ChannelMessageForm } from "@app/channel/components/messages/form"; import { ChannelMetadata } from "@app/channel/components/metadata"; import { ChannelUpdateModal } from "@app/channel/components/updateModal"; import { RelayContext } from "@shared/relayProvider"; import { useActiveAccount } from "@stores/accounts"; import { useChannelMessages } from "@stores/channels"; import { READONLY_RELAYS } from "@stores/constants"; import { dateToUnix, getHourAgo } from "@utils/date"; import { usePageContext } from "@utils/hooks/usePageContext"; import { getActiveBlacklist, getBlacklist } from "@utils/storage"; import { arrayObjToPureArr } from "@utils/transform"; import { useContext, useRef } from "react"; import useSWR from "swr"; import useSWRSubscription from "swr/subscription"; const fetchMuted = async ([, id]) => { const res = await getBlacklist(id, 44); const array = arrayObjToPureArr(res); return { original: res, array: array }; }; const fetchHided = async ([, id]) => { const res = await getActiveBlacklist(id, 43); const array = arrayObjToPureArr(res); return array; }; export function Page() { const pool: any = useContext(RelayContext); const pageContext = usePageContext(); const searchParams: any = pageContext.urlParsed.search; const channelID = searchParams.id; const channelPubkey = searchParams.channelpub; const account: any = useActiveAccount((state: any) => state.account); const [addMessage, clear] = useChannelMessages((state: any) => [ state.add, state.clear, ]); const { data: muted } = useSWR( account ? ["muted", account.id] : null, fetchMuted, ); const { data: hided } = useSWR( account ? ["hided", account.id] : null, fetchHided, ); const now = useRef(new Date()); useSWRSubscription( account && channelID && muted && hided ? ["channel", channelID] : null, ([, key]) => { // subscribe to channel const unsubscribe = pool.subscribe( [ { "#e": [key], kinds: [42], since: dateToUnix(getHourAgo(24, now.current)), limit: 20, }, ], READONLY_RELAYS, (event: { id: string; pubkey: string }) => { const message: any = event; // handle hide message if (hided.includes(event.id)) { message["hide"] = true; } else { message["hide"] = false; } // handle mute user if (muted.array.includes(event.pubkey)) { message["mute"] = true; } else { message["mute"] = false; } // add to store addMessage(message); }, ); return () => { unsubscribe(); clear(); }; }, ); if (!account) return
Fuck SSR
; return (

Public Channel

{muted && } {account && account.pubkey === channelPubkey && ( )}
); }