import React from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { blockAccount } from 'soapbox/actions/accounts'; import { openModal } from 'soapbox/actions/modals'; import { initReport } from 'soapbox/actions/reports'; import List, { ListItem } from 'soapbox/components/list'; import { Avatar, Divider, HStack, Icon, Stack, Text, Toggle } from 'soapbox/components/ui'; import { useChatContext } from 'soapbox/contexts/chat-context'; import { useAppDispatch } from 'soapbox/hooks'; import { useChat, useChatSilence } from 'soapbox/queries/chats'; import ChatPaneHeader from './chat-pane-header'; const messages = defineMessages({ blockMessage: { id: 'chat_settings.block.message', defaultMessage: 'Blocking will prevent this profile from direct messaging you and viewing your content. You can unblock later.' }, blockHeading: { id: 'chat_settings.block.heading', defaultMessage: 'Block @{acct}' }, blockConfirm: { id: 'chat_settings.block.confirm', defaultMessage: 'Block' }, leaveMessage: { id: 'chat_settings.leave.message', defaultMessage: 'Are you sure you want to leave this chat? This conversation will be removed from your inbox.' }, leaveHeading: { id: 'chat_settings.leave.heading', defaultMessage: 'Leave Chat' }, leaveConfirm: { id: 'chat_settings.leave.confirm', defaultMessage: 'Leave Chat' }, title: { id: 'chat_settings.title', defaultMessage: 'Chat Details' }, blockUser: { id: 'chat_settings.options.block_user', defaultMessage: 'Block @{acct}' }, reportUser: { id: 'chat_settings.options.report_user', defaultMessage: 'Report @{acct}' }, leaveChat: { id: 'chat_settings.options.leave_chat', defaultMessage: 'Leave Chat' }, }); const ChatSettings = () => { const dispatch = useAppDispatch(); const intl = useIntl(); const { chat, setEditing, toggleChatPane } = useChatContext(); const { isSilenced, handleSilence } = useChatSilence(chat); const { deleteChat } = useChat(chat?.id as string); const closeSettings = () => setEditing(false); const minimizeChatPane = () => { closeSettings(); toggleChatPane(); }; const handleBlockUser = () => { dispatch(openModal('CONFIRM', { heading: intl.formatMessage(messages.blockHeading, { acct: chat?.account.acct }), message: intl.formatMessage(messages.blockMessage), confirm: intl.formatMessage(messages.blockConfirm), confirmationTheme: 'primary', onConfirm: () => dispatch(blockAccount(chat?.account.id as string)), })); }; const handleLeaveChat = () => { dispatch(openModal('CONFIRM', { heading: intl.formatMessage(messages.leaveHeading), message: intl.formatMessage(messages.leaveMessage), confirm: intl.formatMessage(messages.leaveConfirm), confirmationTheme: 'primary', onConfirm: () => deleteChat.mutate(), })); }; const handleReportChat = () => dispatch(initReport(chat?.account as any)); if (!chat) { return null; } return ( <> {intl.formatMessage(messages.title)} } /> {chat.account.display_name} @{chat.account.acct} ); }; export default ChatSettings;