import classNames from 'clsx'; import React from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { openModal } from 'soapbox/actions/modals'; 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'; import { secondsToDays } from 'soapbox/utils/numbers'; 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 {day} 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(), })); }; if (!chat) { return null; } return ( {needsAcceptance ? ( <> @{chat.account.acct} {' '} {intl.formatMessage(messages.intro)} ) : ( @{chat.account.acct} )} {needsAcceptance ? ( ) : ( {intl.formatMessage(messages.messageLifespan, { day: secondsToDays(chat.message_expiration) })} )} ); }; export default ChatMessageListIntro;