import classNames from 'clsx'; import React from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { openModal } from 'soapbox/actions/modals'; import { initReport } from 'soapbox/actions/reports'; import Link from 'soapbox/components/link'; import { Avatar, Button, HStack, Icon, Stack, Text } from 'soapbox/components/ui'; import { useChatContext } from 'soapbox/contexts/chat-context'; import { useAppDispatch } from 'soapbox/hooks'; import { useChatActions } from 'soapbox/queries/chats'; const messages = defineMessages({ leaveChatHeading: { id: 'chat_message_list_intro.leave_chat.heading', defaultMessage: 'Leave Chat' }, leaveChatMessage: { id: 'chat_message_list_intro.leave_chat.message', defaultMessage: 'Are you sure you want to leave this chat? Messages will be deleted for you and this chat will be removed from your inbox.' }, leaveChatConfirm: { id: 'chat_message_list_intro.leave_chat.confirm', defaultMessage: 'Leave Chat' }, intro: { id: 'chat_message_list_intro.intro', defaultMessage: 'wants to start a chat with you' }, accept: { id: 'chat_message_list_intro.actions.accept', defaultMessage: 'Accept' }, leaveChat: { id: 'chat_message_list_intro.actions.leave_chat', defaultMessage: 'Leave chat' }, report: { id: 'chat_message_list_intro.actions.report', defaultMessage: 'Report' }, messageLifespan: { id: 'chat_message_list_intro.actions.message_lifespan', defaultMessage: 'Messages older than 15 days are deleted.' }, }); const ChatMessageListIntro = () => { const dispatch = useAppDispatch(); const intl = useIntl(); const { chat, needsAcceptance } = useChatContext(); const { acceptChat, deleteChat } = useChatActions(chat?.id as string); const handleLeaveChat = () => { dispatch(openModal('CONFIRM', { heading: intl.formatMessage(messages.leaveChatHeading), message: intl.formatMessage(messages.leaveChatMessage), confirm: intl.formatMessage(messages.leaveChatConfirm), confirmationTheme: 'primary', onConfirm: () => deleteChat.mutate(), })); }; const handleReportChat = () => { dispatch(initReport(chat?.account as any)); acceptChat.mutate(); }; if (!chat) { return null; } return ( {needsAcceptance ? ( <> @{chat.account.acct} {' '} {intl.formatMessage(messages.intro)} ) : ( @{chat.account.acct} )} {needsAcceptance ? ( ) : ( {intl.formatMessage(messages.messageLifespan)} )} ); }; export default ChatMessageListIntro;