Skip to content

Commit

Permalink
Add support to disable chat join messages. Closes #1582 (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabek committed Mar 6, 2022
1 parent f66357d commit ff3cda9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
20 changes: 19 additions & 1 deletion web/pages/config-chat.tsx
Expand Up @@ -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,
Expand All @@ -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) => {
Expand All @@ -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);
}
Expand Down Expand Up @@ -131,6 +142,7 @@ export default function ConfigChat() {
useEffect(() => {
setFormDataValues({
chatDisabled,
chatJoinMessagesEnabled,
forbiddenUsernames,
suggestedUsernames,
welcomeMessage,
Expand All @@ -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}
Expand Down
1 change: 1 addition & 0 deletions web/types/config-section.ts
Expand Up @@ -113,5 +113,6 @@ export interface ConfigDetails {
forbiddenUsernames: string[];
suggestedUsernames: string[];
chatDisabled: boolean;
chatJoinMessagesEnabled: boolean;
federation: Federation;
}
9 changes: 9 additions & 0 deletions web/utils/config-constants.tsx
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions web/utils/server-status-context.tsx
Expand Up @@ -59,6 +59,7 @@ export const initialServerConfigState: ConfigDetails = {
forbiddenUsernames: [],
suggestedUsernames: [],
chatDisabled: false,
chatJoinMessagesEnabled: true,
};

const initialServerStatusState = {
Expand Down

0 comments on commit ff3cda9

Please sign in to comment.