Add support to disable chat join messages. Closes https://github.com/owncast/owncast/issues/1582 (#452)

This commit is contained in:
Gabe Kangas 2022-03-05 22:36:38 -08:00 committed by GitHub
parent f66357da46
commit ff3cda97f3
4 changed files with 30 additions and 1 deletions

View File

@ -15,6 +15,7 @@ import { UpdateArgs } from '../types/config-section';
import {
API_CHAT_FORBIDDEN_USERNAMES,
API_CHAT_SUGGESTED_USERNAMES,
FIELD_PROPS_CHAT_JOIN_MESSAGES_ENABLED,
FIELD_PROPS_DISABLE_CHAT,
postConfigUpdateToAPI,
RESET_TIMEOUT,
@ -32,7 +33,13 @@ export default function ConfigChat() {
const serverStatusData = useContext(ServerStatusContext);
const { serverConfig, setFieldInConfigState } = serverStatusData || {};
const { chatDisabled, forbiddenUsernames, instanceDetails, suggestedUsernames } = serverConfig;
const {
chatDisabled,
chatJoinMessagesEnabled,
forbiddenUsernames,
instanceDetails,
suggestedUsernames,
} = serverConfig;
const { welcomeMessage } = instanceDetails;
const handleFieldChange = ({ fieldName, value }: UpdateArgs) => {
@ -46,6 +53,10 @@ export default function ConfigChat() {
handleFieldChange({ fieldName: 'chatDisabled', value: !disabled });
}
function handleChatJoinMessagesEnabledChange(enabled: boolean) {
handleFieldChange({ fieldName: 'chatJoinMessagesEnabled', value: enabled });
}
function resetForbiddenUsernameState() {
setForbiddenUsernameSaveState(null);
}
@ -131,6 +142,7 @@ export default function ConfigChat() {
useEffect(() => {
setFormDataValues({
chatDisabled,
chatJoinMessagesEnabled,
forbiddenUsernames,
suggestedUsernames,
welcomeMessage,
@ -152,6 +164,12 @@ export default function ConfigChat() {
reversed
onChange={handleChatDisableChange}
/>
<ToggleSwitch
fieldName="chatJoinMessagesEnabled"
{...FIELD_PROPS_CHAT_JOIN_MESSAGES_ENABLED}
checked={formDataValues.chatJoinMessagesEnabled}
onChange={handleChatJoinMessagesEnabledChange}
/>
<TextFieldWithSubmit
fieldName="welcomeMessage"
{...TEXTFIELD_PROPS_SERVER_WELCOME_MESSAGE}

View File

@ -113,5 +113,6 @@ export interface ConfigDetails {
forbiddenUsernames: string[];
suggestedUsernames: string[];
chatDisabled: boolean;
chatJoinMessagesEnabled: boolean;
federation: Federation;
}

View File

@ -30,6 +30,7 @@ export const API_VIDEO_VARIANTS = '/video/streamoutputvariants';
export const API_WEB_PORT = '/webserverport';
export const API_YP_SWITCH = '/directoryenabled';
export const API_CHAT_DISABLE = '/chat/disable';
export const API_CHAT_JOIN_MESSAGES_ENABLED = '/chat/joinmessagesenabled';
export const API_CHAT_FORBIDDEN_USERNAMES = '/chat/forbiddenusernames';
export const API_CHAT_SUGGESTED_USERNAMES = '/chat/suggestedusernames';
export const API_EXTERNAL_ACTIONS = '/externalactions';
@ -192,6 +193,14 @@ export const FIELD_PROPS_DISABLE_CHAT = {
useSubmit: true,
};
export const FIELD_PROPS_CHAT_JOIN_MESSAGES_ENABLED = {
apiPath: API_CHAT_JOIN_MESSAGES_ENABLED,
configPath: '',
label: 'Join Messages',
tip: 'Show when a viewer joins the chat.',
useSubmit: true,
};
export const TEXTFIELD_PROPS_CHAT_FORBIDDEN_USERNAMES = {
apiPath: API_CHAT_FORBIDDEN_USERNAMES,
placeholder: 'username',

View File

@ -59,6 +59,7 @@ export const initialServerConfigState: ConfigDetails = {
forbiddenUsernames: [],
suggestedUsernames: [],
chatDisabled: false,
chatJoinMessagesEnabled: true,
};
const initialServerStatusState = {