Support disabled chat. Closes #1979

This commit is contained in:
Gabe Kangas
2022-09-10 20:03:58 -07:00
parent 52fff3bc30
commit 8ee9be5d88
4 changed files with 37 additions and 17 deletions

View File

@ -24,6 +24,7 @@ export const Main: FC = () => {
const fatalError = useRecoilValue<DisplayableError>(fatalErrorStateAtom); const fatalError = useRecoilValue<DisplayableError>(fatalErrorStateAtom);
const layoutRef = useRef<HTMLDivElement>(null); const layoutRef = useRef<HTMLDivElement>(null);
const { chatDisabled } = clientConfig;
useEffect(() => { useEffect(() => {
setupNoLinkReferrer(layoutRef.current); setupNoLinkReferrer(layoutRef.current);
@ -98,7 +99,7 @@ export const Main: FC = () => {
<ClientConfigStore /> <ClientConfigStore />
<Layout ref={layoutRef}> <Layout ref={layoutRef}>
<Header name={title || name} chatAvailable={isChatAvailable} /> <Header name={title || name} chatAvailable={isChatAvailable} chatDisabled={chatDisabled} />
<Content /> <Content />
{fatalError && ( {fatalError && (
<FatalErrorStateModal title={fatalError.title} message={fatalError.message} /> <FatalErrorStateModal title={fatalError.title} message={fatalError.message} />

View File

@ -180,7 +180,7 @@ export const ClientConfigStore: FC = () => {
const setChatUserId = useSetRecoilState<string>(chatUserIdAtom); const setChatUserId = useSetRecoilState<string>(chatUserIdAtom);
const setChatAuthenticated = useSetRecoilState<boolean>(chatAuthenticatedAtom); const setChatAuthenticated = useSetRecoilState<boolean>(chatAuthenticatedAtom);
const setIsChatModerator = useSetRecoilState<boolean>(isChatModeratorAtom); const setIsChatModerator = useSetRecoilState<boolean>(isChatModeratorAtom);
const setClientConfig = useSetRecoilState<ClientConfig>(clientConfigStateAtom); const [clientConfig, setClientConfig] = useRecoilState<ClientConfig>(clientConfigStateAtom);
const setServerStatus = useSetRecoilState<ServerStatus>(serverStatusState); const setServerStatus = useSetRecoilState<ServerStatus>(serverStatusState);
const setClockSkew = useSetRecoilState<Number>(clockSkewAtom); const setClockSkew = useSetRecoilState<Number>(clockSkewAtom);
const [chatMessages, setChatMessages] = useRecoilState<ChatMessage[]>(chatMessagesAtom); const [chatMessages, setChatMessages] = useRecoilState<ChatMessage[]>(chatMessagesAtom);
@ -375,6 +375,12 @@ export const ClientConfigStore: FC = () => {
} }
}, [hasLoadedStatus, hasLoadedConfig]); }, [hasLoadedStatus, hasLoadedConfig]);
useEffect(() => {
if (!clientConfig.chatDisabled && accessToken && hasLoadedConfig) {
startChat();
}
}, [hasLoadedConfig, accessToken]);
useEffect(() => { useEffect(() => {
updateClientConfig(); updateClientConfig();
handleUserRegistration(); handleUserRegistration();
@ -392,7 +398,6 @@ export const ClientConfigStore: FC = () => {
} }
getChatHistory(); getChatHistory();
startChat();
}, [accessToken]); }, [accessToken]);
useEffect(() => { useEffect(() => {

View File

@ -9,6 +9,7 @@ import {
chatMessagesAtom, chatMessagesAtom,
chatDisplayNameAtom, chatDisplayNameAtom,
chatUserIdAtom, chatUserIdAtom,
isChatAvailableSelector,
isChatVisibleSelector, isChatVisibleSelector,
appStateAtom, appStateAtom,
isOnlineSelector, isOnlineSelector,
@ -77,18 +78,21 @@ const MobileContent = ({
messages, messages,
chatDisplayName, chatDisplayName,
chatUserId, chatUserId,
showChat,
}) => ( }) => (
<div className={classNames(styles.lowerSectionMobile)}> <div className={classNames(styles.lowerSectionMobile)}>
<Tabs defaultActiveKey="0"> <Tabs defaultActiveKey="0">
<TabPane tab="Chat" key="1"> {showChat && (
<ChatContainer <TabPane tab="Chat" key="1">
messages={messages} <ChatContainer
usernameToHighlight={chatDisplayName} messages={messages}
chatUserId={chatUserId} usernameToHighlight={chatDisplayName}
isModerator={false} chatUserId={chatUserId}
height="40vh" isModerator={false}
/>{' '} height="40vh"
</TabPane> />
</TabPane>
)}
<TabPane tab="About" key="2"> <TabPane tab="About" key="2">
<ContentHeader <ContentHeader
name={name} name={name}
@ -111,6 +115,8 @@ export const Content: FC = () => {
const appState = useRecoilValue<AppStateOptions>(appStateAtom); const appState = useRecoilValue<AppStateOptions>(appStateAtom);
const clientConfig = useRecoilValue<ClientConfig>(clientConfigStateAtom); const clientConfig = useRecoilValue<ClientConfig>(clientConfigStateAtom);
const isChatVisible = useRecoilValue<boolean>(isChatVisibleSelector); const isChatVisible = useRecoilValue<boolean>(isChatVisibleSelector);
const isChatAvailable = useRecoilValue<boolean>(isChatAvailableSelector);
const [isMobile, setIsMobile] = useRecoilState<boolean | undefined>(isMobileAtom); const [isMobile, setIsMobile] = useRecoilState<boolean | undefined>(isMobileAtom);
const messages = useRecoilValue<ChatMessage[]>(chatMessagesAtom); const messages = useRecoilValue<ChatMessage[]>(chatMessagesAtom);
const online = useRecoilValue<boolean>(isOnlineSelector); const online = useRecoilValue<boolean>(isOnlineSelector);
@ -127,6 +133,7 @@ export const Content: FC = () => {
tags, tags,
externalActions, externalActions,
offlineMessage, offlineMessage,
chatDisabled,
} = clientConfig; } = clientConfig;
const [showNotifyReminder, setShowNotifyReminder] = useState(false); const [showNotifyReminder, setShowNotifyReminder] = useState(false);
const [showNotifyPopup, setShowNotifyPopup] = useState(false); const [showNotifyPopup, setShowNotifyPopup] = useState(false);
@ -177,6 +184,7 @@ export const Content: FC = () => {
} }
const offlineTitle = !appState.appLoading && `${name} is currently offline`; const offlineTitle = !appState.appLoading && `${name} is currently offline`;
const showChat = !chatDisabled && isChatAvailable && isChatVisible;
return ( return (
<div> <div>
@ -230,6 +238,7 @@ export const Content: FC = () => {
messages={messages} messages={messages}
chatDisplayName={chatDisplayName} chatDisplayName={chatDisplayName}
chatUserId={chatUserId} chatUserId={chatUserId}
showChat={showChat}
/> />
) : ( ) : (
<DesktopContent <DesktopContent
@ -242,9 +251,9 @@ export const Content: FC = () => {
/> />
)} )}
</div> </div>
{isChatVisible && !isMobile && <Sidebar />} {showChat && !isMobile && <Sidebar />}
</AntContent> </AntContent>
{(!isMobile || !isChatVisible) && <Footer version={version} />} {(!isMobile || !showChat) && <Footer version={version} />}
</Spin> </Spin>
</div> </div>
); );

View File

@ -9,16 +9,21 @@ const { Header: AntHeader } = Layout;
export type HeaderComponentProps = { export type HeaderComponentProps = {
name: string; name: string;
chatAvailable: boolean; chatAvailable: boolean;
chatDisabled: boolean;
}; };
export const Header: FC<HeaderComponentProps> = ({ name = 'Your stream title', chatAvailable }) => ( export const Header: FC<HeaderComponentProps> = ({
name = 'Your stream title',
chatAvailable,
chatDisabled,
}) => (
<AntHeader className={`${styles.header}`}> <AntHeader className={`${styles.header}`}>
<div className={`${styles.logo}`}> <div className={`${styles.logo}`}>
<OwncastLogo variant="contrast" /> <OwncastLogo variant="contrast" />
<span>{name}</span> <span>{name}</span>
</div> </div>
{chatAvailable && <UserDropdown />} {chatAvailable && !chatDisabled && <UserDropdown />}
{!chatAvailable && ( {!chatAvailable && !chatDisabled && (
<Tooltip title="Chat is available when the stream is live." placement="left"> <Tooltip title="Chat is available when the stream is live." placement="left">
<Tag style={{ cursor: 'pointer' }}>Chat offline</Tag> <Tag style={{ cursor: 'pointer' }}>Chat offline</Tag>
</Tooltip> </Tooltip>